Repository navigation
fix: resolve session identity before authorizing merge/forget/undo (#260) - #269
Conversation
) 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.
There was a problem hiding this comment.
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 errorsbun 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.
|
🎉 This PR is included in version 0.15.14 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #260
What
memory_merge_review,memory_forgetandmemory_undonowawait bindSessionIdentity(sid)before authorizing, matchingmemory_remember,memory_update,memory_importandmemory_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
bindSessionIdentitybefore authorizing" branch of the decision requested in the ticket body. The ticket notesmemory_forgetandmemory_undoas 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 fromrepo-scope-serve-host.test.ts: context messages carry no location; the session row carrieslocation.directory; no prompt hook runs first):memory_merge_reviewcalled with no prompt hook first must NOT retire the repo-A row1b226e3: merge resolved and the row was retired. GREEN atcf139ac: refused with "another repository",superseded_bystays undefinedmemory_forgetsame gap1b226e3: "Deleted 1 context memory(s)". GREEN: "No memories found", row survivesmemory_undosame gap1b226e3:session.getnever called. GREEN: identity resolved from the host before the restoreNew tests: 3 fail at merge-base
1b226e3for the stated reason, 4/4 pass at headcf139ac.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.tsat merge-base — 1 pass / 3 fail; at head — 4 pass / 0 failDeliberately not changed
recall,list,evidence,status,consolidate) — the ticket scopes the decision to the mutating authorization paths; reads stay on the provisional entry binding.bindSessionIdentityitself and the entry-binding plumbing insrc/index.ts— unchanged.