Skip to content

Developer API POST /v1/dev/user/memories returns 500 on ~20–28% of calls (evidence identity conflict) #17296

Closed

Description

@Git-on-my-level

Summary

POST /v1/dev/user/memories (developer API, routers/developer.py::create_memory) returns 500 on ~20–28% of calls in production, and has been doing so since at least 2026-09-22. It is the dominant source of backend 5xx: two 10-minute windows on 2026-09-23 reached ~0.1% service-wide 5xx almost entirely from this route.

Window (UTC) POSTs 5xx Rate
2026-09-22 08:00–10:00 (release d44d87d) 889 182 20.5%
2026-09-23 06:15–09:15 (release a8975fa) 537 150 27.9%

Traffic is bursty (zero calls 03:00–06:10 on 09-23), so it surfaces as spikes on the service error rate rather than a steady elevation. The same behaviour exists on both releases, so it is not caused by the relevance-gate deploy (#16587, #17089) during which it was noticed.

Error

184 of 234 backend ERROR entries between 08:00 and 09:15 UTC on 2026-09-23 are one exception:

database.memory_apply_store.MemoryFirestoreApplyError: proposed evidence conflicts with existing evidence identity
  utils/memory/canonical_memory_adapter.py:2035  write_canonical_external_memory
  utils/memory/canonical_memory_adapter.py:1865  write_canonical_extraction_memory
  database/memory_apply_store.py:767            apply_direct_user_long_term_patch_firestore
  database/memory_apply_store.py:726            apply_long_term_patch_firestore
  database/memory_apply_store.py:2509           _apply_long_term_patch_firestore_transaction
  database/memory_apply_store.py:3025           _read_or_stage_authoritative_evidence

_read_or_stage_authoritative_evidence raises when an evidence document with the proposed evidence_id already exists, is active, and its semantic payload differs from the proposed one. _reissued_external_evidence (canonical_memory_adapter.py ~1945) only reissues an identity when the existing evidence is tombstoned, so an external write whose derived evidence id collides with an active evidence document of different content has no path except this exception, which propagates as an unhandled 500.

Likely cause (to confirm)

The developer-API write derives a deterministic evidence identity that can repeat for a different payload: e.g. a client re-POSTing the same content with different metadata (category, visibility, timestamps), or retrying after a partial failure. Worth confirming how the evidence id is derived for create_external_memory and which payload fields _evidence_semantic_payload compares.

Secondary errors on the same route

  • GET /v1/dev/user/memories: 504s from utils.other.list_budget ("list read budget exhausted: deadline") and google.api_core.exceptions.DeadlineExceeded (~22 in the same window).

Suggested direction

  1. Decide the contract for a colliding external write: idempotent success when the payload is equivalent, a new reissued identity when it is a genuinely new source artifact, or a 409, but never an unhandled 500.
  2. Add a regression test with an active evidence document and a same-id, different-payload proposal through create_memory.
  3. Add a bounded metric for MemoryFirestoreApplyError by reason, so the rate is visible without log queries (note: Cloud Run metrics must be named omi_* to be scraped, see fix(metrics): name the relevance counter so the Cloud Run sidecar keeps it #17280).

How this was measured

Cloud Logging on the prod backend Cloud Run service (httpRequest.requestUrl:"/v1/dev/user/memories", httpRequest.status>=500) and ERROR-severity entries grouped by the last traceback line. No user identifiers are included here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions