Skip to content

host streams: a trap out of pump()'s sync half is recorded and the op withdrawn (review) - #305

Merged
lannbot merged 1 commit into
mainfrom
fix/review-host-pump-trap
Sep 7, 2026
Merged

host streams: a trap out of pump()'s sync half is recorded and the op withdrawn (review)#305
lannbot merged 1 commit into
mainfrom
fix/review-host-pump-trap

Conversation

@lannbot

@lannbot lannbot commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Adversarial correctness review of main @ 396a216, streams track — the one MEDIUM finding.

HostActivity.pump()'s synchronous serviceSettled()/tick() loop had no try/catch and runs inside every host stream/future op's new Promise(executor) after parked.* = true. A trap from tick() was either mute (the trapping instance held an end of this stream, so the retirement walk had already settled the op's promise and the executor's throw was discarded — unlike #pumpAsync, which records store.hostFailure) or wedging (otherwise the promise rejected but parked.* stayed true and the host buffer stayed in the shared pending slot forever: every later op threw "a write is already in flight"; a direct session's dead pending state re-ran the embedder's callback).

Fix: the sync half records store.hostFailure ??= e and rethrows (the channel #pumpAsync already uses), and each op's executor withdraws on a throw — the same withdrawal cancelWrite/cancelRead/cancelDirect perform (retractDirect is cancelDirect's pending-slot half, factored out and shared).

Regression: host_pump_trap_test.ts (write, read, silent-fault variants). Neighbouring suites (host_pump, host_arm, direct_streams, streams_teardown, e2e_streams, embedder/) unchanged.

Gates: just test-runtime green; just conformance 0 failed; full just gates green on the union of the five review PRs.

Related open question from the same track (sync-half re-entrancy, not addressed here): #298.

Automerge armed.

… withdrawn

`HostActivity.pump()`'s synchronous `serviceSettled()/tick()` loop had no
try/catch, and every host stream/future op invokes it inside its
`new Promise(executor)` after setting `parked.*`. A trap from `tick()`
therefore went one of two bad ways:

- the trapping instance held an end of THIS stream: the poisoning retirement
  walk had already settled the op's promise, so the executor's throw was
  discarded — the component fault was mute (unlike `#pumpAsync`, which
  records `store.hostFailure`);
- otherwise: the promise rejected, but `parked.*` stayed true and the host
  buffer stayed in the shared pending slot forever — every later op on that
  end threw "a write is already in flight", and a direct session's dead
  `pending` state re-ran the embedder's callback on the next guest op.

The sync half now records `store.hostFailure ??= e` and rethrows (the one
channel `#pumpAsync` already uses), and each op's executor withdraws on a
throw — resets its `parked` flag and, while the pending slot is still its
own buffer/session, `shared.cancel()`s it, the same withdrawal
`cancelWrite`/`cancelRead`/`cancelDirect` perform (`retractDirect` is
`cancelDirect`'s pending-slot half, factored out and shared).

Regression: host_pump_trap_test.ts (write, read, and the silent-fault
variant). Neighbouring suites (host_pump, host_arm, direct_streams,
streams_teardown, e2e_streams, embedder/) unchanged.
@lannbot
lannbot enabled auto-merge September 7, 2026 02:12
@lannbot
lannbot merged commit 4ca9198 into main Sep 7, 2026
4 checks passed
@lannbot
lannbot deleted the fix/review-host-pump-trap branch September 7, 2026 02:16
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