Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Reject stale ChatGPT background requests after account changes
gaokui2010e7446abe9565
diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.tsindex ae3b9cf508..70e8ad3ff5 100644--- a/server/drivers/codex.test.ts+++ b/server/drivers/codex.test.ts@@ -1962,6 +1962,26 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)expect(recorder.events).toEqual([]);});+ it.each(["0.164.0", "0.166.0"])("rejects stale background generation after a pending %s version probe", async (version) => {+ const catalog = { default: "gpt-6.1-sol", options: [{ id: "gpt-6.1-sol", label: "GPT-6.1 Sol" }] };+ vi.spyOn(ChatGptPlanAuthController.prototype, "models").mockResolvedValue(catalog);+ vi.spyOn(ChatGptPlanAuthController.prototype, "accessToken").mockResolvedValue("old-synthetic-token");+ vi.spyOn(ChatGptPlanAuthController.prototype, "signOut").mockResolvedValue();+ vi.spyOn(ChatGptPlanAuthController.prototype, "start").mockRejectedValue(new Error("synthetic login"));+ let release!: (err: Error | null, stdout: string) => void;+ const probe = vi.spyOn(procs, "execCli").mockImplementation((_cli, _args, _opts, cb) => { release = cb; });+ const spawn = vi.spyOn(procs, "spawnCli");+ await create({ authMode: "chatgpt-plan" });+ const result = instance.generateMemoryText!("synthetic background prompt");+ const rejected = expect(result).rejects.toThrow("ChatGPT account changed");+ await vi.waitFor(() => expect(probe).toHaveBeenCalled());+ await instance.signOut!();+ await expect(instance.startAuthentication!()).rejects.toThrow("synthetic login");+ release(null, `codex-cli ${version}`);+ await rejected;+ expect(spawn).not.toHaveBeenCalled();+ });+it("blocks new ChatGPT turns and sign-in while active tasks stop and credentials revoke", async () => {const catalog = { default: "gpt-6.1-sol", options: [{ id: "gpt-6.1-sol", label: "GPT-6.1 Sol" }] };vi.spyOn(ChatGptPlanAuthController.prototype, "models").mockResolvedValue(catalog);diff --git a/server/drivers/codex.ts b/server/drivers/codex.tsindex a5c39357ea..0d6883e3ef 100644--- a/server/drivers/codex.ts+++ b/server/drivers/codex.ts@@ -1670,18 +1670,21 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {let authBridge: Awaited<ReturnType<typeof startChatGptTokenBridge>> | null = null;if (planAuth) {if (planSigningOut) throw new Error("This ChatGPT account is being disconnected.");- if (!models.options.length) await refreshModels();const generation = planGeneration;+ if (!models.options.length) await refreshModels();const token = await planAuth.accessToken();- if (planSigningOut || disposed) throw new Error("This ChatGPT account is being disconnected.");+ if (planSigningOut || disposed || generation !== planGeneration) throw new Error("This ChatGPT account changed.");mkdirSync(join(planDirectory, "codex"), { recursive: true, mode: 0o700 });- if (await dynamicPlanSupport()) {+ const dynamic = await dynamicPlanSupport();+ if (planSigningOut || disposed || generation !== planGeneration) throw new Error("This ChatGPT account changed.");+ if (dynamic) {authBridge = await startChatGptTokenBridge(async () => {if (planSigningOut || disposed || generation !== planGeneration) throw new Error("This ChatGPT account changed.");const value = await planAuth.accessToken();if (planSigningOut || disposed || generation !== planGeneration) throw new Error("This ChatGPT account changed.");return value;});+ if (planSigningOut || disposed || generation !== planGeneration) { authBridge.close(); throw new Error("This ChatGPT account changed."); }Object.assign(env, authBridge.env, { ELECTRON_RUN_AS_NODE: "1" });} else env.OPENMAUSBOT_CHATGPT_TOKEN = token;providerArgs = chatgptPlanCodexArgs(!!authBridge);