Skip to content

fix(listen): refill speaker embedding budget and skip unavailable pooled PCM - #21047

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/owner-recog-budget
Oct 9, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/owner-recog-budget

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #20964 (merged a02bee4; deployed to production listen 2026-10-08 21:08Z). Long-lived pendant sockets exhaust the lifetime embedding caps, and one unavailable pooled PCM interval aborts otherwise usable speech.

Before measurements supplied with the incident (not independently queried):

  • embedding_budget: 106k exits in 11.9h (8.9k/h), over twice all live decisions (~47k).
  • 2026-10-09 06:00–08:00Z: 130 of 1,004 live sessions hit the budget; budget exits were 25% of all speaker-ID log lines.
  • no_pcm: 1.4/h → 1,280/h.
  • Live owner pending decisions: 1,018/h → 1,199/h.

Replace lifetime socket exhaustion with a monotonic-wall-time token bucket: initial/capacity 16, refill 240/3600 attempts per second (one per 15 seconds). Attempts over t socket-hours are bounded by floor(16 + 240*t): ≤256 in the first hour and ≤240/hour asymptotically, at ≤10s query PCM per attempt (≤2,560s first-hour and ≤2,400s/hour steady-state query audio). An arbitrary one-hour window can use up to 256 including saved burst credit. Idle credit caps at 16; failures spend tokens; reservation precedes awaits. Conversation/profile churn and client audio timestamps cannot mint tokens. Reconnection still creates a new socket budget, as before; this is not an account-wide cap.

Keep 12 attempts per voice per conversation. Reset uncarried IDs on rollover; carried manual mappings and validated automatic owner carry retain their attempts. Profile refresh within the same conversation preserves attempts. Accepted voices stop spending. All rejected voices, including far/noisy rejections, retain fresh-audio recovery opportunities within the 12-attempt allowance and socket bucket. Later clean clips can evict noisy evidence and re-arbitrate owner claims, withdrawing a competing automatic owner mapping. Failed one-second reconnect evidence is also allowed to accumulate normal full-length owner evidence. Retained evidence can still be re-arbitrated or rechecked against a recovered owner without more model calls.

Skip unavailable PCM intervals; emit no_pcm only for an entirely unusable pool and recheck actual remaining PCM duration. Metric names, labels and exit reasons stay unchanged; the proposed decided_voice reason and early stop were removed after the independent review. Merged origin/main including #21052 (5b42496d5c) without rebasing or rewriting the published branch. Its calibrated [0.65, 0.70) owner near misses remain unknown / pending. Acceptance thresholds, margins, carry eligibility and paid non-owner naming/free owner recognition are unchanged.

Failure-Class: none
The existing classes do not cover permanent exhaustion of a socket-scoped live embedding budget or aborting a pooled extraction on one unavailable interval. The fix is implemented in the matcher admission primitive with behavioral regression tests, rather than adding a separate guard.

Product invariants affected

none (as reported by scripts/pr-preflight --lane local --suggest).

Validation

  • Focused policy/budget/carry/pooling/exit assertions passed through backend/test.sh, including fix(speakers): keep calibrated live owner near misses pending #21052's pending-band tests. The revised budget suite passed all 24 cases with the unchanged default 0.30s CPU guard.
  • Selected all 61 speaker/owner-recognition/owner-profile unit files through backend/test.sh. All 1,491 cases passed their assertions. The parallel run loaded the pre-optimization churn test and flagged its CPU time; it also flagged unchanged mixed-cache and speaker-learning cases at 0.34–0.60s. The final budget file passed the default 0.30s guard; the two unchanged timing-offender files passed serially with the documented CI 1.0s ceiling (50 cases). No timing policy or allowlist is changed in this PR.
  • OMI_PR_BODY_FILE=/tmp/owner-budget-pr.md make preflight: 31 checks passed. PR-body metadata validation and required pre-push contracts also run before publication. The failure-class history ratchet skips on the shallow local clone.
  • Regression tests execute real SpeakerMatcher.match and WAV encoding: original far/noisy recovery, near-threshold recovery, competing automatic owner withdrawal, and replay of the failed one-second reconnect state described by fix(listen): preserve acoustic owner continuity across reconnects #21051. fix(listen): preserve acoustic owner continuity across reconnects #21051 is not merged into this branch; the replay is not a composed reconnect implementation test.
  • No Google credentials, production data or api.omi.me calls.

