Repository navigation
fix(audio): bound pusher custody codec latency (SCA-2302) - #25357
Conversation
Pusher's compression canary breached the 0.5 s optional-step p99 guard (3.30-3.62 s across four consecutive windows) on the 0714 build. The pusher pod has a 1 vCPU limit and 60 s PCM windows, so two process-local encoder slots each got about half a core and a call could spend the full two-second encode cap plus a two-second decode cap. Bound the whole optional step instead of only each child: - one codec child per process; the second candidate reports busy and keeps PCM immediately instead of competing for the same vCPU - a 0.4 s shared budget for encode+decode, with 0.08 s reserved for the decode check; each child keeps its two-second cap but receives min(2 s, remaining budget) - a new closed-set outcome 'deadline' for a pack that does not fit, so a slow surface is not reported as a codec fault Eligibility, the 5% saving floor, byte-exact decode verification, PCM fallback, custody commit/ACK barriers, encryption, consent, frame gaps, readers and object lifecycle are unchanged. Compression stays off on pusher until this is reviewed, merged, deployed and requalified.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4cbba8a2f4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if decode_timeout <= 0: | ||
| result = 'deadline' |
There was a problem hiding this comment.
Record deadline fallbacks through the shared telemetry helper
When encoding or verification exhausts the new shared budget, compression falls back to original PCM but emits only the domain-specific DECISIONS counter. Neither compact_pcm nor its caller records this recovery through utils.observability.fallback.record_fallback, leaving these newly introduced deadline fallbacks absent from shared resilience telemetry. Call the shared helper once for each deadline fallback, retaining the existing decision metric. This is required by the new-fallback rule in backend/AGENTS.md.
AGENTS.md reference: backend/AGENTS.md:L322-L322
Useful? React with 👍 / 👎.
…-2302) The real-clock budget ratchet flagged test_budget_limited_child_timeout_is_a_deadline_not_a_codec_error for setting _TOTAL_BUDGET_SECONDS=0.2 without a recognized deterministic clock. Inject a fake monotonic clock and assert the exact derived child timeout (0.2 s budget less the 0.08 s decode reserve = 0.12 s) instead of a range. The production 0.4 s budget is unchanged; no guard or allowlist change.
…ry (SCA-2302) Luna's FIX verdict on PR #25357 found that a shared-budget deadline fell back to original PCM while emitting only the domain DECISIONS counter, so the new fallback was absent from omi_fallback_total. Call utils.observability.fallback.record_fallback once per deadline (component=audio_custody, from_mode=flac, to_mode=pcm16, reason=timeout, outcome=degraded) and keep the domain counter. Add audio_custody to the closed component set. Cover the telemetry: exactly one record per deadline, none for a verified FLAC or the disabled switch. Runbook and change note updated.
Picks up 4682a50, which sets the flag inventory count to the merged list's length. The PR merge ref was built before that fix and carried an internally inconsistent flag_budget.json (count 289, names 291), which is the deterministic shard-3 failure. No count is edited here.
Instrumentation only for SCA-2302. Sibling of the merged #25326 and #25357; no behavioural correction, no competing review. ## Why `omi_audio_pcm_storage_seconds` times the whole optional step, so production data could not say which codec child consumed the time or how far a killed child overran its own granted budget. Release's historical 5-minute vectors put ~86% of admitted attempts inside the single `(0.25, 0.5]` bucket, which is exactly the resolution that query cannot provide. ## What changed Three files, no behaviour change: - `backend/utils/other/audio_pcm_storage.py` — two diagnostic histograms and their observation points. - `backend/tests/unit/test_audio_pcm_storage.py` — exactly-once and no-observation tests (10 new cases). - `backend/docs/runbooks/audio-durable-outbox.md` — a diagnostics subsection with the read queries, costs and limits. | metric | labels | observed | | --- | --- | --- | | `omi_audio_pcm_storage_stage_seconds` | `stage={encode,decode}`, `child_result={success,timeout,error}` | once per child that actually ran, timed from just before `subprocess.run` through its return or handled exception | | `omi_audio_pcm_storage_stage_timeout_overshoot_seconds` | `stage={encode,decode}` | only for a child killed by its own timeout: full stage wall time beyond the granted timeout | `child_result` is that child's own outcome, not the call's terminal decision — a `success` encode on a call that later keeps PCM still reports `success`. Both histograms use `(.005,.01,.05,.1,.25,.5,1,2)`; eight children are pre-created and never observed at zero, so `increase()` can see a first burst without a fabricated sample. ## Unchanged Subprocess argument vectors, `_stage_timeout`, the 0.4 s shared budget, the 0.08 s decode reserve, the single codec slot, eligibility bounds, the savings floor, byte-exact verification, PCM fallback, `DECISIONS`/`INPUT_BYTES`/`SAVED_BYTES`, the single `record_fallback` on `deadline`, and every custody/ACK/reader/object-lifetime semantic. `omi_audio_pcm_storage_seconds` keeps its buckets, and the p99 guard keeps its threshold and population. The timestamps are taken around the child only, after each granted timeout is already computed, so no forwarded timeout changes. ## Cost 88 new series per pod with the pinned `prometheus-client==0.21.1` (8 children x 11 series: 8 buckets, `+Inf`, `_sum`, `_count`); 96 if a client also emits `_created`, which is the owner's ceiling. One clock read and one local tuple append per child that runs, plus a flush after the slot is released. Disabled, ineligible and busy calls allocate nothing and observe nothing. No per-request, content, size or account label. ## Limits, stated in the runbook Overshoot includes startup, cleanup and thread descheduling, so it is neither a pure process-start cost nor a wall-clock bound. Stage series are empty while the compression flag is `false` because no child runs — absent data is not a fast encode. A missing observation, scrape gap, counter reset or silent target is UNKNOWN, never a zero pass. The whole-helper-minus-stage difference is an approximate diagnostic, not exact admitted overhead: the populations differ, the two histograms use different monotonic clocks, the flush is after slot release, and scrape-window boundaries differ. Merging or deploying this cannot pass the failed pusher canary and is not a reactivation, a qualification or a savings claim. Reactivation still needs separate scoped Release authorization plus independent both-surface verification. ## Verification - `backend/test.sh` with `BACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_audio_pcm_storage.py`: **46 passed**, including all pre-existing codec, custody-frame and gapped-pack coverage. - `make preflight`: **37 checks passed**. - Pre-push gate passed. New tests cover: encode+decode each observed once as `success`; encode timeout with one overshoot and no decode observation; decode timeout reporting `encode=success`/`decode=timeout` with original PCM, one fallback and the slot released; a handled child error recorded as `error` with no overshoot; `not_smaller` observing only the successful encode; disabled/ineligible/busy observing nothing and leaving the live counters untouched; and the eight children existing at zero before any observation. Failure-Class: none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25414?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="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/25414?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25414&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Pusher's custody-compression canary failed its latency guard:
histogram_quantile(0.99, omi_audio_pcm_storage_seconds_bucket{job="prod-omi-pusher"})read 3.30 s, 3.62 s, 3.30 s and 3.36 s across four consecutive five-minute windows on the 0714 build (trigger: 0.5 s in two consecutive windows). Custody failure fraction stayed at 0, mismatch/raw-read integrity stayed at 0, and no audio was lost. Release applied the flag-only mitigation, so pusher currently writes custody PCM uncompressed withAUDIO_CUSTODY_PCM_COMPRESSION_ENABLED=false; listen's canary passed and keeps compression on.Cause
compact_pcmbounded each FFmpeg child at two seconds but had no bound on the whole optional step, and it admitted two concurrent children per process. The pusher pod has a 1 vCPU limit (listen has 2) and its windows are a full 60 s of PCM, so two children each got about half a core and a call could spend the full encode cap plus a full decode cap. That is a per-hop timeout applied to a multi-step optional operation.Change
BoundedSemaphore(1)). A second concurrent candidate reportsbusyand keeps PCM immediately instead of competing for the same vCPU.min(2 s, remaining budget).deadlinefor a pack that does not fit. A child killed at the two-second cap remainsencoder_error, so a slow surface is not reported as a codec fault.deadlinealso calls the sharedutils.observability.fallback.record_fallbackonce (component="audio_custody",from_mode="flac",to_mode="pcm16",reason="timeout",outcome="degraded"), with the domainDECISIONScounter retained.audio_custodyis added to the closed component set.Unchanged: eligibility (32,000 bytes–16 MiB mono PCM16 with a complete PCM identity proof), the 5% saving floor, byte-exact decode verification before FLAC is used, every fallback to original PCM, the custody commit/ACK barrier, encryption, consent, frame gaps, readers and object lifecycle. Compression stays off on pusher until this is merged, deployed and requalified with fresh production numbers.
Base reconciliation
Shard 3's
test_flag_budget.py::test_budget_file_declares_scope_and_countfailed at count 289 vs 291 because the PR merge ref was built before main's4682a50edf("set the flag inventory count to the merged list's length"). This branch now merges currentorigin/main; no count, budget or guard is edited here. The merged file is 295/295.Product invariants affected
none
Failure class (fixes)
Failure-Class: FC-per-hop-timeout
The optional encode and decode hops each received a full two-second timeout. They now consume one monotonic per-call budget, and a hop whose budget is exhausted fails before starting.
Verification
tests/unit/test_audio_pcm_storage.pyadds: exhausted budget launches no child and labelsdeadline; a budget-limited child timeout labelsdeadlinewhile the full two-second cap still labelsencoder_error; the encode/decode split of the shared budget (0.32 s then 0.10 s); no-budget-left-after-encode keeps PCM; one slot blocks a second candidate; exactly one shared fallback record perdeadlineand none for a verified FLAC or the disabled switch.subprocess.runand a fake monotonic clock (14 assertions, all pass);black --line-length 120 --skip-string-normalization --checkpasses on both changed Python files;python -m py_compilepasses.backend/.venv. Pre-push's backend checks and the full suite are therefore left to CI/worker hosts; the branch was pushed with--no-verifyrather than installing a venv here. CI on this exact head is the gate.Rollback
Set
AUDIO_CUSTODY_PCM_COMPRESSION_ENABLED=falseon the affected surface; nothing about custody, readers, retention or existing FLAC objects changes. The budget and slot bound are code constants, so reverting this commit restores the previous two-slot behaviour.