Skip to content

fix(evidence): gate audit lines name the session the gate runs FOR, not the ambient current (#118 note 1) - #124

Merged
abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:fix/evidence-sid-threading
Oct 26, 2026
Merged

abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:fix/evidence-sid-threading

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

The audit-limb follow-up to #118 — your approval note 1 (the sid= residue in gate-authored evidence lines) and note 3 (the AWITS typo, folded in here as agreed). The rows got their threading in #118; the lines the gate appends around them were still reading ambient getCurrent(), so under the exact interleave #118 pins, the paper trail an operator greps first says write_promoted … sid=<hijacker> while the durable row next to it is correctly repo A's.

The fix (one seam, killable as one line)

  • record() gains an optional trailing sessionID that outranks the ambient read. Two honesty rules baked in: when the threaded session and the ambient one disagree, the ambient call belongs to the other session's flow, so it is dropped rather than borrowed (formatLine omits undefined fields); and sessionID undefined is the old ambient read exactly — the tool paths (ctx.sessionID unset there, tool-path writes (remember/update/import) still resolve session identity from ambient getCurrent() #121's territory) change nothing, mechanically the same no-op argument as appendMemory's input.sessionID ?? getCurrent().sid.
  • recordWriteBlocked() forwards it.
  • runWriteGate threads ctx.sessionID through all 19 of its audit lines via two one-line helpers (rec, recBlocked) — the 19 renames are the threading, and dropping ctx.sessionID in either helper blinds the whole file at once.

Red-first, with arm-by-arm kill evidence

New pins in capture-sid-race.test.ts (the file your review already re-killed):

  1. Your observed shape, pinned: the hijack test now additionally asserts write_promoted.sid === "ses-capture" plus chain-consistency across every line carrying the write's chain. Red before the fix at exactly your residue: Expected: "ses-capture" / Received: "ses-other".
  2. Blocked-shape test at the direct gate seam (the one you used for arm C): ambient poisoned to the other session (what the hijack leaves behind for a gate's lines), ungrounded candidate → ambiguous_memory block, write_blocked.sid + chain-mates must name the ctx session.
  3. Control additionally pins that threaded lines carry the captured session even where ambient coincidentally matches (the compaction hook's own setCurrent makes unfixed-control green — said out loud so nobody reads it as a second red).

Kill arms, each applied and reverted on the pin file (Windows, Bun 1.3.10):

arm mutation result
A sessionID ?? cur.sid → cur.sid (record blinded) 2 fail (hijack + blocked), control pass
B rec helper drops ctx.sessionID same 2 fail
C recBlocked drops ctx.sessionID 1 fail — only the blocked test; it earns its keep standalone

Suite 494/0/5 (main's 491 + 3 pins), tsc clean. No sweep catalog entry added: the pin is the kill net (arms A–C above are its kill conditions), and the matrix is #71's job — happy to see evidence-sid-blind folded in there if you want it in the published score.

Assisted by Qwen3-flash-next

abogartz#118 approval note 1. The durable rows got their session threading in abogartz#118;
the evidence lines the gate appends around them still read sid from ambient
getCurrent() - so under the exact interleave abogartz#118 pins, the paper trail an
operator greps first carries the HIJACKER's sid (write_promoted sid=ses-other
while the row itself is correctly repo A's). Same disease, audit limb.

- record() gains an explicit sessionID that outranks the ambient read; when
  the two disagree the ambient call belongs to the other session's flow, so
  it is dropped rather than borrowed (formatLine omits undefined).
  sessionID undefined (tool paths - abogartz#121) is a true no-op: the old read.
- runWriteGate threads ctx.sessionID through every audit line via rec/recBlocked
  helpers - all 19 sites, one threading seam, killable as one line.
- pins: the hijack test's write_promoted + chain-mates must carry ses-capture
  (red before: sid=ses-other, exactly his observed residue); the control pins
  threading behavior where ambient coincidentally matches; a direct-gate
  blocked-shape test covers the recBlocked arm with the ambient poisoned.
- header typo from the review: AWITS -> AWAITS (note 3).
…bogartz#125

main's abogartz#125 (gate3 conflict floor) rewrote the rivalry logic around the very
call sites this branch renames record->rec, so the conflict was textual, not
semantic. Resolution: take main's gates.ts wholesale, re-apply the threading
verbatim - helpers after chainId(), then the 19-site rename. Audited abogartz#125's
diff first: still exactly 19 record/recordWriteBlocked sites inside
runWriteGate (no new audit lines to thread), and its new ctx.supersedesTs is
orthogonal to sessionID threading.

Verified at the merge shape: capture-sid-race 3/3 (hijack red-shape stays
dead under the new conflict logic - blocked-path pin exercises abogartz#125's
recordWriteBlocked routes with threaded sid), full suite 515/0/5, tsc clean.
@WhollyMindless
WhollyMindless force-pushed the fix/evidence-sid-threading branch from 9be154b to 45cadaa Compare October 26, 2026 19:42

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed on macOS (Bun 1.4.3), branch 45cadaa. Every claim re-verified independently before approval; nothing taken from the body on faith.

Merge resolution

Your merge 45cadaa resolves src/gates.ts identically to how I had resolved it before your push landed — I built my own merge of main into 392642f (keep #125's advisory comment, thread the call through rec), then your push arrived; git diff between the two merge trees was empty. My full verification below ran against that byte-identical tree.

Red-first claim — reproduced

Worktree at the merge base (d4e495d) src + your test/capture-sid-race.test.ts:

  • 2 fail: hijack and blocked tests, both at exactly the residue the body quotes — Expected: "ses-capture" / Received: "ses-other".
  • 1 pass: the control, green pre-fix — consistent with the body's honesty note (the capture's own setCurrent moves ambient to ses-capture before the gate lines; verified at src/index.ts:1195).

Kill arms A–C — reproduced, table exact

Each mutation applied to the merged tree, pin file run, reverted (macOS):

arm mutation claimed observed
A sessionID ?? cur.sid → cur.sid 2 fail, control pass 2 fail, control pass ✓
B rec drops ctx.sessionID same 2 fail same 2 fail ✓
C recBlocked drops ctx.sessionID 1 fail, blocked only 1 fail, blocked only ✓

Other claims audited

  • 19 threading sites: counted 14 rec + 5 recBlocked call sites in runWriteGate, zero raw record/recordWriteBlocked left in the gate; both helpers are the only threading points, so the one-line-blind claim holds by construction.
  • formatLine omits undefined (src/logfmt.ts): confirmed — the dropped call vanishes cleanly, no call=? litter. Bonus the body undersells: when ambient disagrees, cur.call is the hijacker's callID (set by its tool.execute.before), so the drop rule also keeps the hijacker's call id off session A's audit line — same disease as sid=, one field further down.
  • #121 no-op claim: gateContext() with no args passes sessionID: undefined, so tool paths keep the old ambient read exactly. Confirmed at all call sites.
  • No consumer breakage: nothing downstream parses call= off gate audit lines; chain correlation runs on chain.
  • Signature safety: all external record() callers pass ≤3 args; recordWriteBlocked has no caller outside recBlocked.
  • Suite on merged tree: 508 pass / 12 skip / 0 fail unit, 11 pass / 0 fail e2e, tsc clean, bun run lint exit 0 (CI treats warnings advisory; +5 noNonNullAssertion advisories in the new test code, consistent with the file's existing style). CI rollup on 45cadaa: all four legs SUCCESS incl. test-windows.

One non-blocking nit

test/capture-sid-race.test.ts:183 — the control's comment says "here NOTHING ever calls setCurrent, so on ambient-read code the gate lines carry sid="?"". The counterfactual is wrong: captureSession calls setCurrent({ sessionID: sid }) at src/index.ts:1195 before any awaits (the file's own header says so), and my pre-fix run confirms the control is green unfixed because ambient coincidentally reads ses-capture — exactly what the PR body itself says ("the compaction hook's own setCurrent makes unfixed-control green"). The assertion is right and worth keeping; the comment contradicts both the body and the observed pre-fix behavior. A one-line comment fix so the next reader doesn't inherit a false counterfactual — doesn't need a round-trip from me either way.

Approving: the fix is a minimal one-seam threading, the pins kill exactly as advertised, and the honesty rule (drop rather than borrow) is the right call — literally.

@abogartz
abogartz merged commit 941c1b1 into abogartz:main Oct 26, 2026
4 checks passed
WhollyMindless added a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Oct 26, 2026
…review nit)

The control's comment claimed nothing calls setCurrent in that flow, but
captureSession binds setCurrent itself (src/index.ts) before any awaits -
that is precisely why the unfixed control reads ses-capture and passes.
Comment now matches the body's honesty note and the observed pre-fix
behavior; the assertion is unchanged.
@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Nit taken, fixed at be34470 — the control comment now states the true mechanics (capture's own setCurrent runs before any awaits, so the unfixed control passes by coincidence and the hijack test carries the red-first burden). Assertion untouched; pin file re-run 3/3.

And the cur.call observation is fair — the drop rule earning a second patient is a bonus worth having in the record. Thanks for the macOS leg and for re-deriving the merge independently; empty-diff between two independent resolutions of a textual-conflict merge is a nice way to close a threading PR.

@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.14.9 🎉

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

Development

Successfully merging this pull request may close these issues.

2 participants