Repository navigation
Bound lyric harmonization timestamps and window count to prevent browser hangs (#28) - #31
Merged
Merged
Conversation
_harmonizeMelody computed its window count from a raw sum of token start + duration, which a valid-numeric token like {start: 1e308, duration: 1e308} can overflow to Infinity (infinite main-thread loop) and which even at large finite spans means iterating one window per slice of the whole melody. Validate the summed endpoint for finiteness and against the 15-minute song horizon (sharing routes.py's MAX_AUDIO_DURATION_SECONDS), cap the window loop regardless of timestamps, and return the existing graceful null for out-of-bound melodies. Adds regression tests for overflow, very large finite timestamps, and an in-horizon boundary.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (6 files)
Reviewed by free · Input: 357.8K · Output: 26.9K · Cached: 223.7K |
cchacs
approved these changes
Oct 11, 2026
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.
Fixes #28.
_harmonizeMelodyfiltered each token'sstart/durationfor finiteness, then summed them (t.start + t.duration) to pick the last window. Two finite values can sum to Infinity — the issue's repro{start: 1e308, duration: 1e308, midi: 60}— turningwindowCount = Math.ceil(Infinity / windowSeconds)into an infinite main-thread loop. Large finite timestamps were equally unhappy: a 1e10s span means ~5 billion synchronous window iterations.Changes:
_harmonizeMelodynow validates the summed endpoint for finiteness and against a supported song horizon (MAX_HARMONIZED_MELODY_SECONDS = 900.0, sharing routes.py's 15-minuteMAX_AUDIO_DURATION_SECONDSbound; unlike the audio path's truncation, an out-of-horizon melody is rejected outright) and returns no chords, which the caller turns into the existing gracefulnull— the same result a rest-only or lyrics-only track already produces.MAX_HARMONY_WINDOWS = 3000) independently of timestamps, so the loop can never iterate an impractical number of times even if the horizon or minimumwindowSecondsever change.nullcan't be waved off as an empty window grid), a very large finite span past the horizon, and an in-horizon boundary (>=890s melody still harmonizes).generateAccompanimentFromLyricsnull conditions, CHANGELOG Fixed entry,plugin.json0.6.1 → 0.6.2, CLAUDE.md prose + test count.Verified: JS suite 110/110 pass (was 107), Python 20/20 pass,
node --checkclean. Reintroducing the oldreduce-based endpoint hangs the new overflow test (killed by a 12s external timeout), confirming the regression coverage pins the fix.big-pickle(free) | 𝕏