Skip to content

docs(dev-api): publish the memory dedupe contract and gate Developer API breaks - #17321

Merged
Git-on-my-level merged 1 commit into
mainfrom
feat/dev-memory-dedupe-contract
Sep 23, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
feat/dev-memory-dedupe-contract

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 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, and docs/doc/developer/api/memories.mdx):

Request Result
Text the user does not have yet A new memory
Text the user already has 200 with the existing memory; nothing new is stored
Same text, different category/visibility/tags 200 with the existing memory as stored; new fields are not applied (use PATCH)
Same text after a delete A new memory with a new id

Matching trims surrounding whitespace and is case-sensitive. In a batch, duplicates return the existing memory at their position; created_count is 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 on main (auth and categorizer patched only).

Why dedupe rather than server-assigned ids: the only client that produced the #17296 500s (one Python-urllib/3.12 integration, 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.yml now 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 --label so 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.py pass.
  • 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/batch removed fails with released endpoint was removed; a copy that makes tags a required request field fails on both create routes.
  • openapi.json and app-client-openapi.json regenerated (docstring text only); Dart/TS/Swift generators --check clean.

Line-Count-Exception: backend/routers/developer.py | 2567 -> 2576 | route docstrings state the published dedupe contract

🤖 Generated with Claude Code

Review in cubic

…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]>
@mintlify

mintlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Sep 23, 2026, 11:54 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@Git-on-my-level
Git-on-my-level merged commit 37a92d3 into main Sep 23, 2026
65 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/dev-memory-dedupe-contract branch September 23, 2026 12:05
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

1 active deployment
staging - docs — ca3c26c2 Deployed Sep 23, 2026 by mintlify[bot]
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