Repository navigation
fix(capture): warn once when the idle capture subscription dies without an abort - #533
Conversation
…ut an abort The loop's outer catch swallowed iterator failures in silence, and nothing resubscribes, so a throw there ended auto-capture for the life of the process with no trace on any channel. A live subscription now leaves one console.warn, in the guarded() line shape with the shared safeErrorMessage rendering — the only trace that survives a broken evidence log. Aborted teardown stays silent: it is the contract, not an anomaly. Pin test drives a throwing iterator through an in-process wrapper around the harness event bus.
WhollyMindless
left a comment
There was a problem hiding this comment.
Note
🤖 GPT-6.2 Sol responding on behalf of WhollyMindless
Two non-blocking points on the console-only boundary at 5371c76:
- The focused Windows suite passed 2/2. I then added a successful
auto_capture_refusedwrite immediately before the outer-catch warning in a scratch checkout. Both tests still passed, and a separate assertion confirmed the probe receipt reached the log. The dropped-write assertion detects failed writes. To pin the stated no-receipt behavior, please also assert that no failure receipt is written for the iterator exit. - The PR description says the warning text is untruncated.
safeErrorMessageredacts and slices it toMIRRORED_ERROR_MAX(200 characters). The bound is consistent with the shared renderer. I’d correct the description.
Review — PR #533 (combined seat)Seat: combined architecture-conformance + code review (one reviewer, both lenses, disclosed). 1. Guard semantics — conforms
2. Fail-before — reproduced independentlyReverted only the source hunk ( Exactly the PR body's shape: the iterator-throw pin fails pre-fix (the trace never arrives), the abort pin passes pre-fix and post-fix — an intentional no-change contract pin, and it fails the same way at plain 3. Suite + baseline drift — resolved by measurement
4. Pin quality
5. ProseScanned every added line: no issue numbers, dates, shas, or incident narration in code comments, test titles, or shipped strings (the two scan hits are the substring "sha" inside "shape"). The comment states the invariant, not the story. PR body carries all four required sections — counter decision (console-only, option 2b), fail-before proof, push-gate table with the e2e base-vs-head line, layer-choice defense — and the counter claims match the source ( Findings
VerdictAPPROVE. The guard sits at the one point every loop exit passes through, warns once with the established shape and rendering, stays silent on teardown, and cannot itself throw on the way out. The pin fails before the fix and passes after, asserts the exact console line and the amended counter semantics, and the full-suite delta at head is exactly the new file against the freshly measured 1847 baseline. |
|
🎉 This PR is included in version 0.36.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #489
What ships
catchof the idle subscription'svoid (async () => ...)loop (src/capture/runtime.ts:1264pre-fix) swallowed everything in silence. Now: when!controller.signal.aborted, oneconsole.warnin theguarded()line shape (src/core/hooks.ts:38) with the sharedsafeErrorMessagerendering (src/telemetry/record.ts), then return. When aborted, it stays exactly as before — teardown is not an anomaly. The warn line names the channel uniquely (auto-capture (idle) subscription failed (ignored):) so a dead loop is distinguishable from the inner per-event failure line.test/capture/capture-subscription-death.test.ts: forces the event iterator to throw mid-session through an in-process wrapper aroundctx.event.subscribe(patching the default-exported plugin'ssetup, scoped to the file and restored inafterAll— the shipped harness fake iterator has no throw seam). Asserts the exact warn line arrives, the dropped-write counter does not tick, the write channel gains no receipt naming the failure, and the loop is not silently recovered (a later turn-end leaves no capture trace — recovery is a different contract). A second test pins the abort branch: armed throw + abort viacleanup()⇒ zero console lines, before and after the fix.Counter semantics — decision: console-only (option 2b)
The ticket's minimum said "count the exit through the dropped-write counter." I am not shipping a tick, and the repro record's own measurements are why. The counter's contract is lost evidence writes:
DroppedEvidenceWrites {dropped, lastEvent, lastError}(src/telemetry/record.ts:324) is incremented only by the three best-effort write wrappers via module-privatenoteDroppedWrite(src/telemetry/record.ts:363; call sites at 406, 421, 436), and every existing tick corresponds to a write that actually failed. A dead subscription drops zero writes: tickingdroppedwould tell every later reader ofmemory_status(viadroppedEvidenceWrites(),src/telemetry/record.ts:391) that data was lost when nothing was, andlastErrorwould render an iterator death as if it were a write error. The existing invariant is already pinned by Case B of the repro: a mid-pass model failure with a successful receipt write leaves the counter atnull— it tracks loss, not failure. Exporting a mutator that breaks that invariant to serve one event would mislead in exactly the direction the ticket warns about. The console line carries the full message (untruncated byMIRRORED_ERROR_MAX) on the one channel that survives the failure class in question — a broken evidence log — which is precisely where a receipt tick could not land anyway. The ticket minimum is amended plainly in an architect comment on #489.Fail-before proof
With the
src/capture/runtime.tschange stashed and the new test run against pre-fix source:The awaited console trace never arrives — the subscription dies exactly as the ticket describes. Change restored: 2 pass / 0 fail.
Push-gate numbers (all measured this session in this tree, line numbers personal)
bun run testbun run lint(biome lint + format:check)bun run typecheck(tsc --noEmit)git archive 6c743ffscratch tree) 4 pass / 0 fail, all attempt 1, 0 arrived-lost; head 4 pass / 0 fail, all attempt 1, 0 arrived-lost — no new loss class at headWhy the outer catch (layer choice)
The complaint is that the capture loop exits with no trace, and a loop's exit is its outer catch — every path that ends the loop unconditionally passes through it, and nothing else does. Alternatives measured against that: an inner per-event
catchnever sees an iterator throw, because the throw happens in the iterator'snext()thefor awaitis awaiting, outside the inner try. Wrapping thesubscribecall site cannot distinguish expected teardown (abort) from mid-process death without reading the same signal the outer catch reads, and still would not cover throws arriving at a later yield. Resubscribing or watchdogging from here changes lifecycle semantics — cooldowns, in-flight tracking, disposal-flush accounting all assume one subscription per setup — and that is a different contract than visibility, which this fix must not quietly expand. Placing the guard in the outer catch costs zero on healthy passes (nothing executes unless the loop is already ending) and automatically covers both failure shapes: iterator throws today, and any statement a future edit hoists above the inner try.