Skip to content

SCA-374: degrade memories first-page 503s by type, not detail string - #12400

Merged
Git-on-my-level merged 2 commits into
mainfrom
fix/sca-374-memories-503-firestore-hardening
Aug 29, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
fix/sca-374-memories-503-firestore-hardening

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What changed and why

SCA-374: rebase the remaining memories-503 hardening onto current main.
The generator mixed-direction rule and the "Historical memory unavailable"
allowlist entry are already on main and are not re-shipped.

GET /v3/memories first-page recoverability was still keyed on a detail-string
allowlist that has grown from 2 entries to 4 for the same bug. This PR replaces
that allowlist with MemoryBackingStoreUnavailable (stream:
canonical / historical / cursor), so a renamed or newly added unavailable
message degrades to the offset read instead of escaping as a hard 503.
The degraded path now calls record_fallback and logs the failing stream.

An independent-oracle test restates Firestore's automatic single-field rule
and asserts every composite-requiring QUERY_SPEC is in the checked-in
manifest — including the three list-scan specs from #11684 — so a generator
shortcut cannot make both sides of the existing generator-vs-file test wrong
together.

Closes SCA-374

Product invariants affected

  • INV-MEM-1
  • INV-MEM-3
  • INV-MEM-4

Line-Count-Exception: backend/utils/memory/memory_service.py | 3922 -> 3939 | add MemoryBackingStoreUnavailable and convert list-scan 503s onto that type in the module the issue names as the owner

How it was verified

: > /tmp/omi-backend-unit-failures.txt
echo tests/unit/test_firestore_query_contract.py >> /tmp/omi-backend-unit-failures.txt
echo tests/unit/test_memories_pagination_clamp.py >> /tmp/omi-backend-unit-failures.txt
echo tests/unit/test_list_read_budget_contract.py >> /tmp/omi-backend-unit-failures.txt
echo tests/unit/test_universal_memory_list_cursor.py >> /tmp/omi-backend-unit-failures.txt
BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-backend-unit-failures.txt bash test.sh

Result: all four files passed
(test_firestore_query_contract.py 47 passed / 2 deselected;
test_memories_pagination_clamp.py 12 passed;
test_list_read_budget_contract.py 34 passed;
test_universal_memory_list_cursor.py 20 passed).

Did not exercise a live Firestore FAILED_PRECONDITION against production;
the unit tests drive the typed exception through the real first-page fallback
and the historical adapter with the prod index-building error.

Tests

  • test_first_page_falls_back_on_typed_unavailable_regardless_of_detail —
    a new detail string on the typed exception still degrades.
  • test_first_page_does_not_match_unavailable_detail_strings — a matching
    string on a plain HTTPException does not fall back.
  • test_first_page_fallback_records_degraded_firestore_read — record_fallback
    fires with component=firestore_read, from_mode=cursor_page,
    to_mode=offset_read, outcome=degraded.
  • test_every_composite_requiring_query_spec_is_declared_in_the_checked_in_manifest
    plus _platform_requires_composite and
    test_manifest_generator_classifies_the_firestore_single_field_rule.

Failure class (fixes)

Failure-Class: FC-undeclared-serving-query-index

New guards (only when adding a check or ratchet)

The independent-oracle test would have caught the #11684 generator shortcut
that shipped GET /v3/memories 503 on 2026-08-17: the existing
generator-vs-checked-in-file test passes when both sides are wrong together.
It lives next to that contract in test_firestore_query_contract.py rather
than a new shared primitive because the rule is Firestore-index-specific.

Review in cubic

Git-on-my-level and others added 2 commits August 30, 2026 03:10
…ring

GET /v3/memories recoverability was still an allowlist of detail strings
that grew from 2 entries to 4 for the same backing-store failure. Catch
MemoryBackingStoreUnavailable instead, record the offset-read fallback,
and assert mixed-direction list-scan indexes from Firestore's rule
independently of the generator.

Failure-Class: FC-undeclared-serving-query-index
Co-authored-by: Cursor <[email protected]>
The route now catches MemoryBackingStoreUnavailable by type, so the
detail constant is unused and fails pyright reportUnusedImport.

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 6d270c1 into main Aug 29, 2026
42 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/sca-374-memories-503-firestore-hardening branch August 29, 2026 23:01
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