Skip to content

fix(editor): refresh finalized companion audio#751

Merged
meiiie merged 4 commits into
mainfrom
fix/708-refresh-companion-audio
Jul 11, 2026
Merged

fix(editor): refresh finalized companion audio#751
meiiie merged 4 commits into
mainfrom
fix/708-refresh-companion-audio

Conversation

@meiiie

@meiiie meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

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

  • Focused audio/cache coverage: 4 files / 37 tests
  • Strict TypeScript and targeted Biome: pass
  • Full Vitest: 105 files, 988 pass, 1 skip
  • Production renderer/main/preload build: pass
  • Windows native-helper build, NSIS package, and packaged binary smoke: pass before the cache-only review follow-up
  • Packaged growing-sidecar repro: duration=16.383188, loadCalls=1; after 45s finalization, loadCalls=2, URL gains recordlyAudioVersion=1, duration=45, readyState=4, and playback advances after seeking to 30s

Risk

Versioning is restricted to Recordly's loopback /video endpoint; remote/signed URLs are unchanged. Windows 11 x64 was runtime-tested. macOS/Linux follow shared TypeScript paths but were not exercised locally.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

sourceAudioResourceVersion now propagates through preview synchronization, timeline peak loading, and waveform caching. New helpers version trusted loopback audio URLs, distinguish resource identities, invalidate stale loads, and refresh versioned waveform entries.

Changes

Audio resource versioning

Layer / File(s) Summary
Resource version helpers and tests
src/components/video-editor/audio/audioResourceVersion.ts, src/components/video-editor/audio/audioResourceVersion.test.ts
Adds normalized resource keys, conditional loopback URL versioning, current-load validation, and coverage for version changes and stale loads.
Preview resource tracking
src/components/video-editor/audio/useAudioPreviewSync.ts, src/components/video-editor/audio/useVideoEditorAudio.ts, src/components/video-editor/VideoEditor.tsx
Propagates the refresh version into preview synchronization, tracks versioned audio identities, validates asynchronous loads, and reloads versioned audio sources.
Versioned waveform peak refresh
src/components/video-editor/timeline/hooks/useTimelineAudioPeaks.ts, src/components/video-editor/timeline/TimelineEditor.tsx, src/components/video-editor/audio/waveform/WaveformGenerator.ts
Passes resource versions through timeline peak loading and waveform generation, updates cache keys, and regenerates peaks when versions change.
Versioned waveform cache
src/components/video-editor/audio/waveform/waveformCache.ts, src/components/video-editor/audio/waveform/waveformCache.test.ts
Adds scoped version activation, stale-write rejection, failure deactivation, and bounded least-recently-used eviction with tests.

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
Loading

Possibly related PRs

Suggested labels: Checked

Suggested reviewers: ExtraBinoss

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: refreshing finalized companion audio.
Description check ✅ Passed The description is detailed and covers the change summary, motivation, verification, and risk, matching the template's core intent.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/708-refresh-companion-audio

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/components/video-editor/audio/waveform/WaveformGenerator.ts (1)

64-69: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

peaksCache never evicts superseded versions of the same resource.

Each resourceVersion bump produces a brand-new cache key for the same underlying url+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 in useAudioPreviewSync.ts), this cache can accumulate stale entries for the lifetime of the singleton waveformGenerator. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 157d9a0 and 08e335f.

📒 Files selected for processing (8)
  • src/components/video-editor/VideoEditor.tsx
  • src/components/video-editor/audio/audioResourceVersion.test.ts
  • src/components/video-editor/audio/audioResourceVersion.ts
  • src/components/video-editor/audio/useAudioPreviewSync.ts
  • src/components/video-editor/audio/useVideoEditorAudio.ts
  • src/components/video-editor/audio/waveform/WaveformGenerator.ts
  • src/components/video-editor/timeline/TimelineEditor.tsx
  • src/components/video-editor/timeline/hooks/useTimelineAudioPeaks.ts

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meiiie meiiie merged commit 9233742 into main Jul 11, 2026
5 checks passed
@meiiie meiiie deleted the fix/708-refresh-companion-audio branch July 11, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant