Skip to content

The capture loop's outer catch is silent: one statement above the inner try reintroduces permanent silent capture death #489

Done

Description

@abogartz

The claim

The capture subscription's outer exception handler is silent. In src/capture/runtime.ts, the for await loop over host events is wrapped by an outer catch {} that returns without logging, counting, or emitting any evidence when it fires. Two paths reach it today:

  1. The event iterator itself throwing — the subscription dies and nothing is recorded.
  2. Any statement added between the loop header and the inner per-event try. The inner guard is described in comments as covering the whole body, but that is true only by position: a maintainer who adds a receipt or hoists bookkeeping above the try — plausibly "for visibility" — routes its throw into the silent outer catch, and capture dies permanently with no console line, no counter tick, and no failing test. The existing loop-survival test still passes because its failing write lands mid-pass, inside the inner guard.

This is the original #479 failure — permanent silent capture death — reintroduced through the shape of the guard rather than through a write.

The fix

Minimum: in the outer catch, if the loop exited with !controller.signal.aborted, console.warn (in guarded()'s shape, using the shared safe-message rendering) and count the exit through the dropped-write counter before returning. One line converts silent death into a visible anomaly.

Pin it: a test that forces the iterator to throw mid-session and asserts the console line appears and the counter ticks — and, on pre-fix source, fails.

Where

Found by the blind architecture review of the merged #482 policy, 2026-11-22. Related: #479 (the policy), #485 (same safe-message plumbing).

Activity

  1. added
    bug
    capture
    severity:medium
    agent:ready
    on Nov 22, 2026
  2. added
    tier:micro
    on Nov 22, 2026
  3. ocsi-architect commented on Nov 25, 2026

    @ocsi-architect

    Repro (repro-only, tier:micro) @ 6c743ff

    Tree: git archive 6c743ff | tar xf - -C /private/var/folders/52/f2djt5m14xl6vty9dxvf0xk40000gn/T/opencode/repro489 plus symlinked node_modules from the main checkout. Main checkout untouched (git status --porcelain empty after all runs; the one scratch mutation was restored byte-for-byte, asserted in-test and by diff -q).

    Scratch scripts (scratch tree only, not the repo):

    • /private/var/folders/52/f2djt5m14xl6vty9dxvf0xk40000gn/T/opencode/repro489/repro-489.test.ts — Cases A, B, C, E; spawns D.
    • /private/var/folders/52/f2djt5m14xl6vty9dxvf0xk40000gn/T/opencode/repro489/repro-489-mut.test.ts — Case D child, run in a fresh bun test process against the mutated scratch source.

    Command: cd /private/var/folders/52/f2djt5m14xl6vty9dxvf0xk40000gn/T/opencode/repro489 && bun test repro-489.test.ts
    Result: 5 pass / 0 fail, run twice with byte-identical REPORT payloads.

    Loader: real plugin through test/harness.ts loadPlugin(dir, {autoCapture:true, captureModel:"fake/model"}) (the harness runs plugin.setup(ctx) at harness.ts:324). The shipped fake iterator (harness.ts:278-303) parks and yields but cannot throw, so the scratch wraps ctx.event.subscribe in-process (patch of the default-exported plugin object's setup before any load) and arms a throw that fires from the parked iterator's next next(), instead of delivering a sentinel wake event. subscribeCalls === 2 (usage + capture) observed before every case; sentinel events left no evidence line, proving the throw fires before delivery.

    CASE A — iterator throw (the ticket's path 1): REPRODUCES

    Candidate: one healthy idle pass first (session.execution.succeeded, sid ses-a-alive; generate.calls === 1, auto_capture_seen present for that sid, 5 evidence lines total), then the iterator throws Error("repro489 iterator exploded") while controller.signal.aborted === false (measured [false, false] across both subscriptions).

    Measured after the throw (250 ms settle):

    • console.warn captured by replacing console.warn (precedent test/host/plugin-shim.test.ts:38-45): [] — zero warn lines from anything after the throw, none naming the capture loop or the iterator.
    • dropped-write counter droppedEvidenceWrites(): null before, null after. No tick.
    • evidence store: new_evidence_lines_after_throw: [] — zero new lines, nothing naming the failure.
    • subscription dead: pushed a fresh turn-end (ses-a-after) 250 ms later — evidence_lines_for_ses_after: [] (no arrival receipt for the new sid), generate_calls_after_all: 1, subscribe_calls: 2 (no resubscribe). Capture is off for the life of the process with no trace on any of the three channels.

    CASE B — throw inside the inner per-event try (control): DOES NOT REPRODUCE the silence; the guard works there

    Same bus, same event shape; failure lands inside the inner try via the existing seam capture.generate.throws = Error("repro489 model gone") (the seam capture-dispose-drain.test.ts uses). Measured:

    • console.warn: "[opencode-self-improvement] auto-capture (idle) hook failed (ignored): repro489 model gone" (exactly 1)
    • evidence: 1 line ev=auto_capture_refused … reason=capture_threw error=repro489 model gone session=ses-b-throw
    • counter droppedEvidenceWrites(): null (the receipt write succeeded — the counter tracks lost writes, not failures; see Fixer inputs).

    The asymmetry the ticket claims is pinned: identical delivery channel, different throw location, opposite observability.

    CASE C — structural between loop header and inner try: LATENT (clean source)

    Inputs tried: read src/capture/runtime.ts:1100-1299 at this sha; enumerated non-comment statements between the for await (const raw of eventApi.subscribe({...})) { header (line 1161) and the inner try { (line 1181). Result — exactly:

    • 1165: if (controller.signal.aborted) break;
    • 1174: let sid: string | undefined;
    • 1180: let opGate: GateContext | undefined;

    None can throw today (AbortSignal property read; two declarations), so on clean source the outer catch is reachable only via path 1. The hoist hazard is unfalsified — measured directly in Case D.

    CASE D — hoisted throw above the inner try (the ticket's path 2): REPRODUCES (mutation, scratch-only)

    Mutation (scratch only, inserted after the unique anchor line 1165, restored after): if ((raw as { data?: { __boom?: boolean } })?.data?.__boom) throw new Error("repro489 hoisted bookkeeping boom"); — a receipt-shaped statement "hoisted for visibility" above the inner try. Child measured on mutated source (alive proof passed first: normal event, full pass, generate.calls === 1), then one __boom event:

    • all_warns: [] — silent; nothing names the boom
    • counter_ticks: 0 (droppedEvidenceWrites() null before and after)
    • boom_evidence_lines: [] — the killed event leaves no receipt (the throw is above the arrival receipt)
    • lines_for_ses_after: [], generate_calls_after_all: 1 — every later turn is dead.

    Fixer inputs (all read at 6c743ff; line numbers personal)

    • Outer catch: src/capture/runtime.ts:1264-1266:
              } catch {
                // the subscription itself ended (abort or host error); nothing to do
              }
      The !controller.signal.aborted discriminator is real: measured signal.aborted === false at throw, and the inner catch already uses the abort-first shape at runtime.ts:1236.
    • guarded() warn shape — src/core/hooks.ts:37-40:
          console.warn(
            `[opencode-self-improvement] ${name} hook failed (ignored):`,
            err,
          );
      Note it hands the raw err as a second arg. The same-loop precedent that satisfies the ticket's "shared safe-message rendering" is the inner catch, src/capture/runtime.ts:1243-1246:
                    const failure = safeErrorMessage(err);
                    console.warn(
                      `[opencode-self-improvement] auto-capture (idle) hook failed (ignored): ${failure}`,
                    );
    • safeErrorMessage — src/telemetry/record.ts:359-361, export function safeErrorMessage(err: unknown): string { return redactSecrets(describeError(err)).slice(0, MIRRORED_ERROR_MAX); }; MIRRORED_ERROR_MAX = 200 at record.ts:351; describeError (module-private) at record.ts:339.
    • Shared dropped-write counter: state is const droppedWrites = new Map<string, DroppedEvidenceWrites>() — src/telemetry/record.ts:333, keyed by evidenceDir(). Increment is noteDroppedWrite(event: EvidenceEvent, err: unknown) — record.ts:363 — called only from the three best-effort wrappers (record.ts:406, 421, 436); it is NOT exported, so counting a loop exit needs a new exported mutator (or a routed best-effort call). Read API: export function droppedEvidenceWrites(): DroppedEvidenceWrites | null — record.ts:391-392. Shape interface DroppedEvidenceWrites { dropped: number; lastEvent: string; lastError: string } — record.ts:324-331.
    • How a test observes the tick (measured, Case E): chmodSync(dayFile, 0o444), call recordSyncBestEffort(<ev>, {}, false), restore mode, then droppedEvidenceWrites() → {"dropped":1,"lastEvent":"repro489_counter_probe","lastError":"EACCES: permission denied, open '…/evidence/2026-11-25.logfmt'"}. Same chmod seam as test/capture/capture-unwritable-log.test.ts. Absent store reads null.
    • Pin-test plumbing: the harness fake iterator (harness.ts:278-303) has no throw seam — a checked-in pin needs either a seam on CaptureFakes.events or a local wrapper; the scratch wrapper recipe above works unchanged.
    • Scope note from the measurement (not part of the claim): the sentinel wake in Case A hit both subscriptions on the shared fake bus, and neither's iterator failure produced a console line — this repro judges only the capture loop named in the ticket.

    Verdicts

    • CASE A (iterator throw): reproduces — capture dies permanently, silent on all three channels.
    • CASE B (inner-try throw): does not reproduce the silence — warns + refuses; asymmetry pinned.
    • CASE C (clean source, hoist path): latent — only the abort check and two lets sit above the inner try today.
    • CASE D (hoisted throw, scratch mutation): reproduces — same silence, same permanent death.
    • CASE E (counter observability): ticks are observable via droppedEvidenceWrites(); the increment site is module-private today.
  4. ocsi-architect commented on Nov 25, 2026

    @ocsi-architect

    Counter-semantics amendment (fixer decision on the ticket's minimum, per PR #533)

    The ticket's minimum said the loop exit should be counted "through the dropped-write counter." Shipped instead: console-only, and the ticket's minimum is amended here so the record is plain.

    Why. The shared counter measures lost evidence writes — DroppedEvidenceWrites {dropped, lastEvent, lastError} (src/telemetry/record.ts:324) is incremented only by the best-effort write wrappers, through the module-private noteDroppedWrite (record.ts:363; its only call sites 406, 421, 436). Every tick therefore certifies that a specific write failed. A dead subscription drops zero writes: a tick would inflate dropped and make every later reader of memory_status believe evidence was lost when nothing was, and lastError would render an iterator death as if it were a write error. The existing invariant is pinned by the repro's Case B — a mid-pass model failure whose receipt write succeeded leaves the counter at null — the counter tracks loss, not failure.

    What ships in its place (#533): when the loop's outer catch fires with the abort signal unset, one console.warn in the guarded() line shape with the shared safeErrorMessage rendering, on a line that names the channel (auto-capture (idle) subscription failed (ignored):), distinguishable from the inner per-event failure line. The console is the channel that survives the exact failure class the ticket is about — a broken evidence log — where a receipt write could not land anyway. The pin test asserts the warn line arrives AND that the counter stays untouched, so the console-only boundary is itself under test.

  5. abogartz-opencode-self-improvement commented on Nov 25, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:readybugcapturereleasedseverity:mediumtier:micro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions