Skip to content

fix: resolve session identity before authorizing merge/forget/undo (#260) - #269

Merged
abogartz merged 2 commits into
mainfrom
fix-issue-260-20261103T162509Z
Nov 3, 2026
Merged

abogartz merged 2 commits into
mainfrom
fix-issue-260-20261103T162509Z

Conversation

@ocsi-fixer

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

Copy link
Copy Markdown

Closes #260

What

memory_merge_review, memory_forget and memory_undo now await bindSessionIdentity(sid) before authorizing, matching memory_remember, memory_update, memory_import and memory_init. The synchronous entry binding (toolIds) only binds an unseen session provisionally to the instance's directory; on a serve host the session row is the only source of truth and a tool call can be the first thing an instance sees for a session, so authorization could resolve against the wrong repository — the boundary #131/#204 protect.

This is the "await bindSessionIdentity before authorizing" branch of the decision requested in the ticket body. The ticket notes memory_forget and memory_undo as unprobed but same-shaped; they are included because they resolve their Reader the same way (pruneMemory → readerFromSid(sid), restoreSnapshot(..., readerFromSid(sid))).

Acceptance criteria and evidence

Ticket reproduction, replayed mechanically in test/security-mutate-identity.test.ts (recorded serve-host shape from repo-scope-serve-host.test.ts: context messages carry no location; the session row carries location.directory; no prompt hook runs first):

Criterion Evidence
memory_merge_review called with no prompt hook first must NOT retire the repo-A row RED at merge-base 1b226e3: merge resolved and the row was retired. GREEN at cf139ac: refused with "another repository", superseded_by stays undefined
Same call after identity resolution behaves correctly (control) New control test: session row naming A still merges A's rows ("Resolved merge")
memory_forget same gap RED at 1b226e3: "Deleted 1 context memory(s)". GREEN: "No memories found", row survives
memory_undo same gap RED at 1b226e3: session.get never called. GREEN: identity resolved from the host before the restore

New tests: 3 fail at merge-base 1b226e3 for the stated reason, 4/4 pass at head cf139ac.

Commands run (measured)

  • bun run typecheck — clean (231 files, no errors)
  • bun run lint — exit 0 (pre-existing warnings/infos only, no errors)
  • bun run test — 914 pass / 14 skip / 0 fail (87 files)
  • bun run test:e2e — 30 pass / 0 fail (8 files)
  • bun test ./test/security-mutate-identity.test.ts at merge-base — 1 pass / 3 fail; at head — 4 pass / 0 fail

Deliberately not changed

  • Read-only tools (recall, list, evidence, status, consolidate) — the ticket scopes the decision to the mutating authorization paths; reads stay on the provisional entry binding.
  • bindSessionIdentity itself and the entry-binding plumbing in src/index.ts — unchanged.
  • No workflow, label-outside-fix:*, or issue-body changes.

)

The three mutating tools that partition by Reader called readerFromSid
straight after the synchronous entry binding, which only binds an unseen
session provisionally to the instance's directory. On a serve host the
session row is the only source of truth and a tool call can arrive before
any prompt hook, so authorization ran against the wrong repository.

memory_merge_review, memory_forget and memory_undo now await
bindSessionIdentity(sid) before authorizing, matching memory_remember,
memory_update, memory_import and memory_init.
@ocsi-triager ocsi-triager Bot added the review:requested Human-admitted for autonomous review by ocsi-reviewer label Nov 3, 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.

Head reviewed: cf139ac24c9202df6d6cbc2c72adf6e77c3c3551

Contract (#260, authored by WhollyMindless — trusted human; spec anchor 306e42228970cbbf matches the issue body, frozen):

Decision requested

Either await bindSessionIdentity(sid) before authorizing in these tools, which looks like one line each, or record that the prompt hook is the guarantee and that the difference from the write tools is intended.

The PR takes the await branch, for all three Reader-resolving mutating tools.

Per-criterion evidence:

Criterion (from the finding + reproduction) Evidence
memory_merge_review awaits identity before authorizing src/tools/merge-review.ts:27 await bindSessionIdentity(sid) before the Reader; test test/security-mutate-identity.test.ts:81-96 refuses with "another repository", superseded_by stays undefined
Same call after identity resolution still works (control) test/security-mutate-identity.test.ts:98-111 → "Resolved merge"
memory_forget same gap closed src/tools/forget.ts:21 before pruneMemory; test :113-126 "No memories found", A's row survives
memory_undo same gap closed src/tools/undo.ts:30 before restoreSnapshot(..., readerFromSid(sid)); test :128-138 asserts session.getCalls contains the sid

Deps wiring verified: src/tools/deps.ts:11 declares bindSessionIdentity, provided at src/index.ts:296, same call shape as remember.ts:28 / update.ts:28 / import.ts:21 / init.ts:18.

Differential (the decisive measurement): new test file replayed at merge-base 1b226e3: 1 pass / 3 fail — the three security tests fail for the stated reason (merge retired the foreign row; forget deleted it; undo never called session.get); the control passes because the provisional binding already names A. At head: 4 pass / 0 fail. Fixed side clean, broken side fails for the stated reason.

Commands run (measured, Bun 1.4.4):

  • bun run typecheck — clean, 231 files, 0 errors
  • bun run lint — exit 0; zero warnings in the four touched files (total 501 = baseline drift from main, none attributable to this diff)
  • bun run test — 928 pass / 14 skip / 0 fail (87 files)
  • bun run test:e2e — 30 pass / 0 fail (8 files)

Test integrity: no .skip, no deleted assertions, no widened tolerances; the new file is purely additive.

Findings: no P0, no P1. Nit (non-blocking): the undo test asserts identity was resolved (getCalls contains sid) but not that a foreign row survives the restore — weaker than the merge/forget assertions; the restore partitioning itself is already covered by #204's suite.

FINAL GATE re-check at filing (verbatim): headRefOid = cf139ac24c9202df6d6cbc2c72adf6e77c3c3551 (unchanged); lint pass, test pass, test-windows pass, smoke pass.

Human merges.

@abogartz
abogartz merged commit 1ab9df1 into main Nov 3, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.14 🎉

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.

memory_merge_review authorizes before resolving session identity (host reach unproven)

1 participant