Skip to content

fix(backend): make daily sweep input-budget failures diagnosable and degrade instead of stalling - #14320

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/jit-sweep-failure-diagnosability
Sep 17, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/jit-sweep-failure-diagnosability

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Summary

The isolated JIT QA plane's daily memory sweep (sweep-verify run 35037067641, 2026-09-15) failed with an opaque MemoryExtractionError, 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 holds roles/datastore.user, the logged INSUFFICIENT_PERMISSION line is Firebase Auth's get_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 at QA_SWEEP_MAX_INPUT_TOKENS bytes. 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 reports source_incomplete, and with QA_SWEEP_MAX_CATCH_UP_DAYS = 1 every later day waits behind it.

Three changes:

  1. Diagnosable failures. The agent logs the content-free reason code of a 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.
  2. Degrade instead of stall. When the bounded input is over budget the agent drops the oldest summary rows, then clamps the last row, then the prior-memories block, re-measuring after each step, sets truncated on the dispatch evidence, and records a full_input → truncated_input fallback. 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.
  3. A QA envelope that can hold a real request. QA_SWEEP_MAX_INPUT_TOKENS 12,288 → 16,384 and QA_SWEEP_MAX_OUTPUT_TOKENS 256 → 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 unchanged QA_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-10 fence 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

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

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.sh with CI's file isolation and fast-unit timing guard:

tests/unit/test_daily_memory_sweep.py            88 passed
tests/unit/test_daily_sweep_summary_agent.py     30 passed
tests/unit/test_daily_summary_generation.py      27 passed
scripts/typecheck.sh                             0 errors

plus test_daily_memory_sweep_job.py, test_jit_qa_sweep_repair.py, test_jit_qa_sweep_operator.py under 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_bytes was never logged, which is what change 1 fixes. Confirmation on the QA plane needs a deploy of this SHA plus a sweep-verify dispatch.

🤖 Generated with Claude Code

Review in cubic

…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]>
@Git-on-my-level
Git-on-my-level merged commit 6140722 into main Sep 17, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/jit-sweep-failure-diagnosability branch September 17, 2026 08:33
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