Repository navigation
Cross-rate live wiring: foreign-rate tracks run live, delivery converts - #143
Conversation
|
Starting review of d9759ab. |
The plan's three gaps, closed. The all-tracks rate check and the engine's constructor guard delete: a foreign-rate track evaluates at its own rate (its chain on its own clock, as its offline stem runs) and every consuming edge converts the materialized buffer wholesale through the offline wrapper — the same kernel on the same samples the offline convert node runs, byte-identical by construction and proven by the golden. A cached conversion freezes to a file window as the plan observed it would, dirty speaks convert labels so the watch's background freeze converges one node deeper, and the compiler mirrors the wrapper's output-length rule with its empty-source branch. The daemon's device refusal retires: delivery converts through the streaming resampler when the device cannot switch, with the lifecycle decision 3 specified — reset at locate, stop, and swap; drained before finished; the heard-position bound recorded. SESSION_VERSION is 2.
d9759ab to
c8fd0a9
Compare
|
Starting review of c8fd0a9. |
minjudd
left a comment
There was a problem hiding this comment.
Reviewing c8fd0a9. d9759ab was superseded by a rebase onto #142 while I was working through it; the implementation is byte-identical across it (git diff d9759ab..c8fd0a9 -- src native is empty), so the measurements below were taken at the earlier SHA and carry unchanged.
The decision-1 golden holds, which is the claim the plan stands or falls on. I built the fixture — a 48 kHz song whose main places a 44.1 kHz child with its own eq chain — and rendered the session both ways against the offline artifact:
cold: tracks=2 low=LIVE(rate=44100, chain=1) dirty=[//songs/opener/track:low, //songs/opener/convert:track-low-48000]
warm: tracks=1 low=ABSENT dirty=[]
offline artifact bytes: 384000
cold (child live) === artifact: true
warm (child frozen) === artifact: true
cold === warm: true
Bit-identity by construction is real, and the warm line is the nicer surprise: the child does not merely freeze, it leaves — once the conversion is a file window nothing reaches the child, so #140's reachability trim drops it. The freeze works one node deeper exactly as decision 5 said it would, and dirty speaks the convert label to get there.
Delivery conversion resolves the finding I filed on #140 by making it not exist, rather than by explaining it better. A 44.1 kHz project on the 48 kHz null device:
item: opener (live)
PLAYED and returned on its own after 3.5s (session is 2.0s of audio)
last position line: 1.4.688 (0:01.9)
It plays, and it ends by itself — so the drain wait in streamFinished works and the tail is not cut. Retiring the CLI's artifact-spelling rescue in the same diff is right: it existed only as an interim answer and dies with its cause.
All three refusals are gone from the tree, the two stale claims in realtime.md are annotated "(since delivered — …)" rather than rewritten, which keeps the history readable, and tracks.md now says "Either spelling plays on any device" where it used to carry the constraint I asked for in #140. cross-rate-live.md flips to Shipped with now.md rewritten in the same diff, carrying a condition for removing the line.
The compiler mirror is exact. convertedLength reproduces resample.cpp:202's flush term for term — same gcd-reduced ratio, same +stride/2 floor, same zero-in-zero-out — and the unit cases pin the two branches that matter, including the #57 two-frame case. Dropping RESAMPLER_TAPS and the old edgeDelay is the amendment I verified on #141 (an impulse at input 1000 lands at output 1088, offset zero), so the delay-free edge is measured, not assumed.
The engine work is careful in the places that matter. Conversions are built on the message thread — the constructor's eager pass covers every window of every track, so the callback's ensureConverted is a find and the read uses .at(), which cannot insert. The FIFO is reserved and compacted by memmove rather than reallocation, convQueued is atomic so streamFinished can wait for the drain without the lock, and the window read still bounds-checks against srcL->size(), so a short converted buffer reads silence rather than off the end. spec.limiter.sampleRate and the eq both moving to track.rate is the detail that makes a foreign-rate chain run on its own clock, and it is easy to miss.
Gates at this head: pnpm typecheck clean, pnpm build:native clean, pnpm test 40 files / 610 tests green.
One finding, on the transport case the tests do not reach.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9759abf27
ℹ️ 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".
…ss finish Four findings on #143, all in the converter lifecycle. A session swap now installs prepared conversion state only when it cannot carry — a fresh start, a moved rate pair, or a flushed stream — so a same-pair live-watch edit keeps the converter, its FIFO, and its filter history (minjudd: dropping the queue skipped 10-20 ms per edit). The kernel design and FIFO reservation happen before liveLock is taken (Codex P1: building under the lock cost a silent block per structural edit). The fill loop clamps the final render to the session extent so total output is exactly the declared conversion's length (Codex P2). streamFinished checks completion under liveLock, seeing the extent-crossing callback's state whole or not at all (Codex P2: a lockless read could catch the position past the extent before the tail was counted, and stop() would drop it). Status gains conv_queued — decision 3's skew, made visible — which is what lets the new swap test assert the FIFO survives: proven to fail (0 vs 384 queued frames) with the install made unconditional.
|
Starting review of ffae1a7. |
minjudd
left a comment
There was a problem hiding this comment.
Approving ffae1a7. The finding is fixed, and I verified the fix against the running daemon rather than reading the diff — a 44.1 kHz session on the 48 kHz null device, paused with audio in flight, then swapped with the same rate pair:
daemon 0.7.0, session rate 44100, device is 48000 (null)
paused with conv_queued=384, sample=5120
after same-pair swap: conv_queued=384, sample=5120
FIFO kept: true position carried: true
The queued frames and the position both survive, where a rebuild would have shown zero. 384 frames at 48 kHz is 8 ms of in-flight audio, which is the artifact that used to be dropped on every edit.
The guard is better than what I proposed. Keying on the remembered (convLiveRate, convDeviceRate) pair is the part I suggested; adding || convFlushed is not, and it is the case I missed — a natural end racing a swap leaves a converter that cannot take more input, so carrying it forward would wedge the stream rather than smooth it. Preparing the kernel and the FIFO reservation outside the lock is the same principle #139 established for session construction, applied to the one remaining allocation on the lock-held path.
The exact-extent fix is a real bug caught, not a tidy-up. Rendering a full block past the extent and converting the padding delivered frames beyond the declared conversion, so a non-looping session stopped late by up to a block. Clamping the final render to liveLength - position makes total input exactly the extent and total output exactly its convertedLength, which is the same arithmetic the compiler mirrors. The loop still terminates in every case: render == 0 implies position >= liveLength, which is precisely the condition that flushes and sets convFlushed.
The raceless finish is correct for the reason given. pullAudio renders inside a ScopedTryLock on liveLock, so the callback that crosses the extent updates position, flushes, and queues the tail as one thing the heartbeat cannot see half of. The old lockless convQueued read really could have caught position past the extent with the tail not yet counted, and stop() would then have dropped it. Keeping convQueued for status and checking completion under the lock puts each where it belongs — and exposing it as conv_queued turns decision 3's skew bound from prose into something observable, which is what let me verify the swap fix at all.
The cost is that streamFinished now contends with the callback's try-lock on the heartbeat rather than only during edits. The hold is a few reads against a ~10 ms callback period, so a missed block is rare enough not to matter, and it buys a real correctness fix — worth being aware of, not worth avoiding.
The render paths are untouched this round — git diff c8fd0a9..ffae1a7 -- src/graph/live.ts native/audiod/src/live.cpp native/audiod/src/live.h src/audiod/session.ts is empty — so the goldens I measured at the previous head carry: the cross-rate fixture renders byte-identically to the offline artifact both with the child live and with the conversion frozen, and cold equals warm.
Gates at this head. pnpm typecheck clean, pnpm build:native clean, pnpm test 40 files / 611 tests green. The new socket test is the right shape: it pauses to get audio in flight, retries the rare exact-drain landing rather than assuming, and then still requires the stream to end itself through the kept converter — so it would catch both a dropped FIFO and a converter that carried forward when it should not have.
The daemon moves to 0.7.0 with the version comment naming the change, and conv_queued lands as an optional field, so an older client reading a newer daemon is unaffected.
Everything else stands from c8fd0a9: the decision-1 golden, the child leaving the session entirely once its conversion freezes, delivery conversion replacing the refusal I filed on #140, all three refusals gone with the CLI rescue retired alongside them, convertedLength mirroring resample.cpp's flush term for term, and the docs sweep — realtime.md annotated rather than rewritten, tracks.md carrying the constraint's removal, the plan flipped to Shipped with now.md in the same diff.
No findings.
The implementation of
docs/projects/all/cross-rate-live.md, one PR as the plan's §3 said, closing its three gaps and flipping the plan to Shipped.The clean case unblocks by deletion: the all-tracks rate check and the engine's own constructor guard (whose message still promised this wiring "later in chunk 2") are gone, so a cached conversion is served as the file window the freeze always knew how to make — the plan's §4 called this path's first proof out explicitly, and the test provides it. The dirty case is decision 1: a
convert:dep that misses the cache and wraps this song'strack:ortap:no longer builds synchronously inside the compile (the re-render-and-swap cliff decision 7 rejected); the child compiles live at its own rate — its chain running on its own clock, exactly as its offline stem does — and every consuming edge converts the child's materialized buffer wholesale through the offlineresample()wrapper. Same kernel, same samples as the offline convert node, so the golden is byte-identity by construction: the new test renders the cold session (child live at 44.1 kHz inside a 48 kHz song) and diffs it against the offline artifact — equal — then freezes the conversion and diffs again — still equal. The compiler mirrors the wrapper's output-length rule with the empty-source branch the plan review sharpened (n > 0 ? max(1, round(n·to/from)) : 0), the direct-ref and converted-edge window paths collapse into one (a same-rate edge is the identity case of both), and dirty speaks convert labels so the watch's background freeze converges one node deeper.The device case is decision 3:
maybeMatchDeviceRatestill moves the device to the session's rate when it can — on real hardware the MacBook speakers simply switched to 44.1 kHz, bit-perfect — and when it cannot (the null device is fixed at 48 kHz), delivery converts through the streamingdsp::Resamplerinstead of refusing. The lifecycle is as specified, sharpened by review: rebuild-as-reset at locate, stop, and device start (primed-with-zeros state, queued output dropped, no pre-seek leakage), while a session swap prepares conversion state outside the lock and installs it only when the rate pair actually moved — a same-pair live-watch edit keeps the converter, its queued FIFO, and its filter history, because that queue is exactly the audio the ear should hear next (minjudd's finding); past the session's extent the inflowing silence pushes the kernel's tail through and one flush delivers the remainder, withstreamFinishedderiving completion from the converter state underliveLock— flushed and drained, judged against the extent-crossing callback whole rather than racing it — so the tail is heard before the transport reports done; the callback stays heap-free via reserved capacity and memmove compaction. SESSION_VERSION bumps to 2 (track rates are load-bearing at edges now; an old daemon's version check refuses with its rebuild message) and the daemon is 0.7.0. The CLI's artifact-spelling rescue for the dead refusal retires with it, tracks.md now says either spelling plays on any device, and realtime.md's two interim-answer clauses gain their since-delivered notes.The suite grows 608 → 611: the cross-rate golden above (which also pins
convertedLength's branches, including the #57 two-frame case), a device-conversion e2e — a 44.1 kHz project against the 48 kHz-locked null device loads where it used to refuse, plays, and reaches its natural end only after the converted tail drains — and a swap-under-conversion test that pauses with converted frames queued, swaps in a recompile, and asserts the queue and the carried position both survive (status reportsconv_queued, decision 3's skew made visible, which is what makes the FIFO observable; the test fails at exactly that assertion when the install is made unconditional).Testing
From the repo root:
pnpm build && pnpm build:native && pnpm test— 40 files / 611 tests green (the native rebuild is required: SESSION_VERSION is 2, and a stale daemon will refuse sessions with its rebuild message —cd examples/bloom && field transport quitif one is running). The live checks, run before writing this:cd examples/bloom && field play creekstill plays (the 48 kHz path is untouched — the whole prior suite is the regression net). For the real thing, make a 44.1 kHz scratch project:field init ff --sample-rate 44100(or edit a scratch project'sfield.yaml), give a song a 44.1 kHz asset and a main track placing it, andfield play <song>— before this PR that refused naming the artifact spelling; now it plays, andfield transport statusshows the device following to@ 44100 Hzwhere the hardware allows (the null daemon, which cannot switch, exercises the conversion arm — visible asresampling: truein status). For a cross-rate child: addrate: 44100to a child track whose asset is 44.1 kHz inside a 48 kHz song,field play <song>cold — it plays immediately with the child live (no stem build wait), andfield build <song>/track:main && field play <song>serves the frozen conversion. What would show it wrong: the golden failing (a materialized edge diverging from the offline convert node's bytes), or a natural end that clips the last ~1.4 ms of tail on a converting device — the drain condition exists for exactly that.