Repository navigation
fix(audio): use monotonic time for the JS queue - #1597
Merged
Lorenzobattistela merged 1 commit intoOct 16, 2026
Merged
Conversation
Lorenzobattistela
approved these changes
Oct 16, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and fix
The silent JS Audio ring measures elapsed time with
Date.now(). A one-second wall-clock rollback at 48 kHz makes an empty write report 48,000 queued frames, exceeding the 4,096-frame ring and causing later writes to be dropped. A forward jump can drain queued frames prematurely.Use
performance.now()for the existing open/write timestamps, matching JSIO.nowandIO.sleep. The queue calculation needs no other change.Blast radius
Two production-line changes in
bend2/effs/audio_open.jsandaudio_write.js, plus one regression intests/io/audio_monotonic_clock.bendwith its JS foreign twin. This affects the source IO runner and generated JS's silent Audio model. Native Audio, sample-rate validation, ring capacity, sample policy and public API remain unchanged; no API migration is required.Regression evidence
The fixture simulates a one-second rollback, opens Audio at 48 kHz and writes no samples. It prints
48000on main, failing its expected#|0, and0with the fix through the actual CLI and generated JS under Bun and Node. It restoresDate.nowimmediately after the write. A following module in the same--checkupprocess verifies the original function identity is restored on both paths.Checks
PASS: 54 / 54, using CI-pinned ttok 0.3.IO.nowcontrol passes through the CLI and generated Bun JS.Validation limits
Local checks used macOS arm64, Bun 1.3.11 and Node 26.8.2. The adjacent
IO.nowcontrol's generated Node run fails to loadbun:ffi; main emits byte-identical JS and fails the same way. The Audio regression and controls pass under Node.Browser execution, native audio-device playback, full cluster gates and GPU execution were not run. The tests simulate clock readings; they do not change the machine clock or play audio.