Skip to content

fix(backend): give inline listen finalization a terminal failure state - #9704

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/pusher-finalization-dead-letter
Jul 14, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/pusher-finalization-dead-letter

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Bug (live on prod)

A conversation whose finalization fails deterministically (LLM refusal, malformed/oversized transcript, a bad segment) never resolves. It stays status=processing forever — a permanently spinning conversation in the UI — and its full LLM post-processing is re-run indefinitely.

Root cause

Prod runs LISTEN_FINALIZATION_DISPATCH_MODE=inline — the default in utils/cloud_tasks.py:83, and the var is set nowhere in backend/deploy/, backend/charts/, or .github/workflows/. So every finalization goes through the pusher WebSocket path, never the Cloud Tasks worker.

Two recent commits compose into an unbounded retry loop on that path:

  • 2d67863cad ("make listen finalization durable") deleted pusher's terminal fallback (set_conversation_as_discarded on process_conversation failure) and replaced it with mark_finalization_retryable → job back to queued. But the only other terminal writer, mark_finalization_dead_letter, is reachable only from the Cloud Tasks router, and reconcile_listen_finalization_jobs() early-returns in inline mode (services/conversation_finalization.py:101).
  • fafee4505e ("fence listen finalization retries") then removed the last bound in the live session's retry loop (utils/listen_pusher_session.py:329-338 resets retries = 0 after each burst) and kept the pending request on error instead of popping it.

Net effect, with no state transition out of queued other than success:

  1. the conversation stays processing forever (_create_or_get_finalization_intent_txn set it; nothing moves it off);
  2. the live session re-requests it in 3-attempt bursts every 300s for the life of the session;
  3. cleanup_processing_conversations() re-schedules it at the start of every later session (routers/transcribe.py:912-925).

Each retry is a full LLM post-processing run — so this is a stuck-UI bug and a cost/retry storm.

Fix (the claimer owns the attempt budget)

  • claim_finalization_job now returns attempt_count alongside lease_epoch (it was already incremented on claim — inline dispatch just had no way to read it).
  • routers/pusher.py dead-letters the job once attempt_count reaches get_listen_finalization_tasks_max_attempts() — the same bound the Cloud Tasks worker enforces — via the existing final_attempt_failed, then resolves the conversation to failed + discarded so it leaves the processing sweep. Retryable failures below the budget behave exactly as before.
  • The failure frame carries terminal: true, and listen_pusher_session pops the pending request on it, so the live session stops re-requesting a job that can never succeed. A claim that returns an already-dead_letter job is reported terminal too.

processing → failed is an existing legal lifecycle transition (test_conversation_lifecycle_contract).

Regression tests

  • test_pusher_dead_letters_a_job_that_exhausted_its_attempt_budget — terminal attempt dead-letters the job, marks the conversation failed + discarded, never calls mark_finalization_retryable.
  • test_pusher_tells_the_live_session_a_dead_lettered_job_is_terminal.
  • test_incoming_terminal_finalization_error_stops_retrying — the live session drops the pending request instead of re-requesting.

Verification

  • pytest on the finalization/pusher/listen suites: 279 passed (test_listen_finalization_cloud_tasks, test_conversation_finalization_jobs, test_conversation_lifecycle_contract, test_listen_pusher_session, test_listen_pipeline, test_listen_fallback_removal, test_transcribe_teardown_flush, test_pusher_*).
  • scan_import_time_side_effects.py, check_module_stub_pollution.py, check_isinstance_return_ratchet.py, scan_async_blockers.py — all clean.
  • UNVERIFIED end-to-end: I did not reproduce a real deterministic finalization failure against a live conversation; the terminal path is covered by hermetic tests only.

🤖 automated by hourly watchdog.

Review in cubic

A conversation whose finalization fails deterministically (LLM refusal,
malformed transcript) never resolved: it stayed `status=processing`
forever and its post-processing was re-run indefinitely.

Root cause: prod runs LISTEN_FINALIZATION_DISPATCH_MODE=inline (the
default; it is set nowhere in deploy config), so every finalization goes
through the pusher WebSocket path, not the Cloud Tasks worker. 2d67863
replaced pusher's terminal fallback (set_conversation_as_discarded) with
mark_finalization_retryable, but the only terminal writer
(mark_finalization_dead_letter) is reachable only from the Cloud Tasks
router, and the reconciler early-returns in inline mode. fafee45 then
removed the last bound on the live session's retry loop (retries reset to
0 after each burst). The result is a retry loop that cannot converge: the
live session re-requests the job in 3-attempt bursts every 300s for the
life of the session, and cleanup_processing_conversations re-schedules it
at the start of every later session. Each retry is a full LLM run.

Fix: the claimer owns the attempt budget. claim_finalization_job now
returns attempt_count, and pusher dead-letters the job once it reaches
get_listen_finalization_tasks_max_attempts() (the same bound the Cloud
Tasks worker uses), resolves the conversation to `failed` + discarded so
it leaves the processing sweep, and tells the live session the outcome is
terminal so it stops re-requesting it. Retryable failures are unchanged.

Verification: backend/.venv pytest on the finalization/pusher/listen
suites — 279 passed (test_listen_finalization_cloud_tasks,
test_conversation_finalization_jobs, test_conversation_lifecycle_contract,
test_listen_pusher_session, test_listen_pipeline, test_pusher_*).
scan_import_time_side_effects, check_module_stub_pollution,
check_isinstance_return_ratchet, scan_async_blockers all clean.
UNVERIFIED against a live prod conversation (no reproduction of a real
deterministic finalization failure).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@kodjima33
kodjima33 merged commit 7942fc1 into main Jul 14, 2026
23 of 26 checks passed
@kodjima33
kodjima33 deleted the watchdog/pusher-finalization-dead-letter branch July 14, 2026 14:36
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 19, 2026
Names the contract violated by BasedHardware#9995 and by the earlier retail fixes
(BasedHardware#9648, BasedHardware#9704): durable ledger-owned work, once claimed, must not
inherit the lifetime of the connection or session that dispatched it.

Co-Authored-By: Claude Fable 5 <[email protected]>
@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants