Skip to content

fix: gate evidence attributes only supersessions the call performed (#208) - #278

Merged
abogartz merged 1 commit into
mainfrom
fix-issue-208-20261103T235700Z
Nov 4, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix-issue-208-20261103T235700Z

Conversation

@ocsi-fixer

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

Copy link
Copy Markdown

Closes #208

What

GATE-2 emitted superseded_by evidence for every planned row whenever any row in the batch was marked, and derived write_promoted.supersedes from 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, and promoted.supersedes could name a row this call never retired. memory_evidence and 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 marked set returned by markManySupersededReport, and supersededTs is taken only from marked rows.

File-scope note

The ticket names src/gates.ts:447-462 and 494-514 at bf9f4d2. The #168 domain restructure moved that file to src/gate/gate.ts; the two loops are the same code (drift batch, canonical batch). src/memory.ts:420-425 (the markManySupersededReport doc) moved to src/store/files/supersede.ts:50-55 and already documents the correct contract — no change needed there.

Acceptance criteria and evidence

  • "Emit superseded_by … only from the returned marked rows" — drift loop and canonical loop in src/gate/gate.ts now gate each rec("superseded_by", …) on membership in the marked set. Pinned by two new tests asserting exactly one superseded_by line naming only the row the call retired.
  • "derive promoted.supersedes only from the returned marked rows" — supersededTs is assigned inside the filtered loops only. Pinned: with the first planned row retired out of band, write_promoted.supersedes names the marked row (M2), never the unmarked one (M1).
  • "Pin both drift and canonical interleavings" — test/gate-evidence-attribution.test.ts drives both interleavings deterministically: a mock.module wrapper retires one armed row out of band (via the real markSuperseded, pointer OTHER-SESSION) immediately before the real batch runs, so no test races a wall clock. Durable assertions confirm the out-of-band row keeps OTHER-SESSION and 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 on marked.length > 0.

  • New tests at merge-base 0fe0f61 (fix reverted): 2 fail — each case emits 2 superseded_by lines (the out-of-band row claimed with this chain/reason) where 1 is correct.
  • New tests on this branch: 2 pass, 15 expect() calls.

Commands run (measured)

  • bun run typecheck — pass
  • bun 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.
  • The durable ledger (ctx.durable) — already correct per fix(update): metadata fidelity and truthful partial results (#154 #155) #158 round 3; only evidence and promoted.supersedes were affected.
  • The canonical-block comment structure and all unrelated gate logic.

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

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.ts from merge-base 0fe0f61, with the same tests: both fail, each observing two superseded_by records instead of one. Restored the reviewed source afterward; checkout is clean.
  • Traced markManySupersededReport: marked contains rows actually published by the batch. Both changed loops now filter the original plan against those IDs before emitting evidence or assigning supersededTs. 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's OTHER-SESSION pointer 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.

@ocsi-triager ocsi-triager Bot added the review:requested Human-admitted for autonomous review by ocsi-reviewer label Nov 4, 2026

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

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.

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

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.20 🎉

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

released review:requested Human-admitted for autonomous review by ocsi-reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gate evidence: attribute only supersessions actually performed by the call

2 participants