Repository navigation
fix(backend): memory read admission denies truncated pages (503) — gate first attempt on time headroom only - #21249
Conversation
… allowance BasedHardware#21227's process-wide RetryAllowance (8 tokens, 1/s refill) exhausts deterministically when the cursor suite pages thousands of rows in under a second. Fresh allowance per test + burst 64 via the existing env knob.
…nt headroom BasedHardware#21227 regression: with an exhausted ListReadBudget document allowance (max_documents spent), _headroom returns 0.0 and first-attempt admission raises 503 Memory read admission exhausted — but an exhausted document budget is a normal truncated page in the list-budget contract (the charge path flags budget.truncated downstream). Restores truncated-page behavior; the retry path keeps the full budget-aware headroom check.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…rdware#21249) into cost/c024-poll-cap
…rdware#21249) into cost/c008-firestore-read-cuts
…rdware#21249) into cost/c025-syncing-local-region
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d2bb302b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # deterministically (attempts=0 → MemoryReadAdmissionDenied). Raise the | ||
| # burst for this suite and give every test a fresh allowance — the shared | ||
| # module-global instance otherwise carries spent tokens between tests. | ||
| import utils.memory.read_resilience as _rr |
There was a problem hiding this comment.
Hoist the resilience import to module scope
The new fixture imports utils.memory.read_resilience inside _memory_read_burst, but backend code and tests are required to keep all imports at module scope. Hoist this alias with the other imports and reference it from the fixture rather than adding a new function-local import.
AGENTS.md reference: backend/AGENTS.md:L161-L161
Useful? React with 👍 / 👎.
| generation == self._generation | ||
| and (probing or self._open_until == 0) | ||
| and self._headroom(state, budget) > 0.05 | ||
| and time_headroom |
There was a problem hiding this comment.
Recheck the request deadline before a retry
If the 25–75 ms backoff is delayed by scheduling until the shared ListReadBudget expires, the pre-sleep _headroom test at line 260 can have passed, but this loop re-entry now checks only the independent one-second state.deadline. It therefore admits a second fn() after the request deadline; read_page can absorb that exhaustion as a truncated page, causing call() to clear transient/log recovered and omit the original provider failure from circuit accounting. Recheck budget time headroom after the sleep/on state.used > 0, while exempting document headroom only for the first attempt.
Useful? React with 👍 / 👎.
…n allowance Same mechanism as the cursor suite: 113 in-process tests exhaust the 8-token process-wide RetryAllowance and shed legitimate bursts as 503 Memory read admission exhausted. Burst 64 + fresh allowance in the e2e conftest; full harness green locally (126 passed, 3 skipped, 2 xfailed).
|
Pushed 8a25cc6: the hermetic E2E harness itself was exhausting the process-wide RetryAllowance (113 in-process tests through the real admission path → same 503s). e2e conftest now mirrors the cursor-suite isolation (burst 64 + fresh allowance). Verified locally: full hermetic harness 126 passed, 3 skipped, 2 xfailed; make preflight 31 checks green with the real PR body. |
…t to us-central1 (#21242) ## What Ops runbook for regionalizing the sync v2 temporal staging bucket (`syncing-local` prod, `syncing-local-development` dev) from multi-region to `us-central1`, where every serving consumer (backend, backend-sync, pusher) already runs. Docs-only change — no code touched. ## Why Cost ledger card C025 (MEASURED, billing export): the bucket pays "Network Data Transfer GCP Replication within Northern America" for staging blobs, plus multi-region Class A unit prices. Combined ops+replication across the sync buckets stepped 2026-10-06 from ~$41/day to ~$129/day run rate (+$46/day WoW ex-drip), scaling with sync v2 adoption. The staging bucket's blobs are disposable (480s janitor + 1-day lifecycle backstop), so multi-region durability buys nothing here. Avoidable share modelled ~$40–60/day at current volume (replication line removal + lower Class A unit price; Class B list prices are identical multi-region vs regional). ## What the runbook covers - Provisioning: regional Standard replacement buckets, UBLA + public-access-prevention, soft-delete disabled, age-1 Delete lifecycle, IAM carry-over review. - **Migration safety — the non-obvious part:** staged raw audio for queued/delayed/retry sync jobs can outlive the 8-minute segment TTL (payloads carry `raw_blob_paths`, resolved against the worker's current env). So the cutover requires: pause intake → drain Cloud Tasks/sequenced/retry jobs → wait out the 15-min signed-URL Redis cache → flip `BUCKET_TEMPORAL_SYNC_LOCAL` in all four chart values (prod+dev, backend-listen+pusher) → deploy → verify → resume. - Rollback: flip env back to the old bucket (kept until all consumers drain); available until old-bucket deletion. - Deletion gates: ≥48h after final write, no outstanding references, confirmed empty. - The durable `omi-private-cloud-sync` bucket is explicitly out of scope. ## Verification - Every `BUCKET_TEMPORAL_SYNC_LOCAL` wiring site enumerated (4 chart values files, storage.py, recovery script, export_openapi, test harnesses). - Signed-URL path verified region-independent (V4 IAM-signed GET; Redis URL cache keyed by object path, not bucket). - `make preflight` passed (13 checks). Docs-only; no tests required. ## Deploy note The GCP-side bucket provisioning + cutover is an operator procedure executed per the runbook after merge; chart values intentionally remain unchanged in this PR until the new buckets exist. 🤖 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/21242?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="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> ## Product invariants affected - **INV-MEM-1** (memory-tiers): untouched — no tier, collection, or default-access change anywhere in this branch (runbook-only; the merged #21249 test-isolation hunks raise the harness's read-admission burst and reset a test allowance). - **INV-MEM-4** (memory-promotion-authority): untouched — no promotion/consolidation logic involved.
What
Two-part repair of the
Memory read admission exhausted503s that have been failing CI on main since #21227 landed (Backend Hermetic E2E red at 2f0e9b2 and a36fe08;test_universal_memory_list_cursor.pyfailing 2/27 on every run; the same admission denial surfaces in the hermetic E2E harness as 503s on memory-search routes).Production fix (
read_resilience.py): first-attempt admission now gates on time headroom only. fix(backend): memories fetch resilience — bounded retry, structured 503 telemetry #21227 gated admission on_headroom(state, budget) > 0.05, which returns 0.0 whenever the request's document budget is exhausted — but an exhausted document budget is a normal truncated page in the list-budget contract (the charge path flagsbudget.truncateddownstream, andtest_budgeted_legacy_hydration_keeps_rows_when_the_charge_exhaustspins exactly that). The conflation turned a legitimate truncation into a 503 admission denial atattempts=0. The retry path keeps the full budget-aware headroom check — no change to retry admission semantics.Test isolation (
test_universal_memory_list_cursor.py): the cursor suite pages thousands of rows throughMemoryServicein under a second, which deterministically drains the process-wideRetryAllowance(8 tokens, 1/s refill). The suite now starts each test with a fresh allowance andOMI_MEMORY_READ_RETRY_BURST=64(the knob fix(backend): memories fetch resilience — bounded retry, structured 503 telemetry #21227 reads at admission time).Why this is the root cause, not a flake
Reproduced on clean
origin/main(a36fe08721) in a fresh worktree:test_universal_memory_list_cursor.py= 2 failed / 25 passed, bothMemoryReadAdmissionDeniedwithattempts: 0on the first attempt — not a retry exhaustion. The denial is deterministic: exhausted-document-budget ⇒ headroom 0.0 ⇒ deny. After the two changes: 27/27 pass, and #21227's own suites stay green (test_memory_read_resilience14,test_memory_service_parity12,test_memories_archive_and_read_contracts21, probe suite 126). pyright clean on the changed module.Failure-Class
Failure-Class: FC-degraded-fallback-consumes-protected-budget
Product invariants affected
Tests
tests/unit/test_universal_memory_list_cursor.py: 27 passed (was 2 failed).test_memory_read_resilience.py14 passed,test_memory_service_parity.py12 passed,test_memories_archive_and_read_contracts.py21 passed,test_firestore_document_probe.py126 passed (all own-process).utils/memory/read_resilience.py: 0 errors.🤖 Generated with Claude Code