Skip to content

fix(capture): read the 2.2.5 session context shape so auto-capture can fire - #328

Closed
abogartz wants to merge 2 commits into
mainfrom
fix-capture-transcript-shape
Closed

abogartz wants to merge 2 commits into
mainfrom
fix-capture-transcript-shape

Conversation

@abogartz

@abogartz abogartz commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Why auto-capture has never fired

The README says auto-capture "has never been observed firing on a live opencode 2.x store". A live probe finds the reason, and it is not the trigger.

Probe: throwaway HOME, autoCapture: true, opencode serve (long-lived, so the host survives turn end), one real turn, plus a second plugin that records every event delivered to subscribers.

What the store and the recorder show, in order:

  1. ev=plugin_load … capture=on subscribed=[session.execution.succeeded,session.execution.interrupted] — the subscription registers.
  2. The recorder sees session.execution.succeeded arrive flat, exactly the shape captureTriggerFor matches, with the session id under data.sessionID, which is the first form captureSessionID tries.
  3. Instrumented dispatch: trigger matched → dispatching capture → captureSession enter {writeTarget:true} → transcript {"chars": 0} → too thin, skip.

So the event fires, the session resolves, and the transcript is empty. session.context() on 2.2.5 returns:

{id, time, type:"user",      text, files}
{id, time, type:"assistant", agent, model, content:[{type:"reasoning"|"tool"|"text", …}], …}
{id, time, type:"idle",      outcome}

There is no role and no parts. flattenTranscript read only info.role | role and parts[].text, so every message failed if (!role || !text.trim()) continue and the transcript rendered as "". The 200-character floor then returned without recording anything, which made a permanently dead feature indistinguishable from a session with nothing worth remembering. That silence is the second bug, and it is why this survived a host generation.

Fix

  • src/capture/transcript.ts — accept the role under type, restricted to user/assistant (2.2.5 interleaves a non-conversation idle record in the same array), and read parts from content[] when parts is absent. Reasoning parts stay excluded; tool parts still contribute nothing, so the transcript keeps its old size.
  • src/capture/runtime.ts — record auto_capture_skipped reason=transcript_too_thin chars=N on that return, and auto_capture_refused reason=capture_threw error=… (redacted, capped) where the turn-end handler previously swallowed every error from captureSession. Fail-closed for the session; visible in the store.
  • test/fixtures/host-session-context-2.2.5.json — the real recorded context, plus unit tests for the shape, the new evidence lines, and a throws seam in the test harness.

Verified live, not just in tests

Same probe, same server, with this branch:

probe transcript {"chars":613}
probe generating {"model":"evo/Qwen3.8-Flash-Next-UD-Q4_K_XL","promptChars":613}
ev=auto_capture_promoted … trigger=idle type=blocker scope=math reason="" model=evo/…
ev=capture_lag … outcome=candidates
row: tags=auto-capture kw=math.ts,addition,subtraction,operator,bug

Turn ended 00:52:22, row landed 00:52:47 — 25 s after the user already had their answer, off the critical path.

Gate: typecheck, bun run lint, 1041 unit tests, 30 terminal/BDD tests against a real opencode host — all green.

What this does not close

Refs #325, #327. Found by the #315 benchmark work.

…n fire

Auto-capture has never fired on a live host, and nothing said why. A live
probe against opencode 2.2.5 (long-lived server, autoCapture on) shows the
trigger arrives and resolves: session.execution.succeeded is delivered flat,
captureSessionID finds data.sessionID, writeTarget is ok. Then
session.context() returns messages whose role lives under `type` and whose
parts live under `content[]`:

  {id, time, type:"user", text, files}
  {id, time, type:"assistant", agent, model, content:[{type:"reasoning"|"tool"|"text", ...}], ...}
  {id, time, type:"idle", outcome}

flattenTranscript read only info.role | role and parts[].text, so every
message failed the `if (!role || !text.trim()) continue` test and the
transcript rendered as "". The 200-character floor then returned without
recording anything, which made a dead feature indistinguishable from a
session with nothing worth remembering.

- transcript.ts: accept the role under `type` (restricted to user/assistant,
  since 2.2.5 also interleaves a non-conversation `idle` record) and read
  parts from `content[]` when `parts` is absent. Reasoning stays excluded;
  tool parts still contribute nothing, so the transcript keeps its size.
- runtime.ts: record `auto_capture_skipped reason=transcript_too_thin
  chars=N` on that return. The silence is the bug that hid the bug.
- test/fixtures/host-session-context-2.2.5.json: the real recorded context,
  plus unit tests for the shape and for the new evidence line.

Verified live with the same probe: transcript 613 chars, capture model
called, `ev=auto_capture_promoted`, and a tags=auto-capture row in the store
25 s after the turn ended.
The same silence that hid the shape break has one more instance: the turn-end
handler caught every error from captureSession and recorded nothing, so a
capture that died mid-model-call looked identical to one that never ran.

Record `auto_capture_refused reason=capture_threw error=...` (redacted, capped
at 200 chars) on that path. The session still sees nothing — fail-closed is
the right contract for the host — but the store now does.

Adds a `throws` failure seam to the test harness's generate stub.

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

Reviewed head 694a6c5c5ae4a2f3bd3a9c41d39674775939e916 locally on native Windows / Bun 1.4.4. The five focused capture, crop/privacy and emitter-attribution suites pass: 75 tests, 352 assertions; typecheck passes. The new fixture reaches generation and excludes its reasoning text. I did not repeat the live-host model probe reported in the PR body.

F1 (P2) — Preserve the operation's attribution for the new throwing-capture receipt (src/capture/runtime.ts:358–383). The new catch calls record(..., sid, undefined) after awaiting captureSession, so record captures the session's repository at failure time rather than using the entry-time captureGate.evidenceContext already used by the other capture receipts. This reintroduces the lifecycle split addressed by #199 for this new path.

Deterministic reproduction through the real plugin harness (temporary stores, no external model): start idle capture in repo A; park generate.text; deliver the recorded-shape session.moved event from A to B and wait until the identity subscriber binds B; release generation with Error("private repo-a capture failure"). The resulting auto_capture_refused reason=capture_threw has repo=B and B's repoPath. A separate B-bound session's memory_evidence reads that error, while an A-bound session gets No evidence. The otherwise identical no-move control stamps A and is invisible to B. The ownership regression probe is 1 pass / 1 fail at this head.

Please retain the capture's entry-time evidence context for the failure receipt too, capturing it after the provisional bind and before asynchronous context/model work, and pin the moving-session error case. Keeping sid explicit alone does not freeze its repository. This finding concerns diagnostic attribution/visibility; it does not establish a durable-memory-row leak or a live-host incident.

@abogartz

abogartz commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Closing as superseded by #354. Nothing here is unfixed — it is fixed on the branch that carries this one.

capture-input-shape contains both commits of this PR (295d0f5, 694a6c5) plus the labelled-split work, so this PR's head is an ancestor of #354's head. Merging #354 lands everything in this diff.

F1 from the review is resolved at f908e92 on #354, exactly as requested: the capture operation's evidence context is frozen in one sync step (bindCapture) after the provisional bind and before the first await, and threaded into the idle catch (which passed undefined) and the compaction dispatch. Pinned by a deterministic test — park generate.text, deliver the recorded-shape session.moved A→B through the host's identity listener, release with an error, assert the refusal line carries A's repo and repoPath. Red at 652ac10 (Expected: "bd53ba33c4bb" / Received: "ce5cb1272ca5"), green at f908e92.

Why close rather than leave open: this head still carries the bug the review found. Merging #328 alone would ship the unfixed catch. Cherry-picking the fix onto this branch instead would put the same lines on both sides of a merge for no gain.

Part of #333; #336 is satisfied when #354 merges.

@abogartz abogartz closed this Nov 8, 2026
abogartz added a commit that referenced this pull request Nov 8, 2026
fix(capture): fire on 2.2.5 hosts and store facts, not briefs (#328 #329)
@abogartz
abogartz deleted the fix-capture-transcript-shape branch November 19, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants