Interrupted settings saves can leave invalid JSON #1431
Replies: 1 comment
|
Confirmed by code inspection. The non-atomic write path is in The project already has the correct atomic-write pattern in function writeTelemetryStateAtomically(path: string, state: TelemetryState): void {
const temporaryPath = `${path}.${process.pid}.${randomUUID()}.tmp`;
try {
writeFileSync(temporaryPath, JSON.stringify(state, null, 2), {
encoding: "utf8",
flag: "wx", // fail if temp file already exists
mode: 0o600,
});
renameSync(temporaryPath, path);
} finally {
try {
unlinkSync(temporaryPath);
} catch {
// The rename succeeded or the temporary file was never created.
}
}
}On POSIX systems The |
Uh oh!
There was an error while loading. Please reload this page.
The coding-agent settings storage locks writes but writes the settings file in place. Reproduction: start a settings update, then terminate the process after truncation and before the JSON is fully written. On the next launch, the settings file may be empty or incomplete JSON and cannot be parsed. Expected behavior: after any interrupted update, the file remains either the complete previous JSON or the complete new JSON. A small candidate fix writes and flushes a temporary file in the same directory, then renames it over the settings file while preserving its existing permissions. I can provide the patch and test results if maintainers consider this in scope.
All reactions