Repository navigation
fix(stt): hold a margin back from the replay prefix so 1x delivery lands inside its wall - #23108
Conversation
…nds inside its wall A full replay prefix was exactly REPLAY_PREFIX_SECONDS of audio delivered at exactly the endpoint rate into a wall of the same length. The whole budget was spent by construction: the last 16 KiB packet is admitted at 19.968s and must be written and observed by the 10ms poll before 20.000s. Any late write confirm on that packet, or one rebased slot earlier, rejected the successor as `replay_send_stalled` (pre-P34: `capacity_full`) while the pump slept and the listen pod sat idle. On 2026-10-21 ~1,050 prefixes/day landed in the `omi_stt_replay_wall_seconds` 20–25s bucket (7–15% of near-full prefixes per provider pair, including successor=parakeet where no network write exists), and the mean prefix was 14–18.5s, so near-full prefixes are the norm. `bounded_snapshot` now retains `(wall - margin) * rate` seconds of audio (`LISTEN_REPLAY_PREFIX_MARGIN_SECONDS`, default 1.0; `0` restores the exact wall prefix). The wall itself is unchanged, so the margin is slack, and the adopted live tail starts 1s further from its 26s bound. The cut comes off the oldest unanswered second and is metered in `omi_stt_replay_skipped_seconds_total` like any budget cut. Tests simulate the death with the real Modulate adapter over a slow-ack fake transport on the virtual clock: with margin 0 a 50ms final confirm rejects the prefix (queue high-water <= 2, 39 of 40 packets written) and a 10ms one survives; with the default margin a final confirm up to ~0.9s lands inside the wall, a 1.5s one is still rejected, and a sustained sub-realtime transport is still rejected. Existing replay pins move from 20s/115s/40 packets to 19s/116s/38 (and 9.5s at a declared 0.5x rate). Rollback: set LISTEN_REPLAY_PREFIX_MARGIN_SECONDS=0 on listen, or revert. Failure-Class: new
Codex Review SummaryThis 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: d78760cfec
ℹ️ 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".
| # The pacer delivers at exactly ``pace`` into a wall of the same length, so | ||
| # audio equal to the wall leaves only the last packet's write-confirm (~30 | ||
| # ms) as slack; hold a margin back so the prefix lands inside the wall. | ||
| budget = max(0.0, min(REPLAY_PREFIX_SECONDS, wall) - replay_prefix_margin_seconds()) |
There was a problem hiding this comment.
Update the owning replay pipeline contract
This changes the default retained replay prefix from 20 seconds to 19 seconds, but backend/docs/listen_pusher_pipeline.mdx:1449-1454 still says longer rings are cut to the newest 20 seconds and omits the new margin control. That document is the designated owning map and must be updated alongside audio/transcription changes, so its replay guarantees are now contradictory; document the margin, default retention, and rollback setting there.
AGENTS.md reference: backend/AGENTS.md:L159-L159
Useful? React with 👍 / 👎.
A healthy demand handover (demand_switch.py) replays the whole unanswered ring uncut and refused only past the exact 20s wall, so exactly-the-wall capture could still miss the wall at 1x and reject the candidate, bypassing the new margin. Its refusal threshold is now the same wall-minus-margin the failure path holds back; past it the healthy source keeps serving (refuse, never cut). The default 15s hidden dwell still fits. Pinned: 19.0s admitted, 19.5s and 20.0s refused with the source retained.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20da7420bd
ℹ️ 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".
| return _default_on(NONWINDOW_EMITTED_TEXT_ACCOUNTING_ENV) | ||
|
|
||
|
|
||
| REPLAY_PREFIX_MARGIN_ENV = 'LISTEN_REPLAY_PREFIX_MARGIN_SECONDS' |
There was a problem hiding this comment.
Wire the rollback margin into backend-listen deployment
The new variable is presented as the production rollback control, but a repo-wide search finds no LISTEN_REPLAY_PREFIX_MARGIN_SECONDS entry in backend/deploy/runtime_env/_base.yaml, the generated runtime_env.yaml, or either backend-listen Helm values file. Consequently the normal deployment path cannot pass 0 to the listen pods, and a subsequent Helm reconciliation would also discard any manual setting, leaving operators unable to use the documented rollback without reverting the release; add the variable to the runtime-env source and regenerate the deployment artifacts.
AGENTS.md reference: backend/AGENTS.md:L153-L153
Useful? React with 👍 / 👎.
…arrying a permanent backlog (#23147) ## Summary Live audio that arrives while a successor dials and replays its prefix is held in the 26 s live tail (`ReplayTailSocket`). The tail pump drained it at exactly the endpoint rate: `_next_audio_slot` discards every missed slot and `ReplayPacer.send` never armed a slot above 1.0×, so after a near-full prefix (the norm: mean prefix 14–18.5 s, 20–25 s bucket ~1,050/day on 2026-10-21) a leg carried a 15–25 s backlog for the rest of its life, every later pump slip (P32 loop-lag max 745 ms) added to it for good, and the next client burst tripped the tail bound as `send_queue_full` while the vendor socket was healthy and the pod idle. Modulate dies last in 74 % of exhausted sessions because it is the most common recovery successor. This is follow-up B of `omi-workspace data/run-2026-10-13-two-lane-nemotron/local-delivery-deaths-2026-10-22.md` §7; P47's #23108 (prefix margin) is the stopgap, this is the structural fix. `ReplayTailSocket._pump_tail` now asks `ReplayPacer.send` for the catch-up rate (`catchup=True`) while the tail holds more than `TAIL_CATCHUP_FLOOR_SECONDS` (1 s) of audio and returns to the sustained rate below it. The rate is `LISTEN_LIVE_TAIL_CATCHUP_RATE` (default **1.5**; `1` restores today's exact-rate tail; clamp [1, 4], unparsable or out-of-range → default) times the endpoint's declared sustained `ReplayLimits.rate`, capped per successor family: Soniox / Modulate / Deepgram **2.0**, the Parakeet window (no wire) **4.0**, unknown **1.0** (an unidentified endpoint never runs ahead). The replay prefix is never accelerated. Recovery legs' `RecoveryWriterPace` is installed at the same ceiling so the transport can carry the drain; admission still sets the sustained wire rate and the two-packet queue still bounds any burst. The tail bound (26 s), residence (28 s) and the `send_queue_full` overflow death are unchanged. `omi_stt_live_tail_catchup_seconds_total{successor}` counts audio seconds delivered above the sustained rate and stays 0 with the switch off (proof the flag is live). Branch `lane/tail-catchup` into `main`. ## Lane / contract P47b `tail-catchup` (two-lane rollout swarm). This PR is the producer of two draft rows in `swarm/contracts.md`: env `LISTEN_LIVE_TAIL_CATCHUP_RATE` and metric `omi_stt_live_tail_catchup_seconds_total{successor}` (successor ∈ parakeet/modulate/soniox/deepgram/unknown, zero-filled under `recovery_enabled()` like the other replay series). No other shared names, labels or outcome tokens touched. Owner sign-offs: none needed — `replay_delivery.py`, `config/live_stt_replay.py`, `live_metrics.py`, their tests and the operational doc. ## Product invariants affected none ## Design choices (the brief asked for these in the PR) - **Catch-up pacing, not drop-oldest on overflow.** Dropping the oldest tail packet at the 26 s bound would keep the leg alive but turn a death into a silent transcript gap on a healthy socket with no recovery attempt, and it would change what the P34 `send_queue_full` series means (today: producer outran the drain for 26 s straight — a transport that genuinely cannot keep up — which is also a circuit-vote input, the same class as §7 A that needs a ruling). With catch-up the tail no longer drifts toward the bound under the measured conditions (24 s backlog + 3 s burst drains; four 750 ms slips are recovered), so the death path becomes the real signal it was meant to be. Residence expiry at 28 s still meters individual over-age packets as before. Drop-oldest stays available as a follow-up if the series does not fall after the roll. - **Rates.** 1.5× default drains half a second of backlog per second of wall time (24 s → floor in ~46 s). Soniox's docs ask for "real-time or near real-time" input and warn that prolonged bursts may disconnect, so its family ceiling is 2.0; Modulate ("frames can be any size", only per-model concurrency limits, docs fetched 2026-10-22) and Deepgram document no ingest ceiling and get the same conservative 2.0; the Parakeet window has no wire and a 60 s PCM cushion, 4.0. The switch value is clamped to [1, 4] and the ceilings sit inside that clamp (pinned by a test). - **Floor-driven, not time-driven.** Catch-up is decided by the bytes the tail holds, never by elapsed time or missed slots, so contiguous silence arriving as PCM is drained like any other audio and earns no credit, and a stalled-then-resumed transport can close up only the packets the queue already held. ## The 2 s write-confirm bound on initial paid legs (brief item 2) Reviewed; **no change proposed** — there is no evidence it is where healthy legs die. In the 24 h window `omi_stt_replay_queue_high_water` never exceeded 4 packets (≤1: 11,822 of 11,923), and the §3 analysis puts the local deaths on the pacer's own arithmetic (exact-rate drain + discarded slots), not on a socket stall; the simulations here keep `write_wait_seconds=2.0` on the initial-leg case and a 5 s client burst settles in ~8 s without touching it. The one path where 2 s is plausibly tight is §7 C: a Soniox idle reopen writes the whole ≤10 s `_pending` as one packet into a fresh TCP connection, where slow-start can take several RTTs (~35k reopens/day). That is a different fix (split the first write or warm the connection), not a wider confirm bound, which would only keep a stalled socket alive longer per packet and delay failover. A bounded increase would need `delivery_expired` counts on initial legs attributable to a confirm stall with an empty queue (the P34 `queue_age` logs cover raw-socket deaths), and that evidence is not in hand. ## Verification Layer: backend unit tests on the shared virtual clock, real `SafeModulateSocket` / `SafeSonioxSocket` adapters over a fake transport, no live vendor. All run through `bin/omi-heavy run -- … backend/test.sh` with `BACKEND_UNIT_TEST_FILE_LIST`, `nice -n 19`, `BACKEND_PYTEST_WORKERS=4`, on this branch rebased onto `d90643dc2b`: - New `tests/unit/test_live_tail_catchup.py` (43 tests). Each scenario drives the real Modulate adapter with a real-time client that captures on its own cadence, so a stalled pump finds every packet it missed; every captured packet carries a distinct marker and the wire is checked byte for byte against the capture (ordered, no gap, no duplicate), and no 2–4 s window of writes exceeds the ceiling plus the two-packet queue allowance: - **near-full prefix + continuous live audio**: 24 s held through dial + prefix drains to within a packet of the 1 s floor by ~47 s against real-time input, the oldest packet never ages past 26 s, the backlog only falls, queue high-water ≤ 2, and a later 3 s client burst is absorbed; with `LISTEN_LIVE_TAIL_CATCHUP_RATE=1` the same leg carries ≥23 s for 60 s and the 3 s burst dies `send_queue_full` with the vendor socket alive. - **client burst on an initial leg** (no writer pace, 2 s confirm, the receiver's real 30 ms flushes): a 5 s frame settles under the floor in ~8 s; at the exact rate it is carried for the rest of the leg. - **pump slips**: four 750 ms stalls of the pump coroutine (P32 maximum) are recovered, backlog never above floor + one slip; at the exact rate all four are permanent (≥2.76 s). - window successor at `3`: eighteen 0.5 s packets go at 3×, the nineteenth sees exactly the floor and the rest go at 1×; the counter reads exactly 9 s. - the prefix replay never uses the catch-up rate; writer pace installed at the family ceiling for Modulate/Soniox and left at the sustained rate for an unidentified transport; rate shapes per family / env / declared sustained rate; env parsing (default, `1`, clamp, `inf`, `nan`, garbage). - Existing pins updated: `test_live_recovery_matrix.py` (writer pause/resume now parametrised over the switch on/off: the queued packets may close up at the ceiling, cadence exactly 1× with it off) and `test_live_replay_provider_pairs.py` (the slow-consumer full-ring case: prefix admissions still ≤1× + one packet, cumulative delivery never past the ceiling + one packet, and the last live packet lands inside ~15 s instead of the ~19 s lag the exact-rate tail kept). 103 passed across the three files. - All 25 unit files importing `live_stt_replay`, `replay_delivery`, `resilient_stream`, `live_metrics` or the listen receiver pass: 1,112 passed, 0 failed (including P34's `test_soniox_local_delivery_deaths.py`, `test_parakeet_window_live.py` 200, `test_live_recovery_canary_regressions.py`, `test_live_recovery_pacing.py`, `test_replay_prefix_wall_margin.py`, `test_live_demand_switch.py`). NOT run: the full backend suite (CI), staging, or any live listen pod. ## Rollback Set `LISTEN_LIVE_TAIL_CATCHUP_RATE=1` on the listen deployment to restore the exact-rate tail without a code deploy (read per leg at pacer construction, so new legs pick it up), or revert this PR. Nothing persisted; one new counter, no label change on existing series. ## Judge it by (after the next listen roll) - `omi_fallback_total{component="stt_live_session", reason="send_queue_full"}` by `from_mode` should fall toward zero (the P34 series §7 B names as the judge). - `omi_stt_live_tail_catchup_seconds_total{successor}` rising proves the flag is live; it stays flat if the switch is `1`. - `omi_listen_demand_exhausted_sessions_total` with Modulate dying last should drop. ## Failure class Declaring `new`: **FC-drain-rate-equals-arrival-rate** — a bounded buffer fed at a fixed rate and drained at exactly that rate, with every missed drain slot discarded, has no restoring force: its occupancy can only grow, so every scheduler slip and every arrival burst becomes permanent lag and a healthy consumer eventually hits the bound and is rejected as a local capacity failure. Root cause: `ReplayPacer.send` armed every slot at `self.rate` and `_next_audio_slot` rebases past a missed slot, so the live tail could never run ahead of the client. Durable guard: the drain has an explicit bounded catch-up rate that engages only while the held backlog exceeds an explicit floor (`TAIL_CATCHUP_FLOOR_SECONDS`), the bound itself is unchanged, and the virtual-clock simulation pins both directions (switch on: backlog returns to the floor with no death, no reordering, no duplication; switch off: the permanent lag and the `send_queue_full` death). Why not a shared primitive: the pacer and the tail are already the shared primitives (`ReplayPacer`, `ReplayTailSocket`); the missing piece was a second rate on the one pump that drains a held backlog, which now lives there. Failure-Class: new <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/23147?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/23147?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23147&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. -->
Peak re-check 2026-10-22 08-16Z (incl. 14-16Z peak, 386-1,021 accepted/15m) after #23108/#23147: ratio p50 0.000, p90 0.0033, max 0.0047. Broken state (pre-#23147) ran p50 0.039, max 0.060. 0.02 is 4x above today's max and half the broken median, so a pacing regression pages sooner. Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
A full replay prefix was exactly
REPLAY_PREFIX_SECONDS(20 s) of audio delivered at exactly the endpoint rate (1.0×) into a wall of the same length, so the budget was spent by construction: the last 16 KiB packet is admitted at 19.968 s and has to be written and observed by the 10 ms poll before 20.000 s. Any late write confirm on that packet — or one rebased slot earlier — rejected the successor asreplay_send_stalled(pre-P34:capacity_full) while the pump slept in its own pacer and the listen pod sat idle. On 2026-10-21 about 1,050 prefixes/day landed in theomi_stt_replay_wall_seconds20–25 s bucket (7–15 % of near-full prefixes per provider pair, includingsuccessor=parakeetwhere no network write exists), and the mean prefix was 14–18.5 s, so near-full prefixes are the norm. Replay queue high-water never exceeded 4 packets, so this was never the 2000-packet queue or a stalled transport.bounded_snapshotnow retains(wall − margin) × rateseconds of audio, margin fromLISTEN_REPLAY_PREFIX_MARGIN_SECONDS(default 1.0;0restores the exact-wall prefix). The wall itself is unchanged, so the margin is pure slack, and the adopted live tail starts 1 s further from its 26 s bound. The cut comes off the oldest unanswered second and is metered inomi_stt_replay_skipped_seconds_totallike any budget cut. Evidence and the wider local-delivery-death analysis:omi-workspace data/run-2026-10-13-two-lane-nemotron/local-delivery-deaths-2026-10-22.md(P47, labeldelivery-deaths).Branch
lane/delivery-deathsintomain.Lane / contract
P47
delivery-deaths(two-lane rollout swarm); no shared contract rows touched (no new metric names, labels, or outcome tokens). Owner sign-offs: none needed — onlyreplay_delivery.py,config/live_stt_replay.py, their tests and the operational doc.Product invariants affected
none
Verification
Layer: backend unit tests, virtual clock, no live vendor. All run through
bin/omi-heavy run -- … backend/test.shwithBACKEND_UNIT_TEST_FILE_LIST,nice -n 19:tests/unit/test_replay_prefix_wall_margin.py(27 tests): the realSafeModulateSocketwith recovery writer pacing over a slow-ack fake transport pumps a full-ring prefix throughreplay_chunks. Margin 0: a 50 ms final write confirm rejects the prefix withreplay_send_stalled/replay wall budget exhausted(40 packets admitted, 39 written, queue high-water ≤ 2); a 10 ms one survives. Default margin: a final confirm up to ~0.9 s lands inside the wall, a 1.5 s one is still rejected, and a sustained sub-realtime transport (0.9 s per 0.512 s packet) is still rejected.bounded_snapshotshapes (wall, rate, margin) and env parsing (default,0, clamp, garbage) are pinned.test_live_recovery_matrix.py(97 passed),test_live_replay_provider_pairs.py(31),test_live_stt_resilient_stream.py(28).live_stt_replay,replay_delivery,resilient_stream,bounded_snapshotorreplay_chunkspass (including P34'stest_soniox_local_delivery_deaths.py,test_parakeet_window_live.py200,test_live_recovery_canary_regressions.py,test_live_recovery_pacing.py).routers/listen/demand_switch.py) replays the whole unanswered ring uncut and refused only past the exact 20 s wall, bypassing the margin. Its refusal threshold now uses the same wall-minus-margin; past it the healthy source keeps serving (refuse, never cut).test_live_demand_switch.py(20 passed): 19.0 s admitted, 19.5 s and 20.0 s refused with the source retained and not dead; the default 15 s hidden dwell still fits.NOT run: the full backend suite (the selector falls back to all 2,126 files for a
config/change; CI runs it), staging, or any live listen pod.Rollback
Set
LISTEN_REPLAY_PREFIX_MARGIN_SECONDS=0on the listen deployment to restore the exact-wall prefix without a code deploy, or revert this PR. Nothing persisted; no schema, metric or label change.Failure class
Declaring
new: FC-wall-budget-equals-paced-work-duration — a fixed wall budget that bounds work delivered at a fixed pace must exceed that work's duration at that pace; sizing the work to the whole budget leaves only scheduler/write-confirm jitter as slack, so a healthy, keeping-up delivery is rejected as a local capacity failure. Root cause:bounded_snapshotkeptmin(REPLAY_PREFIX_SECONDS, wall) × rateseconds whilereplay_chunksgave itmin(wall, REPLAY_PREFIX_SECONDS)of wall, and_next_audio_slotnever earns catch-up credit, so the last packet's slot sits 32 ms before the wall. Durable guard: the margin is an explicit config primitive and the knife edge is pinned by the virtual-clock simulation (exact wall must fail on a 50 ms confirm; margined must pass), so the budget cannot silently return to equality. Why not a shared primitive: the pacer and the wall are already shared (ReplayPacer,replay_chunks); the missing piece was the sizing rule, which now lives in the one function that sizes the prefix.Failure-Class: new