Skip to content

feat(audio): losslessly compact new custody PCM writes (SCA-2302) - #25326

Merged
Git-on-my-level merged 6 commits into
mainfrom
lane/silence-new-storage
Nov 14, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
lane/silence-new-storage

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

New custody PCM is stored uncompressed even when it contains long silent intervals. Listen and pusher now share a bounded representation helper: use lossless FLAC only when decoding reproduces every PCM byte and saves at least 5%; otherwise retain PCM.

Packs without a complete PCM identity proof retain their original container. No classifier or hosted call is added. The existing media/manifest commit barrier, consent, encryption, frame positions and generation/hash verification continue to apply. Existing readers already handle FLAC. Native Opus, PCM8, mobile originals, PCM projections and historical objects are unchanged. No expiration, deletion, storage-class migration or rewrite job.

The margin-owner follow-up adds an optional-step timing histogram, zero-initialized outcome counters, actual hung-child timeout and busy-capacity custody-commit tests, and exact per-surface canary queries and rollback thresholds. The review follow-up counts input bytes only after eligibility and encoder-slot admission, and documents verified per-attempt saved bytes. CI and independent review must cover the final head.

Validation:

  • 146 tests passed across compression, durable outbox, custody frames and gapped raw packs before the final extensions.
  • All 28 compression tests passed, including real codecs, exact samples, both writers, encryption, gaps, retry identity, writer rollback reads, a genuinely timed-out child process and busy-encoder custody fallback.
  • The proper test.sh runner passed all 82 tests in the existing desktop-batch file. Its old raw-container equality assertion now checks verified recovered PCM for compressed captures and exact original bytes for uncertain captures.
  • All 11 real-clock budget ratchet tests passed with the slow-guardrail CI flags. The hung-child test uses the production two-second timeout; its 50 ms test override was removed without changing production settings or adding an allowlist exception.
  • The unrelated erasure-queue deployment file passed all 8 tests with the real runner and unchanged 1.0-second CPU guard after CI reported a 1.10-second timing-only failure.
  • Local preflight passed all 41 checks after merging current main; the bounded pre-push gate also passed, including 82 desktop-batch and 28 compression tests. Published head: 08eace0d360d2e11479e483dd1fbfc77f2bcead7.
  • Synthetic codec CPU/wall probes and five bounded production aggregate queries are attached to SCA-2302's design-response comment. The production read used ro-prod at 2026-11-14T20:48:28Z; no object listing, audio download, customer record or production write. That baseline confirms active PCM writes on both jobs; it does not measure the eligible compression mix or fleet net savings. Credited production savings remain $0 pending measurement. The 5% threshold is per accepted encoding, not a net margin claim.

Release: SCA-2302; deployment intake SCA-2304. David requested implementation here and deployment through Release. The single independent Multica review of record plus green exact-head CI is required before merge. Release owns listen/pusher deployment, rollback and a full 30-minute canary with serving-source proof. The runbook requires eligible traffic, verified FLAC outcomes and committed FLAC-byte growth, zero new integrity failures, and quantitative optional-latency/custody-failure thresholds. Set AUDIO_CUSTODY_PCM_COMPRESSION_ENABLED=false to stop new compression while preserving custody and FLAC reads. No capacity, access or storage-retention change is requested.

Failure-Class: none

This first-release correction updates an existing container-byte assertion to validate losslessly recovered PCM and keeps unproven zero-sample originals in their raw container. The review follow-up corrects pre-release attempt-byte accounting and adds regression coverage for admission, fallback and retries. No existing merged failure class is claimed.

@Git-on-my-level
Git-on-my-level merged commit c6f8c99 into main Nov 14, 2026
74 of 77 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/silence-new-storage branch November 14, 2026 23:12
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