clawwork-ai/ClawWork
View on GitHub[Bug] writeConfig is not atomic — mid-write crash corrupts user config
Open
#385 opened on Apr 15, 2026
area/artifacthelp wantedkind/bug
Repository metrics
- Stars
- (519 stars)
- PR merge metrics
- (PR metrics pending)
Description
Problem
writeConfig calls writeFileSync directly on the target path. If the process is killed or the machine loses power mid-write, the config file is left in a partial state — subsequent readConfig calls trigger a JSON parse error and the user loses their entire configuration (see the companion silent-null bug in the same file).
Location
File: packages/desktop/src/main/workspace/config.ts:168-172
export function writeConfig(config: AppConfig): void {
const cfgPath = configFilePath();
const encrypted = encryptGatewayCredentials(config);
writeFileSync(cfgPath, JSON.stringify(encrypted, null, 2), { encoding: 'utf-8', mode: 0o600 });
}
Fix Approach
Use the classic write-to-temp-then-rename pattern:
- Write the encoded JSON to
cfgPath + '.tmp'with the samemode: 0o600. - Call
renameSync(cfgPath + '.tmp', cfgPath)—renameis atomic on both POSIX and NTFS. - On write failure, best-effort clean up the temp file before re-throwing the original error.
Verification
- Run
pnpm check— must pass. - Manual: force-kill the process immediately after a
writeConfiginvocation, relaunch — config must be either the old version or the new version, never a half-written mix.
Context
- WG: Artifact & File System
- Priority: Low
- Estimated effort: 20-30 minutes