Repository navigation
fix(runtime): thread indexing, inline resumption and deadlock check fixes - #2543
Merged
vados-cosmonic merged 6 commits intoNov 25, 2026
Merged
vados-cosmonic merged 6 commits into
vados-cosmonic merged 6 commits into
Conversation
vados-cosmonic
enabled auto-merge
November 25, 2026 10:03
vados-cosmonic
disabled auto-merge
November 25, 2026 13:08
The Canonical ABI gives a task's implicit thread its index in the instance's thread table in `Task.enter_implicit_thread`, after any wait for backpressure or the exclusive lock. The runtime indexed it when the task was created, so a call held back by backpressure took an index before calls that entered ahead of it, and `thread.index` disagreed with the spec's numbering. Export calls now create their task with `indexOnEntry`: the implicit thread is indexed as the task enters, and a task that never enters releases no index. Both the external and inline runtimes change, and the export glue reads the thread ID after entry.
A stack suspended in a JSPI import resumes in a later job than the one that settles the promise it waits on. The inline import wrapper restored the task registers when that promise settled, so two stacks released in the same turn both restored their task before either ran, and the first then ran as the second's task. Chain resumptions through the registers the way the external runtime does: each stack restores its task only once every stack released before it has run, and the next waits until this one has suspended again or returned.
A guest copy on a stream or future whose other end was lifted to the host can only be completed by the host, whenever it reads, writes or drops that end. The host does that from its own code (e.g. a timer), outside any tracked host operation, so the deadlock check saw only suspended tasks and trapped a store that was waiting on the host. Mark a stream or future as host-held when one of its ends is lifted to the host, and count a pending guest copy on it as a host operation until the copy finishes, in both the external and inline runtimes. The future end class takes the host operation context as an optional second argument for this.
A synchronous guest-to-guest call waits for its callee to enter before it awaits the callee's result. When the store traps during that wait (e.g. the deadlock check fires because the callee's instance is locked for good), the callee's task is rejected, the call fails with the trap, and the result promise, rejected too, was never observed: it surfaced as an unhandled rejection after the trap had already been reported. Mark the result promise as handled when it is created, in both the external and inline runtimes; the failure still reaches the caller through the call itself.
vados-cosmonic
force-pushed
the
fix/threads-audit-followups
branch
from
November 25, 2026 13:31
481ba33 to
2283edb
Compare
Run rustfmt over the intrinsics test that checks a task releases the thread index only when its implicit thread holds one.
Collaborator
|
🎉 The code in this PR was made available in the following release: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-ups to the scheduling work in #2535 and #2536.
Implicit thread index.
The Canonical ABI indexes a task's implicit thread in
Task.enter_implicit_thread,after any wait for backpressure or the exclusive lock.
Export calls indexed it at task creation,
so a call held back by backpressure took an index ahead of calls that entered before it.
Export tasks are now created with
indexOnEntryand indexed as they enter;a task that never enters releases nothing.
Guest-to-guest calls still index when the call is prepared:
their arguments are lowered (and the callee's
reallocmay run) before entry.Inline JSPI resumption.
The inline import wrapper restored the task registers when the import's promise settled,
but the stack resumes in a later job.
Two stacks released in the same turn both restored their task before either ran,
so the first ran as the second's task.
Resumptions are now chained through the registers, as the external runtime already does.
Deadlock check and host-held channels.
A guest copy on a stream or future whose other end was lifted to the host
can only be completed by the host,
which may do so from untracked code (e.g. a timer).
The check trapped such a store as deadlocked.
A pending guest copy on a host-held channel now counts as a host operation until it finishes.
An end stays host-held while the host keeps it,
including when the host passes it back into a guest (jco pumps from it into a new end);
a write that nobody reads then waits rather than trapping.
Unhandled rejection after a deadlock.
A synchronous guest-to-guest call whose callee never entered
failed with the deadlock trap but left the callee's result promise unobserved,
which surfaced as an unhandled rejection.
That promise is now marked handled; the failure still reaches the caller through the call.
Tests:
test/p3/thread-indices.ts: a task held back by backpressure takes its index when it enters.test/p3/deadlock-detection.ts: stream and future writes waiting on a host reader are not deadlocks;a sync call whose callee never enters fails without unhandled rejections.
intrinsics::testsstring checks for the inline runtime.