Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(grok): a sign-in check that fails for a moment is retried, not read as a sign-out (#6997)
Milind Sonide4edc3ee9bc
diff --git a/server/drivers/acp/grok-signals.test.ts b/server/drivers/acp/grok-signals.test.tsindex 8d08417ab9..c450de2744 100644--- a/server/drivers/acp/grok-signals.test.ts+++ b/server/drivers/acp/grok-signals.test.ts@@ -10,10 +10,13 @@ import { ensureDirs } from "../../config.ts";import type { ProviderInstance, RuntimeEvent } from "../../contracts.ts";import { processBudget } from "../../process-room.ts";import { outOfProcesses } from "../../process-shortage.ts";+import { classifyRoutineFailure } from "../../routine-recovery.ts";import { removeTempDir } from "../../testing/cleanup.ts";import { recordEvents } from "../../testing/events.ts";import { CustomAcpDriver } from "./custom.ts";+import { AcpReportedFailure, acpRuntimeFailure } from "./failure-words.ts";import { GrokAgentDriver } from "./grok.ts";+import { grokReportedFailure } from "./grok-signals.ts";const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "../../testing/fake-acp-cli.ts");const TOKIO = "grok: failed to start tokio runtime: blocking pool pre-warm stalled after 14 of 16 threads";@@ -172,3 +175,24 @@ describe("a Grok that could not start its threads", () => {expect(error!.message).toContain("unexpected key");});});++describe("Grok's sign-in check failing for a moment", () => {+ // grok 1.0.41's words, as a session/prompt error on a Cloud whose Grok stayed signed in.+ const BLIP = "Internal error: Unauthorized (401) from https://cli-chat-proxy.grok.com/v1/responses: Authentication required\n\n"+ + " Model: grok-4.6\n Auth: Oidc\n Version: 1.0.41\n Available: grok-4.6, grok-4.5\n\n"+ + "Authentication is temporarily unavailable (often a network blip right after wake). Your session is still signed in and will "+ + "recover automatically — retry in a few seconds; no need to run /login. (session/prompt)";++ it("is a passing failure a routine run retries, never a sign-out", () => {+ expect(classifyRoutineFailure(BLIP)).toMatchObject({ kind: "owner", cause: "signed_out" });+ const reported = grokReportedFailure(Object.assign(new Error(BLIP), { code: -32603 }));+ expect(reported).toBeInstanceOf(AcpReportedFailure);+ expect(acpRuntimeFailure(reported, "Grok").message).toBe(+ "Grok couldn't confirm its sign-in for a moment (often a network error right after waking). It is still signed in: try again in a few seconds.");+ expect(classifyRoutineFailure(reported!.message)).toMatchObject({ kind: "retry" });+ });++ it("leaves a real sign-out as it was", () => {+ expect(grokReportedFailure(Object.assign(new Error("Internal error: Unauthorized (401): Authentication required. Run grok login."), { code: -32603 }))).toBeUndefined();+ });+});diff --git a/server/drivers/acp/grok-signals.ts b/server/drivers/acp/grok-signals.tsindex 1da70d9764..fe29f40a6e 100644--- a/server/drivers/acp/grok-signals.ts+++ b/server/drivers/acp/grok-signals.ts@@ -50,7 +50,14 @@ export async function grokPromptOutcome(): Promise<(result: unknown) => Promise<};}+/** grok 1.0.41's words when its sign-in check failed for a moment while it stays signed in: its own 401 line comes first,+ * so the raw text reads as a sign-out, and a routine run would stop for a sign-in nobody needs to do. */+const GROK_AUTH_BLIP = /\bAuthentication is temporarily unavailable\b[\s\S]*\bstill signed in\b/i;+export function grokReportedFailure(error: unknown): Error | undefined {+ if (error instanceof Error && GROK_AUTH_BLIP.test(error.message)) {+ return new AcpReportedFailure({ message: "Grok couldn't confirm its sign-in for a moment (often a network error right after waking). It is still signed in: try again in a few seconds." }, false);+ }if ((error as { code?: unknown } | null)?.code !== GROK_RATE_LIMITED) return undefined;return grokLimitFailure(error instanceof Error ? error.message : "");}