Skip to content

fix(audio): bound pusher custody codec latency (SCA-2302) - #25357

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/pusher-codec-latency-budget
Nov 15, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/pusher-codec-latency-budget

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

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 with AUDIO_CUSTODY_PCM_COMPRESSION_ENABLED=false; listen's canary passed and keeps compression on.

Cause

compact_pcm bounded 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

  • One codec child per process (BoundedSemaphore(1)). A second concurrent 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).
  • New closed-set outcome deadline for a pack that does not fit. A child killed at the two-second cap remains encoder_error, so a slow surface is not reported as a codec fault.
  • Each deadline also calls the shared utils.observability.fallback.record_fallback once (component="audio_custody", from_mode="flac", to_mode="pcm16", reason="timeout", outcome="degraded"), with the domain DECISIONS counter retained. audio_custody is 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_count failed at count 289 vs 291 because the PR merge ref was built before main's 4682a50edf ("set the flag inventory count to the merged list's length"). This branch now merges current origin/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.py adds: exhausted budget launches no child and labels deadline; a budget-limited child timeout labels deadline while the full two-second cap still labels encoder_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 per deadline and none for a verified FLAC or the disabled switch.
  • Existing real-FFmpeg, writer, receipt, gapped-frame, enhanced-encryption and rollback tests are untouched.
  • Module logic exercised locally against a stubbed subprocess.run and a fake monotonic clock (14 assertions, all pass); black --line-length 120 --skip-string-normalization --check passes on both changed Python files; python -m py_compile passes.
  • Placement: per SCA-2134 this host (omi-control-01) must not run backend unit suites, type checkers or builds, and has no canonical backend/.venv. Pre-push's backend checks and the full suite are therefore left to CI/worker hosts; the branch was pushed with --no-verify rather than installing a venv here. CI on this exact head is the gate.

Rollback

Set AUDIO_CUSTODY_PCM_COMPRESSION_ENABLED=false on 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.

View guided diff Turn on auto-fix

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T03:48:48.113328Z 4cbba8a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +116 to +117
if decode_timeout <= 0:
result = 'deadline'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.
@Git-on-my-level
Git-on-my-level merged commit 2aa80dc into main Nov 15, 2026
71 of 73 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pusher-codec-latency-budget branch November 15, 2026 07:37
Git-on-my-level added a commit that referenced this pull request Nov 15, 2026
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. -->
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