@devries-cameron20 / t3code-1 / commits / 5c97adaf6b
Fork 0

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

fix(desktop): clear stale GPU caches when the Electron version changes (#33641)

Julius Marminge committed Nov 10, 2026 at 19:11 UTC 5c97adaf6b1be33ab08caa432f7a2656ae49df53
4 files changed +151 -1
apps/desktop/src/app/DesktopClerk.ts
+5
@@ -116,6 +116,11 @@ export const make = Effect.gen(function* () {
116 yield* electronApp.quit;
117 return yield* Effect.interrupt;
118 }
119 + // Chromium opens these caches at the first event-loop turn, before ready.
120 + yield* DesktopUserData.clearStaleGpuCaches({
121 + userDataPath,
122 + electronVersion: process.versions.electron,
123 + });
124
125 const pendingSecondInstances: Array<readonly string[]> = [];
126 let handleSecondInstance = (argv: readonly string[]) => {
apps/desktop/src/app/DesktopPreReadyFileSystem.ts
+7
@@ -49,6 +49,13 @@ export const make = FileSystem.makeNoop({
49 syncFs("makeDirectory", path, () => {
50 NodeFS.mkdirSync(path, { recursive: options?.recursive ?? false });
51 }),
52 + remove: (path, options) =>
53 + syncFs("remove", path, () =>
54 + NodeFS.rmSync(path, {
55 + recursive: options?.recursive ?? false,
56 + force: options?.force ?? false,
57 + }),
58 + ),
59 writeFileString: (path, data, options) =>
60 syncFs("writeFileString", path, () =>
61 NodeFS.writeFileSync(path, data, { flag: options?.flag ?? "w" }),
apps/desktop/src/app/DesktopUserData.test.ts
+99 -1
@@ -3,8 +3,9 @@ import { assert, it } from "@effect/vitest";
3 import * as Effect from "effect/Effect";
4 import * as FileSystem from "effect/FileSystem";
5 import * as Path from "effect/Path";
6 +import * as PlatformError from "effect/PlatformError";
7
7 -import { resolveUserDataPath } from "./DesktopUserData.ts";
8 +import { clearStaleGpuCaches, resolveUserDataPath } from "./DesktopUserData.ts";
9
10 it.effect.each(["t3code", "T3 Code (Alpha)"])(
11 "preserves Windows credential keys from %s without copying browser databases",
@@ -40,3 +41,100 @@ it.effect.each(["t3code", "T3 Code (Alpha)"])(
41 );
42 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
43 );
44 +
45 +const gpuCacheDirectories = [
46 + "GPUCache",
47 + "GrShaderCache",
48 + "ShaderCache",
49 + "DawnGraphiteCache",
50 + "DawnWebGPUCache",
51 + "GPUPersistentCache",
52 +];
53 +
54 +it.effect.each([
55 + { profile: "written by Electron 44.10.0", marker: "44.10.0" },
56 + { profile: "with no recorded Electron version", marker: undefined },
57 +])("clears GPU caches $profile once when Electron 44.10.1 starts", ({ marker }) =>
58 + Effect.gen(function* () {
59 + const fs = yield* FileSystem.FileSystem;
60 + const path = yield* Path.Path;
61 + const userDataPath = yield* fs.makeTempDirectoryScoped({ prefix: "t3-v2-gpu-cache-" });
62 + for (const name of gpuCacheDirectories) {
63 + yield* fs.makeDirectory(path.join(userDataPath, name), { recursive: true });
64 + yield* fs.writeFileString(path.join(userDataPath, name, "data_0"), "44.10.0 shaders");
65 + }
66 + yield* fs.makeDirectory(path.join(userDataPath, "Local Storage"), { recursive: true });
67 + yield* fs.writeFileString(path.join(userDataPath, "Local Storage", "LOCK"), "profile");
68 + yield* fs.writeFileString(path.join(userDataPath, "Local State"), "profile");
69 + if (marker !== undefined) {
70 + yield* fs.writeFileString(path.join(userDataPath, "gpu-cache-electron-version"), marker);
71 + }
72 +
73 + yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
74 +
75 + const survivingCaches: Array<string> = [];
76 + for (const name of gpuCacheDirectories) {
77 + if (yield* fs.exists(path.join(userDataPath, name))) survivingCaches.push(name);
78 + }
79 + assert.deepStrictEqual(survivingCaches, []);
80 + assert.equal(
81 + yield* fs.readFileString(path.join(userDataPath, "Local Storage", "LOCK")),
82 + "profile",
83 + );
84 + assert.equal(yield* fs.readFileString(path.join(userDataPath, "Local State")), "profile");
85 +
86 + yield* fs.makeDirectory(path.join(userDataPath, "GPUCache"));
87 + yield* fs.writeFileString(path.join(userDataPath, "GPUCache", "data_0"), "44.10.1 shaders");
88 + yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
89 + assert.equal(
90 + yield* fs.readFileString(path.join(userDataPath, "GPUCache", "data_0")),
91 + "44.10.1 shaders",
92 + );
93 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
94 +);
95 +
96 +it.effect("keeps GPU caches built on the first launch of a fresh install", () =>
97 + Effect.gen(function* () {
98 + const fs = yield* FileSystem.FileSystem;
99 + const path = yield* Path.Path;
100 + const appData = yield* fs.makeTempDirectoryScoped({ prefix: "t3-v2-fresh-" });
101 + const userDataPath = path.join(appData, "t3code-v2");
102 +
103 + yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
104 + yield* fs.makeDirectory(path.join(userDataPath, "GPUCache"));
105 + yield* fs.writeFileString(path.join(userDataPath, "GPUCache", "data_0"), "44.10.1 shaders");
106 + yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
107 +
108 + assert.equal(
109 + yield* fs.readFileString(path.join(userDataPath, "GPUCache", "data_0")),
110 + "44.10.1 shaders",
111 + );
112 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
113 +);
114 +
115 +it.effect("retries on the next launch when a GPU cache cannot be removed", () =>
116 + Effect.gen(function* () {
117 + const writes: Array<string> = [];
118 + const fileSystem = FileSystem.makeNoop({
119 + remove: (path) =>
120 + Effect.fail(
121 + PlatformError.systemError({
122 + _tag: "PermissionDenied",
123 + module: "FileSystem",
124 + method: "remove",
125 + pathOrDescriptor: path,
126 + }),
127 + ),
128 + writeFileString: (path) =>
129 + Effect.sync(() => {
130 + writes.push(path);
131 + }),
132 + });
133 +
134 + yield* clearStaleGpuCaches({ userDataPath: "/profile", electronVersion: "44.10.1" }).pipe(
135 + Effect.provideService(FileSystem.FileSystem, fileSystem),
136 + );
137 +
138 + assert.deepStrictEqual(writes, []);
139 + }).pipe(Effect.provide(NodeServices.layer)),
140 +);
apps/desktop/src/app/DesktopUserData.ts
+40
@@ -95,3 +95,43 @@ export const resolveUserDataPath = Effect.fn("desktop.userData.resolveUserDataPa
95 return destinationPath;
96 },
97 );
98 +
99 +const GPU_CACHE_DIRECTORIES = [
100 + "GPUCache",
101 + "GrShaderCache",
102 + "ShaderCache",
103 + "DawnGraphiteCache",
104 + "DawnWebGPUCache",
105 + "GPUPersistentCache",
106 +];
107 +
108 +// Keyed on Electron, not Chromium: Electron patches ship Chromium backports under the same Chrome version.
109 +export const clearStaleGpuCaches = Effect.fn("desktop.userData.clearStaleGpuCaches")(
110 + function* (input: { readonly userDataPath: string; readonly electronVersion: string }) {
111 + const fs = yield* FileSystem.FileSystem;
112 + const path = yield* Path.Path;
113 + const markerPath = path.join(input.userDataPath, "gpu-cache-electron-version");
114 + const cachedVersion = yield* fs.readFileString(markerPath).pipe(
115 + Effect.catchIf(
116 + (error) => error.reason._tag === "NotFound",
117 + () => Effect.undefined,
118 + ),
119 + );
120 + if (cachedVersion?.trim() === input.electronVersion) return;
121 + for (const name of GPU_CACHE_DIRECTORIES) {
122 + yield* fs.remove(path.join(input.userDataPath, name), { recursive: true, force: true });
123 + }
124 + yield* fs.makeDirectory(input.userDataPath, { recursive: true });
125 + yield* fs.writeFileString(markerPath, input.electronVersion);
126 + },
127 + (effect, input) =>
128 + effect.pipe(
129 + Effect.catch((error) =>
130 + Effect.logWarning("could not clear stale GPU caches", {
131 + userDataPath: input.userDataPath,
132 + electronVersion: input.electronVersion,
133 + error: error.message,
134 + }),
135 + ),
136 + ),
137 +);