Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Teammates: a needs-setup mark clears only after a later turn the engine itself answered (#7009)
Milind Soniba1b9e0f0cbb
diff --git a/server/host/setup-recovered.test.ts b/server/host/setup-recovered.test.tsindex 88544d7776..cf9afb3f16 100644--- a/server/host/setup-recovered.test.ts+++ b/server/host/setup-recovered.test.ts@@ -5,64 +5,116 @@ import { DATA_DIR } from "../config.ts";import type { ModelSelection } from "../contracts.ts";import { peerStatus, peerStatusWords } from "../peer-roster.ts";import { Store } from "../store.ts";-import { clearSetupFailures } from "./setup-recovered.ts";+import { createSetupRecovery } from "./setup-recovered.ts";const selection = (): ModelSelection => ({ instanceId: "claude", model: "claude-sonnet-5" });const roster = (store: Store, botId: string) => peerStatusWords(peerStatus(store.bot(botId)?.activity, store.bot(botId)?.busy));+const ENGINE_TURN = { replayed: false, stopped: false };++/** A bot with a conversation that failed setup and another whose turn is running; `clock` is when marks are made. */+function setup(options: { failedEngine?: ModelSelection } = {}) {+ const store = new Store(selection);+ const bot = store.createBot();+ const failed = store.createTask(bot.id, "signed out", true, undefined, undefined, undefined, options.failedEngine)!;+ const later = store.createTask(bot.id, "later")!;+ let clock = 0;+ const recovery = createSetupRecovery(store, () => clock);+ const markFailed = () => {+ store.setTaskActivity(bot.id, failed.threadId, "dead");+ recovery.failed(bot.id, failed.threadId);+ };+ const startLater = () => {+ store.setTaskActivity(bot.id, later.threadId, "working");+ return store.taskByThread(bot.id, later.threadId)!.turnStartedAt!;+ };+ const activity = () => store.taskByThread(bot.id, failed.threadId)?.activity;+ return { store, bot, failed, later, recovery, markFailed, startLater, activity, at: (time: number) => { clock = time; } };+}describe("a bot whose setup failed once", () => {beforeEach(() => { rmSync(DATA_DIR, { recursive: true, force: true }); });- it("reads as available again once another of its turns succeeds, not until the failed conversation runs again", () => {- const store = new Store(selection);- const bot = store.createBot();- const failed = store.createTask(bot.id, "signed out")!;- const later = store.createTask(bot.id, "later")!;- // Its engine's sign-in had expired in one conversation (server/index.ts marks it "dead").- store.setTaskActivity(bot.id, failed.threadId, "dead");+ it("reads as available again once a turn its engine answered succeeds, not only when the failed conversation runs again", () => {+ const { store, bot, later, recovery, markFailed, startLater, activity, at } = setup();+ at(1);+ markFailed();expect(roster(store, bot.id)).toBe("unavailable — needs setup");- // The person signs in again and another conversation of the same bot works.- store.setTaskActivity(bot.id, later.threadId, "working");- store.setTaskActivity(bot.id, later.threadId, "idle");- expect(roster(store, bot.id)).toBe("unavailable — needs setup");- clearSetupFailures(store, bot.id, later.threadId);- expect(roster(store, bot.id)).toBe("available");- expect(store.taskByThread(bot.id, failed.threadId)?.activity).toBe("idle");+ startLater();+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("idle");+ expect(roster(store, bot.id)).not.toBe("unavailable — needs setup");});- it("keeps a conversation on another engine marked: a turn that works on one engine says nothing of another's sign-in", () => {- const store = new Store(selection);- const bot = store.createBot();- const other = store.createTask(bot.id, "other engine", true, undefined, undefined, undefined, { instanceId: "codex", model: "gpt-5" })!;- const same = store.createTask(bot.id, "same engine")!;- store.setTaskActivity(bot.id, other.threadId, "dead");- clearSetupFailures(store, bot.id, same.threadId);- expect(store.taskByThread(bot.id, other.threadId)?.activity).toBe("dead");- expect(roster(store, bot.id)).toBe("unavailable — needs setup");+ it("keeps a mark made after the succeeding turn started: that turn began before the sign-in lapsed", () => {+ const { bot, later, recovery, markFailed, startLater, activity, at } = setup();+ const startedAt = startLater();+ at(startedAt + 60_000);+ markFailed();+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("dead");+ });++ it("keeps the mark for a turn saved steps answered with no engine call, and for a turn the person stopped", () => {+ const { bot, later, recovery, markFailed, startLater, activity, at } = setup();+ at(1);+ markFailed();+ startLater();+ recovery.succeeded(bot.id, later.threadId, { replayed: true, stopped: false });+ expect(activity()).toBe("dead");+ recovery.succeeded(bot.id, later.threadId, { replayed: false, stopped: true });+ expect(activity()).toBe("dead");+ });++ it("keeps the mark when the succeeding turn never ran as a turn (no start time)", () => {+ const { bot, later, recovery, markFailed, activity, at } = setup();+ at(1);+ markFailed();+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("dead");+ });++ it("keeps a conversation set to another engine marked", () => {+ const { bot, later, recovery, markFailed, startLater, activity, at } = setup({ failedEngine: { instanceId: "codex", model: "gpt-5" } });+ at(1);+ markFailed();+ startLater();+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("dead");});- it("goes by the engine each conversation last ran on: a turn a stand-in engine carried clears nothing on the signed-out one", () => {- const store = new Store(selection);- const bot = store.createBot();- const failed = store.createTask(bot.id, "signed out")!;- const carried = store.createTask(bot.id, "carried by a stand-in")!;+ it("goes by the engine each conversation last ran on: a stand-in engine's success clears nothing on the signed-out one", () => {+ const { store, bot, failed, later, recovery, markFailed, startLater, activity, at } = setup();+ at(1);store.markTaskDispatched(bot.id, failed.threadId, "claude");- store.setTaskActivity(bot.id, failed.threadId, "dead");- store.markTaskDispatched(bot.id, carried.threadId, "codex");- clearSetupFailures(store, bot.id, carried.threadId);- expect(store.taskByThread(bot.id, failed.threadId)?.activity).toBe("dead");- store.markTaskDispatched(bot.id, carried.threadId, "claude");- clearSetupFailures(store, bot.id, carried.threadId);- expect(store.taskByThread(bot.id, failed.threadId)?.activity).toBe("idle");+ markFailed();+ startLater();+ store.markTaskDispatched(bot.id, later.threadId, "codex");+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("dead");+ store.markTaskDispatched(bot.id, later.threadId, "claude");+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("idle");+ });++ it("reads a conversation carried in from elsewhere (no engine yet) as on the engine it is set to", () => {+ const { store, bot, failed, later, recovery, markFailed, startLater, activity, at } = setup();+ at(1);+ store.markTaskDispatched(bot.id, failed.threadId, "__openmaus_external_context__:4f1c");+ markFailed();+ startLater();+ store.markTaskDispatched(bot.id, later.threadId, "claude");+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);+ expect(activity()).toBe("idle");});- it("leaves other activities as they are", () => {- const store = new Store(selection);- const bot = store.createBot();+ it("leaves other activities as they are, and ignores a bot or conversation it does not know", () => {+ const { store, bot, later, recovery, startLater } = setup();const waiting = store.createTask(bot.id, "asks")!;store.setTaskActivity(bot.id, waiting.threadId, "waiting-on-you");- clearSetupFailures(store, bot.id, waiting.threadId);+ startLater();+ recovery.succeeded(bot.id, later.threadId, ENGINE_TURN);expect(store.taskByThread(bot.id, waiting.threadId)?.activity).toBe("waiting-on-you");- clearSetupFailures(store, "no-such-bot", waiting.threadId);+ recovery.succeeded("no-such-bot", later.threadId, ENGINE_TURN);+ recovery.succeeded(bot.id, "no-such-thread", ENGINE_TURN);});});diff --git a/server/host/setup-recovered.ts b/server/host/setup-recovered.tsindex f39eb16576..09c16d92bf 100644--- a/server/host/setup-recovered.ts+++ b/server/host/setup-recovered.ts@@ -1,23 +1,47 @@// A setup failure (an engine signed out or out of credits) marks its conversation "dead", and one dead conversation makes// the whole bot read "unavailable — needs setup" to its teammates (peer-roster.ts), in the app and in reports, until that-// same conversation runs again. A later turn of the bot that succeeds on the same engine shows that engine's setup works-// now, so the label goes with it. A conversation whose engine is another keeps it: that engine may still be signed out.+// same conversation runs again. A later turn of the bot that its engine answered shows that engine's setup works now, so+// the label goes with it, for the conversations marked before that turn started on the same engine. Never for:+// - a conversation on another engine: that engine may still be signed out;+// - a turn saved steps answered with no engine call (saved-steps/dispatch.ts): it proves nothing about the engine;+// - a turn the person stopped;+// - a mark made after the succeeding turn started: that turn began before the sign-in lapsed.import type { Store } from "../store.ts";/** server/index.ts parks this in lastInstanceId when a conversation was carried in from elsewhere: no engine. */const EXTERNAL_CONTEXT = "__openmaus_external_context__:";type Task = { lastInstanceId?: string; modelSelection?: { instanceId: string } };+type Turn = { replayed: boolean; stopped: boolean };-export function clearSetupFailures(store: Pick<Store, "bot" | "setTaskActivity">, botId: string, threadId: string): void {- const bot = store.bot(botId);- const succeeded = bot?.tasks?.find((task) => task.threadId === threadId);- if (!bot || !succeeded) return;- // The engine a turn was last sent to (a stand-in after a failover included), else the one the conversation is set to.- const engineOf = (task: Task) => task.lastInstanceId && !task.lastInstanceId.startsWith(EXTERNAL_CONTEXT)- ? task.lastInstanceId : (task.modelSelection ?? bot.modelSelection).instanceId;- const engine = engineOf(succeeded);- for (const task of bot.tasks ?? []) {- if (task.activity === "dead" && engineOf(task) === engine) store.setTaskActivity(botId, task.threadId, "idle");- }+export function createSetupRecovery(store: Pick<Store, "bot" | "setTaskActivity">, now: () => number = Date.now) {+ /** When each conversation was marked dead, by bot and thread. Marks do not outlive the server (store.ts resets them). */+ const markedAt = new Map<string, number>();+ const key = (botId: string, threadId: string) => `${botId}\u0000${threadId}`;+ return {+ /** A setup failure marked this conversation dead (server/index.ts, runtime.error). */+ failed(botId: string, threadId: string): void {+ markedAt.set(key(botId, threadId), now());+ },+ /** A turn of the bot completed successfully in this conversation. */+ succeeded(botId: string, threadId: string, turn: Turn): void {+ if (turn.replayed || turn.stopped) return;+ const bot = store.bot(botId);+ const done = bot?.tasks?.find((task) => task.threadId === threadId);+ const startedAt = done?.turnStartedAt;+ if (!bot || !done || startedAt === undefined) return;+ // The engine a turn was last sent to (a stand-in after a failover included), else the one the conversation is set to.+ const engineOf = (task: Task) => task.lastInstanceId && !task.lastInstanceId.startsWith(EXTERNAL_CONTEXT)+ ? task.lastInstanceId : (task.modelSelection ?? bot.modelSelection).instanceId;+ const engine = engineOf(done);+ for (const task of bot.tasks ?? []) {+ if (task.activity !== "dead" || engineOf(task) !== engine) continue;+ if ((markedAt.get(key(botId, task.threadId)) ?? 0) >= startedAt) continue;+ markedAt.delete(key(botId, task.threadId));+ store.setTaskActivity(botId, task.threadId, "idle");+ }+ },+ };}++export type SetupRecovery = ReturnType<typeof createSetupRecovery>;diff --git a/server/index.ts b/server/index.tsindex b9ab338495..5e728a7391 100644--- a/server/index.ts+++ b/server/index.ts@@ -277,7 +277,7 @@ import { CLOUD_HOME_SECRET_KEYS, CLOUD_IGNORED_KEYS, cloudHomeConfiguration, cloimport { botBox, startBotBoxAtBoot } from "./bot-box/boot.ts"; import { attachmentsForBox } from "./box-attachments.ts"; import { brokerPath } from "./bot-box/broker-probe.ts";import { createCloudSignedHost } from "./host/cloud-signed-host.ts"; import { createDeleteLeftovers, engineSessionFolders, instanceEnvironment } from "./host/delete-leftovers.ts"; import { createBotNameClash } from "./host/bot-name-clash.ts"; import { hiddenThreadRefusal, hideOthersSyncFolders } from "./host/team-private.ts"; import { createTeamMemberLeft, memoryLayerRecords } from "./host/team-member-left.ts"; import { createUploadOwners, uploadsFor } from "./host/member-uploads.ts"; import { createMemberOwnBot } from "./host/member-own-bot.ts"; import { createVisibilityHost } from "./host/visibility-host.ts"; import { createBotAccessHost, refusalFor, relayedSendRefusal } from "./host/bot-access-gate.ts"; import { createBotAccessRoutes, writeAccess } from "./routes/bot-access.ts"; import { createAccessRequests } from "./host/access-requests.ts";import { cloudPowerNow, createCloudPower, registerCloudPower, wokeFromSleep, type CloudPower } from "./cloud-power.ts"; import { createWokeNotifier } from "./cloud-woke.ts"; import { createSharedComputerRoutes } from "./routes/shared-computers.ts";-import { lentCopies, noteSyncBotTurn } from "./routes/cloud-sync.ts"; import { mcpReconnectLine, retryBrokeredMcp } from "./bot-box/broker-mcp.ts"; import { clearSetupFailures } from "./host/setup-recovered.ts";+import { lentCopies, noteSyncBotTurn } from "./routes/cloud-sync.ts"; import { mcpReconnectLine, retryBrokeredMcp } from "./bot-box/broker-mcp.ts"; import { createSetupRecovery } from "./host/setup-recovered.ts";import { type CloudOwnership } from "./cloud-owner.ts"; import { memberLoginRefusal, personalMoveRefusal } from "./cloud-team.ts"; import { createCloudTeamHost, type MemberProfile } from "./host/cloud-team-host.ts"; import { createTeamFilesHost } from "./host/team-files-host.ts"; import { createTeamFilesRoutes } from "./routes/team-files.ts"; import { engineHomes } from "./engine-homes/engine-homes.ts"; import { audienceMember, layerId, memberAudience } from "./audience.ts"; import { createPersonRooms, createRoomReads, type OwnGroupFrames } from "./host/room-reads.ts"; import { createPersonBotOrder } from "./host/person-bot-order.ts"; import { createMeRoutes } from "./routes/me.ts"; import { createPersonNames } from "./host/person-names.ts"; import { createTeamPhoneRoutes } from "./routes/team-phone.ts"; import { settleCloudHome } from "./cloud-home-settle.ts"; import { CLOUD_NOBODY_KEY, CLOUD_OUTSIDE_KEY } from "./cloud-sharing.ts"; import { createTeamSlackHost } from "./host/team-slack-host.ts"; import { createTeamSlackMessages } from "./team-slack.ts"; import { createTeamSlackRoutes } from "./routes/team-slack.ts";import { createCloudMoveRoutes } from "./cloud-move-http.ts";import { RESTART_EXIT_CODE } from "./restart.ts"; import { installCrashGuard, SERVER_ERROR_CAUSE } from "./crash-guard.ts"; import { markRequestArrival } from "./perf/loop-stalls.ts"; import { createThreadMaps, keepThreadEntry } from "./host/thread-maps.ts"; import { botLimitRefusal } from "./bot-limit.ts";@@ -2742,7 +2742,7 @@ const outsideLineage = createOutsideLineage({node: (id) => coordinator.node(id), active: () => coordinator.active(), language: (threadId) => threadLanguage(threadId),});const { outsideDrivenThread, cloudGuestDriven, cloudGuestDrivenHandoff, outsideWorkStaysHere, confinedWhy, guestEngineRefusal } = outsideLineage; const botApiManager = new BotApiManager(), /** One person's server (own-home.ts: no members, at most one admin and by address), read live; a personal Cloud is its owner's. */ botApiAsOwnerAvailable = () => sharedWorkspaceFullAccessEnabled() || (!HOSTED_WORKSPACE && !CLOUD_TEAM && oneOwner({ managed: false, shared: sharedMembership(), admins: signInAllowList().admins })); /** Fenced unless its key acts as the owner now (bot-api-host.ts). */ function botApiThread(id: string): boolean { const owner = store.botByThread(id), task = owner && store.taskByThread(owner.id, id); return Boolean(owner && task?.botApi && !(task.botApiAsOwner && botApiManager.actsAsOwner(owner.id) && botApiAsOwnerAvailable())); }-const { messagePage, messagePageBefore, messageWindow } = messagePages(store);+const { messagePage, messagePageBefore, messageWindow } = messagePages(store); const setupRecovery = createSetupRecovery(store);const replyVoiceNotes = createReplyVoiceNotes({ store, config: () => cfg, voiceReady: tts.voiceReady, speak: tts.speak, save: saveAudio, remove: deleteAttachment, redact: redactSecretsInText, language: threadLanguage });const { cloudLendingTurn, cloudLendingRefusalNotice, cloudLendingRefusalForBot, cloudLendingRefusal, cloudThreadStarters, cloudBotOpened, cloudLendingView, cloudReportFromOthers, handsOnLending, handedInUnproven, cloudOwnTurnRefusal, roomTurnStarted, roomTurnEnded, roomRun } = createCloudLendingTurns({store, cloudHome: CLOUD_HOME !== null, team: CLOUD_TEAM?.name ?? null, directRequest: (threadId) => directRequestOwners.get(threadId), threadStarter: (threadId) => threadStarters.get(threadId),@@ -6624,7 +6624,7 @@ bus.subscribe((event: RuntimeEvent) => {}landParkedFiles(); // above the failure row, which stays the last, retryable linepushMessage({ role: "bot", kind: "activity", tool: failedTurnTool(event.message, event) });- if (event.setup && bot) store.setTaskActivity(bot.id, event.threadId, "dead");+ if (event.setup && bot) { store.setTaskActivity(bot.id, event.threadId, "dead"); setupRecovery.failed(bot.id, event.threadId); }break;case "thread.token-usage.updated":turnUsage.set(event.threadId, { input: event.input, output: event.output, cachedInput: event.cachedInput });@@ -6670,7 +6670,7 @@ bus.subscribe((event: RuntimeEvent) => {const held = facts.limit ?? (signedOutStop(facts.stopReason, failureDetail) ? "signed-out" as const : undefined); // a limit or a sign-out: one incident a stretch, the person told by its own noticeconst fileIncident = () => { if (broken && (!held || limitTakeover.firstIncident(broken.id, broken.modelSelection, held, facts.limitResetsAt))) reportIncident({ kind: "failed", bot: broken, threadId: event.threadId, detail: failureDetail, facts, notified: Boolean(held) }); };let directSettled = () => {}; const settledDirect = new Promise<void>((resolve) => { directSettled = resolve; }); if (failed && bot) void quotaSwitch.turnFailed(bot, event, internal, Promise.all([settledDirect, directTurnDispatchClaims.released(event.threadId)]));- else if (bot && event.ok) { quotaSwitch.turnSucceeded(bot, event.threadId); if (!stopped) clearSetupFailures(store, bot.id, event.threadId); }+ else if (bot && event.ok) { quotaSwitch.turnSucceeded(bot, event.threadId); setupRecovery.succeeded(bot.id, event.threadId, { replayed, stopped }); }if (bot && event.ok && !stopped && completedTurnId && !routineRun && !coordinator.assignerOf(event.threadId)) askCards.ownQuestion(bot.id, event.threadId, completedTurnId);const lastReported = turnUsage.get(event.threadId);turnUsage.delete(event.threadId);diff --git a/server/setup-recovered.e2e.test.ts b/server/setup-recovered.e2e.test.tsnew file mode 100644index 0000000000..15cc774ee5--- /dev/null+++ b/server/setup-recovered.e2e.test.ts@@ -0,0 +1,80 @@+// The "needs setup" mark end to end, through server/index.ts's runtime.error and turn.completed handling: a fixture+// server with the synthetic Claude CLI, whose sign-in lapses (a file exists) and comes back (the file is gone). A+// conversation that met the lapsed sign-in marks its bot "dead"; a later turn of the same engine in another+// conversation clears it, without that conversation running again.+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { afterAll, beforeAll, expect, it } from "vitest";++import { launchVerificationServer, type VerificationServer } from "../scripts/control-omb.ts";+import { hostTimeout } from "./testing/host-timeout.ts";++type Task = { threadId: string; activity?: string; busy?: boolean };+type Bot = { id: string; activity?: string; busy?: boolean; tasks?: Task[] };++let fixture: VerificationServer;+let script = "";+let url = "";+const signedOut = () => join(script, "signed-out");++const api = async (method: string, path: string, body?: unknown) => {+ const response = await fetch(url + path, { method, headers: { "content-type": "application/json", origin: url }, ...(body === undefined ? {} : { body: JSON.stringify(body) }) });+ return { status: response.status, body: await response.json() as any };+};+const bot = async (id: string) => ((await api("GET", "/api/bots")).body.bots as Bot[]).find((entry) => entry.id === id)!;+const task = async (id: string, threadId: string) => (await bot(id)).tasks!.find((entry) => entry.threadId === threadId)!;+async function until(done: () => Promise<boolean> | boolean, timeoutMs = 60_000): Promise<void> {+ const end = Date.now() + timeoutMs;+ while (!(await done())) {+ if (Date.now() > end) throw new Error("timed out waiting");+ await new Promise((resolve) => setTimeout(resolve, 200));+ }+}+async function send(botId: string, threadId: string, text: string): Promise<void> {+ const sent = await api("POST", `/api/bots/${botId}/messages`, { text, threadId });+ expect(sent.status, JSON.stringify(sent.body)).toBe(202);+ await until(async () => {+ const current = await task(botId, threadId);+ return !current.busy && current.activity !== "working";+ });+}++beforeAll(async () => {+ script = mkdtempSync(join(tmpdir(), "omb-setup-recovered-e2e-"));+ writeFileSync(join(script, "reply.txt"), "Done.");+ fixture = await launchVerificationServer({+ ...process.env,+ FAKE_CLAUDE_SIGNED_OUT_FILE: signedOut(),+ FAKE_CLAUDE_REPLY_FILE: join(script, "reply.txt"),+ });+ url = fixture.info.url;+ // A turn that fails would otherwise be carried on by another engine; this test is about the mark itself.+ expect((await api("PUT", "/api/config", { automaticRecovery: { enabled: false } })).status).toBe(200);+}, hostTimeout(120_000));++afterAll(async () => {+ await fixture?.close();+ if (script) rmSync(script, { recursive: true, force: true });+});++it("clears a bot's needs-setup mark once another of its conversations runs on the signed-in engine again", async () => {+ const created = await api("POST", "/api/bots", { name: "Quill" });+ expect(created.status, JSON.stringify(created.body)).toBe(201);+ const id = created.body.bot.id as string;+ const failedThread = (created.body.bot.mainThreadId ?? created.body.bot.threadId) as string;+ const other = await api("POST", `/api/bots/${id}/tasks`, { title: "Later" });+ expect(other.status, JSON.stringify(other.body)).toBeLessThan(300);+ const laterThread = other.body.task.threadId as string;++ writeFileSync(signedOut(), "");+ await send(id, failedThread, "SIGNED_OUT_TURN_6Q");+ await until(async () => (await task(id, failedThread)).activity === "dead");+ expect((await bot(id)).activity).toBe("dead");++ rmSync(signedOut());+ await send(id, laterThread, "SIGNED_IN_AGAIN_6Q");+ await until(async () => (await task(id, failedThread)).activity !== "dead");+ expect((await task(id, failedThread)).activity ?? "idle").toBe("idle");+ expect((await bot(id)).activity).not.toBe("dead");+}, hostTimeout(120_000));diff --git a/server/testing/fake-claude-cli.ts b/server/testing/fake-claude-cli.tsindex afbc7cef0d..164ec277f1 100755--- a/server/testing/fake-claude-cli.ts+++ b/server/testing/fake-claude-cli.ts@@ -23,6 +23,7 @@// success, as Claude Code 2.1.321 answers once the server is connected again; "refuse" answers it as a failure// FAKE_CLAUDE_LAUNCHES JSON-lines file every stream-json process appends its {pid, argv} to as it starts// FAKE_CLAUDE_EXIT_AFTER_TURN 1: exit once the turn is answered, so later turns relaunch with --resume+// FAKE_CLAUDE_SIGNED_OUT_FILE path: while it exists, every turn answers as not-logged-in (a sign-in that lapses and comes back)// FAKE_CLAUDE_AUTH_AFTER_TURN 1: from the second turn, answer as not-logged-in; FAKE_CLAUDE_AUTH_AFTER_WORK 1: not-logged-in// calls a tool first// FAKE_CLAUDE_GONE_AFTER_TURN path: after the turn stop reading stdin, write <path>.closed, exit once <path> exists@@ -1080,7 +1081,8 @@ const playTurn = (prompt: JsonValue, late = false) => {}// A signed-out CLI's frames, as Claude Code 2.1.296 sends them: only the frame's own error fields mark the failure.- if (mode === "not-logged-in" || process.env.FAKE_CLAUDE_AUTH_AFTER_TURN === "1" && turnsPlayed > 0 || signedInAs === null) {+ const signedOutNow = Boolean(process.env.FAKE_CLAUDE_SIGNED_OUT_FILE && existsSync(process.env.FAKE_CLAUDE_SIGNED_OUT_FILE));+ if (mode === "not-logged-in" || signedOutNow || process.env.FAKE_CLAUDE_AUTH_AFTER_TURN === "1" && turnsPlayed > 0 || signedInAs === null) {if (process.env.FAKE_CLAUDE_AUTH_AFTER_WORK === "1") out({type: "assistant", message: { model: "claude-fixture", content: [{ type: "tool_use", id: "before-sign-out", name: "Bash", input: { command: "pwd" } }] },});