Repository navigation
fix: gate evidence attributes only supersessions the call performed (#208) - #278
Conversation
…208) GATE-2 recorded superseded_by evidence for every PLANNED row whenever any row in the batch was marked, and derived promoted.supersedes from the plan head. When a concurrent session retired a planned row between the scope read and the batch publish, the batch correctly skipped it (re-read under the lock) but the audit trail still named it with this chain and reason, and write_promoted.supersedes could point at a row this call never retired. memory_evidence then blamed the wrong chain. Filter both the drift and canonical evidence loops to the rows returned in marked, and take supersededTs from marked rows only — the same rule #158 round 3 pins for the durable ledger. Pins: test/gate-evidence-attribution.test.ts drives both interleavings deterministically through a module wrapper around markManySupersededReport that retires one planned row out of band before the real batch runs. Both pins fail on main (2 superseded_by lines claiming the out-of-band row) and pass with the fix.
WhollyMindless
left a comment
There was a problem hiding this comment.
Reviewed d9819a831527db53633ea8640605701e80eb6168. Approve for #208's scoped evidence-attribution fix. I filed the original issue; the bot authored this implementation, and I independently checked the diff and reran the reproductions.
Windows / Bun 1.4.4, isolated checkout:
- New drift and canonical interleavings: 2 pass, 15 assertions at this head.
- Restoring only
src/gate/gate.tsfrom merge-base0fe0f61, with the same tests: both fail, each observing twosuperseded_byrecords instead of one. Restored the reviewed source afterward; checkout is clean. - Traced
markManySupersededReport:markedcontains rows actually published by the batch. Both changed loops now filter the original plan against those IDs before emitting evidence or assigningsupersededTs. Existing durable-ledger handling and mutation ordering are unchanged. - The canonical test deliberately skips the first planned row, so it checks the previously misleading
write_promoted.supersedes, not just the evidence count. Both cases confirm that the competing retirement'sOTHER-SESSIONpointer survives.
No blocking finding in this diff. Scope is these deterministic interleavings and source tracing; I did not independently rerun the full suite or cross-process stress tests. Merge timing remains the maintainer's call.
There was a problem hiding this comment.
Reviewed at head d9819a831527db53633ea8640605701e80eb6168. Contract: #208 (authored by WhollyMindless, trusted; spec anchor ec78f65d5801a2c7 — recomputed hash equal, spec frozen). Closes footer present.
Acceptance criteria, verbatim: "Emit superseded_by and derive promoted.supersedes only from the returned marked rows. Pin both drift and canonical interleavings."
Criterion 1 — evidence from marked rows only: drift loop gates rec("superseded_by", …) on retired.has(p.s.memory.ts) with retired = new Set(marked) (src/gate/gate.ts:553-568); canonical loop gates on canonRetired.has(p.ts) (:615-630). supersededTs is assigned only inside the filtered loops, so write_promoted.supersedes can name no unmarked row. markManySupersededReport returns marked: string[] of rows actually retired (src/store/files/supersede.ts:58) — the filter is against the real batch result, not the plan.
Criterion 2 — both interleavings pinned: test/gate-evidence-attribution.test.ts drives drift and canonical deterministically: a mock.module wrapper retires an armed row out of band via the real markSuperseded (pointer OTHER-SESSION) immediately before the real batch, no wall-clock race. Drift case asserts exactly one superseded_by naming M1 and supersedes == M1 while M2 keeps OTHER-SESSION (:144-158); canonical case retires the plan-head row so the old loop would claim the wrong one, asserting supersedes == M2 (:200-212).
Commands run (measured): bun run typecheck clean; bun run lint 0 errors, format clean; bun run test 939 pass / 19 skip / 0 fail (958 tests, 91 files); bun run test:e2e 30 pass / 0 fail.
Differential: new tests at merge-base 0fe0f61 (fix absent): 2 fail — the unfiltered loops replay the plan and emit a superseded_by line for the out-of-band row, exactly the misattribution the ticket describes. Same tests at this head: 2 pass.
Test integrity: file is new (+214/−0); no skipped or weakened assertions anywhere in the diff.
Final gate re-check (verbatim): gh pr view 278 --json headRefOid → d9819a831527db53633ea8640605701e80eb6168; gh pr checks → lint pass, test pass, test-windows pass, smoke pass.
No findings. Human merges.
|
🎉 This PR is included in version 0.15.20 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #208
What
GATE-2 emitted
superseded_byevidence for every planned row whenever any row in the batch was marked, and derivedwrite_promoted.supersedesfrom the plan. When a concurrent session (or the viewer) retired a planned row between the gate's scope read and the batch publish, the batch skipped that row (it re-reads under the lock) — but the audit trail still recorded it with this chain and reason, andpromoted.supersedescould name a row this call never retired.memory_evidenceand audits then attributed a retirement to the wrong chain, contradicting the #158 round-3 rule that the trail never claims a retirement the call did not perform.Fix: both evidence loops (drift and canonical) now filter on the
markedset returned bymarkManySupersededReport, andsupersededTsis taken only from marked rows.File-scope note
The ticket names
src/gates.ts:447-462and494-514atbf9f4d2. The #168 domain restructure moved that file tosrc/gate/gate.ts; the two loops are the same code (drift batch, canonical batch).src/memory.ts:420-425(themarkManySupersededReportdoc) moved tosrc/store/files/supersede.ts:50-55and already documents the correct contract — no change needed there.Acceptance criteria and evidence
src/gate/gate.tsnow gate eachrec("superseded_by", …)on membership in themarkedset. Pinned by two new tests asserting exactly onesuperseded_byline naming only the row the call retired.supersededTsis assigned inside the filtered loops only. Pinned: with the first planned row retired out of band,write_promoted.supersedesnames the marked row (M2), never the unmarked one (M1).test/gate-evidence-attribution.test.tsdrives both interleavings deterministically: amock.modulewrapper retires one armed row out of band (via the realmarkSuperseded, pointerOTHER-SESSION) immediately before the real batch runs, so no test races a wall clock. Durable assertions confirm the out-of-band row keepsOTHER-SESSIONand the marked row carries this chain.Reproduction and differential
REPRODUCES at main
0fe0f61768774b50dda8378fd075a5d042d4f89d: both loops replayed the plan (for (const p of driftPlan)/for (const p of canonPlan)) gated only onmarked.length > 0.0fe0f61(fix reverted): 2 fail — each case emits 2superseded_bylines (the out-of-band row claimed with this chain/reason) where 1 is correct.expect()calls.Commands run (measured)
bun run typecheck— passbun run lint— pass (biome lint: 0 errors;format:check: clean)bun run test— 939 pass, 19 skip, 0 fail (958 tests, 91 files)bun run test:e2e— 30 pass, 0 fail (256 expect calls)Deliberately not changed
markManySupersededReport/supersede.ts— already returns only actually-marked rows; its documented contract is the correct one.ctx.durable) — already correct per fix(update): metadata fidelity and truthful partial results (#154 #155) #158 round 3; only evidence andpromoted.supersedeswere affected.