Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): reset closing state when erasing a profile fails
Sebastian B040dbd21ddd4
diff --git a/server/browser/service.test.ts b/server/browser/service.test.tsindex 6754ac4158..1a2d3bb095 100644--- a/server/browser/service.test.ts+++ b/server/browser/service.test.ts@@ -530,6 +530,26 @@ describe("browsers on one computer", () => {expect(dataDir).toBeTruthy();});+ it.skipIf(process.platform === "win32")("a failed erase reaches the caller and leaves the profile restartable, not stuck closing", async () => {+ const { service, call } = setup();+ await call("agent_browser_open", { url: "https://example.com/form" });+ const profile = service.profiles()[0]!;+ const { chmodSync, existsSync, writeFileSync } = await import("node:fs");+ const dir = profile.downloadDir;+ expect(existsSync(dir)).toBe(true);+ writeFileSync(join(dir, "keep.bin"), "x");+ chmodSync(dir, 0o500);+ try {+ await expect(service.erase("bot:a")).rejects.toThrow();+ expect(service.profiles()).toHaveLength(1);+ expect(profile.control.closing).toBe(false);+ } finally {+ chmodSync(dir, 0o755);+ }+ await service.erase("bot:a");+ expect(service.profiles()).toHaveLength(0);+ });+it("erases the profile's files when the erase joins a close already in progress, and starts nothing queued behind it", async () => {const { service, call, target, backend } = setup();await call("agent_browser_open", { url: "https://example.com/form" });diff --git a/server/browser/service.ts b/server/browser/service.tsindex 34852a5fef..d7a8d77dda 100644--- a/server/browser/service.ts+++ b/server/browser/service.ts@@ -301,10 +301,13 @@ export class BrowserService {if (profile.run === run) profile.run = null;profile.tabs.clear();if (reopened) profile.reopened = reopened;- if (erase) this.#erase(profile);- else if (profile.temporary) this.#eraseFiles(profile.key);- profile.control.closing = false;- profile.control.settle();+ try {+ if (erase) this.#erase(profile);+ else if (profile.temporary) this.#eraseFiles(profile.key);+ } finally {+ profile.control.closing = false;+ profile.control.settle();+ }}})());}