@devries-cameron20 / t3code Mirror · read-only / commits / b0410a4453
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 12:00 UTC

fix(browser): serialize concurrent profile clears (#23434)

Aditya Garud committed Oct 31, 2026 at 02:18 UTC b0410a445397a695782e5ca27da8515e5f845d70
2 files changed +25
apps/server/src/preview/ServerBrowserContexts.test.ts
+23
@@ -183,6 +183,29 @@ describe("ServerBrowserContexts", () => {
183 await pool.close();
184 });
185
186 + it("waits for the context to close when the same profile is cleared concurrently", async () => {
187 + const human = makeContext();
188 + const closed = Promise.withResolvers<void>();
189 + human.close.mockImplementation(async () => closed.promise);
190 + launches.persistent.mockResolvedValue(human as unknown as BrowserContext);
191 + const pool = new ServerBrowserContexts(options());
192 + await pool.contextFor("work/team");
193 +
194 + const first = pool.clearProfile("work/team");
195 + const second = pool.clearProfile("work/team");
196 + const deletionsBeforeClose = launches.rm.mock.calls.length;
197 + closed.resolve();
198 + await Promise.all([first, second]);
199 +
200 + expect(deletionsBeforeClose).toBe(0);
201 + expect(human.close).toHaveBeenCalledTimes(1);
202 + expect(launches.rm).toHaveBeenCalledExactlyOnceWith("/test/profiles/work%2Fteam", {
203 + recursive: true,
204 + force: true,
205 + });
206 + await pool.close();
207 + });
208 +
209 it("opens a profile requested during its clear only after the storage is deleted", async () => {
210 launches.persistent.mockImplementation(async () => makeContext() as unknown as BrowserContext);
211 const configuration = options();
apps/server/src/preview/ServerBrowserContexts.ts
+2
@@ -212,6 +212,8 @@ export class ServerBrowserContexts {
212 async clearProfile(profileId: string) {
213 if (profileId === INCOGNITO_BROWSER_PROFILE_ID) return;
214 const key = JSON.stringify([profileId, null]);
215 + const existing = this.clearing.get(key);
216 + if (existing) return existing;
217 const clearing = (async () => {
218 const pending = this.contexts.get(key);
219 if (pending) {