Repository navigation
Description
Summary
A real opencode run turn does fire an auto-capture pass. The pass then loses its own result: opencode run disposes the plugin the moment the turn ends, captureCleanup aborts, and the pass stops between the model answer and the write gate.
Measured on 12 identical runs on 2026-11-13, macOS, host pinned by package.json, scripted instant model:
passes started (ev=capture_cost) |
12 / 12 |
passes that reached the gate and recorded (ev=capture_lag) |
3 / 12 |
The model answers instantly in these runs. A real model takes seconds, so on a normal CLI session the host is gone before the answer arrives. This is the most likely explanation for the README's standing note that auto-capture has never been observed firing on a live store: the trigger works, the write does not survive.
Mechanism
src/capture/runtime.ts captureCleanup:
captureCleanup = async () => {
controller.abort();
await drainInFlight();
};and inside a pass, after the model call and between candidates, if (controller.signal.aborted) return;.
That is the #211 contract, stated at src/capture/runtime.ts:232-247, and its purpose is sound: a pass must not run the write gate against a store its caller has already torn down, and a gate already mutating is never cut in half. The drain is 1000 ms and the comment is explicit that "teardown never waits on the model".
What the contract does not distinguish is the case where nothing is being torn down. On opencode run the store is not removed and no caller waits for cleanup — the process simply exits. The abort therefore fires on the healthy path, and it fires in the one window where capture is allowed to run, because capture is triggered by the turn-end event.
The evidence trail shows the cut point exactly. A lost run ends here:
plugin_load, epoch_recompute, tool_result, capture_cost
A won run continues:
..., capture_cost, gate_start, graph_current, ref_stale_scan, dedup_clean,
write_promoted, auto_capture_promoted, auto_capture_scan, capture_lag
Why no existing test saw this
Every capture test constructs the event envelope and the session.context by hand and keeps the process alive, so the abort never fires during the pass. The fabricated envelope is precisely what let this feature pass its tests while dead (#402 records the same failure mode from the other direction). e2e/ drove the real host for loading, the store, the ledger, compaction and the viewer, but never capture — and could not: the fake provider only served scenario steps to requests carrying a tools array, and the capture call is a plain generation with none, so the scripted capture reply was unreachable. Both gaps are closed by the e2e/capture.test.ts added alongside this issue (capture lane in e2e/support/fake-model.ts).
Reproduction
e2e/capture.test.ts asserts the parts that hold under the race and prints [capture-race] when the pass is cut; running it repeatedly shows the rate. To measure it directly, run the scenario in a loop and count ev=capture_cost against ev=capture_lag.
Candidate fixes, with the risk each carries
- Let a pass that already holds its model answer finish, bounded by the drain. Distinguish "no new passes" (abort the subscription, unchanged) from "stop writing" (do not abort a pass past the model call). The drain still protects the store-removal case, because it waits for the pass. Risk: it weakens Capture lifecycle: define and stop work that continues after plugin cleanup #211 exactly where Capture lifecycle: define and stop work that continues after plugin cleanup #211 was written to be strong, so it needs the disposal test to be re-derived rather than kept.
- Give the host a reason to stay. Out of this repo's control.
- Accept it and say so. If capture cannot survive CLI teardown, the switch should report that rather than burn a model call per session and store nothing.
capture_costalready records the call; aoutcome=abortedline would make the loss visible in the trail instead of silent.
1 is the fix; 3 is the minimum honesty step if 1 is judged too risky. Either way the trail should distinguish "the pass found nothing" from "the pass was cut", which today it cannot: a cut pass records nothing at all after capture_cost.
Notes
- Discovered while writing the end-to-end capture scenario for feat(capture): tag restatable rows instead of dropping them (#402) #403, not by changing capture behaviour. Nothing here is caused by feat(capture): tag restatable rows instead of dropping them (#402) #403; the race predates it.
- The
e2escenario is deterministic as written (5 consecutive green runs) because it asserts only what the race permits. It should be tightened to require the row unconditionally once this issue is fixed.
Activity
test(e2e): drive auto-capture through a real host, and find it loses …
fix(capture): stop teardown abandoning a capture pass that already an…
abogartz commentedon Nov 13, 2026
Fix landed on the branch carrying #403 (
e12c8a3, PR #403), per the maintainer's instruction to keep the fix with the change that surfaced it rather than open a second PR.\n\nTwo-phase teardown:captureCleanupabandons only a pass still parked ingenerate.textand drains one that already holds its answer. All of #211's disposal assertions pass unchanged. Option 3 (anoutcome=abortedline) was implemented and then removed: it breaks #211's tested "nothing at all after cleanup" contract in all four of its cases, becauseappendLogcallsensureDirand the receipt resurrects a directory the caller deleted. The gap in the existing lines carries the same information —capture_costwith no latercapture_lagfor that session is a pass that was cut.\n\nMeasured A/B/A, 12 runs each: 12/12, 6/12 reverted, 12/12. The scenario ine2e/capture.test.tsnow asserts the row unconditionally. Leaving this issue open until #403 merges.test(e2e): stop reporting a missing trigger event as a teardown failu…
chore(release): 0.25.0 [skip ci]
abogartz commentedon Nov 21, 2026
Verified fixed on main — closing.
Two-phase teardown landed in
e12c8a3(fix(capture): stop teardown abandoning a capture pass that already answered), merged with PR #403 on 2026-11-13.captureCleanupinsrc/capture/runtime.tsnow aborts only NEW passes and callsdrainInFlight(), which abandons a pass still parked ingenerate.textand drains one that already holds an answer.The 3-of-12 figure no longer holds: README now reports that a capture pass starts in 12 of 12
opencode runruns (e2e/capture.test.ts), ande2e/capture.test.tsassertsoutcome=candidateson the lastcapture_lagline.Checked against
origin/main@c48aea6(v0.33.7). The separate open question — no live store has ever been observed completing a pass — is tracked by the README caveat and #386, not this ticket.