Repository navigation
fix(backend): make daily sweep input-budget failures diagnosable and degrade instead of stalling - #14320
Merged
Conversation
…degrade instead of stalling The QA plane's sweep failed before dispatch on a 12,288-byte body cap that the parser instructions plus a real profile always exceed, logged only the exception type name, and left the day's fence indeterminate so later days queued behind it. Log and record the content-free reason code, trim the bounded input instead of refusing it, and size the QA envelope to hold a real request (16,384 in / 2,048 out, still ~$0.006 against the $0.05 run envelope). Failure-Class: FC-batch-fault-domain-head-of-line-poison Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.
Summary
The isolated JIT QA plane's daily memory sweep (
sweep-verifyrun 35037067641, 2026-09-15) failed with an opaqueMemoryExtractionError, and the day it failed on (2026-09-10) has blocked that account's sweep cursor ever since. The recorded diagnosis ("the job's service account lacks Firestore permission") was wrong: the account holdsroles/datastore.user, the loggedINSUFFICIENT_PERMISSIONline is Firebase Auth'sget_user(already fail-soft — it only degrades the display name in the prompt), and no request reached the QA gateway in the four seconds before the failure.The failure is the pre-dispatch input budget in
run_daily_sweep_summary_agent. On the QA path the serialized request body is capped atQA_SWEEP_MAX_INPUT_TOKENSbytes. The parser instructions alone are ~9.6K bytes and profile context adds up to ~3.2K, so the 12,288 cap rejected any day belonging to an account with a real profile before a provider call was ever made. The at-most-once fence then marks the day indeterminate, the scheduler reportssource_incomplete, and withQA_SWEEP_MAX_CATCH_UP_DAYS = 1every later day waits behind it.Three changes:
MemoryExtractionError(and the cause class for anything else) instead of the exception type name, records it on the QA dispatch evidence, and the scheduler appends it to the error:uid=…:source_incomplete:2026-09-10:daily_sweep_summary_input_budget. No prompt, transcript, or user text is logged; reason codes are validated against a snake_case pattern.truncatedon the dispatch evidence, and records afull_input → truncated_inputfallback. It still raises the same reason code if nothing more can be trimmed. The fence, the receipt, the pre-call cost ceiling, and the provider-call limits are unchanged; the production path (no input bound) is unaffected.QA_SWEEP_MAX_INPUT_TOKENS12,288 → 16,384 andQA_SWEEP_MAX_OUTPUT_TOKENS256 → 2,048 (the gateway's own per-attempt output ceiling; 256 completion tokens cannot hold a reasoning model's structured output). Worst-case reserve is about $0.0058 per run against the unchanged $0.05 run envelope and the unchangedQA_SWEEP_MAX_SPEND_MICRO_USD. The operator script's mirrored constants move with them, and the tests now reference the constants instead of repeating the literals.This does not unstick the already-indeterminate
2026-09-10fence on the QA plane; that still goes through the existing operator repair path after deploy.Failure-Class: FC-batch-fault-domain-head-of-line-poison
Product invariants affected
Cited because the change edits files those invariants lock. Memory authority, candidate admission, fences, and receipts are untouched: the change is confined to pre-dispatch input shaping on the bounded QA path, log/evidence reason codes, and QA-only budget constants.
Line-Count-Exception: backend/utils/llm/memories.py | 1127 -> 1232 | bounded-input trimming helper and content-free failure reason recording for the daily sweep agent
Line-Count-Exception: backend/utils/memory/daily_memory_sweep.py | 5807 -> 5814 | reason code appended to the source_incomplete scheduler error; QA envelope comment
Evidence
Local, hermetic (Google credentials blanked), Python 3.11, through
backend/test.shwith CI's file isolation and fast-unit timing guard:plus
test_daily_memory_sweep_job.py,test_jit_qa_sweep_repair.py,test_jit_qa_sweep_operator.pyunder bare pytest (141 passed across the five sweep files). New tests: reason-code logging, cause-class logging, oversized input trims oldest rows and still dispatches exactly once, scheduler error carries the reason code.Layer measured: unit tests and typecheck only. The diagnosis rests on Cloud Logging for the failed execution and on source; the failing run's
input_byteswas never logged, which is what change 1 fixes. Confirmation on the QA plane needs a deploy of this SHA plus asweep-verifydispatch.🤖 Generated with Claude Code