Repository navigation
docs(dev-api): publish the memory dedupe contract and gate Developer API breaks - #17321
Merged
Merged
Conversation
…API breaks Developer API memory creates are identified by their text: re-sending text the user already has returns that memory unchanged, which also makes retries safe. That was the behavior, but undocumented, and the evidence-identity bug in #17296 hid it behind 500s. #17301 made the replay path work; this states the contract in the route docs and the Developer API guide and pins the route half of it with tests. The public Developer API contract now runs the directional OpenAPI compatibility checker in CI, so a request or response break fails review instead of shipping. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Git-on-my-level
added a commit
that referenced
this pull request
Sep 23, 2026
…entity (#17326) 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](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/17326?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This branch was successfully 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.
Follow-up to #17301 for #17296. No behavior change: this publishes the contract #17301 made work, and adds a CI gate so the next Developer API change cannot break consumers silently.
Summary
Dedupe contract, now documented (
POST /v1/dev/user/memories,/batch, route docstrings → OpenAPI, anddocs/doc/developer/api/memories.mdx):200with the existing memory; nothing new is storedcategory/visibility/tags200with the existing memory as stored; new fields are not applied (usePATCH)Matching trims surrounding whitespace and is case-sensitive. In a batch, duplicates return the existing memory at their position;
created_countis the number of memories returned.Every row of that table was measured on the Firestore emulator through the real developer routes,
MemoryService, and canonical apply onmain(auth and categorizer patched only).Why dedupe rather than server-assigned ids: the only client that produced the #17296 500s (one
Python-urllib/3.12integration, 254 500s + 1,022 429s in 12 h, zero successes) re-sends the same text. Under dedupe its retries now return the existing memory; under random ids each accepted retry would have become a duplicate.Future changes stay graceful:
openapi-contract.ymlnow runs the existing directional compatibility checker against the public Developer API contract (docs/api-reference/openapi.json), not just the app-client contract. Removing an endpoint, dropping a required response field, or adding a required request field fails the PR (additive changes, including dropping an optional response field, still pass). The checker gains a--labelso its messages name the contract.Verification
test_dev_api_memory_dedupe.py(new): same text → one memory id and one evidence id, including padded text and changed tags/visibility; different case → a different memory; batch duplicates share one id.test_app_client_openapi_compatibility.py: wiring test now requires the Developer API step.test_developer_memory_adapter.py,test_dev_api_canonical_grant_ordering.pypass.check_app_client_openapi_compatibility.py --head-spec docs/api-reference/openapi.json --label 'Developer API' --base-ref origin/main: passes. The same check against a copy with/v1/dev/user/memories/batchremoved fails withreleased endpoint was removed; a copy that makestagsa required request field fails on both create routes.openapi.jsonandapp-client-openapi.jsonregenerated (docstring text only); Dart/TS/Swift generators--checkclean.Line-Count-Exception: backend/routers/developer.py | 2567 -> 2576 | route docstrings state the published dedupe contract
🤖 Generated with Claude Code