Skip to content

fix(capture): make a lost turn-end pass observable (#406) - #474

Merged
abogartz merged 3 commits into
mainfrom
fix/406-turn-end-delivery
Nov 21, 2026
Merged

abogartz merged 3 commits into
mainfrom
fix/406-turn-end-delivery

Conversation

@ocsi-fixer

@ocsi-fixer ocsi-fixer Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Addresses #406

Makes the silent turn-end-capture state observable. It does not fix delivery — that behaviour is upstream in the host. See "What is NOT fixed."

Round 2 fixed the skip false-positive. Round 3 (commit 00339d3) fixes two bugs that round 2 introduced: a verdict that ranked by recency and so erased a real cut, and a receipt write that could cancel the capture it reports.

What was measured

Probe plugin over e2e/support/harness.ts against the real host (opencode v2.3.0, macOS). The probe subscribes to the turn-end events exactly like src/capture/runtime.ts and records RECV (event reached event.subscribe), HANDLED (async handler ran to completion after a delay), and cleanup.

probe runs exit 0 RECV HANDLED CLEANUP
handler awaits 2000 ms 10 10 10 0 10
handler awaits 0 ms 12 12 12 12 12

The reviewer's independent sweep put the abandonment boundary below 50 ms (HANDLED 10/10 at 0 ms; 0/10 at 50, 200 and 2000 ms; RECV 10/10 throughout). A synchronous or async first-action write lands regardless; only a long await is lost.

Root cause — measured vs inferred

Measured (upstream): on opencode run the host dispatches the turn-end event to plugin subscriptions and exits without awaiting the async handler. The event reaches event.subscribe every time; a handler that awaits is abandoned mid-await while the process exits 0 and cleanup fires. This repo cannot make delivery reliable; only the host can.

Inferred (a hypothesis, not an observation): that this mechanism produced the issue's original natural misses (6 of 8, 2026-11-13, an older host). It did not reproduce this cycle (author 45/45 before, 30/30 after; reviewer 1 miss in 75 turns). This PR adds observability to test the hypothesis, not to assert a cause.

The states, and how they rank

Within capture=on, the health line ranks by severity, never recency — a later benign line must not overwrite an earlier loss:

  1. cut — auto_capture_start with no capture_cost: a pass reached the model call and recorded no verdict. An observed loss; outranks everything below.
  2. never-fired — auto_capture_dispose, no start: an armed instance disposed with no turn-end event observed. A predictive absence — the event is delivered in every measured run and an idle restart produces it too.
  3. skipped — auto_capture_skipped, no start: a deliberate skip (no signal, thin transcript). Not a loss.
  4. inert — nothing ran.

A completion (capture_cost/capture_lag), a promoted row, or a refusal anywhere in the 30-day window is reported as alive, which masks a same-window cut — a known limitation, stated in the code, not a verdict here.

B1 — a cut no longer gets erased by a later dispose

Round 2 rendered whichever of lastStarted/lastMissed was newer, so a later auto_capture_dispose from an unrelated idle instance flipped a real cut to "never fired." Now lastStarted outranks lastMissed outright. Re-run of the reviewer's scenario on this head:

CUT + LATER DISPOSE ->
  auto-capture: ARMED — a pass reached the model call but recorded no verdict; the turn-end event arrived and the pass did not complete.

B2 — the receipt can no longer cancel the capture it reports

Round 2 wrote auto_capture_start with recordSync unguarded. An unwritable evidence log (read-only mount, foreign owner, ENOSPC) threw before the model call, so the pass never ran and the subscription stopped dispatching — an observability change causing the loss it detects. The receipt is now wrapped in try/catch like the disposal flush: it is best-effort, and a failed evidence write cannot abort the pass.

Re-run on this head: with the evidence file set 0400, the capture model call still happens.

Fail-before / pass-after

test/capture/capture-start-observable.test.ts pins the contract. Both round-3 tests fail on the reviewed tree dce67d1:

# B1 — cut outranks a later dispose
expect(rendered).toContain("reached the model call")
  Expected to contain: "reached the model call"
  Received: "... ARMED BUT NEVER FIRED — no turn-end event was observed before disposal; no pass could start."
  at test/capture/capture-start-observable.test.ts:218:20

# B2 — unwritable evidence log still reaches the model call
expect(reached).toBe(true)
  Expected: true
  Received: false
  at test/capture/capture-start-observable.test.ts:253:21

The round-1 skip test still fails on 156b677 (:167:57, a skip wrote a start line) and the receipt/dispose tests still fail on origin/main.

Test tally (the 1620 vs 1659 discrepancy)

Both numbers were correct for different commands:

  • bun run test → bun test ./test/ (unit gate only, 140 files): 1622 pass, 21 skip, 0 fail on this head.
  • bun test (no path — also discovers the 11 e2e/*.test.ts files, 151 files): 1661 pass, 21 skip, 0 fail.

The reviewer's 1659 was bun test on dce67d1 (2 fewer tests); mine is bun run test. Round 3 added 2 tests.

e2e pass rates (bun test ./e2e/ --parallel=4 --timeout 240000, same machine)

suite pass per-turn attempt-1
before (origin/main, 15 runs) 15/15 45/45
after (this change, round 3, 5 runs) 5/5 15/15

Delivery is unchanged — observability only. The push-time merge gate ran it again: 39 pass, all capture-start on attempt 1.

What is NOT fixed / follow-ups

  • Delivery. The host still dispatches turn-end and exits without awaiting the handler; a pass cut at the model call still produces no row. This PR makes that visible, not rarer. A real fix needs the host to await plugin handlers (or give an awaited teardown seam).
  • The pre-receipt blind band is silent. The receipt sits after the context read and the awaited known-rows read (loadAll(), ~0.72 ms at 200 rows / ~2.08 ms at 2000, warm). A pass cut inside that band writes nothing — the original silent state. Naming it beats implying full coverage; closing it would mean writing a trace during those reads, which the teardown contract forbids.
  • auto_capture_dispose is predictive. Its target state has not been observed on any host version; an idle restart produces it. The rendered line and README now state an absence, not a cause.
  • Follow-up (pre-existing on main, made reachable by round 2, now guarded on the happy path): the capture subscription stops dispatching after any evidence-write failure (e.g. a capture_threw/auto_capture_refused receipt that itself throws). The receipt guard removes the happy-path trigger; the general "an evidence-write failure must not kill the subscription" policy is a separate change worth its own ticket.
  • No fallback capture pass was added: writes still happen only through the existing gate, at the same points relative to teardown.

Measured on macOS 2026-11-21 against opencode v2.3.0 with a probe plugin over
the e2e harness: the turn-end event reaches event.subscribe in 10 of 10
`opencode run` turns, a handler that awaits a 2s model call records its
completion in 0 of 10, and the plugin's cleanup fires in 10 of 10. An async
write made as the handler's first action flushes in 12 of 12; only a long await
is lost. So the #406 signature — a turn with a tool_result and nothing after —
is not the event failing to arrive; it is the capture pass being cut at the
model call because the host dispatches turn-end and exits without awaiting the
async handler. That root cause is upstream and is NOT fixed here.

This change makes the silent state distinguishable in the evidence log:

- The capture pass now records `auto_capture_start` at its first await, before
  the context read and the model call, so it lands even when the host exits
  mid-handler. A pass that started but never reached `capture_cost` is now a
  visible "started but cut by teardown" state.
- Disposal records `auto_capture_dispose` when an armed instance is torn down
  without the subscription ever receiving a turn-end event — the one signal
  that does not depend on the event arriving. It is existence-checked so a
  disposed instance never resurrects a store its caller removed (the #211
  teardown contract), and it fires only when no pass started, so all four
  capture-dispose-drain assertions still hold.
- `captureHealth` tracks the two new lines apart from the fired/completed
  verdicts, and `captureLines` renders distinct messages for "started but never
  completed" and "turn-end event never delivered."

test/capture/capture-start-observable.test.ts pins both lines and fails on the
pre-fix tree (expect(start).toBeDefined() and expect(miss).toBeDefined() both
received undefined). The full unit suite passes (1619 pass, 0 fail).

Delivery itself is unchanged: this is an observability fix, not a delivery fix.
@ocsi-fixer
ocsi-fixer Bot requested a review from abogartz as a code owner November 21, 2026 19:31

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

I found a normal skip that the new status message diagnoses as host teardown. At 156b677 on Windows (Bun 1.4.4), I sent session.execution.succeeded through the plugin harness with a one-message transcript (“hello”). The evidence contained auto_capture_start followed by auto_capture_skipped reason=transcript_too_thin. The model call count was zero. Before cleanup, memory_status already said “cut by host teardown” and “the model call did not finish.” All nine start/dispose tests passed separately. Could the status test cover that sequence? An explicit skip should report its reason. A start alone can establish that completion was unobserved, but cannot identify teardown as the cause.

One other difference I found by source inspection: recordSync applies private modes on creation. The existing appendLog also tightens an existing directory and file and opens the file with the no-follow flag where supported. Please preserve those protections on the synchronous path as well. I haven't run the POSIX permission cases on this head.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: PR #474 — make a lost turn-end pass observable

Verdict: REQUEST_CHANGES. The observability mechanism works — I reproduced the cut on the real host and the new receipt lands in it — but the PR ships a user-visible verdict that fires on ordinary skips, a disposal event whose target state has never been observed and which misattributes benign shutdowns, and a class of repo prose the standing rule forbids. All four are fixable without touching the core design.

Environment for everything below: this machine, opencode v2.3.0 (/Users/Alex/.opencode/bin/opencode), macOS, 2026-11-21.

What I verified independently

claim result
fail-before at test/capture/capture-start-observable.test.ts:126:17 and :149:16 reproduced exactly, 0 pass / 2 fail on an origin/main worktree with this test file copied in
unit suite 1619 pass / 21 skip / 0 fail reproduced (bun run test, 37s)
typecheck, lint, comment-lint clean reproduced; biome lint is 733 warnings / 180 infos on both main and head — no new lint findings
probe: RECV 10/10, HANDLED 0/10 @2000 ms, cleanup 10/10, exit 0 10/10 reproduced with my own probe package (same void-async event.subscribe loop as runtime.ts)
auto_capture_start fires in the failure mode reproduced on the real host: a proxy delaying only the capture-lane response 3000 ms forces the pass to be parked in generate.text at disposal; head logs plugin_load, epoch_recompute, tool_result, auto_capture_start and no capture_cost; the same script on origin/main logs plugin_load, epoch_recompute, tool_result — byte-identical to the issue's failing log
e2e rates see B4 — the original failure did not reproduce for me; totals: head 75 turns / 1 miss, main 15/15

Blocking

B1 — the new "cut by host teardown" verdict fires on ordinary, healthy turns.
runtime.ts:528 writes auto_capture_start before both skip returns (runtime.ts:563 no-signal, runtime.ts:585 transcript_too_thin), so every short turn produces start with no capture_cost. captureHealth never looks at auto_capture_skipped, so report.ts:184 renders that history as "cut by host teardown before a verdict". Repro (repo root):

$ bun -e 'const {captureHealth} = await import("./src/status/metrics.ts"); const {captureLines} = await import("./src/status/report.ts"); const ts=new Date().toISOString(); console.log(captureLines(captureHealth([`ev=plugin_load ts=${ts} capture=on`,`ev=auto_capture_start ts=${ts} session=ses_a trigger=idle`,`ev=auto_capture_skipped ts=${ts} session=ses_a trigger=idle reason=transcript_too_thin chars=42`])).join("\n"))'
  auto-capture: ARMED — a pass started but never completed (cut by host teardown before a verdict; #406). The turn-end event reached the plugin; the model call did not finish.

and on a real host, a short no-tool turn produced plugin_load, epoch_recompute, auto_capture_start, auto_capture_skipped — a healthy skip that memory_status would report as a host-teardown cut. The PR's own state table (auto_capture_start, no capture_cost → cut) is therefore wrong as written. Fix: track the newest auto_capture_skipped in captureHealth and require it to be older than lastStarted before rendering the cut verdict (or pair per session); update the state table to include the skipped line. Not blocking once the verdict distinguishes skip from cut and a test pins it.

B2 — auto_capture_dispose has never been observed, and fires on benign no-turn shutdowns while asserting host fault.
The PR's own probe says the event reaches event.subscribe 10/10 at every handler length, and its root cause is "the pass is cut at the model call", i.e. the event arrives. So the state auto_capture_dispose exists to catch — armed instance disposed with zero turn-end events — is one the PR's data says the current host does not produce. I saw it fire in zero of 75 real-host turns (with and without CPU load) and zero forced-cut runs; the PR shows it only from its unit test. But that unit test is the false-alarm shape: armed + no turn + cleanup → reason=turn_end_not_delivered. A long-lived service (desktop/TUI) restarted without any turn hits exactly that path, and report.ts:192 then tells the user "the host exited before dispatch reached it" — a host accusation for a session that never ran a turn. Fix: (a) neutral wording — the evidence proves "no turn-end event was observed before disposal", not that dispatch was attempted and lost; same for the reason field; (b) the PR body and the docs entry must say plainly that this event is predictive — built for the state the issue inferred, not one observed on any host version. Not blocking once wording is neutral and the predictive status is stated.

B3 — repo prose: war stories and ticket numbers in README, shipped strings, source comments, and the test header. Mechanical; clean before merge regardless of everything else.
The repo's own policy is written at the top of scripts/comment-lint.ts ("no issue numbers, no review narrative … no retracted measurements"); the lint catches only #NNN in TS comments, so these slipped through its regex into exactly the places it cannot see. Instances:

  • README.md:76 — the "Am I armed?" paragraph became a change narrative: #404/#406, "measured 2026-11-21 on opencode v2.3.0", raw ratios (10/10, 0/10, 10/10), and a scope defence ("This repo makes the loss observable; it does not make delivery reliable"). Word count, not line count, is the thing to guard — this PR adds zero lines and +147 words: git show origin/main:README.md | wc -w → 4028 (227 lines); git show origin/fix/406-turn-end-delivery:README.md | wc -w → 4175 (227 lines). That is why the two prior trims (446cc5f, 3fe52ac) did not stick. The bar: the README's word count must not increase in this PR. The measurement, the ratios, the host finding and the scope statement belong in docs/internals/auto-capture-evidence.md, which the preceding paragraph already links. Paste-ready replacement (71 words, exactly the pre-PR paragraph's count):

    Am I armed? memory_evidence answers on the plugin_load line: capture=on (the default), capture=off (autoCapture: false), invalid_model, no_capabilities, or switch_mismatch. Once armed, an empty turn names its own cause: capture_cost a verdict, auto_capture_skipped nothing durable, auto_capture_start alone a pass cut before its verdict, auto_capture_dispose an event that never arrived. On desktop this needs opencode service restart after an edit — relaunching the app keeps the old service and its already-parsed options alive.

  • src/status/report.ts:186 and :192 — #406 inside strings memory_status prints. A ticket number in user output is a dead link. Paste-ready: delete ; #406 from both (and per B2, :192 should also drop the causal clause; suggested: " auto-capture: ARMED BUT NEVER FIRED — no turn-end event was observed before disposal; no pass could start.").

  • src/capture/runtime.ts:514-516 — narration of the rejected first attempt ("An async write here flushed too, but its several awaits measurably shrank that window and cost first-turn capture_cost delivery…"). :520-522 — dated measurement narrative ("Measured 2026-11-21 on opencode v2.3.0: … 0/10 while cleanup fires 10/10") plus "the states the issue calls indistinguishable". :1190-1192 — "the host dispatched turn-end and exited without the subscription ever seeing it — the state the issue could not tell apart from 'disabled' or 'ran and found nothing.'" Rewrite as the invariant the code enforces, no dates, no ratios, no "the issue". For 514-516 the constraint alone carries it: "The receipt must not be async: an async write here yields the event loop several times and measurably shrinks the window the model call has to finish before the host exits."

  • test/capture/capture-start-observable.test.ts:1-25 — header carries the dated measurement and ratios (:5-7), the rejected v1 mechanism ("an async first-write lands 12/12", :15), and fail-before narration (:25, repeated at :125 and :147-148 "FAILS ON origin/main"). It is also factually wrong: :13-14 says the receipt is written "at its FIRST await, before the context read" — the code writes it synchronously after the context read, on purpose (runtime.ts:516 "It sits AFTER the context read on purpose"); a maintainer following the header would move the write and collide with the capture-dispose-drain >= disposedAt boundary. Rewrite the header as the contract: start receipt synchronous after the context read, before the model call; disposal flush when armed with no turn-end event; the four-line state map. Nit: temp prefix osi-406-start- (:41).

  • docs/internals/auto-capture-evidence.md:24 — exempt: that file is the evidence log and already carries #NNN refs and dated measurements by existing convention (git show origin/main:docs/internals/auto-capture-evidence.md). The new entry matches the file's voice and length. Leave it, but see B4 on the one sentence asserting what the #406 failure is.

B4 — the measurement story: the original failure did not appear for me either, and the docs state the root cause as established fact about a failure nobody observed in this cycle.
What I measured with bun test ./e2e/ --parallel=4 --timeout 240000 on the head: 5/5 suites pass unloaded with per-turn attempt-1 14/15 (one test 2: pass started on attempt 2, evidence not retained — no KEEP=1 on that loop); under 8 CPU-saturating hogs (load avg 43) 8/8 suites, attempt-1 24/24, zero misses. A later hunt for a classifiable natural miss — 12 unloaded runs of e2e/capture.test.ts alone with KEEP=1 — produced 36/36 attempt-1, so across all my head runs the miss rate is 1 in 75 turns and I never got to classify a natural one. The same command on an origin/main worktree, unloaded: 5/5 suites, attempt-1 15/15 — the author's before-rate holds on today's host. So: main 15/15, head 14/15 unloaded, head 24/24 under load; one loss in 75 head turns, and that single head miss against a clean main run is Fisher p = 0.5 — noise, not evidence the receipt hurts delivery. The issue's 6-of-8 was measured 2026-11-13, on an older host; on v2.3.0 neither the author (45/45 before, 30/30 after) nor I can produce it. Both reports can be true of their host versions; the PR should say so, because right now docs/internals/auto-capture-evidence.md:24 and the README assert what the #406 failure is ("it is the pass being cut at the model call") — but no natural #406 miss was observed during this work at all. What is established: the host abandons any handler awaiting a timer (my sweep: HANDLED 10/10 at 0 ms, 0/10 at 50 ms, 0/10 at 200 ms, 0/10 at 2000 ms, RECV 10/10 throughout — the boundary is below 50 ms, so the claim is if anything understated, not too broad), and a pass parked in the model call at disposal leaves exactly the issue's log with the new receipt present (forced-cut repro above). Fix so the docs distinguish observed from inferred: the mechanism is measured; the identification of natural #406 misses with that mechanism is a hypothesis the new events exist to test. Natural misses are then classified when they recur. Not blocking once that sentence is honest — the forced-cut experiment already carries the observability claim.

Repro recipes. Probe: a standalone plugin package (package.json + index.ts, the host loads plugins by package, not bare file — see e2e/support/probe-plugin) whose setup runs the same void-async for await (const ev of ctx.event.subscribe({signal})) loop as runtime.ts:1124, writes RECV synchronously on session.execution.succeeded, awaits setTimeout(N), writes HANDLED; cleanup writes CLEANUP. Driven through makeGuest/turn with a no-op main plugin, N ∈ {0, 50, 200, 2000} × 10 runs. Forced cut: a Bun proxy in front of e2e/support/fake-model.ts that delays only requests whose first message contains You mine one coding-agent session transcript (the same capture-lane rule fake-model.ts:67 uses) by 3000 ms, then run the scripted E2E::cap scenario through makeGuest({...fake, port: proxy.port}, REPO, [], {autoCapture:true, captureModel:"fake/scripted"}). Head prints plugin_load, epoch_recompute, tool_result, auto_capture_start with no capture_cost; origin/main prints plugin_load, epoch_recompute, tool_result — the issue's silent log exactly.

Non-blocking

  • N1 — the unit tests pin the plugin-side contract, not delivery. Both tests stub the event bus (loaded.capture.events.push) and assert log lines; nothing in them exercises a host that fails to deliver. That is fine — the deterministic half belongs there — but the header's "Regression: a capture pass that the host never lets finish" overstates what the file executes. Say "pins the receipt and the disposal flush"; delivery stays with the e2e flaky test.
  • N2 — commit the probe. The root-cause evidence exists only as tables in the PR body. The repo's precedent for exactly this is e2e/support/probe-plugin (#395): a standalone package under e2e/support/. A turn-end-await-probe package plus the one-line runner would make RECV/HANDLED re-runnable against future host versions — which matters, because the whole "upstream, not fixable here" scope decision rests on it.
  • N3 — recordSync is not quite "same O_APPEND semantics as appendLog" (record.ts:190-191). appendLog opens with O_NOFOLLOW (publish.ts:32) and runs tightenDirectory via ensureDir (publish.ts:12); recordSync uses flag "a" and bare mkdirSync (record.ts:200-212). Low risk inside a 0700 dir, but either match the flags or fix the comment. Hot-path cost itself is fine: one synchronous append of ~280 bytes (measured line), ~4 syscalls, sub-millisecond, zero awaits — it does not consume the teardown window, consistent with the async-regression finding.
  • N4 — verdict precedence. report.ts:184 checks lastStarted before lastMissed: an old start line plus a fresh dispose renders the start verdict. Prefer whichever timestamp is newer.
  • N5 — receipt field duplication. The line carries both sid= (context) and session= (explicit field): ev=auto_capture_start ts=… sid=ses_… call=r1 … session=ses_… trigger=idle model=…. Drop one.

Scope

metrics.ts (+40), report.ts (+16), record.ts (+64) are the minimum surface for "distinct verdicts via memory_status", and no existing evidence line moved — the new events are new names only, and EvidenceEvent is an open string, so no parser break. The scope is fine; the verdict logic (B1) and the wording (B2, B3) are not.

What remains unfixed either way

Delivery is unchanged and unimproved: the host still abandons any handler that awaits a timer, and a pass disposed during the context read still leaves no trace (stated in the PR). Next tickets the maintainer should carry: (1) upstream issue — host should await, or give plugins a flush point before exit; (2) the context-read visibility gap; (3) commit the probe and re-run it per host release so "upstream" stays a measurement, not folklore.

Addresses the REQUEST_CHANGES on #474.

B1 — `auto_capture_start` is now written at the last point before the model
call, AFTER both skip returns, so a turn that deliberately skips (no signal,
thin transcript) records `auto_capture_skipped` and no start line. The receipt
means exactly one thing — the pass reached the model call — so a healthy short
turn is no longer rendered as a host-teardown cut. The fix is at the source, not
the renderer: a start line is never written on a path that then decides not to
run. The receipt still lands on a real cut (forced-cut repro: a capture-lane
delay parks the pass in `generate.text` and the line is written every run).

B2 — `auto_capture_dispose` reason is neutral (`no_turn_end_observed`) and the
event is documented as predictive: the turn-end event is delivered in every
measured run and an idle restart between turns produces it too, so it states an
absence, never an accusation of where a dispatched event went.

B3 — no issue numbers in shipped strings or added comments; the README "Am I
armed?" paragraph is reworded back to its pre-PR length (word count unchanged);
the status strings stand alone; the test header states the contract (receipt
synchronous AFTER the context read, skip writes no start, disposal flush) rather
than dated ratios or fail-before narration.

B4 — the evidence-log entry separates what was measured (the host abandons a
handler that awaits a timer, boundary below 50 ms) from what is inferred (that
this is the mechanism behind the original natural misses — a hypothesis the new
lines exist to test, since no natural miss reproduced this cycle).

N3 — `recordSync` mirrors `appendLog`'s protections (tightened directory,
O_NOFOLLOW, mode narrowed to 0600). N4 — `captureLines` renders the newer of the
start and dispose lines. N5 — the start receipt drops the duplicate `session`
field (the context `sid` already carries it).

Adds a regression test for the skip case: armed, turn-end delivered, pass
skipped, asserting no start line and a rendered health that is not the cut
verdict. Fails on the reviewed tree (a skip wrote a start line).

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

I reran the one-message transcript on Windows at dce67d1. The receipt now correctly shows auto_capture_skipped reason=transcript_too_thin, with zero model calls and no start receipt. One user-visible issue remains. Given those same evidence lines, memory_status prints “ARMED BUT NEVER FIRED” and says there were “no auto_capture_* or capture_lag lines in the last 30d.” The skip line directly contradicts that message.

captureHealth sets lastFired for the skip, but captureLines takes the never-fired branch when lastExecuted, rows, and blocked are empty. Could the status report that the turn was deliberately skipped and include its reason? A positive assertion for that verdict in the new skip test would catch this. All ten capture-start and disposal tests passed with the current assertion.

@WhollyMindless

Copy link
Copy Markdown
Contributor

I put together a small patch on top of dce67d1 if you’d like to pick it up. For the one-message transcript, memory_status now says auto-capture: on, last turn skipped (transcript_too_thin). A newer start or disposal still takes precedence over an older skip.

I changed the existing regression test to assert the displayed reason. It failed on the PR head and passed with the patch. All 69 focused status and capture tests passed on Windows, along with typecheck. Cherry-pickable commit · Download patch

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

REQUEST_CHANGES

Two blocking findings. Both are reproducible against dce67d1 with commands below. The round-1 skip bug is genuinely fixed; the fix's neighbours are not.

Blocking

B1 — the newer-of-two rule lets a benign auto_capture_dispose erase a real cut. src/status/report.ts:186-195. A later dispose line from a different plugin instance overwrites an earlier auto_capture_start with no completion, and the user is told the opposite of what happened. This is the same class of bug as round 1: a verdict driven by the wrong line.

Repro (harness, real code, one scratch test added to a scratch copy of dce67d1 — the branch itself is untouched — a pass parked inside generate.text, then disposed, then a second idle instance disposed the same day):

### pass parked inside the model call (the cut state)
  ev=auto_capture_start ts=... sid=ses-cut ... trigger=idle model=fake/model
  RENDER>   auto-capture: ARMED — a pass reached the model call but recorded no verdict; the turn-end event arrived and the pass did not complete.
### after a later IDLE instance was disposed with no turn-end event
  ev=auto_capture_dispose ts=... armed=true turn_end_events=0 passes=0 reason=no_turn_end_observed ...
  RENDER>   auto-capture: ARMED BUT NEVER FIRED — no turn-end event was observed before disposal; no pass could start.

The cut session did observe a turn-end event and did start a pass. The line now says it could not. Because every idle restart between turns writes a dispose line, the benign line will usually be the newer one, so the primary new signal is masked in the common case. docs/internals/auto-capture-evidence.md ("so memory_status renders skip, cut, and never-fired apart") and the four-row state table in test/capture/capture-start-observable.test.ts:18-22 both assert a property that does not hold.

Not blocking once: lastStarted with no completion outranks lastMissed (a start is an observed fact, a dispose is a predictive absence), or both lines render when both are set, or the comparison is scoped to one instance rather than the whole day file. Add the two-instance case as a test.

B2 — the synchronous receipt can cancel the capture it observes. src/capture/runtime.ts:641-651 calls recordSync unguarded, while the disposal flush at src/capture/runtime.ts:1192-1207 is wrapped in try/catch. When the evidence log is unwritable (read-only mount, immutable flag, foreign owner, ENOSPC — all cases src/core/permissions.ts:33 already names), the throw happens before the model call, so the pass never runs, and the subscription then stops dispatching further turns.

Repro — scratch copy of dce67d1 (git archive dce67d1 | tar -x -C <scratch>, node_modules symlinked), test file test/capture/zz-ro.test.ts: load the plugin, chmod the evidence dir 0500 and its files 0400, deliver a turn-end event with a mineable transcript, count model calls:

$ bun test test/capture/zz-ro.test.ts   # dce67d1
model calls made: 0 (1 = the pass ran)
(fail) READ-ONLY evidence dir: does the capture model call still happen?

$ bun test test/capture/zz-ro.test.ts   # origin/main, same test
model calls made: 1 (1 = the pass ran)
(pass) READ-ONLY evidence dir: does the capture model call still happen?

A control with the log left writable gives 1 call on the first turn and 2 on the next, so the second turn genuinely does dispatch — and on dce67d1 after one failed turn it stays at 0. The failure is silent by construction: the capture_threw receipt cannot be written either. On origin/main the same broken log still ran the capture. A PR about lost passes must not add a way to lose one.

Not blocking once: passesStarted++ then recordSync inside try/catch {}, same as the disposal flush, plus a test that a failing receipt write still reaches the model call.

Should fix, not blocking

The state table overstates coverage. The receipt now sits after await knownRowsFor(captureReader) (src/capture/runtime.ts:579), so a pass that cleared every skip and was cut during that store read leaves no line at all — the original silent state. I measured that read: loadAll() means 0.72 ms at 200 rows, 1.14 ms at 1000, 2.08 ms at 2000 (warm, 20 iterations). Small and bounded, so I accept the trade against round 1's false cut verdict. But src/capture/runtime.ts:636-640 justifies the placement with "the teardown contract", which describes cleanup-driven disposal, not the process exit that #406 is about; and neither README:76, nor the test header, nor the evidence doc lists the still-silent band. Say in the doc and the test header that a cut before the receipt still leaves nothing.

"Predictive" never reaches the user. no_turn_end_observed is the right rename and the hedging in src/status/metrics.ts:189-194, src/capture/runtime.ts:1185-1190 and the evidence doc is correct. The rendered line still reads as a diagnosis — "no turn-end event was observed before disposal; no pass could start" — and README:76 states the cause outright: "auto_capture_dispose an event that never arrived". Drop the causal clause from the rendered line and from README, or mark the line as unobserved.

Nits (do not hold the merge)

  • test/capture/capture-start-observable.test.ts:133 — ev.find((l) => l.ev === "auto_capture_start") dropped the session filter with the session field. The line still carries sid=ses-cut; assert l.sid === sid.
  • README:76 "an empty turn names its own cause" — four states do not cover the silent band (see above).
  • The generic inert line says "no auto_capture_* ... lines" while an auto_capture_skipped line exists. Pre-existing.
  • e2e/capture.test.ts does not assert auto_capture_start, so the forced-cut claim is pinned only in-process.

Verified

  • Tree matches the report. Moved write site src/capture/runtime.ts:641-651 (after both skip returns at 520-534 and 543-556, before generateApi.text at 652); reason renamed at src/capture/runtime.ts:1201; recordSync mirrors appendLog — mkdirSync + tightenDirectory (213-214), O_NOFOLLOW (229), fchmodSync(fd, fstatSync(fd).mode & 0o600) (233), appendFileSync (234); session dropped from the receipt and still present as sid= in the written line; new skip test present.
  • README words: git show origin/main:README.md | wc -w = 4028; wc -w < README.md = 4028.
  • No issue numbers, dates or ratios on any added line outside docs/internals/auto-capture-evidence.md: git diff origin/main...HEAD | grep '^+' | grep -nE '#[0-9]{3}|2026-[0-9]{2}-[0-9]{2}|\b[0-9]+/[0-9]+\b' returns that one doc line only. bun run lint:comments clean.
  • Test integrity 156b677..dce67d1: only test/capture/capture-start-observable.test.ts changed. No .skip, no retry, no widened timeout. Two titles reworded, one assertion changed to the renamed reason, one new test added, one session filter narrowed (nit above). Nothing weakened.
  • The round-1 regression test does fail on 156b677 with the round-2 test file: expect(received).toBe(expected) Expected: false Received: true at test/capture/capture-start-observable.test.ts:167:57 (the report says 172:57 — same assertion, line drifted).
  • Skip case, my own run: bun test test/capture/capture-start-observable.test.ts → 3 pass, 0 fail. Rendered verdict for a skipped turn is the generic inert line, not the cut verdict.
  • Cut case: pass parked inside generate.text writes auto_capture_start with no capture_cost, and it survives disposal of the cut instance.
  • bun test → 1659 pass, 21 skip, 0 fail, 151 files (report says 1620 pass). bun test e2e/capture.test.ts → 4 pass, 0 fail, all attempt 1. bun run typecheck clean. bun run lint exit 0.

If this had been approved, what would still be untrue

Capture delivery is not fixed and was not attempted. Residual risks worth tickets: the subscription stops dispatching after any evidence-write failure (pre-existing on main, B2 makes it reachable from the happy path); the health line shows nothing about a cut once any completion exists in the 30-day window; the pre-receipt silent band (context read and known-rows read) is uninstrumented by design; and the dispose line has no instance or session key, so cross-instance reasoning about it is guesswork.

…t abort a pass (#406 review)

Addresses the second REQUEST_CHANGES on #474.

B1 — the health line ranked the start and dispose signals by recency, so a
later auto_capture_dispose from an unrelated idle instance overwrote an earlier
cut and reported "never fired" for a session that did start a pass. Rank by
severity instead: a cut (a start with no completion — an observed loss) outranks
a never-fired dispose (a predictive absence), which outranks inert. A later
benign line can no longer erase an earlier loss. The precedence and which states
coexist in one 30-day window are stated in the code.

B2 — the synchronous auto_capture_start receipt was written unguarded, so an
unwritable evidence log threw before the model call, cancelling the capture and
stopping the subscription. Guard it with try/catch like the disposal flush: the
receipt is best-effort, and a failed evidence write can never abort the pass it
reports. The broader policy (the subscription stops after any evidence-write
failure) is pre-existing on main and filed as a follow-up in the PR body.

Also: README states auto_capture_dispose as an absence, not a cause (word count
unchanged at 4028); the rendered never-fired line drops its causal clause and
marks the state unobserved; the evidence doc and the test header name the still-
silent band — a pass cut during the context read or the known-rows read, before
the receipt, leaves no line; the cut test asserts the receipt by sid.

Adds two regression tests: a cut outranks a later dispose, and an unwritable
evidence log still reaches the model call. Both fail on the reviewed tree.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Round 3 review, delta dce67d1..00339d3. Approve, with the residuals stated plainly below so nobody reads this as "capture is reliable now."

Verified

  • Ranking (src/status/report.ts:181-204) is severity, not recency. 15 sequences through the real captureHealth/captureLines (scratch script, bun r3-seq.ts): cut+dispose → cut in both orders; dispose-only → neutral predictive; neither → inert; start+lag/promoted/refused/partial → alive; start+skipped → cut (a skip does not mask); 45-day-old start + fresh dispose → never-fired (window honored); 45-day-old lag does not mask a fresh cut; a newer capture=off heartbeat wins over a start. No loss renders benign beyond the documented masking; no benign state renders as a loss.
  • The masking limitation is documented in code, not only the PR body: report.ts:191-193.
  • B2 guard (src/capture/runtime.ts:648-662): the try/catch wraps only recordSync; recordSync mutates no in-memory state (src/telemetry/record.ts:205-238 — fresh openSync per call, no cached fd, so a 0400 file genuinely throws EACCES). Scratch two-turn test: receipt window blocked (0400), restored before the pass's downstream writes → both turns reach the model. The catch leaves nothing that affects the next turn.
  • The B2 test exercises the real throw path: on dce67d1 it fails at test/capture/capture-start-observable.test.ts:251:21 with reached=false — the receipt throw aborted the pass before the model call — and passes on 00339d3. A silent no-op write would pass on both. The ranking test fails on dce67d1 at :216:20 rendering the later dispose ("NEVER FIRED … no pass could start") — it fails because the cut was hidden, the right reason.
  • Delta test diff: no .skip/.only, no widened timeouts. The only assertion change is l.sid === sid added to the receipt find (test:144) — a strengthening. Skip-not-cut (test:153) and the forced-cut receipt test (test:121) are present and assert what they did before.
  • README: 4028 words on the branch and on origin/main (wc -w). No #NNN, dated ratios, or investigation narration in the delta's added lines outside the exempt evidence log.
  • Tallies reproduced here: bun test test/capture/ → 260 pass / 0 fail; bun run test → 1622 pass / 21 skip / 0 fail; bun x tsc --noEmit, bun run lint, bun run lint:comments clean.
  • PR head = 00339d3417b2d003053bf482a386016173006e08; the body's follow-up section matches what I found independently.

Nits (do not hold merge)

  • The cited fail-before lines are off by two: actual :216:20 and :251:21, not :218:20 / :253:21.
  • Pre-existing, untouched by this delta: the inert line (report.ts:202-204) claims "no auto_capture_* … lines in the last 30d" while auto_capture_skipped lines exist in the window (scratch: a skipped-only window renders exactly that line). Fold into a follow-up.

What this approval does NOT mean

  1. Delivery is unchanged. A pass cut at the model call still produces no row; the host dispatches turn-end and exits without awaiting the handler. This PR makes that visible, not rarer.
  2. The pre-receipt band (context read, awaited loadAll()) stays silent — a cut there writes nothing, the original failure signature. Documented in the test header and the evidence doc.
  3. Any completion in the 30-day window (capture_lag, a promoted row, a refusal) renders the line alive and masks a same-window cut (report.ts:191-193).
  4. auto_capture_dispose stays predictive; its target state has never been observed on a released host.
  5. Pre-existing policy stands: the capture subscription stops dispatching after any evidence-write failure. With the log permanently unwritable, turn 1 reaches the model (the new guard) but the unguarded downstream capture_cost write, then the auto_capture_refused write inside the pass-error handler (runtime.ts:1166), both throw and end the subscription loop (runtime.ts:1182). Scratch observation: turn1_reached=true turn2_reached=false. Needs its own ticket, as the body says.

@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 Astra responding on behalf of WhollyMindless

memory_status still reports “recorded no verdict” when the same session has a capture_cost receipt. That receipt is written after generateApi.text returns. Issue #406 uses its presence to distinguish a pass that got a model response from one interrupted before the response.

On 00339d3 I passed three timestamped lines through captureHealth and captureLines on Windows: plugin_load capture=on, auto_capture_start, and capture_cost text_chars=2. Both capture events used the same session ID. Removing the cost line produced exactly the same “recorded no verdict” message. Adding capture_lag switched the output to “on, last fired just now”. This was an evidence replay; all 12 focused capture tests passed separately.

Could the status distinguish “model returned, pass completion unobserved” from a start with no model response? The three-line case would make a small regression test.

@abogartz
abogartz merged commit 52cfc27 into main Nov 21, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.33.8 🎉

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.

2 participants