Skip to content

fix(capture): fire on turn-end events; session.idle is never emitted (#136) - #142

Merged
abogartz merged 3 commits into
mainfrom
fix/capture-trigger-2x
Oct 26, 2026
Merged

abogartz merged 3 commits into
mainfrom
fix/capture-trigger-2x

Conversation

@abogartz

@abogartz abogartz commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #136. Partial #137, #138.

What was wrong

Auto-capture has never run on any opencode 2.x host. The subscription waited on event.type === "session.idle"; a live desktop service never sends it. Zero capture_lle/capture_lag and zero auto_capture_* lines exist in the entire 10-day evidence history on the machine that developed the feature.

session.idle is declared by the protocol and never emitted — see the correction on #136, which also explains why the obvious "use the schema-correct name" fix would have produced a second dead subscription (session.status is not emitted either).

What this does

  • Trigger = recorded reality: session.execution.succeeded and session.execution.interrupted, both captured from a running host (the latter by interrupting a live turn). Declared-but-unobserved names (session.idle, session.status, session.execution.failed) are deliberately excluded, with the reasoning in a comment where someone will be tempted to add them back on faith.
  • plugin_load heartbeat (No artifact distinguishes capture off / misconfigured / inert: add plugin_load heartbeat and hook_error evidence #138): version, capture=off|invalid_model|no_capabilities|on, capabilities present, subscribed vocabulary. "Off", "misconfigured" and "armed but inert" are now one line apart in the evidence log instead of an hour of archaeology. Guarded, so a corrupt store cannot turn plugin load into a throw.
  • test/event-fidelity.test.ts + test/fixtures/host-events.jsonl (Capture tests fabricate {type:"session.idle"} — the green suite pins a trigger the host has never sent #137): every capture trigger must appear in the manifest and in a recording of the live host. The recording assertion is the one that would have caught this two releases ago. Fixture holds event names and counts only — no payloads, no prompt content.
  • The capture tests stop fabricating the envelope. They drove {type:"session.idle"}, which is how 480 green tests pinned a trigger that does not exist.

Evidence

  • Against pre-fix src: 17 failures across the four touched suites — 12 capture, 3 compaction, 1 fidelity (import), 1 framing (the red-check).
  • With the fix: 532 pass / 12 skip / 0 fail, tsc --noEmit clean, biome lint warnings only (+1 noExplicitAny from the heartbeat cast, matching the existing baseline style).
  • Live recordings behind the trigger set: /tmp/sse{2,3,4}.txt on the dev box, summarised into the committed fixture.

Not here

Second commit: the pre-push gate was lying (#141)

While pushing this, the hook failed a gate that passed by hand. Cause: git exports
its own environment to hooks, so GIT_DIR/GIT_WORK_TREE point every test at
this repo. test/init.test.ts measured 6/6 green → 2 failures on GIT_DIR
alone
; the repo-scoped capture test and a serve-host replay time out the same
way. The gate's verdict under a hook was not the verdict of the same code path —
which mostly trains you to reach for SKIP_GATE=1.

scripts/merge-gate.ts now scrubs every GIT_* variable before spawning any
step and logs the count. Re-run with GIT_DIR and GIT_WORK_TREE exported:
521 unit / 11 e2e / 0 fail.

abogartz and others added 2 commits October 26, 2026 15:14
…136)

Auto-capture has never run on any opencode 2.x host. The subscription waited
for `event.type === "session.idle"`, and a live desktop service (2.1.4) never
sends it: 150 s of its own SSE stream over a complete turn plus 80 s of quiet
produced `session.execution.started` -> steps -> `session.usage.updated` ->
`session.execution.succeeded`, and no `session.idle` or `session.status` at all.
Zero `capture_lag` lines exist in the entire evidence history.

`session.idle` IS declared by the protocol, which is why schema membership
alone was never going to catch this — the authority has to be a recording of
the host. So the trigger set is now `session.execution.succeeded` and
`session.execution.interrupted`, both actually recorded (the latter by
interrupting a running turn). Declared-but-unobserved names stay out: adding
one later costs a line, and shipping them is how #136 happened.

Also:
- `plugin_load` heartbeat (#138): version, `capture=off|invalid_model|
  no_capabilities|on`, capabilities present, and the subscribed vocabulary, so
  "off", "misconfigured" and "armed but inert" are distinguishable from the
  evidence log instead of from an hour of archaeology. Guarded — a corrupt
  store must not turn plugin load into a throw.
- `test/event-fidelity.test.ts` + `test/fixtures/host-events.jsonl` (#137):
  every capture trigger must appear in the manifest AND in the live recording.
  The recording assertion is the one that would have caught this two releases
  ago. Fixture holds event names and counts only — no payloads.
- Capture tests no longer fabricate the invented envelope; they drive the
  recorded ones. Against pre-fix src these are red (9 failures); with the fix,
  532 pass / 12 skip / 0 fail, tsc clean, lint at baseline.
- `bench/live-capture-audit.ts` and `bench/live-capture-run.md`: the live
  dogfood harness, its rubric (locked before data), and the run's findings,
  including that relaunching the desktop app does not restart the service that
  holds the parsed plugin options.

Co-Authored-By: Claude <[email protected]>
The pre-push hook runs with git's own environment exported. Tests that assert a
temp dir is NOT a git repo, or that resolve repo scope from the working tree,
then see this repository instead of nothing: `test/init.test.ts` goes from 6/6
green to 2 failures on `GIT_DIR` alone, and the repo-scoped capture and
serve-host tests time out for the same reason. Every push under the hook looked
like a broken build that was not — while the same command run by hand, or by
CI, passed.

Verified by re-running the full gate with GIT_DIR and GIT_WORK_TREE exported:
521 pass / 0 fail unit, 11 pass e2e.

Co-Authored-By: Claude <[email protected]>
@abogartz

Copy link
Copy Markdown
Owner Author

Formal verdict: CHANGES_REQUESTED (posted as comment — GitHub blocks formal change-requests on one's own PR; treat this as blocking until the ask below is addressed)

Verdict: CHANGES_REQUESTED — the fix is verified and mergeable; two undeclared files must come off the branch

Reviewed head 9e5d3db on macOS, local Bun 1.4.3, worktree at /tmp/osi-142.

What I verified independently (all claims below were reproduced, not taken from this body)

The bug is real and the trigger set is recorded, not guessed.

  • session.idle is declared in the installed schema (@opencode/schema/dist/event-manifest.d.ts:5971 Schema.Literal<"session.idle">) — so the body's "declared, never emitted" is the accurate framing.
  • Cross-checked test/fixtures/host-events.jsonl against the raw recordings /tmp/sse{2,3,4}.txt on this machine: all 27 lines match exactly (e.g. skill.updated 36+36+72=144, session.execution.succeeded 1+1+1=3, interrupted=1, session.step.failed=1). session.idle, session.status, session.execution.failed appear in zero recordings.
  • Envelope shape confirmed from the raw SSE: {"type":"session.execution.succeeded","data":{"sessionID":"ses_…"}} — the event.data?.sessionID priority in the subscription matches what the host actually sends.
  • Zero genuine capture_lag/auto_capture_* in the 10-day evidence history (the only two matches today are tool_result echoes of archaeology greps, not capture activity).

Gates reproduce.

  • Branch: 521 unit + 11 e2e = 532 pass / 12 skip / 0 fail; tsc --noEmit clean; CI green on all four legs incl. test-windows.
  • Red check: branch tests against merge-base src/ fail hard — 12 (capture) + 3 (compaction) + 1 (fidelity import) + 1 (framing). The tests genuinely pin the bug.
  • Pre-push gate runs under git's exported GIT_DIR, so it fails tests that CI passes (and vice versa) #141 reproduced exactly: GIT_DIR alone → test/init.test.ts 6/6 green → 2 failures; with the scrub, merge-gate.ts run under exported GIT_DIR+GIT_WORK_TREE logs scrubbed 2 GIT_* variables and passes 521+11/0. Hook wiring (core.hooksPath=.githooks → bun run gate) confirmed.

Design checks that passed: fidelity test has anti-vacuity controls (parse counts >50/>10) and pins the bug in both directions (idle declared ∧ unobserved ∧ not subscribed); negative tests pin all three excluded events; heartbeat states match the real gating logic (autoCapture===true ∧ valid captureModel, src/index.ts:1195-1204); heartbeat is guarded so a broken store can't throw on load; fixture holds names/counts only — no payloads; cooldown stays module-level and shared (#108 preserved); exclusion of session.execution.failed is documented and test-pinned, not silent.

Blocking

  1. bench/live-capture-audit.ts and bench/live-capture-run.md are undeclared scope and violate the repo's dev-artifact policy. Neither is mentioned anywhere in this body — the body enumerates its changes carefully, which makes these the git add -A trap, not an oversight of description. Concretely:

    • The runbook is machine-local dev state: backup paths with timestamps, ~/.config paths, "Status: armed", a reset procedure, the local capture-model seat. This is exactly the "review/report .md are development-only, NEVER committed" category.
    • Nothing in README/docs cites either file (the standing exception is only for cited, reproducible evidence files like bench/RESULTS.md).
    • The runbook actively contradicts the shipped code: F1 asserts "There is no session.idle event type at all", while this PR's own fidelity test pins the opposite (expect(declaredSet.has("session.idle")).toBe(true)) and is correct — the manifest declares it at line 5971. Committing it creates a doc-code drift surface that will mislead the next reader, which is the precise failure mode this policy exists to prevent.
    • It also couples an in-flight experiment harness (rubric "locked before data", experiment not yet run) to a bugfix release. If the audit rubric changes mid-experiment, main carries a stale copy.

    Ask: drop both files from the branch (keep them in the working tree / tmp for the armed run — they're good artifacts, just not repo content). Everything else here is ready to merge on my side.

Nits (non-blocking)

  1. Red-check count doesn't reproduce: body says "9 failures in the capture suites"; I measure 17 across the four touched suites (15 counting only capture+compaction). Direction is right, number is understated — worth fixing in the body so future archaeology matches.
  2. "biome lint at baseline (same as main)" is +1 warning off: the heartbeat's as Record<string, any> (src/index.ts:1349) adds one noExplicitAny. Consistent with the existing baseline style, so fine to keep — but "same as main" is not exact.
  3. The heartbeat's store_rows: (await loadAll()).length reads the whole store on every setup() (×3 per service start). Harmless at current store size; if the store grows, consider counting lazily or once per process.

)

Machine-local experiment artifacts (backup paths, armed state, reset
procedure) cited by nothing; the runbook's F1 also contradicts the
fidelity test this PR ships. Kept in the author's working tree.
@abogartz
abogartz merged commit 429c5f5 into main Oct 26, 2026
4 checks passed
@abogartz

Copy link
Copy Markdown
Owner Author

Fixes applied (1f4ac1b): dropped the two undeclared bench files (kept untracked in the author's working tree for the armed run); body red-check corrected 9→17 and lint claim made exact. Gates re-run on the final head: tsc clean, 521 pass / 12 skip / 0 fail. Merged.

@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.14.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the fix/capture-trigger-2x branch October 26, 2026 23:51
WhollyMindless added a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Oct 27, 2026
CI runs the PR merge commit, and main (0.14.10, abogartz#142) added an
`ev=plugin_load` boot record: instance B's own line — a session-less
write, legitimately stamped with B's repository under the very rule
this round fixed — shares the day file with A's tool_result. Probe 2's
whole-file `not.toContain` tripped on B's legitimate stamp; A's line
itself was correctly unstamped on CI too. Scan the line carrying A's
marker instead: the smoking-gun line is the one that must lose the
foreign repo= field. Red at d56956e (A's own line carries B's stamp
there), green at the fix; unrelated stamped lines cannot redden it.
WhollyMindless added a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Oct 27, 2026
CI runs the PR merge commit, and main (0.14.10, abogartz#142) added an
`ev=plugin_load` boot record: instance B's own line — a session-less
write, legitimately stamped with B's repository under the very rule
this round fixed — shares the day file with A's tool_result. Probe 2's
whole-file `not.toContain` tripped on B's legitimate stamp; A's line
itself was correctly unstamped on CI too. Scan the line carrying A's
marker instead: the smoking-gun line is the one that must lose the
foreign repo= field. Red at d56956e (A's own line carries B's stamp
there), green at the fix; unrelated stamped lines cannot redden it.
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.

Auto-capture subscribes to session.idle, which opencode 2.x never emits — the feature has never run

1 participant