Parent: #502 Related: #980, #982, #984
Executed reproduction
On exact main at 9940ddca8913645caf8c7452aa18014d39b8aed1, a focused production-Worker test sets the public runnable scheduler limit to zero, spawns a script Worker, waits until its typed start is queued, calls terminate(), and joins from a helper thread with a bounded 250 ms observation window. The join does not complete until the scheduler limit is restored. The focused root reports:
worker.test.terminated worker exits while runnable scheduler is paused...FAIL (TestUnexpectedResult)The Worker stop word and channel wakeups are only observed inside workerMain; runtime_threads.startThread is still parked in the allocation-free slot queue before that entry point. The queue has no owner cancellation edge, so termination cannot complete while an embedder intentionally pauses runnable capacity.
Required change
- Give caller-owned typed thread starts an explicit cancellation handle that can remove a still-queued waiter under the coordinator mutex and wake the OS thread.
- Preserve FIFO/weighted scheduling and exact thread, stack, slot, waiter, and lifecycle accounting in grant-versus-cancel races.
- Route script and module Worker termination through that handle. A canceled pre-entry Worker must close inspector/message outputs and publish its terminal state without evaluating user source.
- Keep graceful
close()drain semantics: only hard termination may cancel a queued start. - Expose schema-versioned cancellation telemetry; do not raise capacity, run user code outside a slot, poll, sleep, or add a hidden GIL.
Definition of done
- The zero-capacity reproduction terminates and joins without restoring capacity first.
- Deterministic tests cover cancellation before grant, grant/cancel races, queue removal at head/middle/tail, and exact telemetry/invariants.
- Script and module Workers share the production cancellation path; canceled source/module callbacks do not run.
- Normal and unsuppressed-TSan focused gates pass with zero leaks.
- #502 is updated with the landed commit and evidence.