fix(core): retry bpm-detective import after transient failure#2736
fix(core): retry bpm-detective import after transient failure#2736santhiprakash wants to merge 1 commit into
Conversation
loadBpmDetective cached the promise returned by dynamic import even when that import rejected. A transient failure (network hiccup, bundler issue, missing module at first access) was therefore cached as null for the rest of the session, silently disabling BPM detection. - Reset the cached promise on import failure so the next call retries. - Only cache the default production import; custom loaders bypass the cache. - Make loadBpmDetective testable by accepting an optional importFn. - Add regression tests for failure/retry and module/default resolution.
jrusso1020
left a comment
There was a problem hiding this comment.
Approved on James's go. Verified the bug + fix:
The cached-promise-never-reset bug is real — on a transient import("bpm-detective") failure the old code's .catch(() => null) left bpmDetectivePromise as a resolved-to-null promise that was never cleared, so if (!bpmDetectivePromise) stayed false and every later analyzeMusicFromBuffer silently skipped BPM detection for the rest of the session (breaking music-reactive animations / beat guides with no error).
The fix resets bpmDetectivePromise = null in the failure handler so the next call retries the import, caches only the default production import (custom loaders bypass the cache → unit-testable), and correctly distinguishes a transient import failure (reset + retry) from a successful-but-empty module (cached null, since retrying wouldn't help). Tests cover the retry-after-transient-failure path plus the default-export / module-object fallbacks. CI green.
— Rames
|
Thanks for this — the fix looks good and CI is green, so it's approved. One thing is blocking the merge though: To unblock, sign the commit and force-push: git commit --amend -S --no-edit
git push --force-with-leaseThat needs commit signing configured (a GPG or SSH signing key + Once the commit shows as Verified, this is good to merge. |
Problem
loadBpmDetectiveinpackages/core/src/beats/beatDetection.tsdynamically importsbpm-detectiveand caches the resulting promise. If that dynamic import fails once (network hiccup, bundler race, missing module), the.catch(() => null)resolved the cached promise tonullandbpmDetectivePromisewas never reset. Every future call toanalyzeMusicFromBufferfor the rest of the session then silently skipped BPM detection.Changes
bpmDetectivePromisetonullinside the failure handler so the next call retries the import.loadBpmDetectiveaccept an optionalimportFnso the retry/fallback behavior is unit-testable without mockingimport().packages/core/src/beats/beatDetection.test.tscovering:null;Verification
bunx vitest run src/beats/beatDetection.test.ts— 4/4 passbun run buildinpackages/core— cleanbun run typecheck— cleanbunx oxlint/bunx oxfmton changed files — clean