Skip to content

fix(listen): meter custom-STT speech in an isolated fair-use lane - #10127

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:fix/7690-custom-stt-fair-use-lane
Jul 23, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:fix/7690-custom-stt-fair-use-lane

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Custom-STT sessions' speech now reaches the fair-use meter — in a new isolated custom_stt lane that live enforcement never reads. Previously _flush_usage returned early for these sessions before any recording, so the speech driving Omi-paid LLM post-processing (structuring, memory extraction) was invisible to every meter (Custom STT (BYOK) users: uncapped LLM/post-processing spend (no limit or accounting) #7690).
  • Nothing is gated and no billing semantics change: transcription usage recording stays skipped for these users, and the lane is excluded from LIVE_SPEECH_SOURCES — the same isolation contract sync_backfill already uses ("metered, never live-enforced").
  • This is the accounting half of Custom STT (BYOK) users: uncapped LLM/post-processing spend (no limit or accounting) #7690. Quantifying the spend reads this lane (get_rolling_speech_ms(uid, sources=('custom_stt',)) — the reader already takes a sources tuple); whether to cap is the issue's open policy question and deliberately not decided here.

Addresses #7690 (accounting); capping policy remains open there.

Root cause

use_custom_stt short-circuits _flush_usage before both record_speech_ms (fair-use meter) and record_usage (usage stats). The exemption was designed for transcription billing but silently swallowed all speech accounting with it — so the existing fair-use machinery never sees these users at all, exactly as #7690 describes.

Why a lane, not a flag

The fair-use engine already models this: sources are lane-isolated by key (fair_use:v2:*:{source}:{uid}), live enforcement reads only LIVE_SPEECH_SOURCES, and sync_backfill is the precedent for "metered but never live-enforced". One frozenset entry gives custom-STT the same contract. Critically, an unregistered source coerces to 'realtime' in _normalize_speech_source — which would have put exempt users into the live-enforced lane and gated them; the tests pin that trap.

Failure class

Failure-Class: none

No registered class covers an exemption swallowing adjacent accounting; single instance, decision extracted to the existing lane model rather than a new mechanism.

Product invariants affected

none (verified with scripts/pr-preflight --suggest)

Validation

  • Old-code check (production files stashed, tests kept): 3 failed — the lane coerces to realtime, and the custom-STT flush records nothing; with the fix all pass.
  • New coverage: the lane records under its own Redis keys (fair_use:v2:bucket:custom_stt:*); custom_stt is a valid source and absent from LIVE_SPEECH_SOURCES (with the unknown-source-coerces-to-realtime trap pinned); a runtime-level test drives the real _flush_usage for a custom-STT session and asserts speech reaches the lane and only the lane — any record_usage call raises.
  • Repo runner (file-isolated, as CI executes): tests/unit/test_fair_use_engine.py → 61 passed, tests/unit/test_listen_runtime_regressions.py → 12 passed.
  • make preflight (local lane, this PR body) → all selected checks pass.
  • black clean on all changed files.

Not exercised live: a real custom-STT device session (no BYOK credentials here). The flush seam is driven directly by the runtime test; the engine's lane isolation is driven by the key-shape tests.

Out of scope, named

Review in cubic

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @aryanorastar — narrow, well-targeted change. The lane isolation is real and correctly wired:

  • custom_stt is added to _VALID_SPEECH_SOURCES but kept out of LIVE_SPEECH_SOURCES. Live enforcement (check_soft_caps, is_daily_audio_ceiling_exceeded) calls get_rolling_speech_ms(uid) with no sources arg, so it defaults to ('realtime', 'sync_fresh') — the new lane provably can't gate exempt users. Good call pinning the _normalize_speech_source coercion trap with a test, since an unregistered source would have coerced to realtime and gated them.
  • _flush_usage now meters custom-STT speech into fair_use:v2:*:custom_stt:{uid} and still returns 0, so transcription billing (record_usage) stays skipped. Accounting-only, matching the PR description; the isolation contract mirrors the existing sync_backfill precedent.
  • Tests cover both the engine-level lane keys and the runtime flush path, including the no-delta -> no-write case.

Two things for a human maintainer before merge:

  1. This touches fair-use metering (a billing/abuse-accounting surface), so I'm flagging it for maintainer sign-off rather than approving. The product call on landing the accounting half of Custom STT (BYOK) users: uncapped LLM/post-processing spend (no limit or accounting) #7690 now — versus together with a cap policy — is a maintainer decision.
  2. The preflight/formatting/hygiene checks are showing cancelled/skipped rather than a clean pass on this head; worth confirming they're green (or substantively skipped) so the merge gate is clean.

No gating or billing semantics change here. Core stack gauntlets (Listen Pusher, Hermetic Backend E2E, Sync Cloud Tasks, Public Developer API contract) pass.


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 the needs-maintainer-review Needs a human maintainer to sign off before merge label Jul 20, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level CI is running now since I pushed the test timebomb fix earlier.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Thanks — on your two notes: (1) agreed the accounting-vs-cap sequencing is a product call. This PR is accounting-only (no gating, no billing change), so it can land independently and leaves the cap as #7690's open decision. (2) Backend unit suite is green on this head; the earlier cancelled/skipped preflight/hygiene runs were fork-workflow gating rather than failures.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend fair-use metering for custom-STT (isolated lane) — approve only; failing Desktop Swift checks + more feature than bug, needs green CI

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up verification on the two open items from the earlier pass — both resolve cleanly.

1. CI status (was: "worth confirming preflight/hygiene are green"). Confirmed. The Desktop Swift Build & Tests / Desktop Swift Test Suites entries are an infra timeout, not a code failure: workflow run 29798688948 ran 9h45m and was cancelled; the failing step shows STATIC_RESULT: success, TEST_RESULT: cancelled. This is a backend Python-only change and Desktop Swift is the unrelated native-app workflow. Everything relevant to this diff is green on f68abeb: Backend Hermetic Merge Gate, Backend unit suite, Hermetic Backend E2E, Listen Pusher Stack Gauntlet, Sync Cloud Tasks Stack Gauntlet, Public Developer API contract, Formatting, Hygiene, Static Contracts.

2. Safe reuse of the VAD delta API. consume_speech_ms_delta() (backend/utils/stt/vad_gate.py:490) is the same existing VADStreamingGate method the non-custom path already calls at runtime.py:435 — returns int ms and resets the delta. No new contract is introduced; the custom-STT branch just routes the same number into the isolated lane.

Two smaller confirmations, for the record:

  • The _flush_usage split preserves the DG-accumulator-flush-before-custom-STT-guard ordering (still asserted by test_flush_before_custom_stt_guard).
  • The test_ws_b_short_term_lifecycle.py NOW change is a genuine timebomb fix and matches main (line 123 already uses datetime.now(timezone.utc) there) — not a behavior change.

