Repository navigation
memory.ask and memory.search read a run's working-memory notes only inside the request's read scope - #196
Merged
Conversation
…'s read scope render_run_blocks read loom.working_memory by (org, namespace, run_id) alone, so a token narrowed to one user that named another user's run_id got that user's notes in the synthesis prompt. The statement now carries the request's read-scope predicates, as working_memory.get and working_memory.render do. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…est's read scope scratchpad.load's run-scope read had the same gap as memory.ask's: no user or session predicate. The read-scope predicates now go on the one statement behind scratchpad.load, and render_run_blocks reads through it (scratchpad.run_rows) instead of keeping its own statement. The tests seed one run with two users' notes and check what each reader returns, and that a refused scope reads nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
One function owns the run-scope read, so no call site passes identity arguments the run statement ignores. The refused-scope test covers memory.search's reader too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…oped select run_rows names only the predicates the run read has; the session read keeps its identity axes. Both go through _select, which adds the request's read scope. The working-memory page says which reads carry blocks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…un-notes read render_run_blocks resolves the request's read scope before its fail-open read, so the refusal reaches the caller as the scope error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
memory.askandmemory.searchwith arun_idno longer return another user's working-memory notes when the token is bounded to one user or session.Why
Failing case: a token with
read_scope=own_user(or aread_user_idpin) foru1names therun_idof a runu2wrote working-memory notes under.memory.ask:render_run_blocksreadloom.working_memoryby(org, namespace, run_id)with no user or session predicate, sou2's notes went into the synthesis prompt.memory.search(andcontext.packthrough it):scratchpad.loadread the run's blocks the same way and returned them inscratchpad.Pattern:
working_memory.getandworking_memory.rendercheck the request's read scope; the two run-notes readers did not. The read-scope section of the identities concept page already lists working memory among the reads that carry the scope.Fix: every working-memory read in
server/memory/app/scratchpad.pygoes through_select, which appends the request's read-scope predicates (scope_and(request_scope(), params)).run_rowsis the run read and_session_rowsthe session read.render_run_blocksdrops its own statement and reads throughrun_rows, somemory.askandmemory.searchshare one scoped run read. Undernamespacenothing is added, so unbounded tokens see the same notes as before. A scope that does not resolve raises before any statement runs:memory.askrefuses the call with that error (it resolves the scope before its fail-open read, so a refusal is not logged as a failed read), andmemory.searchdrops the notes, as it does on any scratchpad read error.Scope and risk
Touches the working-memory reads in
server/memory/app/scratchpad.pyandserver/memory/app/working_memory.py, and the Limits section ofdocs/features/memory/working-memory-and-profiles.md, which said blocks never appear inmemory.searchormemory.ask. Tenant isolation tightens; no write path, schema or wire change. Underown_session, a run's notes written withsession_id='-'(as the plugin writes them) are no longer served, even to the run's own user, which matchesworking_memory.getunder that scope.memory.ask's run notes are now orderedupdated_at DESC, block_key(ties broken by key), asmemory.search's already were.Compatibility, rollout and rollback
Tests
tests/unit/test_ask_run_scratchpad.py:test_run_notes_stay_inside_a_narrowed_read_scopeseeds one run with notes fromu1andu2, binds anown_sessionscope foru1, and checks thatrender_run_blocksandscratchpad.loadreturn onlyu1's note, while the whole-namespace read still returns both.test_a_refused_read_scope_reads_no_run_notesbinds a refused scope and checks thatrender_run_blocksandscratchpad.loadboth raise it and that no statement runs.Both fail with the scope line removed. Locally:
tests/unit/test_ask_run_scratchpad.py,test_scratchpad_inject.py,test_pack_agent_working_memory.py,test_working_memory_ops.py,test_package_contracts.pyand the doc and copy checks pass;make format lint typecheckclean. CI runs the full suite.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. The failing case was checked against the code and the new test fails before the fix.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.main; no merged migration is edited.docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code