Skip to content

test(watch): replay audio only as long as the settled state needs - #9781

Merged
kixelated merged 3 commits into
mainfrom
quest/m0/test-flakes-5/watch-replay-under-load
Nov 27, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m0/test-flakes-5/watch-replay-under-load

Conversation

@kixelated

@kixelated kixelated commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/test-flakes-5/watch-replay-under-load.md.

Problem

js/watch/src/audio/replay.test.ts's minute-long replays failed at bun's 5 s timeout in a loaded just check (seen on moq-dev/moq#9712). A replay is CPU bound at about 5 ms per simulated second (linear in length, measured from 7.5 s to 240 s), so a 60 s replay costs about 0.3 s alone and 0.5 to 0.6 s for tests that run two. A loaded host that slows the process about tenfold pushes them past 5 s.

Most of that time was spent after the state they grade had settled. Per-second traces of each scenario show the estimator's prior spent within 6 s (ten 500 ms folds) and the playhead on the clock by 8 s, then identical through 60 s; the tests graded from 30 s.

Approach

Each replay now runs only as long as its graded steady state needs, grading the same regime:

  • Shared clock at auto, fixed 40 ms target with and without the stretch, settled target sizing, and the sparse codec term: 15 s, graded from 10 s (STEADY, SETTLED). The zero-stretch trim bound is now relative: over a third of the audio (5664 ms of 15 s here; 22764 of 60 s before).
  • Codec term change: 10 s per duration instead of 30 s.
  • 1% fast publisher: 20 s with a 100 ms lookahead instead of 60 s with 500 ms. The clock only starts outrunning audio once delay plus lookahead is full, which took 53 s at 500 ms (so only the last 6 s of the minute exercised the splices) and takes 13 s at 100 ms. Lag in the graded window: [-3.3, 13.1] ms, against [-4.0, 11.6] in the old one.
  • Stalled utterance: 20 s of speech held 2.5 s (about 1 s behind, 10 s to catch up) instead of 40 s held 3.5 s.
  • Stall catch-up: 15 s, graded from 12 s (caught up by 10 s).
  • The run-dry count replayed the same deterministic trace twice; it now replays it once.

No assertion is looser: every bound is unchanged except the zero-stretch trim, which scales with the shorter trace.

Failure rate

.tmp-only harness: replay.test.ts run 10 times in parallel, each under systemd-run --user --scope -p CPUQuota=<q> on a 32-core host already at load ~30.

Quota main (eca170c3a6) This PR
25% 10/10 runs fail: both quest-named tests, the 1% fast clock, and the utterance in every run 0/10
15% (not run; already 10/10 at 25%) 0/10
10% 10/10 fail, 13 to 15 tests each 10/10 fail, only the first four 10 s tests (cold JIT), all minute-long ones pass

Slowest test alone: 0.58 s before, 0.26 s after. File total: 4.2 s before, 2.8 s after.

Validation

  • The quota harness above, before and after.
  • bun test src/ in js/watch: 662 pass.
  • just check and just ci pass.

Impact

  • Public API: none. Wire: none. Test-only change.

Alternatives

  • Make the replay cheaper per simulated second. Profiled: per-quantum cost (~5 us, 22500 quanta a minute) and per-frame cost (~45 us) are both spread across the real consumer, track, and ring, with no single hot spot in the test. Not worth it for a test-only gain; the one real library finding is in Follow-ups.
  • Raise the timeout: ruled out by the epic.

Caused by

Follow-ups

  • quest/m3/audit-perf.md (edited, "Check first"): js/hang's container Consumer visits every buffered group on each decoded frame (#look, #updateBuffered, #checkMaxDelay), O(buffered groups) per frame, about a third of the CPU of the stalled-utterance replay at a 60 s lookahead. No open decisions.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown (arm A)

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: d168707
  • Base: origin/main at 9d3f432
  • Risk: low, Nothing a consumer or peer relies on changes: the diff touches only the test file js/watch/src/audio/replay.test.ts (shorter replays and renamed constants), a deleted quest plan, and a quest note in quest/m3/audit-perf.md. The worst outcome is a weakened or flaky test that a contributor meets first in CI, and a plain revert fully undoes it.
  • Classified: low by Claude Code, claude-haiku-5-5, low effort, session dca3c952-2121-4d4b-94f6-7f8dd10f3004
  • Risk file: bb7b1c0de60b
  • Local review: none, since the head is low risk

kixelated and others added 3 commits November 27, 2026 08:46
The minute-long audio replays spent most of their CPU after the estimator and
the playhead had settled (by 8 s), so a loaded host stretched them past bun's
5 s timeout. Run them 15 to 20 s instead, grading the same steady state, and
replay the run-dry trace once instead of twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…group scan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Audio replay tests finish within their timeout under load test(watch): replay audio only as long as the settled state needs Nov 27, 2026
@kixelated
kixelated marked this pull request as ready for review November 27, 2026 18:21
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Replay timing tests now use shorter simulated traces and observation windows, shared timing constants, and updated assertions. The changes cover auto-delay, flush, missing-packet duration, packet-duration changes, buffered stall recovery, and publisher-clock behavior. The prior replay-under-load investigation note was removed. The performance audit now records a profiled cost in js/hang’s container Consumer and asks whether rs/moq-mux has the same behavior.

Severity of issue fixed: Low

Merge Risk: Minimal · up to d1687

This change shortens audio replay tests and updates internal performance notes. It has no effect on production behavior and carries no identified merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the replay tests in js/watch/src/audio/replay.test.ts are shortened to the length their graded steady state needs. The raw summary confirms shorter traces and adjusted…
Description check Passed The description is closely related to the changeset. It explains the problem (minute-long replays hitting Bun's 5 s timeout), the approach (shorter replays that grade the same steady state, with uncha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the replay tests in js/watch/src/audio/replay.test.ts are shortened to the length their graded steady state needs. The raw summary confirms shorter traces and adjusted observation windows, and the objectives describe the same shortening. The title is specific and follows the conventional type(scope) form.

Full details: Description check

Explanation

The description is closely related to the changeset. It explains the problem (minute-long replays hitting Bun's 5 s timeout), the approach (shorter replays that grade the same steady state, with unchanged bounds except the zero-stretch trim), the failure-rate measurements, validation, and the deleted quest plan and audit-perf note. It matches the raw summary and objectives.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4639c857-c649-4283-bf5a-ab8af2da2b9f
Commits

Reviewing files that changed from the base of the PR and between eca170c and d168707.

Files selected for processing: 3

  • js/watch/src/audio/replay.test.ts
  • quest/m0/test-flakes-5/watch-replay-under-load.md
  • quest/m3/audit-perf.md
Files with no reviewable changes: 1

  • quest/m0/test-flakes-5/watch-replay-under-load.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@kixelated
kixelated added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit fcfa5b1 Nov 27, 2026
7 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-5/watch-replay-under-load branch November 27, 2026 20:12
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