RFC: Fix race condition in ~/.claude.json concurrent writes#29077
Closed
4RH1T3CT0R7 wants to merge 1 commit intoanthropics:mainfrom
Closed
RFC: Fix race condition in ~/.claude.json concurrent writes#290774RH1T3CT0R7 wants to merge 1 commit intoanthropics:mainfrom
4RH1T3CT0R7 wants to merge 1 commit intoanthropics:mainfrom
Conversation
Add comprehensive root cause analysis and fix plan for the race condition that corrupts ~/.claude.json when multiple Claude Code sessions run concurrently (30+ open issues). ANALYSIS.md: Decompiled code analysis of v2.1.59 showing 3 critical fallback paths that bypass atomic write and file locking protections. Documents 7 race condition vectors with severity ratings. FIX_PLAN.md: 6 proposed fixes with pseudocode patches, security review findings (2 critical, 3 high), edge cases, testing strategy, and future direction (SQLite migration). Related issues: anthropics#28809 anthropics#28813 anthropics#28824 anthropics#28837 anthropics#28861 anthropics#28888 anthropics#28922 anthropics#28923 anthropics#28965 anthropics#28988 anthropics#29003 anthropics#29032 anthropics#29036 anthropics#27983
|
See #28847 |
3 tasks
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
Comprehensive root cause analysis and fix plan for the race condition that corrupts
~/.claude.jsonwhen multiple Claude Code sessions run concurrently. This affects 30+ open issues and has been reported since June 2025.Key Findings
cli.jsto identify 3 critical fallback paths that bypass existing atomic write and file locking protectionsFe()atomic write function falls back to non-atomicwriteFileSync(withO_TRUNC) whenrenameSyncfails on WindowsW8()/saveGlobalConfigfunction falls back to unlocked writes whenproper-lockfilelock acquisition failss16()/ read function has no retry on JSON parse errors from partial readsW8()create high write contentionProposed Fixes (6 total)
Fe()— retry atomic write insteadW8()/nw()— retry lock with critical/non-critical distinctions16()read — handles partial reads gracefully~/.claude/session-state.jsonSecurity Review Incorporated
All findings addressed in the fix proposals.
Documents
Related Issues
Fixes: #28809, #28813, #28824, #28837, #28861, #28888, #28922, #28923, #28965, #28988, #29003, #29032, #29036, #27983
Additional: #28992, #28966, #28842, #29010, #28898, #29004, #29008, #28829, #28847, #15079, #13287, #24130, #27941, #27902
Historical (closed without resolution): #2593, #2810, #3117, #7243, #7273, #15608, #18998, #26717
Test plan