Skip to content

fix: retain operation scope on gate evidence - #189

Merged
abogartz merged 4 commits into
abogartz:mainfrom
WhollyMindless:fix/gate-evidence
Oct 31, 2026
Merged

abogartz merged 4 commits into
abogartz:mainfrom
WhollyMindless:fix/gate-evidence

Conversation

@WhollyMindless

@WhollyMindless WhollyMindless commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #188. A session move during gate_start let repository B read promotion/refusal evidence for an operation that started in A, even though #186 kept the durable row owned by A. Both cases now have failing-before/passing-after regressions through the real memory_evidence tool. GateContext carries immutable evidence attribution (session, eligible call, and a copied repository scope). Direct gate callers capture it before the first await. Plugin gate contexts capture it at their existing operation boundary, updates before the update-order lock, and init before Git probing. record and recordWriteBlocked accept that snapshot; callers that omit it retain their existing per-call resolution. Named-unresolved snapshots retain a null scope and stay private to their session even if it later binds. Ambient maintenance captures module scope. Scrubbing and includeContext behavior remain intact; foreign ambient call IDs are still omitted. The operation's original call ID is retained across gate awaits. Store ownership and visibility logic are unchanged. Scope: gate-authored audit lines, including early refusals. Other caller-level lifecycle events still use their existing evidence routing; this does not close #121's missing-session fallback or establish live-host session.moved behavior (#176). Validation at 80b0aaa: integrated main d69691c (including #194). On Windows/Bun 1.4.4, the full gate passes typecheck, lint, 758 unit/scenario tests (11 existing skips), and 11 real-host E2E tests. The combined ownership/tombstone suites pass 49 tests. Two added session-move regressions cover dedup_rejected and rejection_vetoed evidence; both fail when entry-time attribution is removed. The original partition regressions also failed on base 525ed89. The inherited Linux concurrent-append read failure is tracked separately in #198; this PR does not claim to fix it or the earlier Windows outer-timeout failure. Please feel free to decline or close this implementation if you prefer a different evidence-attribution policy or API.
Review follow-up at 87f829d: documented the gate-attribution timing and where to read the original partition, clarified the session-less ambient-call rule in comments, and replaced the added non-null assertion with an explicit failure. No production behavior change. Windows / Bun 1.4.4 focused validation: 20 ownership/evidence tests pass, typecheck passes, lint passes with 409 advisory warnings. The full gate above is the prior head's run. Lifecycle split tracking is now #199; it is not a blocker for this PR.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

CI follow-up at f0c098e: please keep this pending while the red checks are accounted for.

  • Linux: two processes sharing one store > a reader process always parses a complete file observed one incomplete row. I reproduced the same assertion on an untouched archive of base/main 525ed89, using Bun 1.4.4 under Linux/WSL: 3 failures in 100 focused repetitions. A separate 100-run pass with diagnostic output added only to the test reproduced it once and captured a last line ending at type=learning scope=str (51 characters, missing content=). That establishes an inherited incomplete-read problem; it does not yet establish the cause. Neither store reader nor append implementation changes in this PR.

    Reproducer from the base: bun test test/concurrency.test.ts --test-name-pattern 'a reader process always parses a complete file' --rerun-each 100.

  • Windows: the viewer deleting and editing while another session writes > each mutation applies, and no row the writer was told it remembered is lost hit the five-second outer timeout at 5021.90 ms. An HTTP 400 assertion appeared afterward, during the already-timed-out run. Ten focused local repetitions passed on the base-equivalent test: report Windows ACL fixture phase timings #190 branch (its only change is the unrelated ACL fixture), and ten passed at this head, all with 220 assertions per ten runs. The hosted timeout is not reproduced locally or explained yet.

The four new evidence regressions passed in both hosted jobs; the full local gate passed before posting. I have not widened any timeout, weakened an assertion, or pushed an empty CI retry. #190 independently passed all four hosted checks on the same base, which does not negate these intermittent failures. If convenient, a rerun of the failed Windows job would provide another hosted observation; the contributor token cannot request one. The Linux incomplete-read behavior deserves separate investigation rather than being folded silently into this evidence-attribution change.

