[PR #5584] [MERGED] fix: recover writer leases after reboot #6834

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5584
Author: @Gunterlie
Created: 8/27/2026
Status: ✅ Merged
Merged: 8/28/2026
Merged by: @Gunterlie

Base: staging ← Head: evict-the-ghosts


📝 Commits (8)

  • 2951524 fix: recover writer leases after reboot
  • cae272c fix: detect reused writer lease PIDs
  • ab14390 fix: use system clock rate for PID checks
  • 453c098 Merge branch 'staging' into evict-the-ghosts
  • 53ee469 Revert "Merge branch 'staging' into evict-the-ghosts"
  • cc2d5aa Reapply "Merge branch 'staging' into evict-the-ghosts"
  • fb3dcdc Revert "Reapply "Merge branch 'staging' into evict-the-ghosts""
  • 5219093 Reapply "Reapply "Merge branch 'staging' into evict-the-ghosts""

📊 Changes

3 files changed (+189 additions, -35 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/server/src/db/file-backed-store.ts (+120 -11)
📝 scripts/regressions/storage-writer-lock.regression.ts (+67 -24)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5580

Why this change

  • A stale writer lease can survive a normal-looking shutdown or device stop. After a reboot, the operating system can reuse the recorded PID for an unrelated process. The current PID-only liveness check then blocks startup every time, even though the original Marinara writer no longer exists.

What changed

  • Add writer lease format version 4 with a boot-session identity.
  • Read the Linux and Termux boot ID from /proc/sys/kernel/random/boot_id.
  • Read the Windows boot time through Win32_OperatingSystem.LastBootUpTime.
  • Reclaim a same-host lease from an earlier boot before checking whether its PID currently exists.
  • Keep lease versions 1-3 readable and keep current-boot or foreign-host leases protected.
  • Add a regression where the stale lease PID is deliberately live but the boot identity differs.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Automated: pnpm regression:node --filter storage-writer-lock passed.
  • Automated: pnpm check passed.
  • Manual Windows reboot verification is still required.
  • Manual Termux reboot verification is still required.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Not applicable. This change affects server startup and storage lease recovery.

Proof

The regression writes a version 4 same-host lease with the current process PID and a prior boot ID. Startup reclaims it and replaces its token. The existing live-writer checks continue to reject a second writer for the current boot.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Linux and Termux storage locks that could remain unavailable after a device reboot.
    • Improved recovery of stale file-storage leases when process IDs are reused.
    • Enhanced detection of active processes to prevent reclaiming valid leases.
  • Tests

    • Added regression coverage for reboot scenarios and reused process IDs across matching and different boot sessions.

🔄 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/5584 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 8/27/2026 **Status:** ✅ Merged **Merged:** 8/28/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `evict-the-ghosts` --- ### 📝 Commits (8) - [`2951524`](https://github.com/Pasta-Devs/Marinara-Engine/commit/29515241b3dcfae9cd869e85da236197b57a66ff) fix: recover writer leases after reboot - [`cae272c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cae272c54c13ea9fffe7e34df2af5c970ca5f9a4) fix: detect reused writer lease PIDs - [`ab14390`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ab14390f3dfe53c4f7a1f8b212d24213335ebc62) fix: use system clock rate for PID checks - [`453c098`](https://github.com/Pasta-Devs/Marinara-Engine/commit/453c0980b77ee0f602ff8fff660e95b00d107d4f) Merge branch 'staging' into evict-the-ghosts - [`53ee469`](https://github.com/Pasta-Devs/Marinara-Engine/commit/53ee469fb0affdcd73ac9a23d5f408477b1d4ae6) Revert "Merge branch 'staging' into evict-the-ghosts" - [`cc2d5aa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cc2d5aaa950a0270f59786ee60c46aaa877456d9) Reapply "Merge branch 'staging' into evict-the-ghosts" - [`fb3dcdc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fb3dcdc600c3bd9202833f58c550fb046ec97f08) Revert "Reapply "Merge branch 'staging' into evict-the-ghosts"" - [`5219093`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5219093e261cbaa25e28a4315f021e4af964395f) Reapply "Reapply "Merge branch 'staging' into evict-the-ghosts"" ### 📊 Changes **3 files changed** (+189 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/server/src/db/file-backed-store.ts` (+120 -11) 📝 `scripts/regressions/storage-writer-lock.regression.ts` (+67 -24) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #5580 ## Why this change - A stale writer lease can survive a normal-looking shutdown or device stop. After a reboot, the operating system can reuse the recorded PID for an unrelated process. The current PID-only liveness check then blocks startup every time, even though the original Marinara writer no longer exists. ## What changed - Add writer lease format version 4 with a boot-session identity. - Read the Linux and Termux boot ID from `/proc/sys/kernel/random/boot_id`. - Read the Windows boot time through `Win32_OperatingSystem.LastBootUpTime`. - Reclaim a same-host lease from an earlier boot before checking whether its PID currently exists. - Keep lease versions 1-3 readable and keep current-boot or foreign-host leases protected. - Add a regression where the stale lease PID is deliberately live but the boot identity differs. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Automated: `pnpm regression:node --filter storage-writer-lock` passed. - Automated: `pnpm check` passed. - Manual Windows reboot verification is still required. - Manual Termux reboot verification is still required. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Not applicable. This change affects server startup and storage lease recovery. ## Proof The regression writes a version 4 same-host lease with the current process PID and a prior boot ID. Startup reclaims it and replaces its token. The existing live-writer checks continue to reject a second writer for the current boot. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed Linux and Termux storage locks that could remain unavailable after a device reboot. * Improved recovery of stale file-storage leases when process IDs are reused. * Enhanced detection of active processes to prevent reclaiming valid leases. * **Tests** * Added regression coverage for reboot scenarios and reused process IDs across matching and different boot sessions. <!-- 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:14:08 +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#6834
No description provided.