Repository navigation
feat(capture): mine the transcript AT compaction, before the summarizer eats it (#41) - #103
Conversation
…er eats it The compaction cliff is where episodic detail dies: one round retains ~53% of exact-wording rules. The session.compaction hook already pushes the memory anchor onto the summarizer's system parts; now it ALSO fires the auto-capture pipeline (same runWriteGate path as the idle trigger - never a direct write) against the hook payload's PRE-compaction transcript, so the facts are mined while they still exist. Rows land tagged auto-capture + auto_capture_compaction, evidence as auto_capture_compaction_<action> with a trigger field on every capture line, so decay/status can attribute capture by trigger and the real-world hit-rate comparison is log analysis, not new plumbing. captureOnCompact defaults on under the autoCapture master switch (zero-token default unchanged; setting it alone warns instead of silently costing tokens). Cooldowns are per-session AND per-trigger so measuring one trigger is not confounded by the other. Payload-less hosts fall back to session.context - the abogartz#79 envelope lesson, pinned by test. bench/capture-trigger-compare.ts measures the claim (49 queries, 3 worlds, 6 self-checks incl. a must-fail negative control): R@3 43% at-compaction vs 24% idle-after-the-cliff vs 0% off; the bench EXITS RED on src without this commit. Fixes abogartz#41.
…ction # Conflicts: # src/index.ts
abogartz
left a comment
There was a problem hiding this comment.
Adversarial review (macOS, Bun 1.4.3). Design is right and the verification discipline shows; two things must change before this lands, one of them about cost.
What I verified myself
The event-shape finding is accurate. Against the pinned dep (@opencode/plugin 2.0.32, dist/promise/session.d.ts):
export interface SessionRequest { …; system: Array<SystemPart>; messages: Array<Message>; options: SessionRequestOptions; }
export interface SessionCompaction extends SessionContext { result?: SessionCompactionResult; }
export interface SessionHooks { …; readonly compaction: SessionCompaction; … }So the hook carries the pre-compaction transcript, and setting result really does skip the summarizer — which makes your "never set result" assertion a load-bearing test, not ceremony.
Bench red-check works in both directions. Branch: exit 0, all six controls PASS. With the merge-base src/index.ts swapped back in: exit 1, compaction | session.compaction | 0 | 0% (0/49), and controls 2/4/5/6 FAIL. That is a harness that can fail, which is the standard this repo uses.
Suite/gates: lint clean, tsc --noEmit clean, bun run test → 448 pass / 5 skip / 0 fail; CI lint/test/smoke green. Cross-PR integration (89 → 101 → 102 → 103 in one worktree): clean merges, 480 pass / 0 fail.
The 8 tests are real, not stage props. capture.context.calls.length === 0 proves the payload was mined rather than silently re-read from session.context; payload immutability and the unset result pin the host contract; the negative control, the captureOnCompact:false isolation, the per-trigger cooldown split, the thin-transcript no-call path and the cleanup-inert test each fail for a reason.
Ask 1 — the cost story is undocumented, and the default is on
captureOnCompact is a new user-facing option that defaults to ON whenever autoCapture is on. Nothing in the branch documents it:
README.md:349-351— the Options table listsautoCapture,captureModel,captureMax. NocaptureOnCompactrow.README.md:35— the feature bullet still says "withautoCaptureon, session-idle events get one cheap model pass". After this PR that is false: anautoCaptureuser who compacts and then idles pays two model calls in the same 5-minute window, per session.
This project's rule is that every option and every token spend is in the README, because the zero-token default is the promise. Please add the table row (default, and that it needs autoCapture), fix the bullet to name both triggers, and state the worst case (2 calls / 5 min / session). The console.warn for captureOnCompact without autoCapture is good; the reverse case — silently doubling spend for existing autoCapture users — is the one that needs prose.
Ask 2 — the cooldown state is per setup(), and setup is not once-per-process
lastRun (src/index.ts:1050) and the new lastCompactRun are both closures inside setup. But this same file carries the lesson that setup runs more than once — bunFloorChecked exists precisely because "setup can run for more than one location". Every setup registers its own compaction hook, so with two workspaces in one process one compaction event can reach two live seams whose cooldown maps do not know about each other: two model calls on the same transcript, and two gate passes for the same candidates. The gates collapse the duplicate rows, so this is a token bug rather than a correctness bug — but it lands on a trigger that is on by default and fires mid-task, which is the worst place to pay twice.
Fix is two lines and it also fixes idle: move the cooldown to module scope keyed by ${trigger}:${sid} (the turns map in src/lock.ts is the same shape). If you can show the host really does serialize hook registration to one setup per process, say so in the body and I'll drop it.
Notes
- Numbers drifted. Body table: compaction R@3 43%. Actual bench output on this commit, and
bench/capture-trigger-results.md: 45% (22/49). Fix the body. bench/capture-trigger-results.mdis committed but cited by nothing —grep -rn capture-trigger README.mdis empty. The repo's policy is that committed bench results are published evidence cited from README (that's whyRESULTS.mdandrecall-results.mdexist). Either add the citation next to the others, or drop the file and keep the numbers in the bench header + PR body.setCurrent({ sessionID: sid })mid-flight.captureSessionbinds the session and then awaits a model call before writing;gateContext()(src/index.ts:239) andappendMemory's stamp (src/memory.ts:253-261) both resolve identity from the global current sid at write time, so whichever session set it last wins the stamp and the evidence attribution. The idle trigger could also hit this, but it fired only when a session was quiet; a compaction fires while the agent is mid-turn, so the window is now open during live activity by construction. The honest fix is to thread the sid intogateContext/the write instead of mutating module state — the same conclusion the earlier receiver-boundsession.contextfix reached. Out of scope here if you want, but it should be a ticket rather than a known blind spot.- Coverage: there is no
e2e/scenario for either capture trigger today (autoCaptureappears only intest/), so the host-shaped replay here is consistent with the idle path. Flagging rather than blocking — for a feature that costs tokens by default, a scripted-host scenario is the level of proof the rest of the repo uses.
Status
Requesting changes for Ask 1 and Ask 2. Everything else is note-level. The trigger choice — hook not event, seeded payload with session.context fallback, shared captureSession so the idle path is byte-for-byte what it was — is the right shape, and the per-trigger evidence naming means the real-world number measures itself. Branch is BEHIND main; gh pr update-branch 103 before merge.
abogartz
left a comment
There was a problem hiding this comment.
Adversarial review (macOS, Bun 1.4.3). Design is right and the verification discipline shows; two things must change before this lands, one of them about cost.
What I verified myself
The event-shape finding is accurate. Against the pinned dep (@opencode/plugin 2.0.32, dist/promise/session.d.ts):
export interface SessionRequest { …; system: Array<SystemPart>; messages: Array<Message>; options: SessionRequestOptions; }
export interface SessionCompaction extends SessionContext { result?: SessionCompactionResult; }
export interface SessionHooks { …; readonly compaction: SessionCompaction; … }So the hook carries the pre-compaction transcript, and setting result really does skip the summarizer — which makes your "never set result" assertion a load-bearing test, not ceremony.
Bench red-check works in both directions. Branch: exit 0, all six controls PASS. With the merge-base src/index.ts swapped back in: exit 1, compaction | session.compaction | 0 | 0% (0/49), and controls 2/4/5/6 FAIL. That is a harness that can fail, which is the standard this repo uses.
Suite/gates: lint clean, tsc --noEmit clean, bun run test → 448 pass / 5 skip / 0 fail; CI lint/test/smoke green. Cross-PR integration (89 → 101 → 102 → 103 in one worktree): clean merges, 480 pass / 0 fail.
The 8 tests are real, not stage props. capture.context.calls.length === 0 proves the payload was mined rather than silently re-read from session.context; payload immutability and the unset result pin the host contract; the negative control, the captureOnCompact:false isolation, the per-trigger cooldown split, the thin-transcript no-call path and the cleanup-inert test each fail for a reason.
Ask 1 — the cost story is undocumented, and the default is on
captureOnCompact is a new user-facing option that defaults to ON whenever autoCapture is on. Nothing in the branch documents it:
README.md:349-351— the Options table listsautoCapture,captureModel,captureMax. NocaptureOnCompactrow.README.md:35— the feature bullet still says "withautoCaptureon, session-idle events get one cheap model pass". After this PR that is false: anautoCaptureuser who compacts and then idles pays two model calls in the same 5-minute window, per session.
This project's rule is that every option and every token spend is in the README, because the zero-token default is the promise. Please add the table row (default, and that it needs autoCapture), fix the bullet to name both triggers, and state the worst case (2 calls / 5 min / session). The console.warn for captureOnCompact without autoCapture is good; the reverse case — silently doubling spend for existing autoCapture users — is the one that needs prose.
Ask 2 — the cooldown state is per setup(), and setup is not once-per-process
lastRun (src/index.ts:1050) and the new lastCompactRun are both closures inside setup. But this same file carries the lesson that setup runs more than once — bunFloorChecked exists precisely because "setup can run for more than one location". Every setup registers its own compaction hook, so with two workspaces in one process one compaction event can reach two live seams whose cooldown maps do not know about each other: two model calls on the same transcript, and two gate passes for the same candidates. The gates collapse the duplicate rows, so this is a token bug rather than a correctness bug — but it lands on a trigger that is on by default and fires mid-task, which is the worst place to pay twice.
Fix is two lines and it also fixes idle: move the cooldown to module scope keyed by ${trigger}:${sid} (the turns map in src/lock.ts is the same shape). If you can show the host really does serialize hook registration to one setup per process, say so in the body and I'll drop it.
Notes
- Numbers drifted. Body table: compaction R@3 43%. Actual bench output on this commit, and
bench/capture-trigger-results.md: 45% (22/49). Fix the body. bench/capture-trigger-results.mdis committed but cited by nothing —grep -rn capture-trigger README.mdis empty. The repo's policy is that committed bench results are published evidence cited from README (that's whyRESULTS.mdandrecall-results.mdexist). Either add the citation next to the others, or drop the file and keep the numbers in the bench header + PR body.setCurrent({ sessionID: sid })mid-flight.captureSessionbinds the session and then awaits a model call before writing;gateContext()(src/index.ts:239) andappendMemory's stamp (src/memory.ts:253-261) both resolve identity from the global current sid at write time, so whichever session set it last wins the stamp and the evidence attribution. The idle trigger could also hit this, but it fired only when a session was quiet; a compaction fires while the agent is mid-turn, so the window is now open during live activity by construction. The honest fix is to thread the sid intogateContext/the write instead of mutating module state — the same conclusion the earlier receiver-boundsession.contextfix reached. Out of scope here if you want, but it should be a ticket rather than a known blind spot.- Coverage: there is no
e2e/scenario for either capture trigger today (autoCaptureappears only intest/), so the host-shaped replay here is consistent with the idle path. Flagging rather than blocking — for a feature that costs tokens by default, a scripted-host scenario is the level of proof the rest of the repo uses.
Status
Requesting changes for Ask 1 and Ask 2. Everything else is note-level. The trigger choice — hook not event, seeded payload with session.context fallback, shared captureSession so the idle path is byte-for-byte what it was — is the right shape, and the per-trigger evidence naming means the real-world number measures itself. Branch is BEHIND main; gh pr update-branch 103 before merge.
Dismissed to land by maintainer decision (2026-10-25): the README gap for captureOnCompact, the per-setup cooldown maps, the bench results file and the sid-binding race are tracked as #108. Not a merge blocker.
|
🎉 This PR is included in version 0.14.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
The event-shape finding first (it decides the design)
Verified against the installed SDK (
@opencode/plugin2.0.32) before coding: the compaction moment exists on 2.x on two surfaces —session.compaction(SessionHooks.compaction: SessionCompaction): payload{ sessionID, system: SystemPart[], messages: Message[], ... }, runs before the summarizer (settingresultskips it — we never do). The payload carries the full pre-compaction transcript at the moment of maximum need.session.compaction.started/.delta/.ended/.failed— but by.endedthe context is already dead, andsessionIDlives underevent.data— the exact envelope shape that silently killed idle-capture pre-fix(capture): read session.idle and message.updated from the 2.x data envelope #79.So this rides the hook, mines
event.messagesdirectly, and falls back tosession.contextfor hosts whose payload omits messages — the #79 lesson pinned by a test.What
The compaction hook already pushes the memory anchor onto the summarizer's system parts. Now it also fires auto-capture — the same
runWriteGatepipeline as the idle trigger, never a direct write — against the transcript it's about to lose. Refactor: both triggers share onecaptureSession(sid, seeded, trigger); the idle path's behavior is byte-for-byte what it was (evidence lines just gain atriggerfield).auto-capture+auto_capture_compactiontags; evidence:auto_capture_compaction_<action>(+triggeron every capture line) → decay/status attribute capture by trigger with no new plumbing.captureOnCompactdefaults on underautoCapture(master switch untouched — zero-token default preserved; setting it alone warns instead of silently costing tokens).Measured, not asserted (
bench/capture-trigger-compare.ts, 6 self-checks)49 dataset queries, 24 facts, 150 equal distractors, shipped matcher, k=3; the cliff is simulated (53% retention, deterministic LCG) and the capture model is a scripted faithful extractor (prompt containment asserted by control 6):
The bench exits red (1) on src without this commit (compaction captures 0/24 — verified in both directions here). The real long-haul number falls out of the evidence lines:
auto_capture_*vsauto_capture_compaction_*hit-rates on a real store.Tests (
test/capture-compaction.test.ts, red-first)8 tests replaying the real registered hook through the harness: positive (payload mined, conservation, anchor contract held — hook never sets
result), negative control (no compaction → nothing captured), zero-token default,captureOnCompact:falseisolation, cooldown + trigger independence, context fallback, thin-transcript = no model call, cleanup inert. Red-check: with src stashed, exactly the 4 fix-dependent tests fail; the 4 controls correctly hold.Honest limits (documented in the bench script)
superseded_overlap). This isolates the trigger cleanly but understates real-world decision capture.cleanup()exactly like the idle path's does today (abort stops new fires only); the known module-global race during the model call is unchanged from idle.Verified
bun run test)Capture neighborhood (
capture,capture-compaction,plugin,status): 64 pass / 0 fail.tsc --noEmit+biome lintclean. New suite 8/8 on both Buns.Fixes #41.
Model-assisted work: Qwen3-flash-next (event-shape research, implementation assistance, verification).