Repository navigation
fix(backend): bound the memory list page's suppressed-row walk in seconds, not only rows (#11803) - #11805
Merged
Conversation
…onds, not only rows GET /v3/memories still 504'd at the 30s edge timeout after the row budget from #11800 reached prod (deployed 2026-08-18T08:09Z): ~40/h, first pages only (offset=0, limit=8/100/500/5000), while successful first pages ran at p90 5-11s with maxima of 26-28s. Root cause: MEMORY_LIST_SCAN_ROW_BUDGET = 4000 bounds rows, not seconds. 4000 skipped rows is ~80 sequential Firestore round trips, so a slow account can spend most of the 30s request budget inside the bound — and the offset-read fallback the budget exists to reach then has no time left to answer, so the request 504s anyway. Give the shared per-request budget a wall-clock deadline (6s) alongside the row bound. Exhausting either raises the same "Memory scan budget exceeded" 503 the route's first-page fallback already keys on, so the page is served from the offset read — which does not walk suppressed rows — with the bulk of the request budget still unspent. Verification: backend/test.sh over all 85 memory test files = green (BACKEND_UNIT_TEST_FILE_LIST). Both new tests fail on clean origin/main with the source hunk stashed (TypeError: no deadline_seconds; the deadline test scans past the row budget) and pass with it. Failure-Class: FC-bounded-read-exceeds-request-budget Fixes #11803
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
GET /v3/memoriesstill 504s at the 30s edge timeout after PR #11800's scan row budget reached prod. I dispatched the prod deploy of922b30db1cthis morning (backend-922b30d-32113104414-1took 100% traffic at ~08:09Z); the 504 rate fell from ~110/h to ~40/h but did not go to zero — still first pages only (offset=0, limit 8/100/500/5000), while successful first pages run at p90 5–11s with maxima of 26–28s.Root cause
MEMORY_LIST_SCAN_ROW_BUDGET = 4000bounds rows, not seconds. 4000 skipped rows is ~80 sequential Firestore round trips, so a slow account can spend most of the 30s request budget inside the bound — and the offset-read fallback the budget exists to reach then has no time left to answer. The request 504s anyway, which is exactly the failure class the bound was meant to close.Fix
Give the shared per-request
_ScanRowBudgeta wall-clock deadline (6s) alongside the row bound. Exhausting either raises the sameMemory scan budget exceeded503 the route's first-page fallback already keys on, so the page is served from the offset read — which does not walk suppressed rows — with the bulk of the request budget still unspent. The clock is injectable so the deadline is asserted without sleeping.Tested
backend/test.shover all 85*memor*test files (BACKEND_UNIT_TEST_FILE_LIST) — green, no failures.origin/mainwith the source hunk stashed (TypeError: _ScanRowBudget.__init__() got an unexpected keyword argument 'deadline_seconds'; the deadline test otherwise scans past the row budget) and pass with it.make preflight— green with the line-count exception below./v3/memories504 rate goes to zero on the new revision.Product invariants
backend/utils/memory/memory_service.py. The diff changes no tier vocabulary, no collection layout, no exposure policy and no ordering: it only bounds how long one page may walk rows it must not emit before falling back to the read path that already serves the same page.Failure-Class: FC-bounded-read-exceeds-request-budget
Line-Count-Exception: backend/utils/memory/memory_service.py | 2540 -> 2558 | one wall-clock bound plus its incident comment inside the existing scan-budget class; splitting the file is not in scope for a live-504 fix
Fixes #11803
🤖 automated by hourly watchdog — tested and merged