Skip to content

auto-capture: a delivered turn-end event can still vanish silently — four unattributable loss paths remain (current rate 0/206, ~1%-class not excluded) #406

Done

Description

@abogartz

What was measured

While stabilising the new e2e/capture.test.ts on #403, the same scenario was run under the CI-shaped command (bun test ./e2e/ --parallel=4 --timeout 240000) repeatedly on macOS, 2026-11-13:

condition runs turn produced a capture pass
./e2e/ at --parallel=4 8 6
e2e/capture.test.ts alone 6 6

Two of eight loaded runs produced no capture pass at all.

The evidence signature

A run that works, and a run that does not, differ by everything after the tool result:

# working
ev=plugin_load …
ev=epoch_recompute …
ev=tool_result …
ev=capture_cost … trigger=idle prompt_chars=…
ev=gate_start … ev=write_promoted … ev=auto_capture_promoted …
ev=auto_capture_scan … ev=capture_lag … outcome=candidates

# failing, in full
ev=plugin_load …
ev=epoch_recompute …
ev=tool_result …

Nothing else. No capture_cost, no capture_lag, no blocked event, no refusal. The host turn completed and exited 0; the store got no row.

Why this is not the #404 teardown bug

#404 was a pass that started and was cut during cleanup — its signature is capture_cost present and no write_promoted. Here there is no capture_cost, so the pass never began: the turn-end event that capture subscribes to (TURN_END_EVENTS = ["session.execution.succeeded", "session.execution.interrupted"], src/capture/runtime.ts) did not reach the plugin before the process exited. The availability check, the write gate and the two-phase drain were never reached, so nothing in #403 or #404 is implicated.

Why it matters more than a flaky test

The failure is silent in the exact way this repo has been burned by before. There is no evidence line, so three different states are indistinguishable from the log:

  1. auto-capture is disabled,
  2. auto-capture is enabled and the pass ran and found nothing,
  3. auto-capture is enabled and the pass never fired.

A user who turns the feature on gets no memory from that turn and no signal that anything was missed. The README already says auto-capture is experimental partly for this reason — the feature shipped once with tests that passed while no live session ever fired a pass.

Where to look

  • Whether the host awaits plugin event handlers for session.execution.succeeded before tearing down, or dispatches and exits. If it does not await, capture cannot rely on the turn-end event on a fast-exiting opencode run, and the guarantee has to come from somewhere else — disposal, or a flush point.
  • e2e/support/harness.ts turn() returns when the child exits; the plugin's last chance is inside that window.
  • The deterministic half of the teardown contract already lives in test/capture-dispose-drain.test.ts; this gap is the opposite case — no event at all, so nothing to drain.

What #403 does about it

Nothing, and it should not: #403 changes what a verdict does, not when a pass starts. What #403 now does is refuse to misreport it. turnUntilCaptureStarts() retries the real turn up to four times, asserts a pass started within those attempts (so a permanently dead capture still fails the test rather than passing vacuously), and prints the attempt count on every run:

[capture-start] test 2: pass started on attempt 1
[capture-start] test 2: pass started on attempt 2

That makes the file's claim the one it can support — a pass that started survives teardown and writes byte for byte — and leaves the start rate visible in CI logs instead of hidden behind a re-run.

Reproduction

bun test ./e2e/ --parallel=4 --timeout 240000

On an unloaded machine this passes. To force the condition, run the full ./e2e/ directory in parallel while another CPU-saturating job runs; the failure appears within a handful of runs. KEEP=1 leaves the guest directories behind so the evidence trail can be read directly.

