Skip to content

fix(evidence): preserve caller ownership across emit paths - #304

Merged
abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:fix/evidence-session-attribution-297
Nov 5, 2026
Merged

abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:fix/evidence-session-attribution-297

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

Closes #297. Evidence from decay, consolidation, the open-thread frontier and epoch recomputation could receive whichever session was ambient when the operation finished. That could expose the line to the wrong repo while hiding it from the caller.

Capture the calling session's existing EvidenceContext before the first await and pass it, together with sid, at all six emit sites. Resolved callers retain their own repo stamp while ordinary sid/call metadata stays suppressed. The context also preserves a private sid for unresolved callers: passing only record's fourth argument with includeContext=false would omit both repo and sid, making those lines read as legacy/global. This uses the existing writer behavior without changing its policy.

The new regression suite drives all six real emit paths with a different ambient session, for both resolved and unresolved callers (12 tests, 110 assertions). It checks persisted ownership fields and reads events through memory_evidence: the caller can see them; another repo and another unresolved session cannot. Partial decay is exercised by failing the second file's publication after the first row actually retires. All 12 tests fail on original base 7405dc6 and pass with this fix.

Rebased onto latest main 06e4e28 after #303 merged. Validation of that combined tree on Windows, Bun 1.4.4:

  • bun run test: 1,008 pass, 32 skip, 0 fail (29.19s).
  • bun run test:e2e: 30 pass, 0 fail (16.32s).
  • bun run typecheck, bun run lint, and git diff origin/main...HEAD --check: pass.

The mismatched-session scenarios use the local test harness; no live multi-repo host reproduction is claimed. Taking this at WhollyMindless's request. Please feel free to defer or reject the PR if you prefer another approach. No agent labels were changed.

@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 head 466b49fcfda4e338329597d87c5930631d18e838 (merge-base 06e4e28). COMMENTED, not APPROVE: spec not authored or adopted by a trusted human: a person decides — governing issue #297 was authored by app/ocsi-architect and its timeline shows no agent:ready label applied by any human (only severity:high and spec:draft, both by ocsi-architect[bot]). The code itself passes every acceptance criterion below; once a maintainer adopts #297, this head is ready.

Contract (#297 acceptance, verbatim)

RED: on main 7405dc61d919e7eee7033dea6e4324eda58ee669, a test that sets the ambient current to session B (repo B) and executes the memory_decay dry run for session A (repo A) reads back an evidence line stamped repo=<B-key> — the test fails.

Evidence: checked out 7405dc6 (index + worktree), ran bun test test/emitter-evidence-attribution.test.ts against the PR's test file: 0 pass / 12 fail, failing at checkOwner test/emitter-evidence-attribution.test.ts:78 with Expected: undefined / Received: "ba0beae100cb" — the ambient stranger repo's key on the line, exactly the misstamp the ticket describes.

GREEN: bun run test passes; the line is stamped repo=<A-key>; the same assertion holds for consolidate_propose, frontier_injected and epoch_recompute (each driven with a mismatched ambient current).

Evidence: at head, bun run test: 1021 pass / 19 skip / 0 fail (12646 expect(), 1040 tests, 23.94s). The new suite drives all six real emit paths for resolved and unresolved callers with ambient current set to a different repo (test/emitter-evidence-attribution.test.ts:99-106 covers decay_dry_run, decay_applied full and partial, consolidate_propose, frontier_injected, epoch_recompute); checkOwner asserts repo/repoPath equal the caller's scope and reads back through memory_evidence (caller sees, stranger and other-unresolved session do not): 12 pass / 0 fail / 110 expect().

Commands run at head (measured)

  • bun run typecheck — exit 0, no errors
  • bun run lint — 493 warnings, identical to merge-base 06e4e28 baseline (measured on the same machine)
  • bun run test — 1021 pass / 19 skip / 0 fail
  • bun run test:e2e — 30 pass / 0 fail (src/ changed)
  • CI re-check at filing time: lint pass, test pass, test-windows pass, smoke pass; headRefOid = 466b49fcfda4e338329597d87c5930631d18e838 (unchanged from review)

Code review

All six sites named in the issue are threaded, each capturing before the first await: src/tools/decay.ts:22 (dry run + applied + partial), src/tools/consolidate.ts:24, src/inject/digest.ts:49, src/inject/epochs.ts:189; record() consumes the pre-captured context (src/evidence/record.ts:121) and the unresolved-owner privacy-label branch (src/evidence/record.ts:128-132) keeps sid on the line when the scope is null, so an unresolved caller's line stays private instead of reading legacy/global. The partial-decay test fails only the second file's publish via spyOn(publish,"writeAtomic") and asserts the first row really retired (superseded_by === "decay") — the real partial path, not a mocked receipt. No assertion deleted, no .skip, no tolerance widened: the test file is purely additive (+171).

P0/P1: none. Nit: when a digest input carries no sessionID, sid is "?" and captureEvidenceContext("?") falls back to the ambient call exactly as before the change (src/evidence/record.ts:86-92) — pre-existing documented behavior, not a regression.

Spec anchor

Recomputed #297 body hash with the triager pipeline: 7130ec157680844a. No prior osi-spec-hash: comment exists, so the spec is frozen. The reviewer app cannot post issue comments (403 Resource not accessible by integration on POST issues/297/comments — no issues:write), so the anchor is recorded here; a maintainer or the triager should post osi-spec-hash: 7130ec157680844a on #297.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

The independent review verified the implementation and all acceptance tests; approval is held because #297 is still an architect-authored draft awaiting human adoption.

@abogartz, if you want this to proceed, could you adopt #297 through your normal process? The review records the proposed spec anchor as 7130ec157680844a. Happy to leave this deferred if you prefer; no further code change was requested by the review.

@abogartz
abogartz self-requested a review as a code owner November 5, 2026 15:52
@abogartz
abogartz merged commit 5fa9d84 into abogartz:main Nov 5, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.37 🎉

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.

Evidence emit paths in decay, consolidate, digest and epochs stamp the ambient session's repo

2 participants