Skip to content

driver: a host call registered while a driver is parked wakes it (stale race snapshot) - #289

Merged
lannbot merged 1 commit into
mainfrom
fix/parked-driver-host-call-arrival
Sep 6, 2026
Merged

driver: a host call registered while a driver is parked wakes it (stale race snapshot)#289
lannbot merged 1 commit into
mainfrom
fix/parked-driver-host-call-arrival

Conversation

@lannbot

@lannbot lannbot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

`driveAsync` parks a quiet guest on `Promise.race([...pendingHostCalls, armDriverArrival])`; the spread is a snapshot. An export entered through the synchronous `drive` path starts no new driver and so fires no driver-arrival; a host call the guest registers during it is invisible to the parked race. When it settles, the continuation readies the thread but nothing drives the store — the settlement pump stands down because the parked driver keeps `storeDriverDepth > 0`. The guest resumes only on the next unrelated export call.

Routine victim: a stream-dom producer. A `readDirect` session keeps a `HostActivity` driver parked as long as one host import (a long poll) is outstanding, and every import awaited from an event handler then stalls until the next event. Found in polyvisor M1; minimal end-to-end repro (wit-bindgen guest, Deno host) at the bottom.

Fix: a host-call-arrival one-shot beside driver arrival, fired by `registerHostCall()` at both lowering sites and raced by `driveAsync`'s two parks and the settlement pump. Same class as #239 with the registration, rather than a second loop, as the unheard event.

Regression test: `runtime/tests/parked_driver_host_call_test.ts` (store-level, fails pre-fix). `just test-runtime`: 702 passed.

End-to-end repro shape

Guest: `run` returns a stream and spawns (a) a task awaiting a never-settling import, (b) a scheduler task. Async export `kick` queues a job that awaits import `ping` (host settles it after 20 ms) and wakes the scheduler. Host holds a `readDirect` session on the stream. Pre-fix: `ping N` settles, `job N` observes it only after `kick N+1`.

Automerge armed.

…le race snapshot)

driveAsync parks a quiet guest on Promise.race([...pendingHostCalls, ...]),
and that spread is a snapshot. An export entered through the synchronous
drive path starts no new driver, so it fires no driver-arrival; a host call
the guest registers during it is invisible to the parked race. When that
call settles, its continuation readies the thread but nothing drives the
store, and the settlement pump stands down because the parked driver keeps
storeDriverDepth > 0. The guest is resumed only by the next unrelated
export call. The routine victim is a stream-dom producer: a readDirect
session keeps a HostActivity driver parked (one long-poll import
outstanding), and every import awaited from an event handler stalls until
the next event.

Fix: a host-call-arrival one-shot, sibling to driver arrival, fired by the
new registerHostCall() at both lowering sites and raced by driveAsync's
two parks and the settlement pump. Same class as #239 with the
registration, rather than a second loop, as the unheard event.

Regression: runtime/tests/parked_driver_host_call_test.ts (store-level,
fails pre-fix).
@lannbot
lannbot enabled auto-merge September 6, 2026 22:53
@lannbot
lannbot merged commit 80ee6cb into main Sep 6, 2026
4 checks passed
@lannbot
lannbot deleted the fix/parked-driver-host-call-arrival branch September 6, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants