fix(editor): refresh finalized companion audio#751
Conversation
📝 WalkthroughWalkthrough
ChangesAudio resource versioning
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant VideoEditor
participant useAudioPreviewSync
participant useTimelineAudioPeaks
participant WaveformGenerator
participant VersionedWaveformCache
VideoEditor->>useAudioPreviewSync: provide sourceAudioResourceVersion
VideoEditor->>useTimelineAudioPeaks: provide resourceVersion
useAudioPreviewSync->>useAudioPreviewSync: validate current resource key
useTimelineAudioPeaks->>WaveformGenerator: generate versioned waveform
WaveformGenerator->>VersionedWaveformCache: activate and store current key
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/video-editor/audio/waveform/WaveformGenerator.ts (1)
64-69: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win
peaksCachenever evicts superseded versions of the same resource.Each
resourceVersionbump produces a brand-new cache key for the same underlyingurl+peakCount, and the previous version's entry is never removed. Combined with the version key being bumped more often than just at finalization (see companion note inuseAudioPreviewSync.ts), this cache can accumulate stale entries for the lifetime of the singletonwaveformGenerator. A simple bound (e.g., LRU eviction or pruning older-version keys for the same base resource when a new version is generated) would keep this safe long-term.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/video-editor/audio/waveform/WaveformGenerator.ts` around lines 64 - 69, Update WaveformGenerator.generate and its peaksCache handling so generating a newer resourceVersion removes or evicts superseded entries for the same URL and peakCount; implement bounded cleanup (such as pruning older-version keys or LRU eviction) while preserving the current version, and ensure cache growth remains limited for the singleton waveformGenerator.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/components/video-editor/audio/waveform/WaveformGenerator.ts`:
- Around line 64-69: Update WaveformGenerator.generate and its peaksCache
handling so generating a newer resourceVersion removes or evicts superseded
entries for the same URL and peakCount; implement bounded cleanup (such as
pruning older-version keys or LRU eviction) while preserving the current
version, and ensure cache growth remains limited for the singleton
waveformGenerator.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 56f60329-9a50-4375-9be6-552991f83cd5
📒 Files selected for processing (8)
src/components/video-editor/VideoEditor.tsxsrc/components/video-editor/audio/audioResourceVersion.test.tssrc/components/video-editor/audio/audioResourceVersion.tssrc/components/video-editor/audio/useAudioPreviewSync.tssrc/components/video-editor/audio/useVideoEditorAudio.tssrc/components/video-editor/audio/waveform/WaveformGenerator.tssrc/components/video-editor/timeline/TimelineEditor.tsxsrc/components/video-editor/timeline/hooks/useTimelineAudioPeaks.ts
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Refreshes companion microphone/system-audio preview resources after recording finalization so the editor and timeline do not remain stuck at a partial 15–30 second duration. Related to #708, #602, and #717.
Root cause and fix
The editor can open while a sidecar WAV is still growing. Chromium caches that first media response by URL, while finalization completes the file at the same path. The existing refresh rediscovered the same path, so neither the media element nor waveform cache changed identity.
This change versions only trusted loopback companion URLs on finalization, reloads the current element with stale-load protection, and applies the same identity to waveform peaks. Superseded waveform versions are pruned, stale in-flight results cannot re-enter the cache, and a 24-entry LRU bounds retained peak arrays. Capture, sidecar encoding, muxing, and export are unchanged.
Verification
duration=16.383188,loadCalls=1; after 45s finalization,loadCalls=2, URL gainsrecordlyAudioVersion=1,duration=45,readyState=4, and playback advances after seeking to 30sRisk
Versioning is restricted to Recordly's loopback
/videoendpoint; remote/signed URLs are unchanged. Windows 11 x64 was runtime-tested. macOS/Linux follow shared TypeScript paths but were not exercised locally.