Repository navigation
fix(songs): read a CBR song's duration from a stream told its size - #1219
Conversation
The duration backfill streamed each song's audio without its byte length. A constant-bitrate MP3 with no Xing or Info header states its length only as size over bitrate, so music-metadata answered undefined for it and the song was skipped as "audio states no duration". Against production that was 16 of the 27 songs holding no duration — all readable, all CBR without an Info header. With the response's content-length passed through, the dry run resolves every one of them, and the 11 it already resolved keep the same lengths. The upload hook is unaffected: it reads a buffer, which carries its own size. Refs #1210 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1219 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of the problem #1210 turned up: one parameter, one call site, two specs, one built fixture. It adds no abstraction for a caller that does not exist, and no refactor rides along. The upload hook really is untouched — parseBuffer already knows its own size, and both hook callers pass a buffer. The production run in the body is the strongest evidence here: 11 lengths unchanged, 16 newly resolved. Three small questions, none blocking.
Findings
consider—byteStreamrestatesnew Blob([bytes]).stream()—tests/utils/audioBytes.ts:16.consider—sizeis a third positional that only one branch reads —src/lib/audio/duration.ts:25.consider— the same why now sits at both ends of one call —scripts/song-durations.ts:69.
What was checked
- Read whole, on the branch:
src/lib/audio/duration.ts,scripts/song-durations.ts,scripts/backfill-song-durations.ts, both specs, the new util. - Ladder on the three new pieces.
sizeis music-metadata's own option, not ours. No stored fixture is a CBR MP3 without an Info header, so building one is right.byteStreamis the finding above. - The frame header checks out:
0xfffb1400is MPEG-1 Layer III, 32 kbps, 48 kHz, so 96-byte 24 ms frames and 125 of them is 3 s exactly. The comment states it correctly. - Consumer side:
extractAudioDuration's callers,MeditationsandSongs, both pass a buffer and see no change. - Weighed and left: a
content-lengthdisagreeing with the decoded body would write a wrong length rather than none. R2 serves MP3 unencoded, and that harm is uncounted. - No preview link is owed — the diff touches none of this repo's
fixture.surfacePaths. - This checkout has no
node_modules, soparseWebStream's option name rests on the new specs, not on a read of the package.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The callee's JSDoc states, beside the parameter it explains, why a stream needs its byte length. The caller repeated it, so the two could drift. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWhR6LJbUmMKuzzBRA
size was a third positional that only the stream branch read, so a buffer caller could pass one and never learn it was ignored. A discriminated union offers it where it has an effect and nowhere else. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWhR6LJbUmMKuzzBRA
byteStream restated new Blob([bytes]).stream(). The util file now holds only the MP3 builder its name promises. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWhR6LJbUmMKuzzBRA
|
All three
No behaviour change. Body refreshed: the signature bullet and the lane counts were false. Lean gate green — lint, format, both typechecks, 282 unit files, 3830 tests. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
The newest commit, dac2a96, is sydevs-bot's own, so it is not approved on your behalf. Read it, then say 🤖 sydevs dispatcher |
|
@sydevs-bot approve |
sydevs-bot
left a comment
There was a problem hiding this comment.
Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run. Enable auto-merge when you want it merged: the queue tests it against its base. 🤖 Written by the sydevs autonomous loop — see what this is
Summary
Refs #1210. The production dry run of
scripts/backfill-song-durations.tsfound 27 songs with noduration. It resolved 11 of them and skipped 16 asaudio states no duration. All 16 files are readable. Each is a constant-bitrate MP3 with no Xing/Info header. Such a file states its length only as size ÷ bitrate. The backfill streamed the audio without passing its byte length, so music-metadata had no size to divide.The fix passes the response's
content-lengththroughreadAudioDurationtoparseWebStream.src/lib/audio/duration.ts—readAudioDuration(source)takes a discriminated union: a buffer, or a stream and the byte length it was served with. Only the stream variant offers a size, since a buffer carries its own.scripts/song-durations.ts— passescontent-lengthas the size.tests/utils/audioBytes.ts— builds a CBR MP3 with no Info header, rather than storing a binary fixture.The upload hook is unaffected, because it parses a buffer.
Production dry run with this branch (read-only)
27 to write, 0 skipped. The 11 songs the unpatched script resolved keep exactly the same lengths. The 16 it skipped now resolve:Done (2026-11-19): this branch ran
--forceagainst production on top of the deployed commit (8b1a9e4, which changes only seeds). Result:27 written, 0 skipped. Afterwards a dry run prints0 song(s) hold no duration.,/api/songsreturns a numericdurationon all 27, and We Meditate's/music-for-meditationshows a real length on every playlist row. #1210 is closed. Merging this keeps the script inmainin step with what ran.Test plan
audio-duration.spec.tsandbackfill-song-durations.spec.ts. The backfill case fails without the fix.tsc --noEmit, and the full unit lane (282 files, 3830 tests).🤖 Generated with Claude Code