Repository navigation
fix(backend): meter custom-STT LLM post-processing without skipping STT-credit bypass - #14300
Conversation
|
Backend unit shard 1/4 failed because the new Pushed
Verified locally with
|
|
Updated the PR body |
|
Pushed empty commit |
aryanorastar
left a comment
There was a problem hiding this comment.
Traced this end-to-end against main. The shape is right: the gate sits at the same post-processing chokepoint as the trial paywall and follows that early-return pattern faithfully, speech_seconds moves independently of transcription_seconds, and the exemption ordering mirrors resolve_transcription_allowance. _usage_speech_seconds rejecting bools, negatives and non-ints is the right input boundary, and both fail-open paths emit record_fallback(outcome='degraded') rather than going silent. The custom_speech_ms // 1000 truncation matches the managed path at runtime.py:616, so it adds no new accounting drift.
Two things I'd want resolved before approval, plus an ownership note.
1. Does the llm_byok exemption fire where this gate runs?
The exemption needs byok_active and _request_has_llm_byok_key(). The first half is persisted state (users_db.is_byok_active); the second resolves through get_byok_uid() → _byok_uid_ctx, a ContextVar(default=None) documented as "the authenticated uid for the current request."
backend/docs/listen_finalization_jobs.mdx says "Listen never calls process_conversation() inline" and describes the lease-claiming pusher / Cloud Tasks worker path, with a separate blocked_byok state for conversations that "require request-scoped BYOK credentials." So the live pusher frame clearly can carry those keys — I'm not claiming the exemption is dead. What I can't tell from the diff is which dispatch modes reach this new gate, and whether in the task-worker path, where request-scoped keys are absent by construction, a BYOK-enrolled custom-STT user on a capped plan silently loses structuring/summary/memory.
test_llm_byok_custom_stt_is_not_blocked can't answer that, because it monkeypatches sub._request_has_llm_byok_key directly — it pins the branch, not the context feeding it. A test that leaves _byok_uid_ctx unset and asserts the intended outcome for a BYOK-enrolled uid would settle it either way. Worth being exact here specifically because silently stripping summaries from BYOK users is the regression #12663 reverted.
2. subscription_inactive is the widest branch and the only one without a test.
if not subscription: return _processing_closed('subscription_inactive') means every custom-STT user without a valid subscription gets no Omi-paid post-processing at all — the largest affected cohort and the biggest user-visible change here. _situate_processing already accepts plan: PlanType | None and returns None for the subscription, so the fixture supports it, but none of the eight tests passes plan=None. One more case would pin it.
3. This decides a policy #7690 deliberately left open.
#7690's step 2 is "Decide policy: should LLM post-processing for non-paying custom-STT users be metered, capped, or otherwise accounted for?" This PR answers it: no subscription means no post-processing, capped plans meter against the catalog listening allowance. That answer is defensible and symmetric with resolve_transcription_allowance, but it changes what free custom-STT users receive, so it wants an explicit maintainer sign-off rather than approval on code merit. I'm not approving on that basis, and I'd rather say so than leave you waiting on me.
Minor, non-blocking: consume_speech_ms_delta() now runs whenever vad_gate is not None rather than only under FAIR_USE_ENABLED, and the new record_usage(speech_seconds=...) is likewise flag-independent. Both consumers sit in mutually exclusive branches so nothing double-drains, and making the budget work with fair-use off looks intentional — just confirming it is.
On the fail-open choice: it inverts a cost gate, so a Firestore incident restores uncapped spend for exactly the cohort this caps. It's bounded to custom-STT and instrumented, so I think it's the right trade given #12663 — flagging it only so whoever signs off on the policy is accepting that too.
|
Verified the metering semantics independently - three observations on top of the review above, then alignment on the two open asks. 1. 2. Partial answer to the BYOK dispatch question. 3. Minor, non-blocking: the custom-STT branch guards the write with On The surrounding pieces check out: the Aligned with the review above on the policy point: this answers #7690 step 2 ("no subscription -> no Omi-paid post-processing; capped plans meter from by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Backend meter fix: root cause, fixes #7690, CI green, tests = 4/5 (diff 448 lines only fails scope). Verified not already-fixed (no custom_stt/speech_seconds gating on main subscription.py). mergeStateStatus UNKNOWN after refetch -- approve only per override b.
Review on BasedHardware#14300 asked for two cases that pin current policy without changing it: leave `_byok_uid_ctx` unset (do not monkeypatch the helper) so a BYOK-enrolled custom-STT user follows the plan check, and add `plan=None` covering `subscription_inactive`. Co-authored-by: Apoorv Darshan <[email protected]>
|
Pushed
Verified with
Free-tier custom-STT policy sign-off remains for maintainers. |
|
Follow-up verification on 7ee3be2 (the two new gate tests): Confirmed this head is a test-only delta over the approved 1a69fca — The two new cases close out the review asks precisely:
Re-ran the suites locally: Spot-checks that held up on this pass:
One pre-existing, non-blocking observation: running With the earlier approval covering the unchanged production code and these tests closing the review asks, nothing specific is pending from my side. Removing by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Re-review on 7ee3be2: the two requested tests are on this tip ( This head is CONFLICTING/DIRTY against current main on Please rebase onto current main — do not resolve that file in the web editor. After rebase, the custom-STT skip is a trial-paywall-style early return (completed, no I am not approving this SHA. GitHub APPROVED is kodjima on 1a69fca. #7690 step 2 (what no-subscription custom-STT users receive) is still a maintainer policy call, not a size-gate approve. |
…TT-credit bypass Custom-STT still skips has_transcription_credits at listen connect and never records transcription_seconds. After BasedHardware#12663 reverted the BasedHardware#10962 blanket LLM skip, those sessions had no processing budget. Cap Omi-paid structuring / summary / memory against the catalog listening allowance read from speech_seconds. Paid unlimited and LLM BYOK stay allowed; lookup errors fail open so a Firestore blip cannot strip summaries. Failure-Class: none Verification: - backend/.venv/bin/python -m pytest -q tests/unit/test_custom_stt_llm_processing_gate.py tests/unit/test_listen_runtime_regressions.py tests/unit/test_process_conversation_usage_context.py tests/unit/test_process_conversation_free_tier_branch.py tests/unit/test_client_processing_acceptance.py tests/unit/test_client_processing_finalize.py tests/unit/test_free_tier_entrypoint_matrix.py tests/unit/test_fair_use_engine.py tests/unit/test_fair_use_plan_aware.py tests/unit/test_subscription_plans.py - 491 passed - Did not exercise a live custom-STT listen session Co-authored-by: Apoorv Darshan <[email protected]>
…tubs The bootstrap admit test imported listen_session_bootstrap after the file stubbed database._client for subscription isolation, so test.sh file isolation failed on fair_use.db. Keep the gate tests isolated and pin the STT-credit skip on the existing bootstrap suite. Failure-Class: none Verification: - BACKEND_UNIT_TEST_FILE_LIST with test_custom_stt_llm_processing_gate.py and test_listen_session_bootstrap.py via backend/test.sh - 8 passed + 5 passed Co-authored-by: Apoorv Darshan <[email protected]>
The new should_skip_omi_paid_postprocessing import bound a truthy AutoMock in test_upstream_boundary, so process_conversation returned before _extract_memories. Consult the gate only for custom-STT conversations and pin the isolation stub to fail-open, matching the other subscription gates. Failure-Class: none Verification: - pending: tests/unit/test_upstream_boundary.py via backend/test.sh Co-authored-by: Apoorv Darshan <[email protected]>
PR body already declares process_conversation.py 3167 -> 3199. Hygiene on 86c79cf still shows the stale 3196 mismatch because body edits do not re-run that check. Co-authored-by: Apoorv Darshan <[email protected]>
Review on BasedHardware#14300 asked for two cases that pin current policy without changing it: leave `_byok_uid_ctx` unset (do not monkeypatch the helper) so a BYOK-enrolled custom-STT user follows the plan check, and add `plan=None` covering `subscription_inactive`. Co-authored-by: Apoorv Darshan <[email protected]>
BasedHardware#14513 made the free-tier store_projection path reachable via free_tier_local_processing_enabled(uid). The custom-STT skip was a trial-paywall-style early return above that branch, so a desktop custom-STT session that would persist the local summary never reached it. Move the skip to after the unpaid desktop path (and the flag-off elifs) so it only gates Omi-paid _get_structured. Gate policy is unchanged. Failure-Class: none Verification: - pending: custom-STT gate + process_conversation unit tests Co-authored-by: Apoorv Darshan <[email protected]>
7ee3be2 to
1e19c74
Compare
|
Rebased this branch onto current Gate policy is unchanged (BYOK /
|
aryanorastar
left a comment
There was a problem hiding this comment.
Re-reviewed 1e19c74 after the local rebase onto b38c545.
The custom-STT skip sits after the #14513 unpaid desktop path (store_projection / deterministic_minimum / legacy defer / eager deny all return first). test_custom_stt_skip_does_not_strip_unpaid_on_device_projection and test_custom_stt_skip_still_blocks_omi_paid_llm_after_unpaid_path pin that ordering. The earlier unset-_byok_uid_ctx and subscription_inactive cases are still on this tip.
Maintainer sign-off on #7690 step 2: no valid subscription → no Omi-paid structuring/summary/memory; capped plans meter from speech_seconds; paid unlimited and request-scoped LLM BYOK stay allowed; lookup failures fail open (instrumented). That is the intended split vs the STT-credit bypass, not a size-gate approve.
kodjima APPROVE was on 1a69fca. This approve is for 1e19c74.
Honest gaps: no live custom-STT listen session; fail-open restores uncapped spend for this cohort during a Firestore blip.
Update the generated profile README snapshot so the omi contribution line reflects BasedHardware/omi#14300 (custom-STT LLM metering). Co-authored-by: Cursor Agent <[email protected]>
Update the generated profile README snapshot so the omi contribution line reflects BasedHardware/omi#14300 (custom-STT LLM metering). Co-authored-by: Apoorv Darshan <[email protected]>
What changed and why
Custom-STT still skips managed STT credits at listen connect (
user_has_credits=True) and never recordstranscription_seconds. After #12663 reverted the #10962 blanket LLM skip, those sessions had no remaining processing budget, so Omi-paid structuring / summary / memory ran uncapped. This restores the intended #7690 split: skip STT credits, still meter and cap LLM post-processing from the catalog listening allowance read fromspeech_seconds. Paid unlimited plans and LLM BYOK stay allowed. Lookup errors fail open so a Firestore blip cannot strip summaries.Rebased onto current
mainafter #14513. The custom-STT skip remains a trial-paywall-style early return (completed, no_get_structured) but now sits after the unpaid desktop on-device /store_projectionpath so it does not strip #14513. Gate policy is unchanged.Fixes #7690.
Product invariants affected
Path-matched via
scripts/pr-preflight --suggestbecauseprocess_conversation.pyis listed on several locked invariants. This PR does not change memory promotion, task capture, chat, auth, or data-plane behavior.How it was verified
Rebase onto
main(b38c5457a1) resolvedprocess_conversation.pylocally (not the web editor). Custom-STT skip moved after the #14513 unpaid desktop path.Result:
test_custom_stt_llm_processing_gate.py10 passed;test_process_conversation_usage_context.py54 passed;test_process_conversation_free_tier_branch.py42 passed (includes the two new ordering pins);test_listen_session_bootstrap.py5 passed;test_upstream_boundary.py5 passed.Focused re-run of the new pins plus the existing custom-STT process_conversation / gate cases: 14 passed.
Did not exercise a live custom-STT listen session (no device / custom STT endpoint in this environment). Free-tier custom-STT policy remains a maintainer call.
Tests
Regression that would have caught the residual uncapped path:
backend/tests/unit/test_custom_stt_llm_processing_gate.py— exhaustedspeech_secondshits the LLM gate; paid unlimited and LLM BYOK stay allowed; Deepgram-only BYOK does not exempt; budget readsspeech_secondsnottranscription_seconds; lookup failure fails open; unset BYOK context falls through to the plan check;subscription_inactiveskips.test_custom_stt_skips_stt_credits_but_still_admitsintest_listen_session_bootstrap.py— custom-STT connect never callshas_transcription_creditsand still admits.test_custom_stt_exhausted_processing_budget_skips_llm_workintest_process_conversation_usage_context.py—process_conversationdoes not call_get_structuredwhen the skip helper returns true.test_custom_stt_skip_does_not_strip_unpaid_on_device_projection/test_custom_stt_skip_still_blocks_omi_paid_llm_after_unpaid_pathintest_process_conversation_free_tier_branch.py— desktop custom-STT still persists free tier: the on-device summary is produced, selected, rendered, and actually reachable #14513store_projection; process_normally fall-through still hits the skip.test_custom_stt_flush_meters_speech_in_isolated_lane— flush records isolatedcustom_sttspeech andspeech_seconds, nevertranscription_seconds.Failure class (fixes)
Failure-Class: none
Line-count exceptions
Line-Count-Exception: backend/utils/subscription.py | 1805 -> 1950 | New conversation-processing allowance lives next to the STT resolver so both share one catalog budget.
Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3203 -> 3240 | Custom-STT LLM skip sits after the #14513 unpaid desktop path at the existing post-processing chokepoint.