Skip to content

fix(backend): fall back to offset read when canonical list scan 503s - #11593

Merged
Git-on-my-level merged 1 commit into
mainfrom
agent/sca-311-memories-list-503
Aug 15, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
agent/sca-311-memories-list-503

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

What changed and why

GET /v3/memories first page failed with 503 Canonical memory unavailable even though the legacy offset read() path was healthy. The first-page fallback added in #11590 only matched the detail Memory cursor unavailable; every failure the canonical keyset scan wraps as Canonical memory unavailable (Firestore FAILED_PRECONDITION, cursor/uid ValueError, anything else) bypassed it and failed the whole list endpoint. The fallback now accepts both 503 details, and the scan wrapper (_CanonicalCursorStream._ensure_slots) logs the underlying exception class/message via logger.exception before raising the opaque 503, so an index miss is distinguishable from a uid mismatch in dev/prod logs. POST was unaffected because writes do not use the scan.

Multica issue: SCA-311.

Product invariants affected

  • INV-MEM-3 (universal memory authority fails closed): the first-page fallback target is MemoryService.read() — the universal offset read that merges canonical and historical rows through the same suppression/authority checks (_canonical_read + adaptive historical scan), not a direct legacy reader. A canonical-check failure inside read() itself still fails closed; only the cursor-paging transport degradation (503 cursor/canonical-scan detail) falls back to the offset shape. Same pattern SCA-310: one MEMORY_ENABLED flag for create+list #11590 already shipped for the cursor-secret detail.
  • INV-MEM-1 (memory tiers): path-match only; no tier vocabulary changed.

How it was verified

  • backend/.venv/bin/python -m pytest tests/unit/test_memories_pagination_clamp.py — 7 passed (4 existing + 3 new).
  • backend/.venv/bin/python -m pytest tests/unit/test_universal_memory_list_cursor.py — 15 passed (14 existing + 1 new).
  • backend/.venv/bin/python -m pytest tests/unit/test_universal_memory_system.py tests/unit/test_memory_service_parity.py tests/unit/test_firestore_indexes.py tests/unit/test_memory_contracts.py tests/unit/test_dev_api_memories_pagination.py — 27 passed.
  • No other test references the old narrow detail match (checked).

Not verified here: the live dev 503 itself — that needs the deploy plus a real GET once this lands. The new logger.exception will identify the underlying exception class (Firestore FAILED_PRECONDITION vs uid/cursor ValueError) the first time the scan path is exercised in dev.

Tests

Regression tests that would have caught the bug:

  • tests/unit/test_memories_pagination_clamp.py::test_first_page_falls_back_to_offset_read_when_canonical_scan_unavailable — read_page raising 503 Canonical memory unavailable now yields the read() result instead of a 503 (this is exactly the live failure).
  • tests/unit/test_memories_pagination_clamp.py::test_first_page_propagates_unrelated_503_detail — an unrelated 503 detail still propagates; no fallback.
  • tests/unit/test_memories_pagination_clamp.py::test_first_page_propagates_non_503_errors — non-503 errors (e.g. 402) still propagate; no fallback.
  • tests/unit/test_universal_memory_list_cursor.py::test_canonical_scan_failure_logs_underlying_exception_and_503s — the wrap logs the original exception (class + message) and chains it as __cause__ on the 503.

Failure class (fixes)

Failure-Class: none

No registry class matches the incident shape: a serving fallback that already existed but was keyed to a single sibling 503 detail string, so a same-class degradation failed closed. FC-undeclared-serving-query-index was considered and rejected: UNIVERSAL_CANONICAL_LIST_SCAN_QUERY is deliberately manifest-exempt under the registry's one-non-__name__-field rule (Firestore-managed single-field index + document-ID ordering; same shape as the two memories historical scans), it is registered in the query inventory contract, and the underlying live exception has not yet been identified — asserting an index class here would be unverified. The new logger.exception makes that determination possible from dev logs; if it shows FAILED_PRECONDITION on the scan, a follow-up can declare the class with evidence.

Scoped cleanups (optional)

none

Line-Count-Exception: backend/utils/memory/memory_service.py | 2487 -> 2495 | Failure-diagnosis logging (8 lines) at the opaque canonical-scan 503 wrap required by the incident; splitting the 2.5k-line service file is out of scope for this incident fix.

Review in cubic

GET /v3/memories first page 503'd with 'Canonical memory unavailable'
whenever the canonical keyset scan failed for any reason, because the
#11590 first-page fallback only matched the sibling detail 'Memory
cursor unavailable'. The offset read() path does not use the scan, so
the first page now falls back to it for both 503 details; unrelated
errors still propagate.

The scan wrapper also swallowed the underlying exception class/message
into the same opaque 503. It now logger.exception's the original error
(no uid or memory content) so a Firestore FAILED_PRECONDITION index
miss is distinguishable from a uid/cursor ValueError in logs.

Co-authored-by: multica-agent <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level
Git-on-my-level merged commit 008ef01 into main Aug 15, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/sca-311-memories-list-503 branch August 15, 2026 02:17
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