@devries-cameron20 / t3code-1 / commits / b113eb0209
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): failed settings saves no longer leave temp files behind (#29635)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Alex Southwell committed Nov 3, 2026 at 23:14 UTC b113eb0209952d404ecb66a0e49c6e7277add703
4 files changed +90 -40
apps/desktop/src/settings/DesktopAppSettings.test.ts
+23
@@ -264,6 +264,29 @@ describe("DesktopSettings", () => {
264 ),
265 );
266
267 + it.effect("removes its temporary file when replacing the settings file fails", () =>
268 + withSettings(
269 + Effect.gen(function* () {
270 + const environment = yield* DesktopEnvironment.DesktopEnvironment;
271 + const fileSystem = yield* FileSystem.FileSystem;
272 + const settings = yield* DesktopAppSettings.DesktopAppSettings;
273 + yield* fileSystem.makeDirectory(`${environment.desktopSettingsPath}/occupied`, {
274 + recursive: true,
275 + });
276 +
277 + const error = yield* settings.setServerExposureMode("network-accessible").pipe(Effect.flip);
278 +
279 + assert.equal(error.operation, "replace-settings-file");
280 + assert.deepEqual(
281 + (yield* fileSystem.readDirectory(environment.stateDir)).filter((name) =>
282 + name.endsWith(".tmp"),
283 + ),
284 + [],
285 + );
286 + }),
287 + ),
288 + );
289 +
290 it.effect("migrates legacy implicit update channels to the runtime default", () =>
291 withSettings(
292 Effect.gen(function* () {
apps/desktop/src/settings/DesktopAppSettings.ts
+22 -20
@@ -442,26 +442,28 @@ const writeSettings = Effect.fn("desktop.settings.writeSettings")(function* (inp
442 }),
443 ),
444 );
445 - yield* input.fileSystem.writeFileString(tempPath, `${encoded}\n`).pipe(
446 - Effect.mapError(
447 - (cause) =>
448 - new DesktopSettingsWriteError({
449 - operation: "write-temporary-file",
450 - path: tempPath,
451 - cause,
452 - }),
453 - ),
454 - );
455 - yield* input.fileSystem.rename(tempPath, targetPath).pipe(
456 - Effect.mapError(
457 - (cause) =>
458 - new DesktopSettingsWriteError({
459 - operation: "replace-settings-file",
460 - path: input.settingsPath,
461 - cause,
462 - }),
463 - ),
464 - );
445 + yield* Effect.gen(function* () {
446 + yield* input.fileSystem.writeFileString(tempPath, `${encoded}\n`).pipe(
447 + Effect.mapError(
448 + (cause) =>
449 + new DesktopSettingsWriteError({
450 + operation: "write-temporary-file",
451 + path: tempPath,
452 + cause,
453 + }),
454 + ),
455 + );
456 + yield* input.fileSystem.rename(tempPath, targetPath).pipe(
457 + Effect.mapError(
458 + (cause) =>
459 + new DesktopSettingsWriteError({
460 + operation: "replace-settings-file",
461 + path: input.settingsPath,
462 + cause,
463 + }),
464 + ),
465 + );
466 + }).pipe(Effect.ensuring(input.fileSystem.remove(tempPath, { force: true }).pipe(Effect.ignore)));
467 });
468
469 /** @public */
apps/desktop/src/settings/DesktopClientSettings.test.ts
+23
@@ -144,6 +144,29 @@ describe("DesktopClientSettings", () => {
144 ),
145 );
146
147 + it.effect("removes its temporary file when replacing the settings file fails", () =>
148 + withClientSettings(
149 + Effect.gen(function* () {
150 + const environment = yield* DesktopEnvironment.DesktopEnvironment;
151 + const fileSystem = yield* FileSystem.FileSystem;
152 + const settings = yield* DesktopClientSettings.DesktopClientSettings;
153 + yield* fileSystem.makeDirectory(`${environment.clientSettingsPath}/occupied`, {
154 + recursive: true,
155 + });
156 +
157 + const error = yield* settings.set(clientSettings).pipe(Effect.flip);
158 +
159 + assert.equal(error.operation, "replace-settings-file");
160 + assert.deepEqual(
161 + (yield* fileSystem.readDirectory(environment.stateDir)).filter((name) =>
162 + name.endsWith(".tmp"),
163 + ),
164 + [],
165 + );
166 + }),
167 + ),
168 + );
169 +
170 it.effect.each([
171 { label: "permission", reason: "PermissionDenied" },
172 { label: "I/O", reason: "Unknown" },
apps/desktop/src/settings/DesktopClientSettings.ts
+22 -20
@@ -162,26 +162,28 @@ const writeClientSettings = Effect.fnUntraced(function* (input: {
162 }),
163 ),
164 );
165 - yield* input.fileSystem.writeFileString(tempPath, `${encoded}\n`).pipe(
166 - Effect.mapError(
167 - (cause) =>
168 - new DesktopClientSettingsWriteError({
169 - operation: "write-temporary-file",
170 - path: tempPath,
171 - cause,
172 - }),
173 - ),
174 - );
175 - yield* input.fileSystem.rename(tempPath, targetPath).pipe(
176 - Effect.mapError(
177 - (cause) =>
178 - new DesktopClientSettingsWriteError({
179 - operation: "replace-settings-file",
180 - path: input.settingsPath,
181 - cause,
182 - }),
183 - ),
184 - );
165 + yield* Effect.gen(function* () {
166 + yield* input.fileSystem.writeFileString(tempPath, `${encoded}\n`).pipe(
167 + Effect.mapError(
168 + (cause) =>
169 + new DesktopClientSettingsWriteError({
170 + operation: "write-temporary-file",
171 + path: tempPath,
172 + cause,
173 + }),
174 + ),
175 + );
176 + yield* input.fileSystem.rename(tempPath, targetPath).pipe(
177 + Effect.mapError(
178 + (cause) =>
179 + new DesktopClientSettingsWriteError({
180 + operation: "replace-settings-file",
181 + path: input.settingsPath,
182 + cause,
183 + }),
184 + ),
185 + );
186 + }).pipe(Effect.ensuring(input.fileSystem.remove(tempPath, { force: true }).pipe(Effect.ignore)));
187 });
188
189 export const make = Effect.gen(function* () {