Skip to content

Fix project corruption caused by removing empty clips on load - #12544

Merged
kryksyh merged 1 commit into
audacity:masterfrom
kryksyh:load-snapshot-before-track-fix
Oct 23, 2026
Merged

kryksyh merged 1 commit into
audacity:masterfrom
kryksyh:load-snapshot-before-track-fix

Conversation

@kryksyh

@kryksyh kryksyh commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Resolves: project corruption when one sample clip is saved in the project

Before the fix an empty clip (one sample long) was removed before creating a saved state, and its sample were removed from the sample block table, while the saved project document still referenced it.

STR:

  1. Generate a chirp
  2. Split
  3. Move right part of the clip one sample to the right
  4. Select audio around the gap
  5. Apply nyquist effect, for example Legacy Limiter
  6. Observe that one sample clip now filling the gap
  7. Save and close
  8. Open and close
  9. Open and observe
  • I signed CLA
  • This PR includes AI assistance
  • If the PR is AI-assisted, I have read, understood and complied with the guidelines for AI-assisted contributions
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

@kryksyh kryksyh self-assigned this Oct 20, 2026
@kryksyh
kryksyh requested a review from saintmatthieu October 20, 2026 16:00
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Walkthrough

The change adds RemoveEmptyClips and Sanitize to WaveTrackUtilities. Sanitize removes empty clips, resolves overlaps, and removes clips emptied by overlap removal. Project loading now calls Sanitize for each wave track. LinkConsistencyFix no longer removes empty clips and calls ZipClips() only when the track remains linked.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🟡 Moderate · up to 1153d

Legacy-loaded projects can retain empty clips, leaving the corruption scenario unresolved for that supported load path.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: preventing project corruption caused by removing empty clips during project loading.
Description check Passed The description explains the corruption scenario, provides reproduction steps, and includes all required checklist sections. The Resolves entry does not include a direct issue link, but the descriptio…
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.
Full details: Description check

Explanation

The description explains the corruption scenario, provides reproduction steps, and includes all required checklist sections. The Resolves entry does not include a direct issue link, but the description is otherwise complete and relevant.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Linked repositories: Public OSS repositories can only analyze public repositories installed in this organization. No linked repositories were analyzed; skipped musescore/musescore.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 51262e04-e31a-4025-a779-898fb793f788
📥 Commits

Reviewing files that changed from the base of the PR and between 8829ba9 and 6506ae8.

📒 Files selected for processing: 4
  • au3/libraries/au3-wave-track/WaveTrack.cpp
  • au3/libraries/au3-wave-track/WaveTrackUtilities.cpp
  • au3/libraries/au3-wave-track/WaveTrackUtilities.h
  • src/au3wrap/internal/au3project.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@kryksyh
kryksyh force-pushed the load-snapshot-before-track-fix branch from 6506ae8 to 1153d81 Compare October 20, 2026 16:10

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Clean empty clips in the legacy load path after FixTracks. · WaveTrack.cpp:607-690

au3/libraries/au3-wave-track/WaveTrack.cpp:607-690
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clean empty clips in the legacy load path after FixTracks.

ReadProjectFile snapshots the saved tracks before FixTracks, but the legacy path does not call WaveTrackUtilities::RemoveEmptyClips or Sanitize afterward. Since LinkConsistencyFix no longer removes empty clips, a successful legacy load can commit empty mono or unlinked clips. Add the cleanup after FixTracks; do not restore it in LinkConsistencyFix, because the wrapper load path must delay cleanup until after its saved-state update.

Suggested fix
         FixTracks(
             tracks,
             // Keep at most one of the error messages
             [&](const auto& errorMessage) { otherError = errorMessage; err = true; },
             [&](const auto& unlinkReason) { linkTypeChangeReason = unlinkReason; });
 
+        tracks.Any().Visit(
+            [](WaveTrack& track) {
+                WaveTrackUtilities::RemoveEmptyClips(track);
+            },
+            [](Track&) {});
+
         if (!err) {

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 46b277df-597f-4a6c-b8e9-0221144f675b
📥 Commits

Reviewing files that changed from the base of the PR and between 6506ae8 and 1153d81.

📒 Files selected for processing: 1
  • au3/libraries/au3-wave-track/WaveTrackUtilities.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

ExpandClipTillNextOne(const WaveTrack& track, WaveTrack::Interval& interval);

//! Remove clips for which `WaveClip::IsEmpty()` is true
WAVE_TRACK_API void RemoveEmptyClips(WaveTrack& track);

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.

Only used in the .cpp file. Is it needed in the API?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't need any XXX_API in all libraries, since we link statically. I kept it for uniformity.

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.

I meant that the function is only used internally, in WaveTrackUtilities.cpp.

@kryksyh kryksyh added this to the Audacity 4.0.2 milestone Oct 21, 2026
@github-project-automation github-project-automation Bot moved this to Design - Todo in Audacity 4.1 Oct 21, 2026
@kryksyh kryksyh moved this from Design - Todo to Ready for QA in Audacity 4.1 Oct 21, 2026
@dozzzzer dozzzzer moved this from Ready for QA to In QA in Audacity 4.1 Oct 22, 2026
@dozzzzer dozzzzer self-assigned this Oct 22, 2026
@dozzzzer

Copy link
Copy Markdown
Contributor

@kryksyh

Open and close

At this step, an attempt to open causes a crash :(

@dozzzzer dozzzzer moved this from In QA to In Progress in Audacity 4.1 Oct 23, 2026
@dozzzzer dozzzzer moved this from In Progress to Ready for Merge in Audacity 4.1 Oct 23, 2026
@dozzzzer

Copy link
Copy Markdown
Contributor

The above-mentioned issue has nothing to do with this PR, it already exists on master

Before the fix an empty clip (one sample long) was removed before creating a saved state,
and its sample were removed from the sample block table, while the saved project document still referenced it

Assisted-by: Claude Code (Claude Opus 5.5)
@kryksyh
kryksyh force-pushed the load-snapshot-before-track-fix branch from 1153d81 to de7fdae Compare October 23, 2026 11:42
@kryksyh
kryksyh merged commit 386d5f3 into audacity:master Oct 23, 2026
3 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Merge to Done in Audacity 4.1 Oct 23, 2026
@kryksyh
kryksyh deleted the load-snapshot-before-track-fix branch October 23, 2026 11:43
kryksyh added a commit that referenced this pull request Oct 27, 2026
Fix project corruption caused by removing empty clips on load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants