Repository navigation
fix(backend): give inline listen finalization a terminal failure state - #9704
Merged
Merged
Conversation
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]>
5 tasks
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]>
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 (live on prod)
A conversation whose finalization fails deterministically (LLM refusal, malformed/oversized transcript, a bad segment) never resolves. It stays
status=processingforever — 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 inutils/cloud_tasks.py:83, and the var is set nowhere inbackend/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_discardedonprocess_conversationfailure) and replaced it withmark_finalization_retryable→ job back toqueued. But the only other terminal writer,mark_finalization_dead_letter, is reachable only from the Cloud Tasks router, andreconcile_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-338resetsretries = 0after each burst) and kept the pending request on error instead of popping it.Net effect, with no state transition out of
queuedother than success:processingforever (_create_or_get_finalization_intent_txnset it; nothing moves it off);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_jobnow returnsattempt_countalongsidelease_epoch(it was already incremented on claim — inline dispatch just had no way to read it).routers/pusher.pydead-letters the job onceattempt_countreachesget_listen_finalization_tasks_max_attempts()— the same bound the Cloud Tasks worker enforces — via the existingfinal_attempt_failed, then resolves the conversation tofailed+ discarded so it leaves theprocessingsweep. Retryable failures below the budget behave exactly as before.terminal: true, andlisten_pusher_sessionpops 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_letterjob is reported terminal too.processing → failedis 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 conversationfailed+ discarded, never callsmark_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
pyteston 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.🤖 automated by hourly watchdog.