Skip to content

fix: preserve state when atomic replacement fails - #12

Merged
CL-BAF merged 1 commit into
CL-BAF:mainfrom
fatihcvs:fix/atomic-state-replacement
Sep 22, 2026
Merged

CL-BAF merged 1 commit into
CL-BAF:mainfrom
fatihcvs:fix/atomic-state-replacement

Conversation

@fatihcvs

Copy link
Copy Markdown
Contributor

Preserve the last valid state file when replacement fails. Both stores now use a shared flushed temporary-file writer with at most three rename attempts (50ms and 100ms backoff), best-effort temporary cleanup, and a clear persistence error retaining the original cause. The unsafe direct-write fallback is removed.

Closes #4.

Six regression cases cover both stores: first rename fails then succeeds; repeated rename failure preserves the exact previous bytes; and a partial temporary write fails without changing the destination or leaving temporary files. The repeated-failure tests failed before this fix. Persistence documentation is updated.

Validation: typecheck/build pass; 343 unit tests pass, 1 skipped; both contract tests pass. Touched TypeScript files pass Prettier. Repository-wide format checking still reports 89 unchanged files. The AGENTS graphify update command could not run because graphify is not installed (no graph file is present). Live provider integration was not exercised.

AI assistance: implemented and tested with OpenAI Codex.

@CL-BAF

CL-BAF commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Looks good. Thanks for fixing this and adding regression coverage for both stores.

@CL-BAF
CL-BAF merged commit 085330f into CL-BAF:main Sep 22, 2026
1 check passed
@fatihcvs

Copy link
Copy Markdown
Contributor Author

You're welcome! Thanks for reviewing and merging the state persistence fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve atomic state writes when Windows rename fails

2 participants