Net: accounting-only, no gating/billing semantics change, isolation is real, tests are strong. Still a positive signal rather than a formal approval — this touches the fair-use metering surface and is the accounting half of an open product/policy issue (#7690), so the accounting-vs-cap sequencing call belongs with a human maintainer before merge. needs-maintainer-review stays accurate.


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

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — kodjima33 approved; accounting-only change with real lane isolation and strong tests. Ready for a maintainer to merge.

aryanorastar and others added 2 commits July 23, 2026 00:09
Custom-STT sessions are exempt from transcription billing and live
caps by design — but _flush_usage returned early for them before any
recording, so their speech never reached the fair-use meter at all,
while everything downstream (conversation structuring, memory
extraction) still runs on Omi-paid LLM post-processing with no
accounting (BasedHardware#7690).

The speech now records into a new 'custom_stt' fair-use lane: valid in
_VALID_SPEECH_SOURCES (an unknown source would coerce to 'realtime' and
gate exempt users), excluded from LIVE_SPEECH_SOURCES so live
enforcement never reads it — the same isolation contract sync_backfill
already uses. Transcription usage recording stays skipped: no billing
semantics change, nobody gets gated. Quantifying and capping the spend
(the issue's policy questions) read this lane and are deliberately
separate decisions.

Regression tests (3 fail on old code): the lane records under its own
Redis keys; the source is valid and outside live enforcement; a
custom-STT session's flush meters speech into the lane and only the
lane — recording transcription usage for one asserts a failure.

Addresses the accounting half of BasedHardware#7690; capping policy remains open
there.

Failure-Class: none

Co-Authored-By: Claude Fable 5 <[email protected]>
@aryanorastar
aryanorastar force-pushed the fix/7690-custom-stt-fair-use-lane branch from f68abeb to 9f9aab9 Compare July 22, 2026 18:44
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — this PR is approved, rebased onto latest main today, and all checks are green (mergeable, clean). Ready for a maintainer to merge (regular merge, no squash). Thanks!

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix (#7690): custom-STT speech now metered in isolated lane, no billing change; scoped, tests, CI green — 5/5

@kodjima33
kodjima33 merged commit 564d232 into BasedHardware:main Jul 23, 2026
31 checks passed
mdmohsin7 added a commit that referenced this pull request Sep 3, 2026
## What changed and why

Reverts the Omi-paid LLM post-processing gate from #7690 (commit
`3c998bf`, PR #10962).

Custom-STT users bring their own STT key. The gate skipped **all** LLM
enrichment for
their conversations — title, overview, memories, action items,
embeddings, app results —
unless they *also* carried an OpenAI/Anthropic BYOK key on the request.
Bringing an STT
key is not a request to lose summaries, and almost nobody carries a
second LLM key, so
in practice the cost cap read as "summarization is off" for the entire
custom-STT
population. Same story on the live photo path: `_process_photo` stored
the literal string
`Custom STT: photo description skipped (no LLM BYOK key).` instead of
calling
`describe_image`.

## Removed

- The `process_conversation` gate and its deferred `is_byok_active`
lookup.
- The `_process_photo` gate in `routers/listen/receiver.py`.
- `should_skip_custom_stt_postprocessing`, now unreferenced.

## Kept

`Conversation.uses_custom_stt` and its creation / resume / merge
plumbing. It is
provenance only now — it keeps custom-STT spend queryable and feeds the
isolated
fair-use lane (#10127) — so the API contract and the generated
Dart/OpenAPI clients
are unchanged. Comments that described it as a cost gate were corrected
to match.

Cost visibility therefore survives the revert; only the enforcement is
gone. If a cap
is wanted later it belongs in the fair-use lane that already meters this
traffic, keyed
on actual spend rather than on a BYOK key almost no gated user holds.

## Product invariants affected

- INV-MEM-4
- INV-TASK-2

Neither changes behavior here. The diff removes an early return, so
custom-STT
conversations now reach exactly the promotion and task-capture paths
every other
conversation already takes. No guard test needed updating.

## Failure class (fixes)

Failure-Class: none

The gate did what it was written to do; the policy behind it was wrong
for the
population it selected. This is a product-policy revert, not the repair
of a violated
code contract, so no class is declared and none is opened.

## Tests

The two gate assertions are inverted into regression tests: a custom-STT
conversation
with no LLM BYOK key must run structuring, and a custom-STT photo must
reach
`describe_image`. The "hot path never reads BYOK state" deferral tests
are dropped
along with the deferral they guarded.

## Verification

`cd backend && pytest tests/unit/<file>.py` (one file at a time):

| File | Result |
|---|---|
| `test_process_conversation_usage_context.py` | 53 passed |
| `test_listen_multichannel_mix_buffer_leak.py` | 5 passed |
| `test_transcribe_decisions.py` | 25 passed |
| `test_listen_process_pending_shutdown.py` | 13 passed |
| `test_merge_audio_chunk_copy_failure.py` | 5 passed |
| `test_shared_conversation_field_exposure.py` | 8 passed |
| `test_byok_security_enrollment.py` | 34 passed |
| `test_new_usage_tracking_gaps.py` | 45 passed |

`make preflight` — all manifest checks pass.

Not exercised against a live custom-STT session: that needs a real
third-party STT key
bound to an account. The behavior is covered at the
`process_conversation` and
`_process_photo` seams instead.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12663?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Git-on-my-level pushed a commit to Git-on-my-level/omi that referenced this pull request Sep 3, 2026
Revert the Omi-paid LLM post-processing gate from BasedHardware#7690 (commit 3c998bf).
Custom-STT users bring their own STT key, and the gate skipped ALL LLM
enrichment for their conversations unless they ALSO carried an LLM BYOK
key: no title, no overview, no memories, no action items, no app results.
Bringing an STT key is not a request to lose summaries, and almost nobody
carries a second OpenAI/Anthropic key, so in practice the gate silently
turned summarization off for every custom-STT user.

Removed:
- the process_conversation gate and its deferred BYOK lookup
- the live-session photo gate that stored "Custom STT: photo description
  skipped" instead of calling describe_image
- should_skip_custom_stt_postprocessing, now unreferenced

Kept: the durable Conversation.uses_custom_stt marker and its
creation/resume/merge plumbing. It is provenance only now — it keeps
custom-STT spend queryable and feeds the isolated fair-use lane (BasedHardware#10127)
— so the API contract and generated clients are unchanged. Comments that
described it as a cost gate were corrected to say so.

Tests invert the two gate assertions into regression tests: a custom-STT
conversation with no LLM BYOK key must run structuring, and a custom-STT
photo must reach describe_image. The now-moot "hot path never reads BYOK
state" deferral tests are dropped with the deferral.

Verification:
  cd backend && pytest tests/unit/<file>.py   # one file at a time
  test_process_conversation_usage_context.py     53 passed
  test_listen_multichannel_mix_buffer_leak.py     5 passed
  test_transcribe_decisions.py                   25 passed
  test_listen_process_pending_shutdown.py        13 passed
  test_merge_audio_chunk_copy_failure.py          5 passed
  test_shared_conversation_field_exposure.py      8 passed
  test_byok_security_enrollment.py               34 passed
  test_new_usage_tracking_gaps.py                45 passed

Failure-Class: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants