Repository navigation
fix(evidence): gate audit lines name the session the gate runs FOR, not the ambient current (#118 note 1) - #124
Conversation
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.
9be154b to
45cadaa
Compare
abogartz
left a comment
There was a problem hiding this comment.
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
setCurrentmoves ambient toses-capturebefore the gate lines; verified atsrc/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+ 5recBlockedcall sites inrunWriteGate, zero rawrecord/recordWriteBlockedleft in the gate; both helpers are the only threading points, so the one-line-blind claim holds by construction. formatLineomits undefined (src/logfmt.ts): confirmed — the droppedcallvanishes cleanly, nocall=?litter. Bonus the body undersells: when ambient disagrees,cur.callis the hijacker's callID (set by itstool.execute.before), so the drop rule also keeps the hijacker's call id off session A's audit line — same disease assid=, one field further down.- #121 no-op claim:
gateContext()with no args passessessionID: 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 onchain. - Signature safety: all external
record()callers pass ≤3 args;recordWriteBlockedhas no caller outsiderecBlocked. - Suite on merged tree: 508 pass / 12 skip / 0 fail unit, 11 pass / 0 fail e2e,
tscclean,bun run lintexit 0 (CI treats warnings advisory; +5noNonNullAssertionadvisories in the new test code, consistent with the file's existing style). CI rollup on45cadaa: 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.
…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.
|
Nit taken, fixed at And the |
|
🎉 This PR is included in version 0.14.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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 ambientgetCurrent(), so under the exact interleave #118 pins, the paper trail an operator greps first sayswrite_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 trailingsessionIDthat outranks the ambient read. Two honesty rules baked in: when the threaded session and the ambient one disagree, the ambientcallbelongs to the other session's flow, so it is dropped rather than borrowed (formatLine omits undefined fields); andsessionIDundefined is the old ambient read exactly — the tool paths (ctx.sessionIDunset 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 asappendMemory'sinput.sessionID ?? getCurrent().sid.recordWriteBlocked()forwards it.runWriteGatethreadsctx.sessionIDthrough all 19 of its audit lines via two one-line helpers (rec,recBlocked) — the 19 renames are the threading, and droppingctx.sessionIDin 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):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".ambiguous_memoryblock,write_blocked.sid+ chain-mates must name the ctx session.setCurrentmakes 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):
sessionID ?? cur.sid→cur.sid(record blinded)rechelper dropsctx.sessionIDrecBlockeddropsctx.sessionIDSuite 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-blindfolded in there if you want it in the published score.Assisted by Qwen3-flash-next