Skip to content

fix(songs): read a CBR song's duration from a stream told its size - #1219

Merged
Ardnived merged 5 commits into
mainfrom
fix/1210-song-duration-stream-size
Nov 19, 2026
Merged

Ardnived merged 5 commits into
mainfrom
fix/1210-song-duration-stream-size

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #1210. The production dry run of scripts/backfill-song-durations.ts found 27 songs with no duration. It resolved 11 of them and skipped 16 as audio 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-length through readAudioDuration to parseWebStream.

  • 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 — passes content-length as 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:

Song Length
songs#19–27 (Shlokas ×9) 223, 220, 227, 144, 147, 239, 250, 325, 137 s
songs#7 Setar Dashti 259 s
songs#6 Persian Vibes · Segah Avaz 184 s
songs#5 Santoor · Ambient 1185 s
songs#4 Persian Vibes · Rast-Panjgah Story 1321 s
songs#3 Flute · Soothing vibes 663 s
songs#2 Sitar · Raag Yaman 1490 s
songs#1 Sitar · Raag Bhairavi 641 s

Done (2026-11-19): this branch ran --force against production on top of the deployed commit (8b1a9e4, which changes only seeds). Result: 27 written, 0 skipped. Afterwards a dry run prints 0 song(s) hold no duration., /api/songs returns a numeric duration on all 27, and We Meditate's /music-for-meditation shows a real length on every playlist row. #1210 is closed. Merging this keeps the script in main in step with what ran.

Test plan

  • New unit cases in audio-duration.spec.ts and backfill-song-durations.spec.ts. The backfill case fails without the fix.
  • Lint, prettier, tsc --noEmit, and the full unit lane (282 files, 3830 tests).

🤖 Generated with Claude Code

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]>
@railway-app

railway-app Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-1219 environment in sahajcloud

Service Status Web Updated
SahajCloud 😴 Sleeping (View Logs) Web Nov 19, 2026 at 6:17 pm UTC
1 service not affected by this PR
  • mailpit

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1219 November 19, 2026 04:41 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 17:41Z address-review · attempt 1 · session · done
  • 17:41Z address-review · attempt 1 · session
  • 17:35Z review-pr · attempt 3 · session · done
  • 17:35Z review-pr · attempt 3 · session
  • 08:30Z review-pr · attempt 2 · session · timed out

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 19, 2026
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@Ardnived
Ardnived enabled auto-merge November 19, 2026 16:17
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 19, 2026

@sydevs-bot sydevs-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.

🧐 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 — byteStream restates new Blob([bytes]).stream() — tests/utils/audioBytes.ts:16.
  • consider — size is 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. size is music-metadata's own option, not ours. No stored fixture is a CBR MP3 without an Info header, so building one is right. byteStream is the finding above.
  • The frame header checks out: 0xfffb1400 is 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, Meditations and Songs, both pass a buffer and see no change.
  • Weighed and left: a content-length disagreeing 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, so parseWebStream'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

Comment thread tests/utils/audioBytes.ts Resolved
Comment thread src/lib/audio/duration.ts Resolved
Comment thread scripts/song-durations.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 19, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 19, 2026
sydevs-bot and others added 4 commits November 19, 2026 17:43
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
@sydevs-bot

Copy link
Copy Markdown
Contributor

All three consider findings adopted. origin/main merged in first, clean.

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

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1219 November 19, 2026 17:51 Destroyed
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 19, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

The newest commit, dac2a96, is sydevs-bot's own, so it is not approved on your behalf. Read it, then say @sydevs-bot approve.

🤖 sydevs dispatcher

@Ardnived

Copy link
Copy Markdown
Contributor Author

@sydevs-bot approve

@sydevs-bot sydevs-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.

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

@Ardnived
Ardnived added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 3825d7b Nov 19, 2026
15 checks passed
@Ardnived
Ardnived deleted the fix/1210-song-duration-stream-size branch November 19, 2026 22:17
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 19, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-1219 — dac2a96a Deployed Nov 19, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants