Repository navigation
fix(memory): give a resend whose text-derived row moved on a fresh identity - #17326
Merged
Merged
Conversation
…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]>
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.
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_rowcorrectly refuses to treat an edited/inactive/rejected row as the same memory, so the add fails on every retry.Fix.
write_canonical_external_memoryprobes the text-derived id before writing: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_failsunchanged and passing).This matches the published contract from #17321: text the user does not have (any more) becomes a new memory.
Verification
MemoryService→ canonical apply, onmainbefore 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.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.pygains the edited-resend regression throughwrite_canonical_external_memory. All 34 unit files importingcanonical_memory_adapterpass.Product invariants affected
MemoryServiceand the canonical writer, with no fallback writer.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