Skip to content

memory.dedup_resolve names the pair by memory id and tombstones only that pair's rows - #199

Merged
zlareb1 merged 11 commits into
mainfrom
fix/dedup-resolve-by-id
Nov 3, 2026
Merged

zlareb1 merged 11 commits into
mainfrom
fix/dedup-resolve-by-id

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

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_resolve takes canonical_id and duplicate_id (the ids memory.dedup_list returns) and acts only on that pair. The removed canonical_key and duplicate_key are still accepted, never applied, and named in ignored_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_resolve looked up each side with find_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 key k, the second flagged as a duplicate of the first, made both lookups return the same row, so keep_canonical could 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_list already reports each cluster by memory id (canonical_id, duplicates[].memory_id), so the pair has an exact address.

Fix: the input carries canonical_id and duplicate_id. The handler reads both by id (strong read, as the lock guard needs), and answers 404 DEDUP_PAIR_NOT_FOUND unless both rows are live in the request's namespace, the duplicate is marked duplicate and its duplicate_of is the canonical id. An id is read in its dashed form, so a braced or urn: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_key now 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_namespace and KeyedRow are removed.

Scope and risk

Touches only memory.dedup_resolve and 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_resolve addresses documents by URI and is unchanged.

Compatibility, rollout and rollback

  • Wire: memory.dedup_resolve requires the new canonical_id and duplicate_id. The removed canonical_key and duplicate_key stay 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 new ignored_args (and the X-Loom-Ignored-Args header) names them. A call that sends only the keys gets 422 VALIDATION_FAILED naming the missing canonical_id and duplicate_id, and writes nothing; that 422 does not list the keys as ignored, as no validation failure lists ignored_args today. Output fields canonical_key and duplicate_key are now the rows' keys rather than echoes. The keep_both docs no longer claim it writes the conflict allowlist; it never did. The Python SDK's memory.dedup_resolve(canonical_id, duplicate_id, ...) changes its positional parameters accordingly. No dashboard page calls the op.
  • Operator steps: none. During a rolling upgrade a call whose version does not match the replica it lands on writes nothing: keys sent to a new build fail validation on the missing ids, and ids sent to an old build are refused with 422 UNKNOWN_ARGUMENT (canonical_id → canonical_key). Retry once the rollout completes.
  • Rollback: revert; no stored data or migration changes.

Tests

  • tests/unit/test_dedup_ops.py: canonical and duplicate share key k under two agents; keep_canonical tombstones 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 in ignored_args; a call without them names none; a call with only the keys fails validation on exactly the two id fields; a locked side refuses keep_canonical / keep_duplicate with 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.py pass. 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 calls memory.dedup_resolve; the unit tests fake get_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 typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/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 under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 11 commits November 3, 2026 10:05
…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]>
…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]>
…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]>
@zlareb1
zlareb1 merged commit 1fdf61c into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/dedup-resolve-by-id branch November 3, 2026 18:00
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant