Skip to content

fix(capture): warn once when the idle capture subscription dies without an abort - #533

Merged
abogartz merged 1 commit into
mainfrom
fix/489-outer-catch-visibility
Nov 25, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix/489-outer-catch-visibility

Conversation

@ocsi-fixer

@ocsi-fixer ocsi-fixer Bot commented Nov 25, 2026

Copy link
Copy Markdown

Closes #489

What ships

  • The guard. The outer catch of the idle subscription's void (async () => ...) loop (src/capture/runtime.ts:1264 pre-fix) swallowed everything in silence. Now: when !controller.signal.aborted, one console.warn in the guarded() line shape (src/core/hooks.ts:38) with the shared safeErrorMessage rendering (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.
  • The pin. test/capture/capture-subscription-death.test.ts: forces the event iterator to throw mid-session through an in-process wrapper around ctx.event.subscribe (patching the default-exported plugin's setup, scoped to the file and restored in afterAll — 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 via cleanup() ⇒ 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-private noteDroppedWrite (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: ticking dropped would tell every later reader of memory_status (via droppedEvidenceWrites(), src/telemetry/record.ts:391) that data was lost when nothing was, and lastError would 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 at null — 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 by MIRRORED_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.ts change stashed and the new test run against pre-fix source:

error: waitFor timed out
      at waitFor (/Users/Alex/Documents/.ocsi-worktrees/wt-489/test/capture/capture-subscription-death.test.ts:114:51)
      at async <anonymous> (/Users/Alex/Documents/.ocsi-worktrees/wt-489/test/capture/capture-subscription-death.test.ts:166:9)
(fail) a throwing event iterator names the dead capture loop on the console, with no receipt and no dropped-write tick [10070.74ms]

 1 pass
 1 fail

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)