Linux failure: https://github.com/abogartz/opencode-self-improvement/actions/runs/41106043386/job/124236024583
Windows failure: https://github.com/abogartz/opencode-self-improvement/actions/runs/41106043386/job/124236025093

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Updated at 80b0aaa: merged current main d69691c and added two integration regressions for #194's dedup_rejected and rejection_vetoed events during a session move. Both stay visible to the original operation's repository and hidden from the new repository. Both tests fail if the gate drops its captured evidence context.

Windows / Bun 1.4.4: 49 focused ownership+tombstone tests pass. Full gate passes typecheck/lint, 758 unit/scenario tests (11 skips) and 11 real-host E2E tests. The push triggers a fresh CI run for this integration change; no timeouts or existing assertions were weakened.

The Linux incomplete-read failure remains reproducible on untouched current main, independently of this PR. I recorded it as #198, including page-boundary fragments and the test's blind spot when a truncated row already contains content=. This update does not fix that inherited read issue, nor does it establish a cause for the earlier hosted Windows five-second timeout. Keeping the evidence-attribution change scoped while making the residual actionable.

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

Review: APPROVED_WITH_NITS

Re-verified at your current head 80b0aaa (macOS / Bun 1.4.3). The attribution rule is the right one, it is implemented in the narrow place it should be, and the durable-row ownership from #186 is untouched. Nothing blocking.

