mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7812] [MERGED] fix(storage): prove local Windows storage so a dead writer lease is reclaimed #7940
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7940
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7812
Author: @SpicyMarinara
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/7801-windows-lease-locality📝 Commits (1)
2cb98e4fix(storage): prove local Windows storage so a dead writer lease is reclaimed📊 Changes
2 files changed (+289 additions, -13 deletions)
View changed files
📝
packages/server/src/db/file-backed-store.ts(+117 -13)📝
scripts/regressions/storage-writer-lock.regression.ts(+172 -0)📄 Description
Linked issue
Follow-up to #7801 and #7804. #7801 is already closed, so this PR has no closing line. The maintainer decided to finish the Windows part before the release.
Why this change
writerLeaseStorageIsMachineLocal()reads Linux statfs magic numbers, so on Windows it always returns false.data/storage/.writer-leaseby hand after a crash:hostId: nullbecause the process that wrote it had a failed probe. The #7801 reporter's current lease is like this. A later start whose probe works hits the #5799 path, which also needs the storage proof.What changed
All changes are in
packages/server/src/db/file-backed-store.tsandscripts/regressions/storage-writer-lock.regression.ts.New
writerLeaseWindowsStorageIsMachineLocal(). It resolves the storage folder withfs.realpathSync.native, so a mapped network drive or a link to a share shows up as its UNC path. It strips a\\?\prefix and then accepts only anX:\path. UNC (\\server\share,\\?\UNC\...), volume GUID and device paths are not local. For a drive path it runspowershell.exe -NoProfile -NonInteractive -Command "[System.IO.DriveInfo]::new('X:\').DriveType"hidden, with a 5 s timeout, and compares the enum name, which is not localized. OnlyFixedcounts. Network, Removable, CDRom, Ram, Unknown, NoRootDirectory, any error and a timeout all mean "not local". A failed probe logs one warning. The answer is cached per drive for the process.Lazy probe. The drive type is asked only when a lease blocks startup, one side has no host id, and the lease passes the writer check below. It is never asked at module load or on a normal start.
New
writerLeaseWrittenByWindowsHere()guard. This was not in the original plan, and reviewers should check it. A Fixed drive proves where the files are, not who wrote them. Docker Desktop bind mounts, WSL's/mnt/cand VM shares reach the same disk from another kernel, and another PC can reach it through a share. Without the guard, the boot check alone would reclaim a live container's lease, because its UUID boot id never matches a Windows timestamp. The Windows proof therefore covers only a lease from a native Windows writer with this machine's name, which requires all of:LastBootUpTimeboot id;acquireWriterLease(). On win32 it uses a newhostProofvalue,windows-local-storage, which also appears in the "Reclaimed the writer lease" log. Windows has no PID namespaces, so the PID checks decide directly:ESRCH) is reclaimed;pidWasReusedis skipped on this proof);EPERM) keeps the lease.The existing boot check applies as it does for every same-host proof: a writer from an earlier boot of this machine, outside #7804's 5-minute jitter window, is reclaimed.
Test hooks. New hooks
writerLeasePlatform,writerLeaseRealpathandwriterLeaseDriveType. When the existingwriterLeaseStorageIsMachineLocalhook is set, it still selects the Linux-style proof, so the existing regression cases behave the same on every platform.writerLeaseBootIdsMatchnow receives the writer's platform, which in production is the sameprocess.platformas before.Unchanged: the Linux/Android statfs proof and its PID-namespace rule,
writerLeaseStorageIsMachineLocal()itself, the macOS strict path, the host-id and Termux proofs, the on-disk lease format,storage-format.jsonandSTORAGE_VERSION.Cases still left to manual recovery, by design:
Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands run by the agent, on macOS and in a Linux container:
pnpm build:shared && node ./scripts/run-regressions.mjs --filter storage-writer-lockon macOS: passed. New cases:d:\and\\?\C:\, and the probe receives the drive root in upper case.\\?\UNC\, volume GUID, device and relative paths are not local, and the drive probe is never asked for them.nullprobe answer (failure or timeout), a probe that throws and an unresolvable path are all not local.createFileNativeDBwith an injected platform, realpath result and probe answer, using the reporter's two jittered boot ids:pidWasReusedis allowed on the Windows proof. This one fails on Linux only, becausepidWasReusedalways returns false on macOS.node:24-bookwormcontainer with an/etc/machine-id, as on the Ubuntu CI runners):storage-writer-lockpassed./etc/machine-id, the existing case "a lease naming a different machine is never reclaimed through the storage proof" fails on unmodifiedstagingtoo. Since #7804, a process without a host id applies the mirror rule, and that case does not pinwriterLeaseHostId.backup-folder-leasepassed.robustness-boot-performancepassed, and its source scan confirms the new drive-type probe runs withwindowsHide: true.pnpm check: passed. Its only lint warning is a pre-existingreact-hooks/exhaustive-depswarning in a client file not touched here.pnpm --filter @marinara-engine/server lint: passed.format:checkdoes not coverscripts/.tsctype check of the regression file: the new lines are clean. Its three errors are pre-existing, outside this diff, and the file runs under tsx.Not testable off Windows. These are covered by the manual checks below:
DriveTypeprobe: command line quoting, its output, the 5 s timeout and the hidden window.realpathSync.nativereturns on Windows for a mapped network drive, asubstdrive or a link to a share.process.kill(pid, 0)on Windows, which should returnESRCHfor an exited PID andEPERMfor an elevated process.LastBootUpTimevalues andos.hostname()across restarts.On macOS and Linux, the decision logic ran with the platform, realpath result and drive-type answer injected.
Manual verification notes
node.exewith Task Manager "End task".data\storage\.writer-lease\owner.json, set"hostId": null. This is the reporter's current lease shape..writer-lease, and the log should show "Reclaimed the writer lease after confirming its same-host PID exited." withhostProof: "windows-local-storage".hostId, followed by a start whose MachineGuid probe fails, is reclaimed the same way. Use a machine where the firstreg.execall is slow (the #7801 reporter offered to test a staging build), or a local build wherereadStableMachineId()temporarily returnsnull. Do not use a bogusSystemRoot: it also breaks the drive-type probe."hostId": nullin itsowner.json.DATA_DIR. It should be refused withStorageWriterLeaseError.DATA_DIR(orFILE_STORAGE_DIR) to a mapped drive such asZ:\mapped to\\nas\share.DriveInfoPowerShell runs. On the blocked path, the probe should finish well inside its 5 s budget.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)No docs were edited.
docs/TROUBLESHOOTING.mdalready says that Marinara reclaims a crashed lease on local disks and that manual removal remains the fallback for network or shared storage. On Windows, a normal start that has its machine ID already reclaimed a dead lease before this PR. No version, changelog,storage-format.jsonorSTORAGE_VERSIONchange.UI evidence (if applicable)
Not applicable: server-only change.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.