Skip to content

test(stt): keep a gate replay sample in the fast lane, full sweep in slow - #20344

Merged
Git-on-my-level merged 2 commits into
mainfrom
fix/live-gate-replay-fast-lane
Oct 2, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
fix/live-gate-replay-fast-lane

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

What

tests/unit/test_live_gate_replay.py keeps a 10-seed sample of its two seeded sweeps in the fast unit lane and marks the remaining seeds slow; the file is added to tests/slow_guardrail_manifest.txt so the full sweep still runs in the slow guardrail lane.

Why

On CI the file takes ~298 s (722 passed in 297.86s), about half of unit shard 2's 600 s wall budget. Shard 2 now fails on time alone — 627 s and 614 s on two attempts for #20340, a config-only PR — with every test passing. The sweep is 200 seeds × 3 rates × 20,000 gate transitions (plus 100 day-long trial simulations).

After this change (local): fast lane 62 tests in 3.9 s; slow lane 660 tests in 51 s. The module-level false-bench bounds (0, <= 4, <= 32 per 4M sessions) are upper bounds, so they hold for the 10-seed sample and are still enforced over the remaining 190 seeds in the slow lane. No production code changes.

Product invariants affected

None — test-only change.

Failure-Class: none

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 2 commits October 2, 2026 19:54
…slow

The file took ~298s on CI, half of unit shard 2's 600s wall budget, so the
shard failed on time with every test passing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@cubic-dev-ai cubic-dev-ai 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.

2 issues found across 2 files

Confidence score: 3/5

  • test_live_gate_replay.py adds about five minutes to the backend unit guardrails job, which was previously around two minutes. Reduce the sweep cost before it slows every full-CI run.
  • test_live_gate_replay.py checks the fast and slow seeds separately, so both subsets can pass even when their combined false-bench count exceeds the original 200-seed limit. Preserve an aggregate check across both subsets.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/tests/unit/test_live_gate_replay.py">

<violation number="1" location="backend/tests/unit/test_live_gate_replay.py:33">
P2: This sweep will likely consume several minutes of the backend-unit-guardrails job on every full-CI run, a lane previously in the ~2-minute range. The PR's own CI measurement for the full file is ~298 s, and the 660-test slow subset is ~91% of that work, so on CI the slow lane should expect roughly 4-5 minutes from this file alone against the job's 10-minute `timeout-minutes` (backend-unit-tests.yml). Unlike the unit shards, this job has no step-level wall-budget check, so the wall-time failure mode being fixed in shard 2 is relocated to the guardrails job, which now sits closer to its timeout with every manifest growth. Validate the post-PR guardrails job wall time on CI, and consider running the heavy file with `-n auto` (it currently runs single-process alongside the static scans) or splitting it out so a seed-count change cannot silently push the lane over budget.</violation>

<violation number="2" location="backend/tests/unit/test_live_gate_replay.py:37">
P2: The module-scoped bounds now apply separately to the 10 fast seeds and 190 slow seeds, so each subset can pass while their combined false-bench count exceeds the original 200-seed limit. Preserve one aggregate check across all 200 seeds, or assign partition-specific caps whose sum stays within the original bounds.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


