Skip to content

Fix project corruption (backport of #11378) - #11714

Merged
kryksyh merged 7 commits into
audacity:audacity3from
kryksyh:backport-11378-au3
Aug 19, 2026
Merged

kryksyh merged 7 commits into
audacity:audacity3from
kryksyh:backport-11378-au3

Conversation

@kryksyh

@kryksyh kryksyh commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

This may resolve these issues, but we can't reproduce them. We will keep the issues open for now to improve discoverability if more reports come in:

Might fix: #8319, #11244

This pr is a backport of #11378

Changes:

  • when closing a recovered unsaved project we should drop autosave
  • there was a tiny but possible corruption when the disk is full
  • there was a possible data loss on close if, for example, an external drive was unplugged immediately after closing the project
  • when disk went full, the checkpointing was stopped, so on close wal file was left unmerged
  • For better recoverability, a length field for each waveblock was added
  • I signed CLA
  • 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

QA:

  • Testflow test cases have been run

@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: cf65211a-dcb2-4590-b96c-5437b4364433

📥 Commits

Reviewing files that changed from the base of the PR and between 367439df9cc4ebac16104b3771a08fad30fa5101 and 53585110bef72656df7391e61b2d1deb40282e25.

📒 Files selected for processing (1)
  • libraries/lib-project-file-io/DBConnection.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • libraries/lib-project-file-io/DBConnection.cpp

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Project database closing now performs a final truncating WAL checkpoint. Checkpoint retries continue after failures and limit repeated warnings. Project transactions use a dedicated mutex. Compaction flushes database files before rename. Blob read failures are reported during loading, which rejects read-only databases. Waveblock XML now stores sample counts in a length attribute.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🟡 Moderate · up to 53585

During project close, delayed checkpoint-failure handling can race project destruction because the callback does not retain the project after checking its reference; this could cause a crash or corrupted close path, so the issue should be fixed or explicitly accepted before merge.

Sequence Diagram(s)

sequenceDiagram
  participant CheckpointThread
  participant SQLite
  participant ProjectCallback
  CheckpointThread->>SQLite: execute checkpoint
  SQLite-->>CheckpointThread: return success or failure
  CheckpointThread->>ProjectCallback: notify the first failure when valid
  CheckpointThread->>SQLite: retry after failure
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address the linked issues by improving recovery, autosave cleanup, checkpoint handling, disk-full behavior, and corruption tolerance [#1754, #11359, #11419, #8319].
Out of Scope Changes check ✅ Passed The transaction locking, file syncing, read-error handling, checkpoint changes, and waveblock length field support the stated project integrity and recovery objectives.
Title check ✅ Passed The title clearly identifies the main change: fixing project corruption through a backport.
Description check ✅ Passed The description explains the motivation, affected issues, key changes, and checkbox status; only optional testing confirmation remains unchecked.

Warning

Review ran into problems

🔥 Problems

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: Pro Plus

Run ID: 9ae7ebe6-8731-4eb5-9766-b0caff170e8a

📥 Commits

Reviewing files that changed from the base of the PR and between c90c052 and 367439df9cc4ebac16104b3771a08fad30fa5101.

📒 Files selected for processing (5)
  • libraries/lib-project-file-io/DBConnection.cpp
  • libraries/lib-project-file-io/DBConnection.h
  • libraries/lib-project-file-io/ProjectFileIO.cpp
  • libraries/lib-project-file-io/SqliteSampleBlock.cpp
  • libraries/lib-wave-track/Sequence.cpp

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.

@kryksyh
kryksyh force-pushed the backport-11378-au3 branch 2 times, most recently from 5358511 to 313bf4d Compare August 18, 2026 12:24
@github-project-automation github-project-automation Bot moved this from To-Do to Ready for QA in [AU3] Main board Aug 18, 2026
@kryksyh kryksyh added this to the Audacity 3.7.9 milestone Aug 18, 2026
When opening a dirty project the loaded doc is an "autosave" that the user could reject and rollback to the last saved one.
If we delete orphans now we may delete blocks that are referenced by the saved project, and this will cause a corruption: audacity#11359

Orphans will be removed on close anyway

Backport of ac65627 (audacity#11378)
NOTE: This is a speculation, and might be not the case. A scenario:

- AudioThread/: User is recording an audio, new Block audacity#500 is created
- MainThread: starts autosaving, updates project doc and opens TransactionScope
- AudioThread: New audio block 501 gets into block list, it gets into the current transaction, and AudioThread thinks it is saved
- MainThread: gets an error (out of disk?), and Transaction is rolled back, including block 501
- Sequence still holds reference to block 501, even though it was never stored

This mutex prevents simultaneous doc and sample write to the database

Backport of 8890bb5 (audacity#11378)
Also explicitly checkpoint on close

Backport of 00479c0 (audacity#11378)
Length value is used during project recovery only, not used during normal operations

Backport of aacedf2 (audacity#11378)
@kryksyh
kryksyh force-pushed the backport-11378-au3 branch from 313bf4d to 43bf263 Compare August 19, 2026 08:21
@kryksyh
kryksyh merged commit afefbd9 into audacity:audacity3 Aug 19, 2026
7 of 8 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for QA to Done in [AU3] Main board Aug 19, 2026
@kryksyh
kryksyh deleted the backport-11378-au3 branch August 19, 2026 08:21
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.

2 participants