Repository navigation
fix(memory): keep retrying a lock put-back that Windows refuses for a moment - #5637
Conversation
… moment On Windows a rename over a file that anything holds open fails with EPERM. When a stale-lock break took a live lock aside by mistake, the writer that created the lock in the gap kept opening its file while it waited out the break, so putting the live lock back could fail. The failure was swallowed as a busy lock, the guard was dropped with the live lock still aside, and that writer ran beside its holder: the #5565 hand-off window, reopened on Windows. The put-back is now retried under the guard until it lands, for up to staleMs. Closes #5635 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
🦋 Changeset detectedLatest commit: 7a1511c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 9 | 0 | 1 | 0 |
| Head | 9 | 0 | 1 | 0 |
Updated by this run for 7a1511cd2e0e6ce1019e259bdef959621492fe26.
There was a problem hiding this comment.
🟡 Changes recommended
Critical lock-restoration flaws can allow concurrent writes after guard expiry and misclassify exhausted EPERM failures as contention, resuming acquisition with the live lock still set aside.
2 open issues
What changed in this PR
This PR addresses #5635 by adding retries for Windows rename failures when the memory server restores a live lock during stale-lock cleanup.
Changes:
- Retries Windows
EPERM,EACCES, andEBUSYrestoration failures under the breaking guard. - Adds tests for transient failures, non-Windows error propagation, and retry exhaustion.
- Includes a patch changeset; no public MCP interface or configuration changes.
| File | Description |
|---|---|
src/memory/index.ts |
Adds guarded restoration retries and passes through retry timing. |
src/memory/__tests__/file-lock.test.ts |
Adds three restoration-failure regression tests. |
.changeset/memory-lock-restore-windows.md |
Records the memory server patch release note. |
Review effort: Balanced
…inly Review of #5637. The retry deadline counted from the first attempt rather than from when the guard was taken, and was not re-checked after the pause, so a retry could land after the guard went stale and another writer moved on. It now counts from just before the guard is taken, at half of staleMs, and is checked before every retry. A put-back that never lands now fails with an error of its own (the rename's error as its cause): Windows' EPERM would otherwise read as a busy lock and send the breaker back to acquiring with the live lock still aside. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
Round 1 answered in 7a1511c (gate exit 0). Both findings were defects in code this PR added, and both are fixed:
|

Closes #5635
Description
On Windows, the memory server's lock could still let two writers run at once. This is the hand-off #5565 meant to close (#5623). When a stale-lock break takes a successor's live lock aside by mistake, it renames that lock back over whatever a third writer created at the lock path in the gap. On Windows, a rename that replaces a file fails with
EPERMwhile anything holds that file open. The third writer keeps opening its own lock file while it waits out the break (confirmLock→refreshLock), so the put-back could fail.The failure was then swallowed as a busy lock, and the guard was dropped with the live lock still aside. The third writer confirmed its own token and ran beside the successor's holder.
The put-back now goes through
restoreLock, which retries under the guard while Windows refuses the rename. It retries only onEPERM,EACCESorEBUSY, and only onwin32. The retries stop afterstaleMs, past which the guard is taken to be a crash's and protects nothing anyway. Off Windows those codes mean a lasting failure, which still propagates at once.Server Details
Motivation and Context
#5635: since #5623 merged,
Test memory (Windows)had failed 4 of its first 9 runs, every PR included, on "does not let a writer that created the lock while a live one was aside run beside its holder". The cause was established on Windows CI with a throwaway branch that ran that test 20 times with the renames instrumented:v2/main'sindex.ts(job 135662372066)index.ts(job 135663708895)So this was a defect in the lock code on Windows, not a timing assumption in the test.
How Has This Been Tested?
file-lock.test.ts, each injecting the failure at the restore rename withprocess.platformmocked:EPERMrefusals are retried: the breaker and the third writer both time out, the third never runs, and the successor's lock is back in place with nothing left over.EPERMis not retried and propagates.staleMsstops the retries and propagates.v2/main'sindex.ts, the first and third fail. The first fails exactly as memory: hand-off test "does not let a writer that created the lock while a live one was aside run beside its holder" fails intermittently on Windows since #5623 #5635 does, with the breaker resolving instead of timing out.file-lock.test.tspass.npm run local:gateexits 0.Breaking Changes
None.
Types of changes
Checklist
🤖 Generated with Claude Code