Skip to content

fix(capture): stop queued idle events after abort - #530

Merged
abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:fix/522-abort-queued-capture
Nov 25, 2026
Merged

abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:fix/522-abort-queued-capture

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

Closes #522.

The idle subscription checks cancellation immediately after the iterator yields. A queued event yielded after abort exits the loop before capture can record an arrival or begin dispatch.

The regression test queues an event and calls cleanup in the same turn. Against the old loop it observed a new auto_capture_seen receipt. With the guard, the test observes neither an arrival receipt nor a capture context call.

Windows verification: 16 focused capture tests passed. Typecheck, Biome lint and format for changed files, and comment lint passed.

Implemented with GPT-6.2 Sol in T3 Code.

@ocsi-reviewer

ocsi-reviewer Bot commented Nov 25, 2026

Copy link
Copy Markdown

Review: PR #530 — fix(capture): stop queued idle events after abort

Combined seat (architecture conformance + code review, one reviewer, disclosed). Measured at head 898583d on a scratch copy; base is 963a7c5. CI: all four checks pass at head. This sits in the live dispatch hot path, so it got the standing treatment: guard placement read in source, mutation on the new test, full suites, and a base-vs-head e2e comparison.

The guard — placement verified in source, not inferred from the diff

src/capture/runtime.ts:1165: if (controller.signal.aborted) break; sits immediately at the for await yield head — before the sid read (1174), before the auto_capture_seen receipt (1202), before setCurrent/dispatch (1207). The ticket's contract item ("no NEW pass starts after dispose") is now enforced by a check at the dispatch head instead of resting on subscription-teardown timing, exactly as scoped. The comment edit ("Only abort or the subscription ending may leave the loop") keeps the paragraph's invariant honest: break here is the named second exit, and the outer-catch rationale still covers everything between the guard and the loop tail.

The regression test — mutation proves the race is real

Removing only the guard line makes the new test fail (a queued turn-end event is discarded when cleanup aborts before dispatch → 1 fail, the other 7 in the file pass). So the fake iterator does yield a queued event after abort, the old loop did record an arrival receipt for it, and the guard — not the fixture — is what the test pins. The test asserts both halves the ticket asked for: no auto_capture_seen receipt and no capture-context call.

Metric semantics — the guard also cleans the arrived-lost count

Before this change, a post-abort queued event wrote discard=none and was then killed by a later guard, producing exactly the shape the #406 arrived-lost predicate counts as a loss: a proceeding arrival with no start and no skip. Those dispose-race receipts inflated the masked-loss signal with events that were never arrivals into a live capture. After the guard they leave no line at all, which is the honest outcome — disposal is not a loss band. The predicate itself is untouched; this only removes rows from its denominator, so it cannot manufacture a new loss class. Base-vs-head e2e confirms empirically: at head and at base (963a7c5), every turn started on attempt 1 with 0 arrived-lost, 4 pass / 0 fail on both sides. No new loss class.

Claims audit

  • "A queued event yielded after abort exits the loop before capture can record an arrival or begin dispatch" — confirmed by line order above.
  • "Against the old loop it observed a new auto_capture_seen receipt. With the guard, the test observes neither an arrival receipt nor a capture context call" — both halves reproduced by mutation and by green run.
  • "Windows verification: 16 focused capture tests passed" — the three capture files that own this contract are dispose-drain (8) + arrival-receipt (3) + start-observable (5) = 16. Consistent; Windows CI green.

Cross-PR note (not a defect in this PR)

docs/internals/auto-capture-evidence.md states "Every turn-end event that reaches the idle subscription writes auto_capture_seen synchronously at the dispatch head." After this PR, an event yielded after abort reaches the loop body and exits with no line. The design is right and the test pins it; the doc sentence needs one qualifier ("a live subscription"). PR #529 edits that exact paragraph, so the fold-in is one clause in whichever PR lands second. Raised on both so it cannot fall between them.

Full suites

1844 pass / 22 skip / 0 fail at this head, identical totals at the #529 head (each PR adds exactly one test on the same base).

Verdict

APPROVE. No keep-to-refusal or loss-class change is even possible here, per the metric-semantics section, and the e2e comparison confirms it. Guard is minimal and correctly placed, the test kills the mutation it names, the doc drift is a one-clause follow-up shared with #529, and no user-visible behavior changes on the non-aborted path: the guard is one boolean read per event that is false until cleanup runs.

@abogartz
abogartz merged commit b6f1502 into abogartz:main Nov 25, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.35.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The idle subscription loop trusts the iterator: no aborted check before dispatch

2 participants