Skip to content

fix(recordings): preserve media referenced by saved projects#282

Merged
webadderall merged 2 commits intowebadderallorg:mainfrom
meiiie:fix/protect-project-recordings-from-prune
Apr 20, 2026
Merged

fix(recordings): preserve media referenced by saved projects#282
webadderall merged 2 commits intowebadderallorg:mainfrom
meiiie:fix/protect-project-recordings-from-prune

Conversation

@meiiie
Copy link
Copy Markdown
Collaborator

@meiiie meiiie commented Apr 19, 2026

Description

Prevent the auto-recording retention job from deleting recordings that are still referenced by saved project files in the Projects directory.

Motivation

The retention logic currently only preserves recordings when a sibling project file exists next to the media file. Saved Recordly projects live under recordings/Projects, so older recordings can be pruned even though the project metadata still points at them.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update

Related Issue(s)

Testing Guide

  • npx vitest --run electron/ipc/recording/prune.test.ts
  • npx @biomejs/biome check electron/ipc/recording/prune.ts electron/ipc/recording/prune.test.ts
  • npx tsc --noEmit

Checklist

  • I tested these changes locally
  • I kept the scope focused on the reported bug
  • I added a regression test for the Projects directory reference case

Summary by CodeRabbit

  • Bug Fixes

    • Improved auto-recording cleanup to reliably preserve recordings referenced by saved projects (including legacy project files) and avoid removing protected or linked files; parsing errors now prevent accidental deletion.
  • Tests

    • Added tests covering auto-recording cleanup, project-file reference handling, legacy project support, and error scenarios to prevent regressions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7b306b71-ec71-4954-bc18-08d00eb16618

📥 Commits

Reviewing files that changed from the base of the PR and between f7e3494 and 3509ecf.

📒 Files selected for processing (2)
  • electron/ipc/recording/prune.test.ts
  • electron/ipc/recording/prune.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • electron/ipc/recording/prune.test.ts
  • electron/ipc/recording/prune.ts

📝 Walkthrough

Walkthrough

Adds a test suite for pruneAutoRecordings and enhances prune logic with loadSavedProjectMediaPaths() to detect recordings referenced by saved projects and skip pruning of those files.

Changes

Cohort / File(s) Summary
Prune Logic & Helper
electron/ipc/recording/prune.ts
Introduces loadSavedProjectMediaPaths() to scan the Projects directory, parse saved project JSON (current and legacy extensions), extract videoPath and editor.webcam.sourcePath, normalize/resolve paths into a protected set. pruneAutoRecordings() now computes this set once and skips deleting recordings present in it (checked against normalized and realpath forms).
Test Suite
electron/ipc/recording/prune.test.ts
New Vitest tests create isolated temp AppData/UserData/Temp/App directories, mock Electron app APIs, create MP4 recordings with staggered mtimes and saved project files referencing some recordings. Tests verify referenced recordings are preserved, unreferenced are pruned, and parsing failures prevent pruning.

Sequence Diagram

sequenceDiagram
    participant App as App
    participant Prune as pruneAutoRecordings()
    participant Projects as Projects Dir
    participant Files as Recording Files

    App->>Prune: invoke pruneAutoRecordings()
    Prune->>Projects: loadSavedProjectMediaPaths()
    Projects->>Projects: read project files (json / legacy)
    Projects->>Projects: extract videoPath & editor.webcam.sourcePath
    Projects->>Projects: normalize paths & attempt realpath()
    Projects-->>Prune: return Set(protected paths)
    Prune->>Files: list recordings in recordings dir
    loop per recording file
        Prune->>Prune: compute normalized and realpath forms
        alt path in protected Set
            Prune->>Files: skip deletion
        else
            Prune->>Files: delete file
        end
    end
    Prune-->>App: complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble through projects, soft and light,

Saving clips that sparkle through the night.
I skip the ones your projects love to keep,
While tidy pruning hums a careful sweep.
Hooray for files that wake and hop back bright!

🚥 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
Title check ✅ Passed The title clearly and concisely describes the main change: preventing deletion of recordings referenced by saved projects.
Description check ✅ Passed The PR description includes all required template sections: Description, Motivation, Type of Change, Related Issue, and Testing Guide with actionable steps.
Linked Issues check ✅ Passed The code changes directly address issue #240 by implementing logic to preserve recordings referenced by saved projects in the Projects directory [#240].
Out of Scope Changes check ✅ Passed All changes are focused on fixing the prune retention logic to protect project-referenced recordings; minor formatting adjustments are incidental and within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
electron/ipc/recording/prune.test.ts (1)

50-87: Add coverage for webcam media references too.

This test locks down videoPath, but the implementation also preserves editor.webcam.sourcePath. A small second case or parameterized test would prevent that branch from regressing silently.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@electron/ipc/recording/prune.test.ts` around lines 50 - 87, The test only
covers preservation when a project references recordings via videoPath but
misses the editor.webcam.sourcePath branch; update the test for
pruneAutoRecordings to include a second saved-project file (or parameterize the
test) whose JSON contains editor: { webcam: { sourcePath: protectedRecordingPath
} } so that a recording referenced via editor.webcam.sourcePath is also asserted
preserved (and a different late recording asserted removed). Use the same
helpers/constants (getRecordingsDir, PROJECTS_DIRECTORY_NAME,
PROJECT_FILE_EXTENSION) and the existing recordingPaths array to create the
protected and prunable paths and then call pruneAutoRecordings and assert access
outcomes as done for videoPath.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@electron/ipc/recording/prune.ts`:
- Around line 49-94: The pruning currently treats any fs.readdir or per-project
JSON parse/read error as benign and continues, which can cause valid projects to
be ignored and recordings to be deleted; change the logic so only a missing
Projects directory (fs.readdir error code 'ENOENT') is treated as empty, but any
other error from fs.readdir should abort pruning (rethrow or propagate).
Likewise, inside the projectEntries.map block, do not swallow
JSON.parse/fs.readFile errors for existing project files—if reading/parsing a
project (the JSON.parse(await fs.readFile(projectPath, "utf-8")) step) fails,
propagate/abort pruning instead of continuing; still allow ignoring fs.realpath
failures for missing referenced media (the existing try/catch around
fs.realpath), and continue adding normalizedCandidatePath (via
normalizeVideoSourcePath and normalizePath) to protectedPaths when valid.

---

Nitpick comments:
In `@electron/ipc/recording/prune.test.ts`:
- Around line 50-87: The test only covers preservation when a project references
recordings via videoPath but misses the editor.webcam.sourcePath branch; update
the test for pruneAutoRecordings to include a second saved-project file (or
parameterize the test) whose JSON contains editor: { webcam: { sourcePath:
protectedRecordingPath } } so that a recording referenced via
editor.webcam.sourcePath is also asserted preserved (and a different late
recording asserted removed). Use the same helpers/constants (getRecordingsDir,
PROJECTS_DIRECTORY_NAME, PROJECT_FILE_EXTENSION) and the existing recordingPaths
array to create the protected and prunable paths and then call
pruneAutoRecordings and assert access outcomes as done for videoPath.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4ed398ea-6912-48f6-aba6-7d8a24994fa5

📥 Commits

Reviewing files that changed from the base of the PR and between daf99c0 and f7e3494.

📒 Files selected for processing (2)
  • electron/ipc/recording/prune.test.ts
  • electron/ipc/recording/prune.ts

Comment thread electron/ipc/recording/prune.ts Outdated
@webadderall webadderall merged commit 09f487d into webadderallorg:main Apr 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If you save more than 5 - 6 videos the older ones get deleted

2 participants