Skip to content

fix(conversations): persist completed custom-STT captures when processing budget is exhausted (#23923) - #24095

Open
ocakciomursel-pixel wants to merge 5 commits into
BasedHardware:mainfrom
ocakciomursel-pixel:fix/custom-stt-exhausted-budget-persist-23923
Open

ocakciomursel-pixel wants to merge 5 commits into
BasedHardware:mainfrom
ocakciomursel-pixel:fix/custom-stt-exhausted-budget-persist-23923

Conversation

@ocakciomursel-pixel

@ocakciomursel-pixel ocakciomursel-pixel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Fixes #23923. When a user with exhausted monthly processing credits captures a Custom-STT conversation (uses_custom_stt=True), process_conversation previously mutated status=completed only in memory and reported persistence_observer(False), leaving live /v4/listen?custom_stt=enabled conversations stranded in Firestore at status='processing' with blank titles and causing finalizer.py to fence as lifecycle persistence lost. Persist a deterministic zero-LLM completed conversation (terminal_no_derived_effects=True, discarded=False, deferred=False) and skip Omi-paid summary-vector embedding/LLM metadata calls while preserving existing summaries on reprocess of already-completed rows.

Product invariants affected

INV-MEM-4, INV-TASK-2 (touched path glob backend/utils/conversations/process_conversation.py; zero canonical memory promotion or task-capture behavior changed because exhausted custom-STT rows remain terminal with TERMINAL_NO_DERIVED_EFFECTS).

How it was verified

  • Ran unit and regression suites covering process_conversation, free-tier entrypoints, processing backlog, and finalizer.py (pytest tests/unit/test_process_conversation_usage_context.py, tests/unit/test_process_conversation_free_tier_branch.py, tests/unit/test_free_tier_entrypoint_matrix.py, tests/unit/test_processing_backlog.py, tests/unit/test_listen_finalization_cloud_tasks.py — 512 passed).
  • Ran black --check --line-length 120 and python scripts/pr_preflight_all.py.

Tests

  • backend/tests/unit/test_process_conversation_usage_context.py:
    • test_custom_stt_exhausted_processing_budget_persists_live_capture
    • test_custom_stt_exhausted_processing_budget_reprocess_preserves_completed_summary
    • test_custom_stt_exhausted_processing_budget_skips_summary_vector_paid_calls
  • backend/tests/unit/test_process_conversation_free_tier_branch.py:
    • test_finalizer_completes_exhausted_custom_stt_capture_without_paid_work

UI evidence

UI-Evidence: none -- backend-only custom-STT post-processing persistence fix

Failure class (fixes)

Failure-Class: none

Line-Count-Exception: backend/utils/metrics.py | 1601 -> 1609 | Add CUSTOM_STT_BUDGET_EXHAUSTED_COMPLETION_TOTAL metric counter for #23923

View guided diff

@Git-on-my-level

Copy link
Copy Markdown
Member

The core fix is correct and well tested: exhausted-budget custom-STT captures now durably persist as completed instead of being stranded in status='processing' (#23923) — one design question and a couple of small gaps below, nothing blocking on correctness.

Per-file notes:

  • backend/utils/conversations/projection_payload.py — complete_exhausted_custom_stt_conversation is a clean zero-LLM materialization: deterministic 8-word title via the existing _build_deferred_structured, deferred/discarded cleared, summary_retryable=None, TERMINAL_NO_DERIVED_EFFECTS stamped, and enriched rows preserved (the has_existing_title + refresh-fence branch calls defer_held_budget_denial and leaves the stored summary intact). The strict_bool/non-strict split in should_skip_custom_stt_postprocessing preserves the old bool() semantics at report_persistence while being stricter at the vector gates.
  • backend/utils/conversations/process_conversation.py — the reworked gate in report_persistence replaces the old in-memory-only completion; the silent_backfill branch raising RecoveryStructureUnavailableError mirrors the funded-gate protocol already used a few lines up (process_conversation.py:2679-2680), so the error contract is consistent. save_structured_vector now also fences paid embedding calls for exhausted custom-STT rows.
  • backend/utils/conversations/finalizer.py — the new pre-gate in _save_summary_vector_fail_soft returns before save_structured_vector, so the vector-skip metric increments exactly once per path (no double count with the gate inside save_structured_vector). Function-local imports avoid the import cycle; fine.
  • backend/tests/unit/test_process_conversation_free_tier_branch.py — the real finalizer → process_conversation integration test (real modules, forbidden paid calls wired to raise) is exactly the right shape for this bug.
  • backend/tests/unit/test_process_conversation_usage_context.py — good coverage trio: live-capture durable persist, reprocess-preserves-summary, and vector-skip with metric assertion.

Notes:

USER IMPACT: Users on an exhausted free plan who transcribe with their own STT key will now see those recordings saved with a plain title (no AI summary) instead of being lost/stuck in processing.

What I'd still want:

  1. A test for the ingress initial-creation branch (CreateConversation with exhausted budget → create_completed_conversation idempotent path in complete_exhausted_custom_stt_conversation); the new tests only exercise the existing-row persist path.
  2. The vector-skip metric reuses outcome=skipped_processing_deferred for a non-deferred skip — consider a distinct outcome label so dashboards can tell deferred-backlog apart from budget-exhausted custom-STT.
  3. A maintainer call on re-enrichment: persisted placeholder-title conversations have summary_retryable cleared and are marked terminal, so enrichment after credits reset appears to require a manual reprocess — please confirm that's the intended product behavior.

Leaving the merge/product call for human maintainer review (persistence behavior on a budget-gated surface).


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution needs-maintainer-review Needs a human maintainer to sign off before merge backend Backend Task (python) labels Oct 30, 2026
@ocakciomursel-pixel

ocakciomursel-pixel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Follow-up implemented in 3d10ddc:

  • Added CreateConversation initial-creation regression cases at the actual completion helper seam, covering both successful and rejected persistence, stable generated ID, completed/not-discarded transcript payload, terminal-no-derived-effects marker, and create_completed_conversation(..., idempotent=True). The public CreateConversation schema does not carry uses_custom_stt; these are helper-branch tests, not a claim that a public create request can set that flag.
  • Split skipped_custom_stt_budget_exhausted from skipped_processing_deferred in both the vector writer and finalizer. Both static outcomes are initialized for idle metric export. Regression cases check exactly one matching increment and no embedding/vector writer call, including the deferred-priority case.

Validation on the published file contents: complete test_process_conversation_free_tier_branch.py 49 passed; complete test_process_conversation_usage_context.py 72 passed, each in its own pytest process. Python 3.11.16, isolated wheel environment (not lock-identical), Black 26.5.1, git diff --check passed. These are offline unit contracts, not live finalization evidence. Full repository preflight was attempted but blocked by missing history and sparse-checkout manifest paths; no full-preflight pass is claimed.

The product decision about automatic enrichment after credit renewal versus explicit reprocessing remains unchanged and needs maintainer acceptance. Please review these concrete test/telemetry changes on the new head.

Follow-up CI caught CRLF line endings introduced by the Windows checkout. These files have now been normalized to LF, committed and read back byte-for-byte. The failed earlier Hygiene run is not a pass; please use the latest head checks.

@Git-on-my-level

Copy link
Copy Markdown
Member

Since my last review: addressed (initial-creation branch now tested — test_initial_custom_stt_budget_denial_uses_idempotent_completed_creation covers create_completed_conversation(..., idempotent=True) with both persistence outcomes, verified on this head) · addressed (vector-skip telemetry split — skipped_custom_stt_budget_exhausted is now a distinct outcome, preexported in backend/utils/metrics.py and asserted exactly-once with no embedding/writer call in both the writer and finalizer tests) · still open (the product call on re-enrichment after credit renewal — you've flagged it as needing maintainer acceptance, agreed) · newly introduced (nothing of substance; the trust-boundary registrations in backend/tests/unit/test_client_processing_trust_boundary.py and the client_summaries_at_cap_enabled() projection gating in complete_exhausted_custom_stt_conversation are consistent with the existing client-processing contract).

Verdict: follow-up cleanly addresses the prior review; the production change is correct and well hardened, and checks are green on this head (Backend unit suite, Backend Hermetic Merge Gate, Hygiene, Formatting). I reviewed statically against the full diff; I did not rerun the suites locally.

Cost: unchanged from last review and still protective — the distinct outcome label now makes the saved paid embedding/metadata skips visible on dashboards. Blast radius: unchanged — only custom-STT conversations on exhausted accounts; managed-STT paths untouched.

USER IMPACT: Users on an exhausted free plan transcribing with their own STT key get recordings saved with a plain transcript-derived title instead of them hanging at "processing"; existing enriched recordings keep their summaries on reprocess.

What I'd still want: only the open maintainer decision — whether these terminal, summary_retryable-cleared rows should auto re-enrich when monthly credits reset or require an explicit user reprocess. A one-line ruling on that closes the last item.

Leaving that merge/product call for human maintainer review (enrichment-after-renewal behavior on a budget-gated persistence surface).


by AI on behalf of David

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Free tier: frozen account ignores own STT key, pending queue can't be deleted, billed minutes exceed transcribed (408 vs 319)

2 participants