Skip to content

feat(capture): name every turn-end arrival with auto_capture_seen - #525

Merged
abogartz merged 2 commits into
mainfrom
fix/406-arrival-receipt
Nov 25, 2026
Merged

abogartz merged 2 commits into
mainfrom
fix/406-arrival-receipt

Conversation

@ocsi-fixer

@ocsi-fixer ocsi-fixer Bot commented Nov 25, 2026

Copy link
Copy Markdown

Closes #406. The architecture review (posted on the issue) measured the current loss
rate at zero across ~206 real-host turns — the ticket-era 2-of-8 is falsified,
though a ~1%-class rate is not excluded (P(0/206 │ p=0.01) ≈ 0.13). What remains real
is the ticket's other half: a delivered turn-end event could still vanish without a
store trace, through the no_sid skip, the cooldown skip, the arrival-to-start band,
and a dispose-flush that suppresses itself whenever any event arrived. This PR ships
the one arrival receipt that makes every future loss attributable, plus the companions
that keep it from lying.

The receipt

Three synchronous recordSyncBestEffort("auto_capture_seen", …) writes in the idle
dispatch loop (src/capture/runtime.ts), each before the branch decision it names:
discard:"no_sid" inside the undefined-sid branch before its continue,
discard:"cooldown" inside the cooldown branch before its continue,
discard:"none" on the proceed path before newPhase()/bindCapture. One line per
delivered event, no new await before bindCapture; auto_capture_start stays exactly
where the earlier severity trade pinned it — arrival attribution without unpinning the
start boundary.

The guard that keeps it honest

src/status/metrics.ts handles auto_capture_seen in a dedicated branch before the
generic auto_capture_* fall-through (verified: seen-branch continue at :300, generic
gate at :302, lastFired advance at :323 — the receipt can never reach it). Only
discard=none sets the new lastArrived; arrivedWithoutStart withholds its verdict
when a deliberate auto_capture_skipped is newer than the arrival, and when timestamps
collide in the same millisecond (withholds, never invents). src/status/report.ts adds
one severity slot between cut and never-fired — ARMED BUT NEVER STARTED — with the
existing arms byte-identical, and a store containing no seen lines renders the
pre-existing verdicts verbatim (pinned by exact strings).

Rate honesty in e2e