Gate Result
Focused new test 2 pass / 0 fail (6 expect)
Full suite bun run test 1849 pass / 22 skip / 0 fail (1871 tests, 151 files)
bun run lint (biome lint + format:check) exit 0, 322 files
bun run typecheck (tsc --noEmit) exit 0
e2e base-vs-head base (git archive 6c743ff scratch 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 head

Why 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 catch never sees an iterator throw, because the throw happens in the iterator's next() the for await is awaiting, outside the inner try. Wrapping the subscribe call 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.

…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 WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_refused write 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. safeErrorMessage redacts and slices it to MIRRORED_ERROR_MAX (200 characters). The bound is consistent with the shared renderer. I’d correct the description.

@ocsi-reviewer

ocsi-reviewer Bot commented Nov 25, 2026

Copy link
Copy Markdown

Review — PR #533 (combined seat)

Seat: combined architecture-conformance + code review (one reviewer, both lenses, disclosed).
Head: 5371c76 · Base: 6c743ff (current main). Scope verified: git diff 6c743ff..pr533 --name-only lists exactly src/capture/runtime.ts and test/capture/capture-subscription-death.test.ts — README, bench, fixtures untouched.
How measured: scratch trees only — git archive of pr533 into $T/rev533 and of 6c743ff into $T/rev533base, node_modules symlinked, main checkout untouched. All numbers below are this session's runs in those trees; every cited line was opened here.

1. Guard semantics — conforms

  • Warn exactly when live: src/capture/runtime.ts:1268 is if (controller.signal.aborted) return; before any output; the abort path leaves the catch byte-identical to the base swallow (base outer catch confirmed at git show 6c743ff:src/capture/runtime.ts — same silent exit, no console path added).
  • Line shape reused, not hand-rolled: [opencode-self-improvement] … failed (ignored): matches guarded() (src/core/hooks.ts:38); rendering is the shared safeErrorMessage (src/telemetry/record.ts:359), already imported at src/capture/runtime.ts:30 and already the precedent inside this loop's inner catch (:1243-1246). Interpolating the string rather than passing the raw error also matches the record.ts contract of never handing the original object to a surface. Channel naming auto-capture (idle) subscription failed (ignored): is unique in src — distinguishable from the inner per-event … hook failed … line at :1245.
  • Nothing new can throw between warn and exit: after the console.warn the block ends — no further statements. The argument render is throw-free by construction: describeError returns a string for any input (instanceof guard, String() wrapped in try/catch), and redactSecrets (src/store/secrets.ts:79) is pure string ops on that string.
  • Comment truthfulness (read :1264-1279): teardown-not-anomaly — true (abort → iterator ends → silent return). "Nothing resubscribes" — true: grep -n "subscribe" finds one subscription site in the file (:1161) and no retry logic. "The receipt loop that could say so is dead with it" — true: receipts are written inside this same loop. "Console is the one trace that survives a broken evidence log" — true: console.warn touches no store path. The pre-existing loop invariant "Only abort or the subscription ending may leave the loop" (:1176-1179) still holds with the guard added — the guard observes the exit, it does not add one (the aborted break at :1165 still exits via the normal path).

2. Fail-before — reproduced independently

Reverted only the source hunk (git show 6c743ff:src/capture/runtime.ts over the scratch copy), ran with the repo's own gate timeout (bun run test uses --timeout=20000; package.json:61):

error: waitFor timed out
      at waitFor (.../rev533/test/capture/capture-subscription-death.test.ts:120:51)
      at async <anonymous> (.../rev533/test/capture/capture-subscription-death.test.ts:173:9)
(fail) a throwing event iterator names the dead capture loop on the console, with no receipt and no dropped-write tick [10090.42ms]
(pass) an aborted iterator exit leaves no console line — teardown is not an anomaly [596.53ms]
 1 pass / 1 fail

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 bun test (bun's 5 s default kills it first: (fail) … [5004.36ms], then 2 pass at head). Source restored, focused file at head: 2 pass / 0 fail, 6 expect.

3. Suite + baseline drift — resolved by measurement

  • Head (5371c76), bun run test: 1849 pass / 22 skip / 0 fail (1871 tests, 151 files, 14976 expect) — matches the PR body exactly.
  • Baseline (6c743ff), same recipe: 1847 pass / 22 skip / 0 fail (1869 tests, 150 files).
  • So head = baseline + 2, and the delta is exactly the new file. The recalled 1844 was stale (3 tests landed between the earlier round and current main); the fixer's "baseline drift" claim is confirmed, not a discrepancy.
  • e2e base-vs-head (my runs, bun test ./e2e/ --parallel=4 --timeout 240000): base 55 pass / 0 fail, head 55 pass / 0 fail. The three hot-path traces are identical on both sides: [capture-start] … pass started on attempt 1, 0 arrived-lost (discard=none arrival, no pass, no skip) for test 1, test 2, and the default-options test — no retries, no new loss class at head. (The PR body's "4 pass / 0 fail" line corresponds to a targeted run of e2e/capture.test.ts, which holds exactly 4 tests; my full-directory run covers it.)

4. Pin quality

  • Asserts the exact line, not "any warn": expect(captureWarns()).toEqual([${WARN_NAME} event iterator exploded]) (:174) — full prefix plus message, exactly one line. The filter string (:74-75) cannot collide with the inner per-event warn ("subscription" vs "hook"), so a merely-noisier loop would not pass.
  • Dead-but-visible pinned: counter frozen (:177, toEqual(counterBefore)) matching the amended counter contract; a later turn-end provably reaches nothing (:180-183); the abort branch pins zero lines (:197).
  • Timing: every positive wait is the file's bounded waitFor (10 s cap, :117-123); the two fixed sleeps (:182 250 ms, :196 500 ms) back absence assertions — a slow machine could false-pass them but cannot false-fail them, which is the safe direction and the same pattern the sibling capture tests use.
  • State hygiene: armedSubs and warns cleared in beforeEach; plugin, console.warn, env vars, cooldowns, repo scope restored in afterEach; the setup patch restored in afterAll (:99-102, :113-115). patched === true guard (:164, :187) makes the test refuse to measure nothing if the patch silently no-ops. The in-process subscribe wrapper (:28-71) throws both before and after awaiting inner.next(), so arming lands whether the iterator is parked or between pulls — honest seam given the harness fake (test/harness.ts) cannot throw, and the load pattern (subscribeCalls === 2 → push turn-end → await generate call) is the existing capture-test pattern.

5. Prose

Scanned 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 (DroppedEvidenceWrites at record.ts:324, noteDroppedWrite private at :363 with its only call sites :406/:421/:436, reader export at :391). The console-only reasoning is consistent with the architect's amendment comment on #489.

Findings

Verdict

APPROVE. 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.

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

Copy link
Copy Markdown

🎉 This PR is included in version 0.36.0 🎉

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 capture loop's outer catch is silent: one statement above the inner try reintroduces permanent silent capture death

2 participants