First, the CI red at f0c098e — ambient, not yours. test/concurrency.test.ts (expect(partial).toBe(0)) on Linux and the Windows "viewer deleting and editing while another session writes" scenario both belong to the contention family that has been failing across unrelated branches this week — I found the same class on fix/rejection-tombstone-35 f2796ef (prune sweep swallows no concurrent append), fix/gate-reader cfb6023 (auto-capture dupe collapse), fix/complete-store-reads 14dd130 (Windows ACL store directory) and twice on ci/parallel-tests (supersede racing appends … half-written file). Mechanistically this diff cannot have caused it: captureEvidenceContext is fully synchronous and runWriteGate now calls it once per operation instead of once per audit line — strictly less work, no added lock, no added await, and the two failing tests drive appendMemory/markSuperseded and the viewer without going through the gate at all. The clincher is your own re-run: all four legs are green at 80b0aaa, same suite, both previously-red tests included. (The root of that family is #196, which #197 is addressing separately — I have not reviewed the interaction.)

Verified against the tree

Body claim How checked Result
Both partition regressions fail on main 525ed89 your pre-merge test file on a clean 525ed89 tree: gate evidence stays with operation repository (blocked: false), (blocked: true), captured unresolved evidence stays private and scrubbed after binding, ambient evidence captures its scope without adding suppressed session fields → 4 fail / 14 pass; at 80b0aaa the same file is 20 pass / 0 fail confirmed (four, not two)
726 unit / 12 skips, 11 e2e, typecheck + lint suite green at head, lint exit 0 with 410 warnings vs base main's 409 confirmed
Immutable attribution (session, eligible call, copied repository scope) src/evidence.ts:60-92: EvidenceContext is readonly + Object.freeze, and the scope is a frozen copy ({ ...scope }) rather than the live object sessionScope() hands out confirmed
Direct gate callers capture before the first await src/gates.ts:286 resolves the context once at entry; rec/recBlocked both take it (:289, :292) instead of re-resolving per line confirmed
Callers that omit the context keep per-call resolution src/evidence.ts:101 context ?? captureEvidenceContext(sessionID) confirmed
Named-unresolved keeps a null scope and stays session-private your test 2 + evidenceVisibleTo pairing; memory.ts visibility code is not in this diff confirmed
Ambient maintenance captures module scope, and suppressed context fields stay suppressed your test 4 asserts the stamp survives a later setRepoScope flip and that includeContext: false emits no sid=; passes at head, fails on base confirmed
Store ownership and visibility unchanged diff touches no memory.ts / logfmt.ts / repokey.ts visibility logic confirmed

Residual — one question about the session-less ("?") arm

captureEvidenceContext computes call = sessionID !== undefined && sessionID !== cur.sid ? undefined : cur.call. For a session-less operation, that means the captured call is whatever the ambient ledger held at entry, and if another session's tool hook was current at that instant the whole operation's lines lose the call id — permanently, because it is now frozen. I confirmed the asymmetry directly:

captured context for a session-less gate: {"sid":"?","scope":null}
LINE: ev=write_promoted sid=? mem=X note=head-path          ← frozen context: no call=
LINE: ev=write_promoted sid=? call=OP-CALL-1 mem=Y note=main-path ← per-line ambient read: keeps it

I could not construct a production ordering where this bites: the normal flow is execute.before → tool → gateContext, so ambient should still name this call at capture time, and in that (usual) ordering the frozen context is strictly better than main's per-line read, which loses the id as soon as another session dispatches. So this is a question, not a defect report: is there an entry point that builds a gate context before its own setCurrent? If yes, thread the operation's call explicitly into captureEvidenceContext rather than relying on the ambient-mismatch rule; if no, a comment saying "session-less callers take the ambient call at entry by design" would save the next reader this exact hunt.

Nits

  • README is silent on the new timing rule. README.md:118 explains evidence partitions but not that gate-authored lines take entry-time attribution — so after a move, an operation's audit trail stays in the partition of the repository it started in. One sentence in that paragraph saying so (and where to read those lines afterwards) would prevent a "where did my evidence go" issue.
  • +1 biome warning ((await row(outcome.ts!)) in test/update-collapse-visibility.test.ts), consistent with existing style in that file. Take it or leave it.
  • Split partitions deserve a tracking issue. As the body says, init_start/init_complete and the auto_capture_* lines still resolve per call, so one operation can straddle two partitions after a move (gate lines in A, lifecycle lines in B). That is deliberate and in scope — but it belongs in an issue next to #121 rather than only in a PR sentence.

Not verified here: Windows / Bun 1.4.4 (your validation host and the CI pin) — covered indirectly, since 80b0aaa is green on both legs there.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Thanks for the re-verification. Follow-up pushed at 87f829d; no production behavior changes.

Validation on Windows / Bun 1.4.4: all 20 ownership/evidence tests pass, typecheck passes, lint passes. The full gate result in the body remains the prior 80b0aaa run; I did not rerun E2E for this docs/comment/assertion-only change. CI will validate the new head.

The four original regressions you enumerated are the fuller count; “both” referred to the promotion/refusal pair, not the whole evidence test set. The later integrated head also adds rejection/tombstone coverage.

Please feel free to defer or close #199 if the existing lifecycle policy is intentional; it does not hold this PR.

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

Round 2: APPROVED

Re-verified at 87f829d. All three notes from my review are closed and the change is docs-and-comment only on top of what I already checked.

  • README has the missing paragraph: gate-authored evidence captures attribution at entry, so a mid-operation move leaves the audit trail in the starting repository's partition where a session bound there can still read it — and it says plainly that caller-level init/capture events resolve per event and can land elsewhere. That is the asymmetry a reader would otherwise trip over.
  • Issue #199 is filed for exactly that lifecycle boundary, so it is tracked rather than buried in a PR sentence.
  • My session-less question got the answer I was hoping for, in the right place: the comment on captureEvidenceContext now states that "?" keeps the ambient call only while the ambient session is also "?", and that the snapshot deliberately never guesses a missing operation call from a later setCurrent. That is a decision rather than an accident, which is all I asked for — I could not construct an ordering where it bites, and now the next reader does not have to try.

Drive-by that I appreciate: the test's outcome.ts! became an explicit throw naming the missing row id, so the lint delta I reported is gone — biome is back to 409 warnings, flat versus main. Unit at this head is 758 pass / 11 skip / 0 fail, and CI is green on all four legs.

@abogartz
abogartz merged commit 538cf5a into abogartz:main Oct 31, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.14.27 🎉

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

2 participants