Repository navigation
memory.dedup_resolve names the pair by memory id and tombstones only that pair's rows - #199
Merged
Merged
Conversation
…that pair's rows The op took two keys and looked each up with LIMIT 1 by key alone, so a key held by several identities resolved to any of their rows: keep_canonical could tombstone the canonical itself, or an unrelated user's live row. The input now carries canonical_id and duplicate_id from memory.dedup_list; the duplicate must be live in the namespace, marked duplicate and point at the canonical, else 404. The key lookup is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…sed with the id fields to use Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
ClickHouse parses only the dashed UUID form; a braced or urn:uuid: id Python accepts now names its row instead of failing the read. 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]>
…ey and names them in ignored_args The keys stay on the input model as optional, MCP-hidden fields the handler never reads; the output's ignored_args names the ones a call sent. canonical_id and duplicate_id stay required, so a call with only the keys fails validation and writes nothing. 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]>
…e refuses through the id path 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]>
…heck makes it a 404 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… decisions 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.dedup_resolvetakescanonical_idandduplicate_id(the idsmemory.dedup_listreturns) and acts only on that pair. The removedcanonical_keyandduplicate_keyare still accepted, never applied, and named inignored_args; a call that sends only the keys fails validation on the missing ids and tombstones nothing. Before, a key held by several identities could make it tombstone the canonical row or another user's live row.Why
Failing case:
memory.dedup_resolvelooked up each side withfind_row_by_key_namespace,SELECT ... FROM loom.memory FINAL WHERE org, namespace, memory_key, tombstoned_at IS NULL LIMIT 1: no identity tuple, no status filter, no order. Two agents writing keyk, the second flagged as a duplicate of the first, made both lookups return the same row, sokeep_canonicalcould tombstone the canonical. When an unrelated user held the duplicate key, that user's live row could be the one tombstoned: a delete its writer never asked for.Pattern: a key alone does not name a row in a namespace; several identities can hold it.
memory.dedup_listalready reports each cluster by memory id (canonical_id,duplicates[].memory_id), so the pair has an exact address.Fix: the input carries
canonical_idandduplicate_id. The handler reads both by id (strong read, as the lock guard needs), and answers 404DEDUP_PAIR_NOT_FOUNDunless both rows are live in the request's namespace, the duplicate is markedduplicateand itsduplicate_ofis the canonical id. An id is read in its dashed form, so a braced orurn:uuid:spelling names the same row, and a value that is not a UUID is a 404 rather than a ClickHouse parse error.confirm_canonical_keynow must equal the canonical row's key. The rows read for the pair are the ones the lock check sees, so the second read per side is gone.find_row_by_key_namespaceandKeyedRoware removed.Scope and risk
Touches only
memory.dedup_resolveand its SDK method. Tenant isolation: the read is scoped to the token's org and the row's namespace must equal the request's namespace (which the transport authorizes for the admin role); a row elsewhere answers the same 404 as a missing one.knowledge.dedup_resolveaddresses documents by URI and is unchanged.Compatibility, rollout and rollback
memory.dedup_resolverequires the newcanonical_idandduplicate_id. The removedcanonical_keyandduplicate_keystay on the input model as optional, MCP-hidden fields the handler never reads; a call that sends them is served by id and the output's newignored_args(and theX-Loom-Ignored-Argsheader) names them. A call that sends only the keys gets 422VALIDATION_FAILEDnaming the missingcanonical_idandduplicate_id, and writes nothing; that 422 does not list the keys as ignored, as no validation failure listsignored_argstoday. Output fieldscanonical_keyandduplicate_keyare now the rows' keys rather than echoes. Thekeep_bothdocs no longer claim it writes the conflict allowlist; it never did. The Python SDK'smemory.dedup_resolve(canonical_id, duplicate_id, ...)changes its positional parameters accordingly. No dashboard page calls the op.UNKNOWN_ARGUMENT(canonical_id→canonical_key). Retry once the rollout completes.Tests
tests/unit/test_dedup_ops.py: canonical and duplicate share keykunder two agents;keep_canonicaltombstones the duplicate id only. A 404 with nothing tombstoned for a missing row, a duplicate pointing at another canonical, a row not marked duplicate, either row in another namespace or another org, a gone canonical and a non-UUID id; braced,urn:uuid:and upper-case ids resolve to the row they name. Written first; failed against the key-based handler.tests/unit/test_dedup_ops.py: a call with the ids and the removed keys is not refused, is served by id, and its body and header name both keys inignored_args; a call without them names none; a call with only the keys fails validation on exactly the two id fields; a locked side refuseskeep_canonical/keep_duplicatewith 423 and nothing is tombstoned.tests/unit/test_memory_webhooks.py: the tombstone event names the side the decision removes.make format lint typecheck;tests/analyzer,test_lock_guard_consistent_read.py,test_sdk_surface_contract.py,test_public_copy.py,test_doc_links.py,test_package_contracts.pypass. The analyzer's statement corpus loses the removed key lookup's shape. The full unit suite runs in CI. Not run: the integration suite. No integration test callsmemory.dedup_resolve; the unit tests fakeget_by_id, whose org filter, tombstone exclusion and strong read are unchanged by this diff.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 store query and handler.
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.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).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