Skip to content

fix(publish): the gesture capture test runs on a manual clock - #9466

Merged
kixelated merged 1 commit into
mainfrom
fix/publish-gesture-capture-clock
Nov 23, 2026
Merged

kixelated merged 1 commit into
mainfrom
fix/publish-gesture-capture-clock

Conversation

@kixelated

@kixelated kixelated commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

captures once a gesture resumes a context built before one (js/publish/src/audio/capture.test.ts) read the host clocks. When the OS preempted the test between the capture handler's media-clock read and its Date.now() read, the frame was stamped early by the length of the pause and failed the >= before - quantum - 1ms bound. It failed test js in the merge queue for moq-dev/moq#9349 (run), a PR that doesn't touch the publish package. The flake is on main.

Approach

Run the test on a Manual clock, as its neighbours in the file already do. Pausing the clock for 5 s before the click now shows the audio is stamped when it was rendered, not when the source appeared. The stamp is exact, so the assertion drops its millisecond of slack and compares against the render time minus one quantum.

Impact

Test only. No public API or wire change.

Validation

  • Reproduced on main: bun test src/audio/capture.test.ts -t "gesture resumes" --rerun-each 3000 with stress-ng --cpu 3×nproc failed 4 of 3000 runs (Expected: >= …, Received: … at line 399, the same failure as the queue). With no load, 300 of 300 passed.
  • With this change, the same stress run passes 3000 of 3000, and the whole file passes.
  • Mutation check: adding 1 ms to the capture's render delay in capture.ts fails the new assertion (Expected: 4997333.33, Received: 4996333.33). The old bound allowed that error.

Caused by

  • moq-dev/moq#9188 - asserted the render-time stamp against the host clocks with a fixed 1 ms margin (found by queue)

Alternatives

  • Reading the wall clock before the monotonic one in capture.ts would only flip the sign of a preemption's error, since two clocks can't be read atomically. The production stamp's error is one preemption pause on the first quantum's anchor, which drift steering absorbs, so this PR leaves it alone.

Models

Size: XS
Implementer: Claude Code, claude-opus-5-5, unknown effort

Review

Rewritten by quest review after each round.

  • Head: 520aba1

  • Base: origin/main at a843d23

  • Risk: low, The only change is to one test file, js/publish/src/audio/capture.test.ts, which switches a test to a manual clock; nothing a consumer or peer relies on reads it, and a revert fully undoes it.

  • Classified: low by Claude Code, claude-haiku-5-5, low effort, session c25e9fd7-7f2b-4f5b-9820-4ac8283c3a73

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a20822-1938-7ab1-8204-27cce1b4bb4b, round 1

  • Score: 10/10, Ready to land based on source review: the test uses deterministic time and precisely verifies the capture timestamp; tests were not run as instructed.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

The test read the host clocks, so a preemption between the capture
handler's monotonic and wall reads stamped the frame early by the pause
and tripped the assertion under CI load. On a manual clock the stamp is
exact, so the assertion drops its millisecond of slack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 23, 2026 11:20

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound. The flaky test moves to a Manual clock, as its neighbours already do, so no host pause can shift the stamp.

Reviewed changes

  • Manual clock: captures once a gesture resumes a context built before one installs a Manual clock and restores it in finally, matching the other tests in capture.test.ts (lines 704, 714, 822).
  • Exact assertion: the 1 ms slack is gone. The test compares the frame timestamp to rendered - quantum with toBeCloseTo, and a 5 s clock.jump before the gesture still shows the stamp is the render time.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The gesture-resume regression test now uses a manual clock, advances it by five seconds before simulating the gesture, and checks the first audio timestamp against media time immediately before rendering. Clock cleanup runs in a finally block.

Merge Risk: Minimal · up to 520ab

This change makes a flaky audio capture test deterministic and does not touch production code. It is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the test file's switch to a manual clock and the publish package, which matches the changeset: the gesture-resume test in capture.test.ts now runs on a Manual clock. The title uses the…
Description check Passed The description explains the flaky test, its cause (host clock reads and OS preemption), the switch to a Manual clock, the validation runs, and the scope (test only). It matches the changeset closely.
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 test file's switch to a manual clock and the publish package, which matches the changeset: the gesture-resume test in capture.test.ts now runs on a Manual clock. The title uses the 'fix' prefix for a flaky-test repair, and it is specific enough for a teammate scanning history.

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: 27329b41-52ee-471f-8efc-42b0f8d9dfae
Commits

Reviewing files that changed from the base of the PR and between a843d23 and 520aba1.

Files selected for processing: 1

  • js/publish/src/audio/capture.test.ts

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

@kixelated
kixelated added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 9a06a1c Nov 23, 2026
9 checks passed
@kixelated
kixelated deleted the fix/publish-gesture-capture-clock branch November 23, 2026 11:49
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