# The fast lane keeps a 10-seed sample; the full 200-seed sweep (4M sessions per
# rate, ~5 minutes on a CI runner) runs in the slow guardrail lane.
_BASELINE_SEEDS = [seed if seed < 10 else pytest.param(seed, marks=pytest.mark.slow) for seed in range(200)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This sweep will likely consume several minutes of the backend-unit-guardrails job on every full-CI run, a lane previously in the ~2-minute range. The PR's own CI measurement for the full file is ~298 s, and the 660-test slow subset is ~91% of that work, so on CI the slow lane should expect roughly 4-5 minutes from this file alone against the job's 10-minute timeout-minutes (backend-unit-tests.yml). Unlike the unit shards, this job has no step-level wall-budget check, so the wall-time failure mode being fixed in shard 2 is relocated to the guardrails job, which now sits closer to its timeout with every manifest growth. Validate the post-PR guardrails job wall time on CI, and consider running the heavy file with -n auto (it currently runs single-process alongside the static scans) or splitting it out so a seed-count change cannot silently push the lane over budget.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_live_gate_replay.py, line 33:

<comment>This sweep will likely consume several minutes of the backend-unit-guardrails job on every full-CI run, a lane previously in the ~2-minute range. The PR's own CI measurement for the full file is ~298 s, and the 660-test slow subset is ~91% of that work, so on CI the slow lane should expect roughly 4-5 minutes from this file alone against the job's 10-minute `timeout-minutes` (backend-unit-tests.yml). Unlike the unit shards, this job has no step-level wall-budget check, so the wall-time failure mode being fixed in shard 2 is relocated to the guardrails job, which now sits closer to its timeout with every manifest growth. Validate the post-PR guardrails job wall time on CI, and consider running the heavy file with `-n auto` (it currently runs single-process alongside the static scans) or splitting it out so a seed-count change cannot silently push the lane over budget.</comment>

<file context>
@@ -28,8 +28,13 @@ def baseline_counts():
 
+# The fast lane keeps a 10-seed sample; the full 200-seed sweep (4M sessions per
+# rate, ~5 minutes on a CI runner) runs in the slow guardrail lane.
+_BASELINE_SEEDS = [seed if seed < 10 else pytest.param(seed, marks=pytest.mark.slow) for seed in range(200)]
+
+
</file context>


@pytest.mark.parametrize('rate', [0.03, 0.05, 0.075])
@pytest.mark.parametrize('seed', range(200))
@pytest.mark.parametrize('seed', _BASELINE_SEEDS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The module-scoped bounds now apply separately to the 10 fast seeds and 190 slow seeds, so each subset can pass while their combined false-bench count exceeds the original 200-seed limit. Preserve one aggregate check across all 200 seeds, or assign partition-specific caps whose sum stays within the original bounds.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_live_gate_replay.py, line 37:

<comment>The module-scoped bounds now apply separately to the 10 fast seeds and 190 slow seeds, so each subset can pass while their combined false-bench count exceeds the original 200-seed limit. Preserve one aggregate check across all 200 seeds, or assign partition-specific caps whose sum stays within the original bounds.</comment>

<file context>
@@ -28,8 +28,13 @@ def baseline_counts():
+
 @pytest.mark.parametrize('rate', [0.03, 0.05, 0.075])
[email protected]('seed', range(200))
[email protected]('seed', _BASELINE_SEEDS)
 def test_twenty_thousand_session_baseline(rate, seed, baseline_counts):
     rng, state = random.Random(seed), GateState()
</file context>

@Git-on-my-level
Git-on-my-level merged commit 001020f into main Oct 2, 2026
64 of 66 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/live-gate-replay-fast-lane branch October 2, 2026 13:37
Git-on-my-level added a commit that referenced this pull request Oct 2, 2026
Provider health was inferred from socket liveness and teardown
independently of the serving decision. That both censored early Modulate
deaths and invented Soniox failures during client churn. This change
makes a leg's exactly-once terminal settlement emit both the existing
fallback event and router observation, with the original bounded cause
frozen before transport cleanup. Liveness getters are read-only;
accepted deaths need no VAD minimum; terminal-provider exhaustion is
visible too.

`cost-v6` gives each hashed user at most three classified votes per
target/scope/five-minute Redis-time window, enforced by CAS with bounded
state. Raw observations remain uncapped for emission accounting. Healthy
windows have 2,048 ordinary fingerprints plus an eight-distinct-user
outage reserve that resets on every classified success; eight new
failures still bench after saturation without failure-only CUSUM
sampling. Healthy Redis keys expire after 900 idle seconds;
benches/trials persist so expiry cannot bypass staged recovery.
Independent chain-opened / terminal-settled / transport-open lifecycle
metrics and honestly named emission-acknowledgement/error/vote counters
and an intent-to-treat router-canary transcript SLI support the
runbook's 60–120 minute shadow qualification and 5→25→100 ramp. The gate
remains 8%; reproducible synthetic calibration reports zero false
benches in each 400,000-session healthy-floor scenario and p95 detection
at 48/21/8 sessions for 40%/60%/100% failures.

Production remains `STT_ROUTING_MODE=shadow`,
`STT_ROUTING_ON_PERCENT=0`. Deliberate serving changes: configured
fallback order becomes Parakeet window → Soniox → Modulate → Deepgram;
Soniox timing/configuration, local VAD and other censored input causes
no longer accumulate provider circuit failures at connect or terminal
settlement; client teardown transport errors cannot start recovery or
open provider circuits; local queue/loop/input failures retain
non-provider causes; an active router cannot reappend a
registry-withdrawn default endpoint as a legacy tail. No-text remains
censored and diagnostic; the existing transcript-success alert remains
the detector, with no new silent-stream rescue.

#20332 merged while this lane was in progress. This branch merges that
main revision and supersedes its parallel receipt writers, retaining and
extending its real parser/receiver tests and preserving the new
`soniox_request_timeout` label. No merge or deployment is performed by
this lane. Merged origin/main again at 81a51d0 after #20340 landed.
Its Parakeet allocation/capacity values are preserved exactly at 100/16;
#20344 slow marks remain intact.

## Validation

- Real `LiveLegSocket` + provider parser + receiver tests reconcile 120
accepted deaths, before-audio/subsecond/no-VAD paths, typed terminal
causes, connect rejection, exhaustion, cancellation, and client
teardown.
- Fleet CAS tests cover 46 reconnects across pods, concurrent budget
admission, bounded fingerprint storage and generation fencing.
- Initial STT/provider/runtime regression run before the final review:
**2,268 tests passed across 50 isolated files**, with
`BACKEND_FAST_UNIT_FAIL_SECONDS=1.0`; two real listen-runtime parity
tests also passed under the same guard with an external `--basetemp`
(their capture validator intentionally rejects checkout-local roots).
Type checking: zero errors. `make preflight`: all 38 selected checks
passed with this PR body; normal push hooks passed.
- Test command: `cd backend && BACKEND_UNIT_TEST_FILE_LIST=<selected
file list> BACKEND_FAST_UNIT_FAIL_SECONDS=1.0 BACKEND_PYTEST_WORKERS=3
TMPDIR=$PWD/../.pytest-tmp bash test.sh`. Focused real-object cases also
used `.venv/bin/python -m pytest -q -p no:cacheprovider <files>
--durations=8`.
- The separate slow lane also passed all 668 calibration tests and both
files are registered in the existing slow-guardrail CI manifest; main's
slow marks are retained; the fast baseline sample uses 20k sessions per
rate and the full separate calibration retains 400k per scenario. Full
realistic-floor calibration was run separately. Exact qualification
PromQL and canary/abort conditions:
`backend/docs/runbooks/live-stt-routing.md`.

- Synthetic calibration: `cd backend && .venv/bin/python
scripts/stt/calibrate_live_gate.py`; no user transcript/audio access or
production-state writes. Production acceptance is pending coordinator
deployment/shadow checks.

## Product invariants affected

- INV-MEM-4: generated runtime env is touched only for the live STT
order; canonical memory promotion authority and its flags are unchanged.

Failure-Class: FC-decoded-outcome-discarded-before-canonical-record

Line-Count-Exception: backend/routers/listen/receiver.py | 1835 -> 1844
| Wire the shared settlement and teardown fence at existing
serving-owner boundaries; extracting unrelated receiver/provider logic
would widen this incident fix.

Line-Count-Exception: backend/utils/stt/streaming.py | 2186 -> 2188 |
Wire the shared settlement and teardown fence at existing serving-owner
boundaries; extracting unrelated receiver/provider logic would widen
this incident fix.


## Review decisions

The 30-second pending-hop bound is intentional: `degraded` means
recovery was unproven by the deadline. Late successor text remains
visible in leg/session and router-canary transcript SLIs; it does not
emit a second fallback or change the source provider-failure vote.
Waiting indefinitely for successor speech would again make outage
detection depend on user audio.

Review corrections include invalid-percent telemetry fail-open, a
teardown recheck after awaited recovery, settlement on engine-mismatch
recursion and cancelled replacement retries, aligned prod
ConfigMap/inline order, and explicit censored local circuit causes. The
long calibration files are now registered in the existing slow-guardrail
CI manifest, while the fast lane stays below its per-test CPU budget.


## Serving behaviour changes

| Location (under backend/) | Before → after; intent and accepted risk |
| --- | --- |
| charts/backend-listen/prod_omi_backend_listen_values.yaml:457;
deploy/runtime_env/prod.overlay.yaml:39,295; regenerated
deploy/runtime_env.yaml | Parakeet → Modulate → Soniox becomes Parakeet
→ Soniox → Modulate. Sessions unable to use Parakeet now start on
Soniox: cost up, reliability up. Modulate remains in the static chain
and registry, with the separate new-endpoint ramp supported. |
| routers/listen/receiver.py:1741; utils/stt/live_session.py:843;
utils/stt/live_failure.py:550; utils/stt/resilient_stream.py:266 | Owner
teardown fences later transport symptoms before tail sends. A published
death already latched before that fence is now settled as a failure even
without a monitor claim; a death beginning during/after teardown is
censored. Connected streaming deaths still invoke recovery. |
| utils/stt/live_outcome.py:61; utils/stt/live_session.py:529 | Accepted
provider deaths no longer require >=1s VAD speech; actual text counts
success without VAD. This removes early-death undercounting; normal
no-text stays censored. #20332 independently merged that early-death
policy while this PR was in progress. |
| utils/stt/live_session.py:854; utils/stt/live_failure.py:170,255 |
Health settles at the serving owner, not a liveness read or transport
close. Close of an already-claimed failed leg defers settlement to its
hop; a 30s timer bounds that deferral and reports degraded if recovery
is unproven. Terminal-provider exhaustion now emits a fallback. These
change telemetry, not audio/transport actions. |
| utils/stt/live_chain.py:372; utils/stt/live_failure.py:108 | Censored
connect reasons release admission without accumulating circuit failures.
Terminal transport reasons shrink to connection_lost/send_failed,
removing vad_failed and soniox_request_timeout; separate typed
account/serve-error protection stays. Repeated Soniox 408 connect
rejections can therefore be retried across sessions: accepted because
408 alone cannot distinguish outage from input timing, while the same
connect still falls through. Reason counters and latency/transcript SLIs
support manual withdrawal if an outage is demonstrated. |
| utils/stt/soniox.py:212,238; utils/stt/streaming.py:1323,1456 | Soniox
publishes cause before death. Queue-full/loop misuse/invalid input
retain bounded censored causes instead of connection_lost; accepted-dead
connects retain their normalized cause instead of collapsing to
provider_5xx. Same-session fallback remains. |
| utils/stt/live_chain.py:161 | Active selection cannot reappend a
registry-withdrawn/excluded default endpoint as a legacy tail;
configured-order error fail-open remains. Shadow/0 does not activate
this selection branch. |

## Luna final review corrections

- Saturated-window + eight new-failure regression; existing UID budgets
never refill. Normal capacity exceeds 10x the stated 1,800
sessions/hour; any saturation still stops rollout because normal
brownout evidence is sampled; the independent outage reserve resets on
successes and cannot be filled by one reconnecting user.
- Death-before-teardown now counts, including the real receive_data
path; errors arising during its final flush remain censored.
- `omi_stt_cost_routing_emission_ack_errors_total` replaces the
misleading reconciliation name. It does not prove classification,
settlement coverage or Redis persistence.
- Independent `omi_stt_managed_legs_opened_total -
omi_stt_managed_legs_settled_total - omi_stt_managed_legs_open` is
exported by target/pod. A regression deliberately suppresses settlement
and verifies that this gap grows while acknowledgement errors need not
change. Go/no-go rejects a nonzero gap persisting two minutes (30s
deferred settlement is allowed).
- Healthy fairness keys get a 900s TTL. Benches and recovery trials
deliberately do not expire into healthy state; they contain no
healthy-window fingerprint list.


Final review-round validation: **1,614 fast tests across 50 isolated
files passed with the stricter 0.30s CPU guard**, followed by **139
focused tests** covering the final overflow/CAS and lifecycle-oracle
changes. Re-ran the six 400,000-session calibration scenarios: zero
false benches in each; detection median/p95 remains 20/48, 13/21, 8/8 at
40/60/100%. The earlier 2,268 count predates main's additional slow
split; it is not the new fast-lane count. Generated runtime env
regeneration and `--check` pass. PR metadata preflight passed all 38
checks.

Final type check: zero errors. The final main merge includes #20340,
with 100% allocation / cap 16 retained and runtime env regenerated and
checked.
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