Activity

  1. added
    bug
    capture
    severity:high
    on Nov 14, 2026
  2. added a commit that references this issue on Nov 21, 2026
  3. added
    severity:low
    tier:standard
    tier:full
    and removed
    tier:standard
    severity:low
    on Nov 23, 2026
  4. ocsi-architect commented on Nov 25, 2026

    @ocsi-architect

    Pre-arch review, posted by the orchestrator on the architecture seat's behalf. Measured
    at main @ 19ca5b3 (base frozen at dispatch, rule 8; runner budget ~32 min, checkout
    read-only).

    Citation integrity, stated before the findings because this review got one thing
    wrong in prose and nothing in data.
    The seat's first draft cited a tracker entry
    "#526" (a ~1.2% hidden-rate measurement over 11 turns) at three points, and a "stale
    sentence" about the disposal flush carrying a pid at two more. None resolve: no issue
    or PR #526 exists, the string appears nowhere in the repo, and git log -S shows no
    pid sentence ever existed in any version of the evidence doc. Under audit the seat
    withdrew all six sites and supplied the corrected wording used below (the substance
    each site carried survives on measurements that do exist or on #406's own body), and
    disclosed that a docs file it quoted had only reached its context compressed — it
    asserted a sentence from text it never fully saw. Its first account attributed the
    "#526" string to a recalled memory row; that account also failed verification: the
    store contains no row with #526 dated before the seat's own session, and the only
    row ever written containing it was the auto-captured echo of the seat's own draft.
    Every measurement below was independently reproduced or cross-checked by the
    orchestrator (silent dispatch-head continues, the per-event refused catch with the
    abort-return inside it, the metrics.ts:284 generic auto_capture_* fall-through that
    advances lastFired, the flush fields armed/turn_end_events/passes/reason/subscribed
    with no pid, invalid_model in src/index.ts:361, commit 00339d3); no retracted
    reference appears in this posted version.


    Host: opencode v2.3.0 (compiled 2026-11-13) macOS arm64, bun 1.4.3, 8 cores, ambient
    load 3–33 logged per arm. All experiments ran against scratch copies
    (arch406/repo, arch406/repo-e1).

    REPRO

    The current loss rate is zero across every attempt. Counts, honestly:

    Arm Attempts (measurement turns) Losses What it discriminates
    e2e/capture.test.ts solo (full file) 21 file-runs → 63 turns, all attempt 1 0/63 solo rate; consistent with historical 0/6
    Canonical bun test ./e2e/ --parallel=4 --timeout 240000 25 passes → 75 turns, all attempt 1 0/75 the load-shaped rate; the 2/8 (25%) of 2026-11-13 is falsified at p≈1e-9 (0.75⁷⁵)
    Driver, no retry, fresh guest per turn, idle 5 0/5 per-turn classification, no retry masking
    Driver under 8 busy spinners (load 14.6) 24 0/24 rate under CPU contention, no probe attached
    Driver + delivery-probe plugin alongside a suite pass (load 29) 12 0/12 arrival at bus level
    E1-patched driver, busy (load 27–33) 25 0/25 receipt feasibility + perturbation
    Poisoned config captureModel:"no-slash-model" 2 2 attributed branch 3 — see below
    Total real-host turns ≈ 206 0 invisible losses

    Statistics honestly: 0/75 under load excludes any rate ≥ ~3.9% at 95%; 0/206 overall
    excludes any rate ≥ ~1.5%. A 1%-class rate remains not excluded by these zeros —
    P(0/206 │ p=0.01) ≈ 0.13 — so zero is the finding, not a clean bill.

    Which branch each measurement discriminates:

    • Delivery probe (14/14): a second standalone plugin (delivery-probe, same
      pattern as e2e/support/probe-plugin) subscribed alongside capture and
      appendFileSync-ed every turn-end event. 14/14 received
      session.execution.succeeded
      (idle and load-29), and 14/14 processes were still
      alive 500 ms into cleanup
      (cleanup_start → after50 → after500 all present).
      Bus-level non-delivery is not happening in the opencode run shape on this host
      build, corroborating fix(capture): make a lost turn-end pass observable (#406) #474 round-1's 10/10, and the host does await plugin cleanup
      well beyond the drain's 1000 ms… at least past the probe's own 500 ms.
    • Silent disable — closed, and the ticket's framing inverted: the poisoned-config
      arm ran clean of any subscription (no auto_capture_start, 0 capture lines) but
      the store names it: plugin_load … capture=invalid_model
      (src/index.ts:365-376). And the console channel the ticket mourns does not exist
      on the real host
      : the poisoned turn's stderr was empty — the plugin's console.warn
      never surfaces through opencode run --standalone. The CI console line the
      orchestrator saw was the unit harness's captured console, not a user-visible
      channel. Branch 3 is attributable from the store alone today; plugin_load is the
      arrival-side receipt this branch needed, and fix(capture): make a lost turn-end pass observable (#406) #474 shipped it.
    • Subscription-state discard — partly unreachable by this reproduction shape, and
      still silent where reachable:
      the cooldown continue
      (src/capture/runtime.ts:1190) and the sid === undefined continue (:1187)
      write nothing. I attempted to demonstrate the cooldown shape with two same-guest
      turns seconds apart: it captured both times — opencode run is a fresh process
      per turn, so the module-level lastCaptureRun map is always empty. Cooldown-shaped
      silence is therefore long-lived-server-only (desktop/TUI), and the
      run --standalone e2e shape is structurally blind to it. The no_sid discard is
      equally silent in every shape.
    • Handler death — attributable today, per-turn not permanent: the per-event
      try/catch (:1199) writes auto_capture_refused reason=capture_threw with the
      message on any non-teardown throw. Zero refused lines in 206 turns. The two silent
      deaths that remain are the if (controller.signal.aborted) return inside that catch
      (:1203) and the outer iterator-death catch (:1216-1218) — both belong to The capture loop's outer catch is silent: one statement above the inner try reintroduces permanent silent capture death #489's
      filed statement, not to this ticket's per-turn shape.
    • E1 arrival receipt (executed on scratch, repo-e1): one
      recordSyncBestEffort("auto_capture_seen", {trigger, sid, discard:none|no_sid|cooldown})
      immediately after turnEndSeen++, before both continue decisions. 25/25 clean-
      config turns wrote the receipt, and the loss rate did not change (0/25)
      — the write
      is synchronous file I/O (recordSync at src/telemetry/record.ts:205:
      mkdir+open+chmod+append, no lock, no sqlite) with no observable timing cost.
    • One collateral data point: the 24th suite pass under my heaviest contention
      (spinners + driver + suite, load ≈29 — beyond the CI shape) reported 1 fail in a
      non-capture e2e file — all three capture measurements in that same pass were
      attempt 1. My grep filter dropped the failing test's name before it hit the log;
      that is an artifact of my collection, disclosed rather than hidden. It matches the
      documented contention-flake family, not capture availability.

    Caveat: for ~60 s during Phase 1 the unpatched scratch tree briefly carried the E1
    patch (my patch script lacked a dry-run). Any opencode run in that window loaded a
    plugin that wrote extra auto_capture_seen lines and reordered bindCapture;
    behavior is unchanged (additive sync write), all measurements in that batch were
    attempt-1, and no classification depends on the line's absence.

    Design space

    The ticket asks to discriminate four branches. At 19ca5b3 the store already names
    six outcomes — capture_lag (ran), auto_capture_skipped (deliberate skip),
    auto_capture_refused (skip/cut-over-throw with reason), auto_capture_start ∧
    ¬capture_cost (cut AT the model call), plugin_load capture=off|switch_mismatch|invalid_model|no_capabilities (never armed),
    auto_capture_dispose (armed, disposed, no event seen). What remains unattributable,
    precisely:

    1. (a) Dispatch failure (branch 1): the only trace is auto_capture_dispose,
      which requires all of: cleanup called, store directory exists, the async append
      flushed before exit, and turnEndSeen===0 && passesStarted===0. Three of those
      four are themselves subject to the exit race.
    2. (b) no_sid discard (:1187): silent, and arriving sets turnEndSeen=1,
      which suppresses the dispose line.
    3. (c) cooldown discard (:1190): silent, same suppression; server-only shape
      (measured above).
    4. (d) cut between arrival and auto_capture_start — during the awaited
      session.context read (:501) or knownRowsFor (:581): no line at all;
      documented as silent by design in test/capture/capture-start-observable.test.ts
      ("NOT covered … that band stays silent like the original failure") and
      src/capture/runtime.ts:637-646.
    5. (e) throw during teardown (:1203): silent by the abort check; The capture loop's outer catch is silent: one statement above the inner try reintroduces permanent silent capture death #489 territory.
    6. (f) subscription iterator death (:1216): silent permanent death; The capture loop's outer catch is silent: one statement above the inner try reintroduces permanent silent capture death #489
      territory.

    The discriminating measurements, with execution status:

    • E1 arrival receipt (executed, scratch): converts (a)–(d) from guesswork into
      store-readable classes — ¬seen ∧ dispose = delivery; ¬seen ∧ ¬dispose = delivery
      with the dispose write itself lost (needs the receipt to be sync at arrival, which it
      is); seen ∧ discard=cooldown|no_sid = branch 4 named; seen ∧ ¬start = the (d)
      band. One receipt, four classes.
    • Poisoned configuration (executed): closes branch 3 — done, see REPRO.
    • Outside-observer probe (executed): measures bus-level delivery independent of the
      capture instance, and cleanup-wait; distinguishes (a) from (b)/(c)/(d) in e2e without
      touching production code.
    • Long-lived-server arm (unexecuted, and structurally impossible with
      opencode run): the only shape where (c) and any prior-instance module-state leak
      can fire.
    • Deliberate handler throw (deterministic unit level exists —
      capture-unwritable-log, capture-start-observable): pins that a throw is per-turn
      and attributed via refused, not permanent; the permanent variants are (e)/(f) =
      The capture loop's outer catch is silent: one statement above the inner try reintroduces permanent silent capture death #489.

    Placement verdict

    The one receipt: auto_capture_seen, recordSyncBestEffort, in the dispatch loop
    directly after turnEndSeen++ (src/capture/runtime.ts:1185) and before the two
    continue decisions, with discard:"none"|"no_sid"|"cooldown" as a field, session
    passed so context resolves at call time (the write is synchronous and happens-before
    any await, so it needs no frozen context and bindCapture stays at :1194).
    It must
    be sync (the start-receipt comment at :637-655 documents exactly how much window an
    async write yields) and it must be written before the discards so every delivered event
    has written something before it can be silently skipped. With it, every future loss is
    one of: ¬seen ∧ ¬dispose (delivery, with a named second-order case where even
    dispose lost), seen ∧ discard=… (subscription state), seen ∧ ¬start (arrival-to-
    model band), start ∧ ¬cost (model call). No further logging is needed for branch
    attribution — adding anything else is the "more logging everywhere" trap; every
    other line is already attributable.

    Required companions, or the receipt manufactures a new blindness:

    • src/status/metrics.ts — a raw auto_capture_seen line falls through to the generic
      auto_capture_* branch (:270) and advances lastFired, making an
      arrived-but-always-cut capture read as "fired and alive". Like start and dispose,
      it needs early handling; add lastArrived, and a report arm "arrived but never
      started" (one severity slot beside cut > never-fired > inert in
      report.ts:200-213).
    • e2e/capture.test.ts — turnUntilCaptureStarts must count a turn that wrote
      auto_capture_seen but no pass as arrived-lost in its printed rate: today
      [capture-start] … attempt 2 logs the success and not the loss it masked, which is
      the hiding auto-capture: a delivered turn-end event can still vanish silently — four unattributable loss paths remain (current rate 0/206, ~1%-class not excluded) #406's own body asks against ("the start rate visible in CI logs instead
      of hidden behind a re-run"). The failure message's claim "not reaching the plugin at
      all" becomes verifiable rather than inferred.
    • docs/internals/auto-capture-evidence.md — a new table row for the receipt, so the
      interpretation table names auto_capture_seen alongside auto_capture_start and the
      arrival-to-start band becomes a named state.
    • Branch 3 needs no new line (plugin_load names it); the invalid-model
      console.warn may stay as unit-visible prose, but a note that the real host swallows
      plugin console output keeps the next reader from assuming a user channel exists.

    Alternatives

    1. Observer probe as the permanent instrument (the delivery-probe I ran, as a
      committed e2e fixture): zero production change, measures bus delivery — but invisible
      in users' stores and to the status surfaces, so it cannot attribute a production
      loss. Adopt as complementary CI fixture; reject as the receipt.
    2. Upstream host-side per-handler dispatch log (opencode itself): the honest
      long-term home of branch 1; out of this repo's control, and the plugin still needs
      its own arrival line to attribute post-arrival bands. Filed-not-shipped here
      (unexecuted by definition).
    3. Async arrival write (await appendFile at handler top): the 2.3.0 probe says
      async first writes flushed 12/12 — but sync yields zero event-loop windows, and the
      margin this bug lives in is exactly event-loop timing. Rejected in favor of sync.
    4. Move auto_capture_start earlier, before the context read: rejected — it would
      misreport deliberate skips as cuts, the precise trade 00339d3 paid to avoid. The
      seen receipt gets arrival attribution without unpinning that boundary.

    Rot mechanism

    What let this bug survive invisibly, and what will do it again:

    • The dispose-flush suppression coupling: turnEndSeen===0 && passesStarted===0.
      Every future early-continue added to the dispatch body silently converts
      attributable losses into invisible ones, and no test fails when you add one — the
      two continues already in there are untested for their silence. The seen receipt
      makes the invariant local and checkable: an event that is delivered has written a
      line before it can be skipped.
    • The retry loop hides the rate: [capture-start] … attempt 2 reads as a success
      line; the loss under it surfaces only if four fail in a row. auto-capture: a delivered turn-end event can still vanish silently — four unattributable loss paths remain (current rate 0/206, ~1%-class not excluded) #406's own body names
      the requirement — the start rate must be visible in CI logs instead of hidden behind
      a re-run — and the arrival receipt is what finally makes the hidden class countable
      rather than merely retried.
    • plugin_load capture=on means armed, not delivered — the only healthy-reading
      state name is written before any event could fail. Fine as a heartbeat, wrong as a
      health guarantee; lastArrived is what closes that gap.
    • Doc drift: the "NOT covered" header in capture-start-observable.test.ts is
      today an accurate description of a silent band; left as-is, the next bug report files
      it with a ready-made root cause. The comments here are high-quality; the risk is
      prose outliving the code in both directions.

    State-boundary map

    State Where Lifetime / cleared by Loss-relevant consequence
    lastCaptureRun cooldown Map runtime.ts:135, module level process exit / resetCaptureCooldowns (test preload) Shared across all setups in one process (deliberate: multi-location setups must not double-pay). A long-lived server re-registering the plugin inherits the previous instance's windows → silent (c)-shape losses, server-only. Fresh opencode run processes make it structurally invisible to the e2e (measured).
    turnEndSeen / passesStarted per-setup closure (:285-286) instance The dispose flush's zero-test is the suppression coupling; multi-instance processes get one line per armed instance.
    controller (abort) per-instance cleanup #522: the iterator may dispatch events queued before abort (bindCapture runs, then captureSession's abort checks contain it) — extra work after abort, not a loss mechanism; keep it out of this fix's diff.
    setCurrent / bindSessionProvisional ambient globals overwritten per event / test isolation Capture already freezes its context sync at bindCapture before first await; the seen receipt adds no new global state and no frozen context (call-time resolution is safe inside the synchronous block).
    inFlight / passPhases per-instance drain at cleanup, 1000 ms bound Probe observed the host waiting ≥500 ms into a plugin cleanup 14/14, but that is this probe's cleanup; the host's bound on capture's cleanup is unmeasured — the drain remains a hope bounded by host behavior.
    droppedWrites record.ts, process memory process exit A lost evidence write in a dead process is unreportable forever; report.ts already says so — any new receipt inherits this limit.

    Standard

    BLOCKS — and the ticket's premise needs re-scoping in the same breath, because
    that is what the data says.

    • BLOCKS closure as "fixed" or "unreachable": the loss rate at 19ca5b3 is zero
      across ~206 real-host turns including ~99 under canonical and injected contention,
      but zero is not exclusion of a ~1% rate, and the silent code paths (b)/(c)/(d) plus
      the async-only branch-1 receipt are present and verified by reading, so the
      invisibility half of this bug is real at any rate, including zero.
    • BLOCKS any fix that merges without: the seen receipt at the named placement;
      metrics.ts early-handling so it cannot advance lastFired; retry-loop rate
      honesty — a turn that wrote auto_capture_seen but produced no pass must count as
      arrived-lost in the printed rate, not as a retried success; and a new evidence-doc
      row for the receipt. An observability diff that adds the receipt but not the metrics
      handling would make lost turns look found in memory_status — the one outcome the
      ticket forbids.
    • Re-scope: "some loaded runs produce no capture pass" is no longer demonstrated on
      the canonical reproduction (0/75 canonical, 0/206 total, where the ticket's era gave
      2/8). The demonstrable defect is attribution: three silent discards and a
      suppression coupling in the plugin, a delivery branch whose only trace is a
      cleanup-time async write, and a CI retry pattern that hides whatever rate remains.
      With more budget, the discriminating measurement is exactly two: (1) ship the seen
      receipt and let ~100+ CI passes classify every future loss from the store alone —
      measured unperturbing here (0/25 at load 33), and the only way to pin a rate this
      session's zeros cannot; (2) a long-lived-server arm (opencode serve, many turns
      per process) — the sole shape where branch 4's cooldown and prior-instance paths can
      actually fire, structurally unreachable from the run --standalone instrument that
      produced every number in this ticket.
  5. changed the title [-]auto-capture: the turn-end event can fail to reach the plugin under load, and the turn leaves no trace of it[/-] [+]auto-capture: a delivered turn-end event can still vanish silently — four unattributable loss paths remain (current rate 0/206, ~1%-class not excluded)[/+] on Nov 25, 2026
  6. abogartz-opencode-self-improvement commented on Nov 25, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.35.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

    bugcapturereleasedseverity:hightier:full

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions