Repository navigation
fix(#116): capture gates and stamps the captured session, not the last setCurrent - #118
Merged
abogartz merged 2 commits intoOct 26, 2026
Merged
Conversation
… the last setCurrent
captureSession binds setCurrent({sessionID: sid}) and then AWAITS - context
re-reads and, decisively, the generate.text model call. On a server hosting
several workspaces, any other session's hook moves the module-global current
during that await, and everything the capture then resolves follows the hijacker:
the gate judges its candidate against the other session's (empty) evidence, and
appendMemory's choke point stamps the row with the other session's repo. A fact
mined from repo A's transcript becomes repo B's memory - invisible to A, a
cross-repo leak into B.
Thread the identity instead of reading it back:
- GateContext.sessionID: known-session writers name their session; gateContext(sid)
binds liveRoot/evidence/engagement for THAT session (getCurrent() fallback
keeps the tool-hook paths bit-identical);
- AppendMemoryInput.sessionID: the choke point prefers it over the ambient
current, unnamed writers (tools, viewer, restore) unchanged;
- captureSession threads its sid - setCurrent stays for the synchronous
stretches, but it is no longer load-bearing across the awaits.
Pin (test/capture-sid-race.test.ts) interleaves deterministically via a new
harness park seam inside the model stub: red now (blocked under the hijacker's
evidence - and an unthreaded persistence variant stamps the wrong repo), green
here; each threading arm alone is kill-verified. Control test pins the happy
path unchanged. Suite 490/0/5 + tsc clean.
abogartz
approved these changes
Oct 26, 2026
abogartz
left a comment
Owner
There was a problem hiding this comment.
APPROVED at b40c03a — every body claim verified independently on macOS (Bun 1.4.3); all three threading arms re-killed by me, not taken on faith.
What I verified and how
- The race is real and the fix lands where the contract says:
gateContext(sid)bindsliveRoot/evidenceCalls/hasGateCheck/hasEngagementfor the named session;GateContext.sessionIDflows intoappendMemory's choke point (input.sessionID ?? getCurrent().sid); capture threads itssid.setCurrentstays for the sync stretches, no longer load-bearing across awaits — matches the body exactly. - Kill-verification, my own mutations (each restored after): (A) choke point back to
repoScopeFor(getCurrent().sid)→ red, row carries the hijacker's key (Expected 5b393bce5a35, Received 0baf7026d607); (B)appendMemory({...candidate})droppingctx.sessionID→ red, wrong key again; (C)gateContext()instead ofgateContext(sid)→ red in the blocked shape (capturedundefined — the gate judged the hijacker's empty evidence). Matches the two shapes the pin's comment describes. - Fallback is a true no-op for unnamed writers:
GateContext.sessionIDisundefinedwherevergateContext()is called without an argument (tool hooks atindex.ts:371/484/638,init.ts), soappendMemory's resolution is byte-identical to before; viewer/restore/import direct appends untouched. - Determinism of the pin: the park seam waits inside the model stub after logging the call — the interleave is causal, no sleeps on the critical path; hermetic temp root,
resetSessionScopes()+resetCaptureCooldowns()inbeforeEach(the #113 cross-file-state lesson applied). Control test pins the happy path and its completion wait is itself race-free. - Gates: full suite 498 / 0 / 11,
tscclean; CI all four green includingtest-windows(1m57s) on the rebased head — the earlier Windows red was the #117 flake, now fixed on main.
Non-blocking notes (follow-up material, not asks)
- Evidence
sid=residue:record()still resolves the ambient current, so under exactly the hijack shape this PR fixes, the capture'sauto_capture_*audit lines — andwrite_promotedfrom inside the gate — can carry the hijacker'ssid=and land in its evidence stream. The durable artifact (the stamped row) is correct, so this is audit attribution only; same threading (an optionalsessionIDfield onrecord) would close it. - Tool-path windows:
memory_remember/update/importkeep ambient resolution — consciously deferred per the code comment ("needs per-callID plumbing"), and the windows are fs-sized rather than model-sized. Worth one tracking issue so #116's contract gets finished where it can be, same as this PR did for capture. - Cosmetic: "AWITS" → "AWAITS" in the test header.
One commit, no scope creep: the pin's red legs are the issue's stated decision made concrete, and the fallback discipline means every non-capture writer is provably unchanged.
|
🎉 This PR is included in version 0.14.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This was referenced Oct 26, 2026
abogartz
pushed a commit
that referenced
this pull request
Oct 26, 2026
#118 approval note 1. The durable rows got their session threading in #118; the evidence lines the gate appends around them still read sid from ambient getCurrent() - so under the exact interleave #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 - #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).
abogartz
added a commit
that referenced
this pull request
Oct 26, 2026
fix(evidence): gate audit lines name the session the gate runs FOR, not the ambient current (#118 note 1)
abogartz-opencode-self-improvement Bot
pushed a commit
that referenced
this pull request
Oct 26, 2026
This was referenced Nov 4, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #116 — capture's repo stamp (and the whole gate evaluation) followed whichever session called
setCurrentlast, not the session being captured.The race, in one paragraph
captureSessionbindssetCurrent({ sessionID: sid })and then awaits — the context re-read and, decisively,generate.text. On a server hosting several workspaces, any other session's hook moves the module-global current during that await. Everything the capture then resolves follows the hijacker:gateContext()reads evidence/engagement/liveRoot for the wrong session, andappendMemory's choke point resolves the stamp viarepoScopeFor(getCurrent().sid)— so a fact mined from repo A's transcript lands carrying repo B'srepo/repoPath. Invisible to A; a quiet cross-repo leak into B. ThesetCurrentcomment claimed the binding "so captures stamp (and gate against) that session's repo" — true only if nothing interleaves, which a single model call guarantees can happen.The fix — thread the identity, don't read it back
GateContext.sessionID(gates.ts): known-session writers name their session.gateContext(sid)in index.ts bindsliveRoot/evidence/engagement for that session; thegetCurrent()fallback keeps the tool-hook paths bit-identical (they run inside their session's hook dispatch — threading them further needs per-callID plumbing, noted below).AppendMemoryInput.sessionID(memory.ts): the single write choke point prefers the caller's session over the ambient current; unnamed writers (tools, viewer, restore) are unchanged.captureSessionthreads itssidintorunWriteGate.setCurrentstays for the synchronous stretches — it's just no longer load-bearing across the awaits.The pin — deterministic, not timing-luck
test/capture-sid-race.test.tsinterleaves via a new park seam in the harness's model stub (generate.park: the stub awaits a test-held promise inside the call — same precedent as #110's determinism rule, no sleeps). Sequence: compaction capture for session A parks mid-model-call → the test runs another session'ssetCurrent(session B, bound to a second workspace dir) → release → judge what landed.3589658): the capture blocks — the gate evaluated B's empty evidence — and while chasing the red we also caught the sibling shape with the seam un-parked: promoted but stamped with B's key (682ddf2210c0where A'sf677cf6e7244was expected). Both shapes violate one contract, and the pin asserts the contract.input.sessionID ??dropped) or thegateContext(sid)thread alone re-reddens the pin.Suite 490 pass / 0 fail / 5 skip on Windows (matches your 490 from #113),
tscclean.Not in this PR (deliberately)
The three tool-path
runWriteGatesites (remember/update/import) still readgateContext()without a sid. They're the same disease one seam away — the tool hook dispatch carriessessionID, but theexecutebodies get current viasetCurrentfromexecute.before, so a per-callID thread (or reading the sid off the tool ctx) is the right home for it. Didn't want to widen this PR's blast radius on a path where the dispatch timing is much tighter than a model call; happy to follow up if you see a real window.Assisted by Qwen3-flash-next