fix: harden Windows state persistence retries - #6
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens Windows session state persistence by adding retries around transient filesystem and partial-read failures, reducing the chance that temporary locks or partial reads cause dropped jobs or unnecessary non-atomic writes.
Changes:
- Retry
readStateon transient/partial JSON reads before treating state as corrupt. - Retry
renameon transient Windows lock errors before falling back to non-atomiccopyFile/overwrite inwriteFileAtomically. - Add deterministic comprehensive regressions for rename-lock retries and partial JSON read retries; remove duplicated README heading.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/index.js | Adds retry loops for transient state reads and for Windows rename failures before falling back to copy/overwrite. |
| scripts/comprehensive-test.mjs | Adds regressions simulating EPERM destination locks and partial JSON reads; exposes stateFile via the harness. |
| README.md | Removes a duplicated “Example progress.md” heading section. |
Suppressed comments (1)
scripts/comprehensive-test.mjs:552
- This test can become flaky if
loop-status(or related internals) reads the state file more than once; that would makepartialReadsexceed 3 even though the retry behavior is correct. Use a >= assertion so the test only enforces that retries happened before treating state as corrupt.
await h.command("loop-status")
assert.equal(partialReads, 3, "partial JSON should be retried before treating state as corrupt")
assert.equal(h.records.toasts.at(-1)?.message, "1 loop job(s).")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+529
to
+533
| const state = await h.readState() | ||
| assert.equal(state.jobs[0]?.name, "retry-safe") | ||
| assert.equal(renameAttempts, 3, "transient EPERM should retry rename") | ||
| assert.equal(fallbackCopies, 0, "successful rename retry should avoid non-atomic copy fallback") | ||
| } finally { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up hardening for #5.
renamefailures before falling back to non-atomic copy/overwrite.EPERMrename locks and partial JSON reads.Example progress.mdheading introduced in fix: Windows-safe atomic session state writes (EPERM) #5.Verification
node --check src/index.jsnode --check scripts/comprehensive-test.mjsThis keeps the fallback from unnecessarily widening the non-atomic write window and prevents a transient partial read from looking like
jobs: [].