Reviewer risks

  • The smaller burst can delay a busy early conversation after 16 attempts; refill recovers one attempt every 15s. Long-lived sockets can now spend recurring hourly cost, unlike the lifetime cap.
  • Rejected voices can still exhaust their 12-attempt allowance before later clean speech; the socket bound prevents conversation churn from minting free budget. Review the far/noisy and near-threshold recovery regressions and competing-owner withdrawal.
  • Check carry-attempt accounting around profile/donor awaits, generation fencing and owner contention. Existing carry and entitlement regression tests remain part of validation.
  • No production deployment or recognition-quality measurement is performed by this PR.

View guided diff Turn on auto-fix

@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.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Coordinating the #21051 review fixes: I have added actual matcher regressions for a noisy one-second accumulation, a failed two-second reconnect shortcut at nearest-print distance >=0.75, then clean fresh speech reaching the ordinary five-second floor. Both must stay retryable until normal recognition. The current #21047 confident-rejection early stop would violate that contract for shortened evidence; I am waiting for its removal and will merge main again without force-pushing, then run the combined budget/reconnect tests. Other fixes keep retained rollover peers competition-only and fence donor receipt revisions and cancelled cache publications.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

The #21051 review fixes are now published at dc8c3c4, with 117 targeted regressions passing and zero type errors. This includes the one-second pending / failed two-second shortcut / ordinary five-second recovery contract. I verified current #21047 head ac13f6d has terminal green CI. Per the coordinator instruction I am waiting for #21047 to land, then will merge origin/main again (no history rewriting), run the combined budget/pool/carry/reconnect suite, and push the final integrated #21051 head.

@Git-on-my-level
Git-on-my-level merged commit 983d770 into main Oct 9, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/owner-recog-budget branch October 9, 2026 14:23
Git-on-my-level added a commit that referenced this pull request Oct 10, 2026
…1051)

Reconnects reset diarizer ids and evidence, leaving short owner replies
unknown. Preserve same-account/device owner continuity acoustically
while keeping enrollment thresholds, margins, joint arbitration and paid
non-owner naming unchanged.

Use one accepted owner centroid, enrolled-profile digest and donor
receipt provenance in the existing private authenticated per-user
encrypted cache: 120-second TTL, 16 KiB cap, atomic consumption and
device/writer revision fencing. A reconnect needs two fresh seconds and
the stricter 0.35 session-distance gate as well as the enrolled profile.
Shortened accepts cannot seed another handoff; absent, expired, corrupt,
different-device or changed-profile evidence retains ordinary
five-second recognition. Preserve #21047's refilling budget/retry
behavior and #21052's pending near-miss band.

Retain rollover peers only as competition until they provide five fresh
seconds. An accepted short owner's proof survives capsule expiry while
its original donor and receiving authority remain valid. Read receiving,
original acoustic donor and immediate rollover donor authority in one
projected Firestore transaction, bounded to three documents; fence the
matcher generation and rebuild/arbitrate/publish without another await.

One shared publication gate applies already-known receiving
rejections/retractions, then denies every publication or renewal if
final authority is unavailable. Earlier positive receipts cannot create
or refresh manual, automatic, carried or shortened owner labels. The
acquisition, retained-evidence reevaluation, mapped-voice renewal and
rollover paths all use this gate; idle refresh also stops when
reevaluation cannot publish. No cache refresh follows a failed final
read. Existing labels without a known rejection remain unchanged on read
failure; observed corrections retract them. Failed carry releases the
old per-conversation attempts without replenishing the socket budget.

Merged origin/main at `b2f6d2fe26b6` with an ordinary merge, preserving
upstream owner-retry changes and pipeline documentation. Translation,
dream inventory and Swift CI repairs are already upstream; this PR
contains no app/desktop repair diff. The success-path failover fixture
now dispatches the real final-authority transaction against its strict
store; the rollover test rebuilds continuity when rebinding its host so
the account id agrees with the store. Both retain all their original
assertions.

Spent-attempt telemetry: a spent query vetoed by unavailable final
authority emits exactly one bounded `authority_unavailable` live match
exit; zero-seeded labels and the closed reason inventory include it. No
acoustic rejection is synthesized and the negative-only publication gate
is unchanged. The reviewer reproduction is extended across two/five
seconds and known/absent receiving rejection, asserting one exit, no
live decision, no identity/cache publication, retraction of a known
stale manual mapping, and unchanged short-probe reconnect accounting.
All four new cases failed before the telemetry fix and now pass. The six
targeted suites pass 332 tests, including the full 72-case authority
matrix, rejection/renewal protections, reconnect/rollover suites,
bounded exit inventory and current-main owner retry telemetry. No
identity, arbitration, cache, threshold or budget behavior is changed by
this accounting fix.

Validation (all local test commands use `env -u
GOOGLE_APPLICATION_CREDENTIALS -u GOOGLE_CLOUD_PROJECT
CLOUDSDK_CONFIG=$(mktemp -d)`):
- The 72-case matrix crosses earlier positive/negative/absent receipts,
manual/automatic/carried publication, two/five seconds, healthy/failed
snapshots and a real receiving correction committed during the
transactional read. It failed 32 cases before the gate and now passes
all 72. Actual assignment/rejection operations and strict transaction
reads exercise the behavior, not mocked decisions.
- Mapped two/five-second owners and idle refresh additionally check that
failed authority cannot change an uncorrected mapping, renew the speech
gap or write a capsule. Existing known-rejection regressions continue to
require manual/automatic retraction.
- Current telemetry-focused validation: all 332 tests across six suites
pass through backend/test.sh, including the full authority matrix, exit
inventory, reconnect/rollover and current-main owner retry telemetry.
Typecheck has zero errors; all 34 make preflight checks pass. Exact head
`19571162160c186dc7f4ba66a7595c059ecad061`: [Backend Unit
Tests](https://github.com/BasedHardware/omi/actions/runs/38012356343).


Measurement: supplied rollover counts imply 48.4% `none` among automatic
owner outcomes, not proven identity loss. Archived-scope drops are the
leading code-based hypothesis; bounded rollover reasons expose the gate
taxonomy. `omi_owner_reconnect_total{outcome,reason}` separates
lookup/acoustic attempts, accepts and rejections. Gap choice,
denominators and carry reasons are documented in
`backend/docs/owner-continuity.md`.

Risks and reviewer focus: inspect the single negative-only publication
gate and every caller, especially a stale positive manual receipt
followed by a failed transaction and a receiving correction. Review
encrypted consume/revision ordering, the three-document read bound, and
competition-only carry across plan changes. Two seconds/0.35 lack
production false-accept calibration. Strict synthetic tests prove
binding and control flow, not live Firestore contention/retries or
real-audio calibration. No Google credentials, production data or
production API calls; no deployment or product-acceptance claim. Leave
unmerged for owner review.

Failure-Class: FC-independent-owner-voice-accepts

## Product invariants affected

none

Line-Count-Exception: backend/routers/listen/speakers.py | 1147 -> 1425
| Keep rollover accounting and joint arbitration integrated while
isolating encrypted handoff/cache I/O and centralizing negative-only
final authority across acquisition, rollover and revalidation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant