Skip to content

fix(memory): give a resend whose text-derived row moved on a fresh identity - #17326

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/external-memory-resend-collision
Sep 23, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/external-memory-resend-collision

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #17301 / #17321 for #17296.

Summary

After #17301 reached prod (backend-79e340a-35852459809-1), the evidence conflict in front of the developer memory write was gone, and the same client's resends started failing one step later: 15 × RuntimeError: canonical write failed: ApplyStatus.invalid_patch (add patch new_memory_id already exists) between 12:03 and 12:05Z.

Cause. External memory ids are derived from the submitted text, but a row keeps its id when it is edited (PATCH), superseded by consolidation, or rejected by the user. Re-sending the original text proposes an add for that id. _existing_identical_add_row correctly refuses to treat an edited/inactive/rejected row as the same memory, so the add fails on every retry.

Fix. write_canonical_external_memory probes the text-derived id before writing:

  • absent → write it;
  • an active, unrejected row holding the same text → reuse it (the published dedupe contract);
  • otherwise → a deterministic reissued id (canonical-external-memory-occupied-reissue, bounded at 25 probes), exactly as a re-add after delete already works. A retry of the resend lands on the same new row.

Only ids derived from the exact submitted text may move. A caller-supplied id reused for different text still fails (test_reusing_a_row_id_for_different_content_still_fails unchanged and passing).

This matches the published contract from #17321: text the user does not have (any more) becomes a new memory.

Verification

  • Firestore emulator, real developer route → MemoryService → canonical apply, on main before this change: edited, superseded, and rejected resends each reproduce the exact prod error. With this change each creates one new memory and a retry returns the same id; the edited original keeps its edited text; a plain duplicate still returns the existing memory.
  • Unit: test_external_memory_resend_identity.py (new: derived id kept, live identical row reused, edited/superseded/rejected rows reissue to one stable id, retry after commit resolves to the reissued row, occupied candidates skipped); test_ws_j_delete_privacy.py gains the edited-resend regression through write_canonical_external_memory. All 34 unit files importing canonical_memory_adapter pass.

Product invariants affected

  • INV-MEM-1 — no tier change.
  • INV-MEM-3 — writes still go through MemoryService and the canonical writer, with no fallback writer.
  • INV-MEM-4 — intake routing, promotion, and receipts are unchanged; only which row id an external create targets changes when its text-derived id is occupied by a row that no longer holds that text.

Failure-Class: FC-content-derived-identity-retired-by-deletion

Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py | 4121 -> 4166 | occupied text-derived id reissue beside the existing tombstone reissue it mirrors

🤖 Generated with Claude Code

Review in cubic

…entity

External memory ids are derived from the submitted text, but a row keeps
its id when it is edited, superseded, or rejected. Re-sending the
original text then collided with that row, the duplicate-add resolution
correctly refused to treat it as the same memory, and every retry failed
with 'canonical write failed: invalid_patch (add patch new_memory_id
already exists)'. After #17301 removed the evidence conflict in front of
it, this is what the #17296 client hit in prod.

The user no longer has that text, so the resend is a new memory: the
write now probes the derived id and moves to a deterministic reissued id,
as a re-add after delete does. Retrying lands on the same new row. Only
ids derived from the exact text move; a caller-supplied id reused for
different text still fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit f4e59e6 into main Sep 23, 2026
65 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/external-memory-resend-collision branch September 23, 2026 12:22
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