[PR #5014] [MERGED] fix: prevent concurrent storage writers #6590

Closed
opened 2026-10-23 04:11:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5014
Author: @SpicyMarinara
Created: 8/14/2026
Status: ✅ Merged
Merged: 8/14/2026
Merged by: @SpicyMarinara

Base: staging ← Head: hotfix/5013-storage-single-writer


📝 Commits (8)

  • b50a007 Merge pull request #5012 from Pasta-Devs/staging
  • 219331b fix: prevent concurrent storage writers
  • 5896a4f fix: prevent concurrent file storage writers
  • d02cb7f Revert "fix: prevent concurrent file storage writers"
  • ef67f34 fix: add portable storage writer lock
  • f360e55 Merge remote-tracking branch 'origin/main' into hotfix/5013-storage-single-writer
  • 1aca082 fix: harden storage writer lease lifecycle
  • 83c11ea fix: close storage writes before releasing lease

📊 Changes

6 files changed (+544 additions, -29 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 docs/TROUBLESHOOTING.md (+6 -0)
📝 package.json (+2 -1)
📝 packages/server/src/db/file-backed-store.ts (+313 -27)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+5 -1)
➕ scripts/regressions/storage-writer-lock.regression.ts (+214 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository’s staging branch or a same-repository hotfix/* branch to main.

Linked issue

Refs #5013

Why this change

Two live Engine processes can currently open the same local data directory as independent file-backed database writers. A stale process can then overwrite newer table snapshots and make successfully reported lorebook writes disappear.

What changed

  • Added an exclusive cross-platform storage writer lease with conservative same-host stale-owner recovery.
  • Waited briefly for an owner record that another process is still publishing instead of reporting false corruption.
  • Permanently closed the retained store to new writes before waiting for accepted transactions and releasing its lease, including shutdown-error paths.
  • Preserved all loaded rows while healing stale diagnostic manifest counts.
  • Rebound Professor Mari storage when the database identity changes.
  • Added the focused regression to the automatic issue-regression lane.

Validation

  • pnpm check passes locally
  • pnpm regression:storage-writer-lock passes locally
  • pnpm regression:docs passes locally
  • Container (Docker / Podman) built and ran without issue
  • Manually verify a second process using the same data directory fails safely
  • Read and followed CONTRIBUTING.md

Manual verification notes

Manually verify one Engine instance can write, flush, close, and reopen lorebooks without loss. Manually verify a second instance using the same data directory fails with an actionable error and cannot overwrite the first instance data. Manually verify stale manifest diagnostics heal without hiding rows.

Docs and release impact

  • Updated docs/TROUBLESHOOTING.md with the safe stale-lease recovery procedure
  • Translated troubleshooting follow-up is tracked in #5015
  • Version/release files updated (not applicable; Engine remains 2.4.2)

UI evidence

No UI change is expected.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented multiple Marinara processes from overwriting shared local storage.
    • Added recovery for stale storage locks after interrupted processes.
    • Repaired outdated diagnostic counts without deleting stored data.
    • Protected stored data from unexpected manifest changes during writes.
    • Ensured database services correctly rebind after storage is reopened.
    • Improved shutdown handling to preserve pending data safely.
  • Documentation

    • Added troubleshooting guidance for resolving storage writer-lock conflicts.
  • Tests

    • Added regression coverage for storage locking, recovery, persistence, manifest repair, and database rebinding.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5014 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 8/14/2026 **Status:** ✅ Merged **Merged:** 8/14/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `hotfix/5013-storage-single-writer` --- ### 📝 Commits (8) - [`b50a007`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b50a007e665ff81845228c7db9d1e32e9c4dc3a2) Merge pull request #5012 from Pasta-Devs/staging - [`219331b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/219331befb3a4f98236d7433871dddbdf4fc1059) fix: prevent concurrent storage writers - [`5896a4f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5896a4f36b08926a1fcc7719a39fb4c940b9f0cb) fix: prevent concurrent file storage writers - [`d02cb7f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d02cb7fb2fc98f5e18fd8038ef8403e6697e33a4) Revert "fix: prevent concurrent file storage writers" - [`ef67f34`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ef67f34a3ed4ccfaa11b51f644d1b4a273bb2d58) fix: add portable storage writer lock - [`f360e55`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f360e551afe41115940ea188e0579836b08c39ad) Merge remote-tracking branch 'origin/main' into hotfix/5013-storage-single-writer - [`1aca082`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1aca08276a1721ab59d0d2a9096e62f90e4c1024) fix: harden storage writer lease lifecycle - [`83c11ea`](https://github.com/Pasta-Devs/Marinara-Engine/commit/83c11ea31b3059372c03bd0e3f3f920c3e94200a) fix: close storage writes before releasing lease ### 📊 Changes **6 files changed** (+544 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `docs/TROUBLESHOOTING.md` (+6 -0) 📝 `package.json` (+2 -1) 📝 `packages/server/src/db/file-backed-store.ts` (+313 -27) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+5 -1) ➕ `scripts/regressions/storage-writer-lock.regression.ts` (+214 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository’s `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Refs #5013 ## Why this change Two live Engine processes can currently open the same local data directory as independent file-backed database writers. A stale process can then overwrite newer table snapshots and make successfully reported lorebook writes disappear. ## What changed - Added an exclusive cross-platform storage writer lease with conservative same-host stale-owner recovery. - Waited briefly for an owner record that another process is still publishing instead of reporting false corruption. - Permanently closed the retained store to new writes before waiting for accepted transactions and releasing its lease, including shutdown-error paths. - Preserved all loaded rows while healing stale diagnostic manifest counts. - Rebound Professor Mari storage when the database identity changes. - Added the focused regression to the automatic issue-regression lane. ## Validation - [ ] `pnpm check` passes locally - [ ] `pnpm regression:storage-writer-lock` passes locally - [ ] `pnpm regression:docs` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Manually verify a second process using the same data directory fails safely - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Manually verify one Engine instance can write, flush, close, and reopen lorebooks without loss. Manually verify a second instance using the same data directory fails with an actionable error and cannot overwrite the first instance data. Manually verify stale manifest diagnostics heal without hiding rows. ## Docs and release impact - [ ] Updated `docs/TROUBLESHOOTING.md` with the safe stale-lease recovery procedure - [ ] Translated troubleshooting follow-up is tracked in #5015 - [ ] Version/release files updated (not applicable; Engine remains 2.4.2) ## UI evidence No UI change is expected. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Prevented multiple Marinara processes from overwriting shared local storage. - Added recovery for stale storage locks after interrupted processes. - Repaired outdated diagnostic counts without deleting stored data. - Protected stored data from unexpected manifest changes during writes. - Ensured database services correctly rebind after storage is reopened. - Improved shutdown handling to preserve pending data safely. - **Documentation** - Added troubleshooting guidance for resolving storage writer-lock conflicts. - **Tests** - Added regression coverage for storage locking, recovery, persistence, manifest repair, and database rebinding. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:11:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6590
No description provided.