Repository navigation
Conversation
A namespace-wide token writing for several users merged one user's restatement into another user's row; the writer's user_id-scoped search then found nothing. The write-time conflict check now treats another user's rows as absent for a write that names its user_id, as it already did under a token narrowed to one user. Another user's pinned row still refuses the write; a write without a user is judged as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
9 tasks done
The writer's scope narrows a namespace-wide token to the write's user for the peer statements, the batched candidates and the Postgres admission, so other users' rows neither take the read's places nor reach a verdict. A restatement of another user's pinned value is written, not refused. Tests cover the bulk and update wiring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…s required on the peer helpers Under a token bounded to one user, a restatement of another user's pinned value is refused like any close write, so the answer does not tell which value was pinned. The conflict docs claim the verdict only, name the restatement rule and the extra pinned read; tests cover the Postgres admission helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ocs name the paths it does not cover Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
1 task done
…ed user; the conflict test reads Bob's row back Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…y; tests cover the bulk restatement and Bob's whole row Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
… the batched path too; memory concepts name the user rule Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…on; a test pins a shared peer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ns it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ge-authority docs name the writer scope Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…d argument; two docs read plainly Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…hout a filter Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
9 tasks done
…write's real user Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…cstrings read plainly Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
This branch has not been deployed
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.
Related: #696 (the Google ADK memory service, whose review found this)
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):
The write-time conflict verdict of a write that names its
user_idreads and judges only that user's memories: a service writing for many users through one token no longer loses a user's memory into another user's row, where that user's own searches could not find it.Why
The write-time conflict check (
check_on_commit) compares a new value with the namespace's close rows. Under a token narrowed to one user (read_user_id), rows of other users are already treated as absent (_split_by_read_scope). Under a namespace-wide token, which is how a framework adapter or any backend serving many users connects, every user's rows were peers.Failing case, against a running server with a namespace-wide token:
memory.set("seat_a", "Prefers aisle seats", user_id="alice")→clear.memory.set("seat_b", "Prefers aisle seats", user_id="bob")→conflict_verdict: "merge",noop: true,merged_into_key: "seat_a".memory.search("aisle seat", user_id="bob")→ nothing; Bob's memory is gone from Bob's reads.The same holds for every write path that runs the check (
memory.set,memory.bulk_setand somemory.set_from_messages,memory.update), and for the other verdicts a peer can produce (duplicate, anewest_winssupersession, aconflictmark on the other user's row).Making the cross-user restatement a
duplicate(as a run-scoped write does) does not help: search hides aduplicaterow and seats its canonical in its place, and the canonical is the other user's row, which Bob's filter excludes. So the fix extends the narrowed-token rule: a write that names auser_idreads and is judged against that user's rows only._writer_scope(user_id)(replacing_scope_or_none) narrows a namespace-wide request scope toown_userfor the write's user, and every peer read takes it: the per-fact statements (nearest_peer_rows), the batched candidates (candidate_rows_many), and the Postgres authority'speer_rows,could_be_peer,trim_peersand admission gap check. Other users' rows therefore neither take the read's 10 places nor reach a verdict, and the narrowed-token pinned arm (_foreign_pinned_rows,pinned_sql_many) applies unchanged.docs/features/tasks-and-decisions.mdsays so): a close decision of another user under another key is no longer flagged.memory.setlands under the approver'suser_id, so it is judged against the approver's rows, as any write naming its user is (its docstring said "namespace scope"; it never was one for reads).-) is judged against every user's rows, as before, so shared namespace facts still deduplicate.user_id-) either: a user-filtered read does not serve them, so folding the user's fact into one would hide it the same way. The user's fact is written as its own row beside a shared one, unflagged; a shared pinned row still refuses a close write, and a restatement of it is written as the user's row under a namespace-wide token, as for another user's pin.memory.bulk_set's own fold of a byte-identical value already required the same agent and user.Design rationale is in
docs/architecture/memory-architecture.md(conflict verdict step); the rule is indocs/features/memory/conflicts-and-refusal.mdanddocs/concepts/memory.md(write path, step 5).Scope and risk
Not covered here, and unchanged: two retirement paths outside the verdict still read the request's scope, not the write's user: same-key supersession under
newest_wins(key_supersession._live_same_key_rows) and the value-update pass (value_updates, withdetect_updates). Under a namespace-wide token they can still retire another user's row; they need the same writer scope and their own tests, tracked in #723.Cost: a write that names its user under a namespace-wide token now runs the separate pinned read a narrowed token already runs (
PINNED_PEERS_SQLper fact,pinned_sql_manyper batch chunk). The per-fact path andpeer_rowsstart it together with the scoped peer read (_scoped_and_pinned_peers), and each batch chunk starts it with its candidate statement, so it adds read volume, not a round trip.tests/integration/test_conflict_read_cost.pybounds that pair at two namespace-wide reads; on its fixture locally, the namespace-wide read was 64 MB and the user's own read 5 MB plus the pinned read 25–79 MB.Server memory write path only:
server/memory/app/conflicts.py(_writer_scope),pg_admission.py, and the callers inset_commit.py,bulk_set.pyandupdate.pypass the user; the writer's user is a required argument ofcheck_on_commit(new_user_id) and of the peer helpers, so no caller falls back to every user's rows by omission; the direct test callers pass"-". No wire, schema or setting change. A namespace whose writers name users now keeps one row per user for a fact several users state; nothing already written changes.Compatibility, rollout and rollback
Tests
tests/unit/test_dedup_verdict.py: a restatement of Alice's row written for Bob isclearwith no peer; Alice's own restatement still merges; a write with no user still merges into Alice's row; a write for Alice beside a shared-row isclear, and one with no user merges into it; Bob's decision beside Alice's close decision under another key isclear, and a decision with no user conflicts with it; Alice's pinned row still refuses Bob's close write, and Bob's restatement of the pinned value isclear, as is Alice's restatement of a shared pinned row; the peer statement of Bob's write carries Bob as its scope.tests/unit/test_write_peer_reads.py: a bulk write for Bob beside Alice's same-text row clears each entry, and its nearest-peer statements read Bob's rows, batched and per fact; Bob's bulk restatement of Alice's pinned value is written, through the batched pinned arm and per fact.tests/unit/test_memory_update_conflict.py:memory.update_by_idof Alice's row is judged withnew_user_id="alice". This and the Postgres_pg_peer_rowstest check the wiring on purpose: the verdict for a given user is tested atcheck_on_commitand through the HTTP path, and faking the whole update or Postgres write to reach it again would test the fakes.tests/unit/test_write_scope.py: V's close pinned row refuses a write for U, per fact and through the batched candidates' pinned arm, under a token bounded to U and under a namespace-wide token naming U; a namespace-wide token writing for U reads U's rows then the pinned ones, is refused by V's pin for a different value and writes a restatement of it; under a token bounded to U the restatement is refused.tests/unit/test_pg_authority.py: a Postgres point write reads the peers of its user (_pg_peer_rowspassesuser_id); the Postgres admission gap check of Bob's write ignores Alice's unpinned row inside the reach (a write with no user does not);could_be_peer/trim_peersfor Bob keep Bob's rows and Alice's pinned one.user_idfieldMemoryBulkSetInputalways has;test_conflict_read_costandtest_decision_opsfollow the rename to_writer_scope.tests/integration/test_memory_conflicts.py::test_a_restatement_by_another_user_keeps_its_own_row: through the HTTP path, Bob's restatement isclearwith its own id, read back as Bob's active, unpinned row with his value, agent, session and type and noduplicate_of, Alice's restatement merges, and each user's search returns their own key. It fails on main ('merge' == 'clear') and passes with this change, against a local server (fake embedder).tests/integration/test_memory_conflicts.pyandtest_bulk_conflicts.py: 8 passed against a local server (the teardown's org purge needs ClickHouse credentials the local env lacks).tests/integration/test_conflict_read_cost.py: 4 passed locally.make format lint typecheck; the full unit suite locally (36130 passed; 36137 on the round-12 head; rerun on the final head before merge); CI runs it again.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. Checked: the failing case and the fix against a running server, and the search path that hides
duplicaterows.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 (locally, the full unit suite); the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code