turnUntilCaptureStarts now classifies every failed attempt: a seen receipt with no
start counts arrived-lost, and the printed rate always carries the number — a retry
success no longer erases the loss it masked (#406's own body asks for exactly this).
Test-1's failure claim "not reaching the plugin at all" is conditional on
arrivedLost === 0: verifiable, not inferred.

Proof

Mutant table (each write deleted, restore verified byte-identical):

Mutant Red Green
no_sid write no_sid test cooldown + none tests
cooldown write cooldown test no_sid + none tests
none write ordering test and cooldown test no_sid test

Verifications: typecheck clean; lint + format:check clean; comment-lint vs base clean
(102 added comment lines); full suite 1808 pass / 22 skip / 0 fail; dispose-drain
×5 and capture-start-observable ×5 each 0 fail; e2e solo, alternating base/head ×3:
attempt-1 starts 9/9 base and 9/9 head, arrived-lost 0 at head in all runs — no new
loss class
. Scope: 8 files, src/ confined to runtime/metrics/report; bench fixture
and README untouched; no pre-existing assertion edited (the one capture-start-observable
change is a header comment whose "stays silent" claim became false; the status.test.ts
diff has zero removed lines).

A design note the tests pin: bounding arrivedWithoutStart by the newest skip's
timestamp is what keeps the healthy thin-transcript-skip trail rendering the old inert
verdict instead of a false ARMED-BUT-NEVER-STARTED — without it the pre-existing skip
test goes red, so the bound is requirement-shaped, not defensive decoration.

…ceipt

The idle dispatch loop counted delivered events in process memory only, so
an event skipped for a missing session id or a cooldown, or lost between
arrival and the start receipt, left no store trace. Every delivered event
now writes auto_capture_seen synchronously before the loop's skips, with
discard=none|no_sid|cooldown; metrics handles it ahead of the generic
auto_capture_* fall-through so it never advances lastFired, tracks
lastArrived, and reports an arrival that no start or skip accounts for.
The status ranking gains one slot between cut and never-fired; stores with
no arrival lines render unchanged. The e2e retry now prints the
arrived-lost count it masks.
@ocsi-fixer
ocsi-fixer Bot requested a review from abogartz as a code owner November 25, 2026 02:48
@ocsi-reviewer

ocsi-reviewer Bot commented Nov 25, 2026

Copy link
Copy Markdown

Review: PR #525 — combined seat (architecture conformance + code review)

Disclosing up front: this seat performed both the architecture-conformance pass against the #406 review's Standard and the full code review. One reviewer, both hats.

Verified at head 57acf32 against base 19ca5b3 in scratch copies (git archive, checkout untouched). Claims below were measured, not read.

Conformance

All four required items ship, and both forbidden outcomes are held:

  1. Receipt before the discards — src/capture/runtime.ts:1186-1216: one recordSyncBestEffort("auto_capture_seen", …) directly after turnEndSeen++, with no_sid written inside the undefined-sid branch before its continue, cooldown before the cooldown continue, none on the proceed path before newPhase(). All three synchronous, session passed as the context argument on the two sid-carrying writes, auto_capture_start unmoved.
  2. Metrics early handling — the auto_capture_seen branch at src/status/metrics.ts:286 continues before the generic auto_capture_ gate at :303, so the receipt can never reach the lastFired advance at :323. Only discard=none sets lastArrived; a seen line with no discard field claims nothing (pinned behavior: String(f.discard ?? "") === "none").
  3. e2e rate honesty — turnUntilCaptureStarts classifies each failed attempt (receipt count grew, start count did not) and the count rides back on the result, so it is printed on eventual success, not only on failure. Test-1's "not reaching the plugin at all" is conditional on arrivedLost === 0.
  4. Doc row — new bullet in docs/internals/auto-capture-evidence.md names auto_capture_seen alongside the start receipt, and the prior bullet's "stays silent" claim is corrected to "names the band without moving the start line."

Forbidden: lost turn reading as FOUND — the seen branch continue is the structural guarantee; the pinned test asserts lastFired stays null for a seen-only trail. Forbidden: new logging — the only added recordSync* calls in the whole diff are the three receipt writes; the three console.log additions are the e2e rate lines, replacing (not adding to) the existing print.

Same-millisecond collision, constructed (not just read): built trails at head where seen(discard=none) and start share one timestamp → arrivedWithoutStart=false, verdict renders the pre-existing cut arm, no ARMED-BUT-NEVER-STARTED. Same-ts with auto_capture_skipped instead of start → no verdict, inert rendering preserved, in both line orders. Stepping the arrival +1 ms past the start restores arrivedWithoutStart=true (cut still outranks, correctly — a start exists). The strict > is the whole tie policy and it withholds, never invents. Nit: this behavior is implemented but not pinned — no test in the diff uses a same-ts pair (all fixtures use at(6)/at(5)). A follow-up pin would be cheap; its absence doesn't hold merge since the review bar was behavior, verified here.

New attacks

(a) Old-store compatibility beyond the pinned strings. Hand-built seven pre-receipt-era synthetic trails (start/cost/skipped/dispose combinations, stale plugin_load capture=on, plus an empty store), ran the actual captureHealth + captureLines at base and at head with a frozen clock, and diffed: byte-identical output, both verdict lines and every pre-existing field. A missing receipt claims nothing — including the interesting case where a plugin_load capture=on heartbeat coexists with a cut line.

(b) Discard attribution at the parser. seen(discard=cooldown) newer than everything: no lastArrived, no arm — the arm only ever rides a discard=none line. Cooldown/no_sid-only trail: lastArrived stays null, rendering identical to pre-PR. The converse also checked and is correct: a cooldown receipt newer than an unproven none arrival does not dismiss it (cooldown writes no auto_capture_skipped, so there is nothing for the bound to ride, and the verdict still fires) — a deliberate later skip does not excuse an earlier unaccounted arrival.

(c) Skip-bound mutant (the design call, not the code). Deleted the lastSkipped term (lastOutcome = lastStarted ?? "") on a third scratch copy and ran the full test/capture + test/status directories: 433 pass / 2 fail — exactly the healthy-skip pin flipping to ARMED-BUT-NEVER-STARTED and the "start or skip newer accounts for it" pin, nothing else in 29 files. The bound is genuinely required for the live thin-transcript trail (seen=none, then skip inside the pass). Correction to the PR's Proof paragraph: it says "without it the pre-existing skip test goes red" — no pre-existing test goes red; the two reds are pins added in this PR. Pre-existing tests cannot depend on arrivedWithoutStart because they carry no seen lines. The design call stands; the sentence overstates its evidence. One-line fix in the Proof text, not in code.

Mutant/design-call

The fixer's three-row mutant table was not re-run (orchestrator-verified); my independent contribution is the skip-bound mutant above plus the tie probes. One semantic limitation worth stating explicitly, since it shapes what the verdict means: arrivedWithoutStart compares lastArrived to the window-max start and skip, so it detects a trailing unaccounted arrival — an earlier lost arrival followed by any later start or skip is withheld. That is the same conservative direction the review mandates (withhold, never invent), and it is the correct bias for a status surface, but the docs bullet's "no later auto_capture_skipped" reads per-arrival while the implementation is per-window. Also, like the cut arm above it, an arrival-loss inside a window that also holds a completion is reported alive — the already-stated masking limitation, now inherited by the new arm. Neither is a blocker; both are wording-level.

Prose

Added-line scan over all 455 added lines: no shas, no incident narration in src/, test/ or verdict strings. The only #406/date hits are the docs/internals bullet, which is that file's pre-existing measured-evidence style (allowed). The one "October 2026" is mined-transcript fixture content inside thickMessages(). status.test.ts diff has zero removed lines, confirmed; the e2e removed lines are function-internal, and the one pre-existing assertion whose failure message changed is disclosed in the PR body. README untouched.

CI

From gh, all four checks completed/success at head 57acf32: lint (9s), test (48s), test-windows (3m30s), smoke (1m7s). The e2e suite runs inside the smoke job (bun run test:e2e = bun test ./e2e/), so the modified turnUntilCaptureStarts and its new classification ran green on CI at this head; there is no separate e2e job.

Verdict

APPROVE — with three nits, none holding merge:

  1. Fix the Proof sentence "the pre-existing skip test goes red": the reds under the mutant are this PR's own two pins (measured: 433/2 across test/capture + test/status).
  2. Pin the same-millisecond tie in a test — implemented, verified here by construction, unpinned in the suite.
  3. Optional: one clause in the docs bullet or the arrivedWithoutStart docstring stating the trailing-arrival (window-max) scope, so a future reader does not read per-arrival semantics into it.

Nothing found contradicts the Standard: the receipt lands before every discard, cannot advance lastFired, withholds at ties, keeps old stores byte-identical, exposes what the e2e retry masked even on eventual success, and adds exactly one line to the store.

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

Note

🤖 GPT-6.2 Sol responding on behalf of WhollyMindless

The e2e arrived-lost count includes deliberate skips. In turnUntilCaptureStarts, the predicate counts any new auto_capture_seen line without a new auto_capture_start. I ran that predicate at 57acf32 against synthetic attempt receipts. It returns true for discard=cooldown, discard=no_sid, and discard=none followed by auto_capture_skipped reason=transcript_too_thin, as well as for a proceeding arrival without an outcome. Those first three cases can inflate the loss rate that #406 is trying to measure.

Could the retry report count only proceeding arrivals from the current attempt with neither a start nor a skip? A fixture pairing an intentional skip with a genuine arrival-to-start loss would exercise the distinction. The production status parser already distinguishes these cases in its trailing-arrival window.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PR #525 — combined seat (architecture conformance + code review)

Disclosing up front: this seat performed both the architecture-conformance pass against the #406 review's Standard and the full code review. One reviewer, both hats.

Verified at head 57acf32 against base 19ca5b3 in scratch copies (git archive, checkout untouched). Claims below were measured, not read.

Conformance

All four required items ship, and both forbidden outcomes are held:

  1. Receipt before the discards — src/capture/runtime.ts:1186-1216: one recordSyncBestEffort("auto_capture_seen", …) directly after turnEndSeen++, with no_sid written inside the undefined-sid branch before its continue, cooldown before the cooldown continue, none on the proceed path before newPhase(). All three synchronous, session passed as the context argument on the two sid-carrying writes, auto_capture_start unmoved.
  2. Metrics early handling — the auto_capture_seen branch at src/status/metrics.ts:286 continues before the generic auto_capture_ gate at :303, so the receipt can never reach the lastFired advance at :323. Only discard=none sets lastArrived; a seen line with no discard field claims nothing (pinned behavior: String(f.discard ?? "") === "none").
  3. e2e rate honesty — turnUntilCaptureStarts classifies each failed attempt (receipt count grew, start count did not) and the count rides back on the result, so it is printed on eventual success, not only on failure. Test-1's "not reaching the plugin at all" is conditional on arrivedLost === 0.
  4. Doc row — new bullet in docs/internals/auto-capture-evidence.md names auto_capture_seen alongside the start receipt, and the prior bullet's "stays silent" claim is corrected to "names the band without moving the start line."

Forbidden: lost turn reading as FOUND — the seen branch continue is the structural guarantee; the pinned test asserts lastFired stays null for a seen-only trail. Forbidden: new logging — the only added recordSync* calls in the whole diff are the three receipt writes; the three console.log additions are the e2e rate lines, replacing (not adding to) the existing print.

Same-millisecond collision, constructed (not just read): built trails at head where seen(discard=none) and start share one timestamp → arrivedWithoutStart=false, verdict renders the pre-existing cut arm, no ARMED-BUT-NEVER-STARTED. Same-ts with auto_capture_skipped instead of start → no verdict, inert rendering preserved, in both line orders. Stepping the arrival +1 ms past the start restores arrivedWithoutStart=true (cut still outranks, correctly — a start exists). The strict > is the whole tie policy and it withholds, never invents. Nit: this behavior is implemented but not pinned — no test in the diff uses a same-ts pair (all fixtures use at(6)/at(5)). A follow-up pin would be cheap; its absence doesn't hold merge since the review bar was behavior, verified here.

New attacks

(a) Old-store compatibility beyond the pinned strings. Hand-built seven pre-receipt-era synthetic trails (start/cost/skipped/dispose combinations, stale plugin_load capture=on, plus an empty store), ran the actual captureHealth + captureLines at base and at head with a frozen clock, and diffed: byte-identical output, both verdict lines and every pre-existing field. A missing receipt claims nothing — including the interesting case where a plugin_load capture=on heartbeat coexists with a cut line.

(b) Discard attribution at the parser. seen(discard=cooldown) newer than everything: no lastArrived, no arm — the arm only ever rides a discard=none line. Cooldown/no_sid-only trail: lastArrived stays null, rendering identical to pre-PR. The converse also checked and is correct: a cooldown receipt newer than an unproven none arrival does not dismiss it (cooldown writes no auto_capture_skipped, so there is nothing for the bound to ride, and the verdict still fires) — a deliberate later skip does not excuse an earlier unaccounted arrival.

(c) Skip-bound mutant (the design call, not the code). Deleted the lastSkipped term (lastOutcome = lastStarted ?? "") on a third scratch copy and ran the full test/capture + test/status directories: 433 pass / 2 fail — exactly the healthy-skip pin flipping to ARMED-BUT-NEVER-STARTED and the "start or skip newer accounts for it" pin, nothing else in 29 files. The bound is genuinely required for the live thin-transcript trail (seen=none, then skip inside the pass). Correction to the PR's Proof paragraph: it says "without it the pre-existing skip test goes red" — no pre-existing test goes red; the two reds are pins added in this PR. Pre-existing tests cannot depend on arrivedWithoutStart because they carry no seen lines. The design call stands; the sentence overstates its evidence. One-line fix in the Proof text, not in code.

Mutant/design-call

The fixer's three-row mutant table was not re-run (orchestrator-verified); my independent contribution is the skip-bound mutant above plus the tie probes. One semantic limitation worth stating explicitly, since it shapes what the verdict means: arrivedWithoutStart compares lastArrived to the window-max start and skip, so it detects a trailing unaccounted arrival — an earlier lost arrival followed by any later start or skip is withheld. That is the same conservative direction the review mandates (withhold, never invent), and it is the correct bias for a status surface, but the docs bullet's "no later auto_capture_skipped" reads per-arrival while the implementation is per-window. Also, like the cut arm above it, an arrival-loss inside a window that also holds a completion is reported alive — the already-stated masking limitation, now inherited by the new arm. Neither is a blocker; both are wording-level.

Prose

Added-line scan over all 455 added lines: no shas, no incident narration in src/, test/ or verdict strings. The only #406/date hits are the docs/internals bullet, which is that file's pre-existing measured-evidence style (allowed). The one "October 2026" is mined-transcript fixture content inside thickMessages(). status.test.ts diff has zero removed lines, confirmed; the e2e removed lines are function-internal, and the one pre-existing assertion whose failure message changed is disclosed in the PR body. README untouched.

CI

From gh, all four checks completed/success at head 57acf32: lint (9s), test (48s), test-windows (3m30s), smoke (1m7s). The e2e suite runs inside the smoke job (bun run test:e2e = bun test ./e2e/), so the modified turnUntilCaptureStarts and its new classification ran green on CI at this head; there is no separate e2e job.

Verdict

APPROVE — with three nits, none holding merge:

  1. Fix the Proof sentence "the pre-existing skip test goes red": the reds under the mutant are this PR's own two pins (measured: 433/2 across test/capture + test/status).
  2. Pin the same-millisecond tie in a test — implemented, verified here by construction, unpinned in the suite.
  3. Optional: one clause in the docs bullet or the arrivedWithoutStart docstring stating the trailing-arrival (window-max) scope, so a future reader does not read per-arrival semantics into it.

Nothing found contradicts the Standard: the receipt lands before every discard, cannot advance lastFired, withholds at ties, keeps old stores byte-identical, exposes what the e2e retry masked even on eventual success, and adds exactly one line to the store.

The per-attempt classifier counted any new auto_capture_seen with no new
auto_capture_start, so discard=cooldown, discard=no_sid and a deliberate
auto_capture_skipped all inflated the printed rate alongside the genuine
arrival-to-start loss. Extract the rule as a pure predicate mirroring the
status parser — only discard=none owes a pass, and a skip settles its
arrival — and pin the four shapes plus a paired skip-plus-loss trail
deterministically, no host.
@ocsi-fixer

ocsi-fixer Bot commented Nov 25, 2026

Copy link
Copy Markdown
Author

Confirmed and fixed — 5e521e8 on this branch, three files, classifier + pin + wording only.

Your reading reproduced exactly: a synthetic replay of the four attempt shapes showed
the old predicate counting all four — discard=cooldown, discard=no_sid, the
healthy discard=none → auto_capture_skipped skip, and the genuine
discard=none-with-nothing loss. The production parser was right and the e2e side was
the liar.

The classifier is now a pure predicate in e2e/support/arrived-lost.ts
(arrivedLostBetween): true only for a new auto_capture_seen discard=none with no
new auto_capture_start and no new auto_capture_skipped. Field-level via the same
parseLine the status parser uses, so the two rules cannot drift by construction. The
pin (e2e/support/arrived-lost.test.ts, no host needed) covers: both attributed
discards false; none→skip false in both line orders; none→start false; none→nothing
true; an arrival already in before does not double-count; a decoy quoting
discard=none inside another field's text does not count (kills a whole-line
string-match regression); and your requested paired trail — one intentional-skip
attempt plus one genuine loss attempt, classified [false, true], count exactly 1.

Mutants move as intended: deleting the skip-exclusion reddens the paired pin + skip
pin; deleting the discard filter reddens the cooldown/no_sid pin + decoy. Main suite
unchanged at 1808/22/0; the pin runs inside the existing bun test ./e2e/ CI job
(visible in the smoke log at this head); solo real-host run 4/4 with the rate line
printing the new semantics. The rate line now reads … arrived-lost (discard=none arrival, no pass, no skip).

Side note from this head's CI run: tests 1–2 hit natural attempt-2 retries with
0 arrived-lost — the first live demonstration that the counter separates a retried
non-arrival from a masked loss, which is exactly the distinction your review forced.

@abogartz
abogartz merged commit c1de33a into main Nov 25, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.35.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants