Skip to content

SCA-2302: instrument optional PCM codec stages - #25414

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/pcm-codec-stage-instrumentation
Nov 15, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/pcm-codec-stage-instrumentation

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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

View guided diff Turn on auto-fix

The whole-helper histogram cannot say which codec child consumed the time or
how far a killed child overran its own budget, so a latency question about the
optional PCM representation step could not be answered from production data.

Add two diagnostic histograms beside the unchanged guard:

- omi_audio_pcm_storage_stage_seconds{stage,child_result} times one child that
  actually ran, from just before subprocess.run through its return or handled
  exception. child_result is that child's own outcome (success/timeout/error),
  never the call's terminal decision.
- omi_audio_pcm_storage_stage_timeout_overshoot_seconds{stage} is observed only
  for a child killed by its own timeout, as full stage wall time beyond the
  granted timeout.

Both use fixed buckets (.005,.01,.05,.1,.25,.5,1,2), no per-request label, and
eight pre-created children without fabricated zero observations: 88 series per
pod with the pinned client, within the 96-series ceiling. Timestamps are taken
around the child only, so granted timeouts, subprocess arguments, the 0.4 s
budget, the 0.08 s decode reserve, the single slot, eligibility, byte-exact
verification, PCM fallback, existing counters and one timeout fallback are
unchanged. Observations are flushed after the codec slot is released, and the
disabled/ineligible/busy paths allocate nothing and observe nothing.

The diagnostics never feed the 0.5 s p99 guard, which keeps its buckets and its
population. Overshoot includes startup, cleanup and descheduling, so it is not a
pure process-start cost and not a wall-clock bound. Instrumentation alone cannot
pass the failed pusher canary; reactivation still needs Release authorization
and independent both-surface verification.

Verification: test_audio_pcm_storage.py 46 passed through the repository runner,
covering exactly-once observations on success/timeout/error, per-stage outcome
attribution, overshoot only on timeout, no observations on non-admitted paths,
pre-created children at zero, and unchanged returns/counters/fallback/slot
release. make preflight passed 37 checks.

Failure-Class: none
Review round 1 on #25414. The decode sample was appended after the byte
comparison and SAVED_BYTES accounting, so the histogram included verification
work that is not part of the child. Capture the end timestamp at the child's
return or handled exception, before any comparison or accounting, and keep the
deferred flush after slot release. The encode stage now stops its clock in the
same place for a symmetric boundary.

Measured with an injected clock whose comparison adds 0.30 s and whose saved-byte
accounting adds 0.20 s: the previous head recorded a 0.55 s decode stage for a
0.05 s child, the corrected head records 0.05 s. The new deterministic regression
fails on the previous head and passes here.

Also correct the runbook: the per-surface scrape jobs are pusher-metrics and
backend-listen-metrics, and the instrumentation cost is two timestamp reads per
invoked child, not one.

No change to subprocess arguments, forwarded timeouts, the 0.4 s budget, the
0.08 s reserve, the slot, eligibility, verification, fallback or custody path.

Failure-Class: none
@Git-on-my-level
Git-on-my-level merged commit fd66e7f into main Nov 15, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pcm-codec-stage-instrumentation branch November 15, 2026 16:35
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