Repository navigation
fix(capture): fire on 2.2.5 hosts and store facts, not briefs (#328 #329) - #354
Conversation
…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.
…e evidence Measured on the fixture that reproduces #329, the framing rows are an input fault, not a prompt fault. flattenTranscript hands the model the user's brief in the same undifferentiated block as the work, and the model stores the brief back as a durable preference. splitTranscript partitions the parsed turns into work (agent + tools) and user (the brief). buildCapturePrompt renders them as two labelled blocks with a rule that mines a preference from the brief only when it names a tool, package, format or convention that outlives the task. Same fixture, real builder, temperature 0, thinking on: TODAY 3 rows, 2 true framing rows, 1 lesson, preference kept ROUTED 3 rows, 0 framing rows, 2 lessons, preference kept Dropping the prose entirely also gives zero framing rows but loses the genuine preference ("we use bun here, not npm"), which is one of the six memory types, so routing beats dropping. Cost goes the wrong way: 1,007 -> 1,796 completion tokens, 19.2s -> 34.9s. More rules and a second block buy precision with reasoning. Unrelated to #330, which is about reasoning the host cannot turn off. Gate: 1066 unit + 30 e2e green, typecheck clean. Refs #329, #333
The labelled REQUESTS block stops the model storing the session's own brief back as a durable preference, but it says nothing about volume. One instruction still arrives as the same fact under three scope names, and the store's 0.9 overlap floor does not see it once the wording differs. Port the "few is better than full" rule from the prompt-rules variant of the fix. It does not improve precision — it bounds deliberation. Measured on the reproducing fixture against the rules variant, removing it took completion tokens 1,095 -> 3,084 and wall clock 19.7s -> 63.2s, with the same rows out. Refs #329 Refs #337
WhollyMindless
left a comment
There was a problem hiding this comment.
Reviewed 652ac1064199d39d1dd8169f0c8dee5a785f2ee9 against #333/#336 and the maintainer's #337 decision. The labelled split retains the thin-work fallback, shared parsing/privacy filters, and redaction before cropping. Independent native Windows / Bun 1.4.4: 82 focused tests / 371 assertions pass, typecheck passes. I did not reproduce the live-model precision/cost measurements; #338 remains the stated post-merge validation.
F1 (P2) — inherited #328 attribution regression remains in this combined PR (src/capture/runtime.ts:368–390). This is the same unresolved mechanism reported on #328, re-executed at this exact head because #354 carries that code. The new capture_threw catch still calls record(..., sid, undefined) after the capture await, resolving the session's repository at failure time.
Deterministic real-plugin/fake-host probe: start capture in A, park generation, deliver the recorded-shape session.moved event A→B, wait for the identity binding, then throw Error("private repo-a capture failure"). The refusal receipt is stamped B; a B-bound memory_evidence reader receives A's error, while an A-bound reader gets No evidence. The no-move control correctly stamps A. Result: 1 pass / 1 fail, 6 assertions. This establishes diagnostic attribution/visibility, not a durable-row leak or live-host incident.
Please preserve the capture operation's entry-time evidence context for the throwing receipt too, captured after provisional binding and before asynchronous context/model work, and pin the moving-session case. The split/prompt additions do not repair the inherited catch. No additional blocking finding from this scoped review; the implementation and merge decision remain yours.
…ailed record() resolves a session's repository at call time. The idle catch appended its auto_capture_refused reason=capture_threw line AFTER awaiting the model, so a session.moved delivered during that await re-stamped the receipt with the session's new home: repo A's private capture failure became repo B's evidence, a B-bound reader received A's error, and an A-bound reader saw no evidence at all. Bind the session and freeze the operation's evidence context in one sync step, before the first await, and thread it through both triggers: the idle catch and the compaction dispatch. captureSession now takes the frozen gate and falls back to binding it itself for direct callers. Pinned by a deterministic test through the host's own identity listener: park generate.text, deliver session.moved A to B, release with an error, and require the refusal line to carry A's repo and repoPath. That test is red before this commit and green after it.
|
Addressed in F1 fixed as requested. The capture operation's evidence context is now frozen in one sync step ( Pinned deterministically in Red/green proof: at Scope note: the mechanism came in with the #328 commits this branch carries, so the fix lands here rather than on the separate branch. |
WhollyMindless
left a comment
There was a problem hiding this comment.
Rechecked 56a0ebf72c3348dece48ca58eae17d97486304d9. F1 is resolved; this approval supersedes my earlier changes request.
The capture gate/evidence context is now frozen synchronously after provisional binding and before asynchronous context/model work, then reused by the idle failure receipt. The compaction trigger threads the same frozen gate. The main merge imports the separately reviewed #324; the capture fix/test blobs are unchanged from f908e92.
Independent verification on native Windows / Bun 1.4.4: my original moving-session probe and no-move control both pass (2 tests / 6 assertions). After A→B during parked generation, the diagnostic remains stamped A, the A-bound evidence reader receives it, and B gets No evidence. The five focused capture/privacy/emitter suites pass (83 tests / 378 assertions), and typecheck passes. All four hosted checks are green at this head.
No remaining blocking finding from my scoped review. I did not reproduce the live-model precision/cost results; the agreed merged-main remeasurement remains #338. Merge timing remains the maintainer's decision.
|
🎉 This PR is included in version 0.16.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What this lands
Four commits. The branch is stacked on
fix-capture-transcript-shape, so this carries PR #328 as well: merging it satisfies #336 and decides #337.295d0f5— read the 2.2.5 session-context shape:typeas the role,content[]as the parts, and non-conversationidlerecords filtered by aCONVERSATION_ROLESwhitelist. Before this,session.context()rendered a 0-character transcript on every live host and the 200-character floor skipped it in silence — auto-capture never fired.694a6c5— record a throwing capture (auto_capture_refused reason=capture_threw) instead of swallowing the error in the idle hook, and record thin-transcript skips (auto_capture_skippedwithchars). "Host never emitted the event" and "transcript too thin" are now distinguishable from the evidence file alone.29268ef— partition the transcript.splitTranscriptseparates what the agent did from what the user asked; the user block renders as a labelledREQUESTSsection with one expiry rule.652ac10— port the "few is better than full" rule from PR fix(capture): stop storing the session's own brief as a durable memory (#329) #331.Why the split rather than prompt rules (#337)
#329 measured 7 of 14 captured rows restating the session's own brief, one instruction arriving as three near-identical rows in three scopes.
Two candidate fixes existed. PR #331 added three prose rules to
buildCapturePrompt. This branch changes the input instead: the model sees the brief as a separate, labelled block, so it does not have to infer which half of an undifferentiated transcript is the task.Work-block-only capture was also tested and also fails: zero framing rows, but zero real preferences too, because "we use bun here, not npm" lives in the same prose as the constraints. Labelling the block keeps both.
The hint-chain benchmark validated
29268efend-to-end on 2026-11-07: 30/30 chain links, zero framing rows. PR #331 was only ever measured offline against the fixture.The one rule ported from PR #331
The labelled block fixes framing but says nothing about volume, and it removes the deliberation bound. Without "few is better than full", the same seat on the same fixture went 1,095 → 3,084 completion tokens and 19.7 s → 63.2 s, with the same rows out. That line is cost control, not precision, so it is kept unconditionally — it applies to both block shapes.
The other two rules from #331 are not ported. "Skip the task as it was asked" is what the
REQUESTSrule does, more sharply. The durability test is already covered by the existing "details that only mattered inside this conversation" skip plus theREQUESTSexpiry rule. Merging all three onto the split would give a small capture model two overlapping rule sets, which is the contradiction #337 warns against.Fallback kept
buildCapturePromptstill renders the single un-partitioned block when the work lines alone are under 200 characters (seeded or compacted transcripts). Dropping the prose on that path would silently change capture behavior.Test plan
bun scripts/merge-gate.ts— 1048 pass / 19 skip / 0 fail unit, 30 pass e2e, typecheck clean, lint and format clean.idlerecords never render; a throwinggenerate.textlandsauto_capture_refused reason=capture_threw; a <200-char transcript landsauto_capture_skipped.REQUESTSblock, its absence on the fallback path, and the new volume bound.f908e92— the throwing-capture receipt keeps the operation's entry-time evidence context, so asession.movedduring the model call cannot re-stamp repo A's failure as repo B's evidence. Pinned by a parkedgenerate.textplus a realsession.movedA→B through the host's identity listener (review F1 on this PR).Refs #329 — leave it open until #338 records the post-merge numbers.
Closes #336. Refs #337 — close that one after #338 records the numbers, not on merge. Part of #333.