Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Report a hand-off that never continued in the browser as not done
AdityaUmale95105e1dad46
diff --git a/server/host/handoff-browser.test.ts b/server/host/handoff-browser.test.tsindex 5d8eb2565b..af1e0a79c3 100644--- a/server/host/handoff-browser.test.ts+++ b/server/host/handoff-browser.test.ts@@ -1,8 +1,13 @@import { expect, it } from "vitest";-import { handoffSurface } from "./handoff-browser.ts";+import { HANDOFF_BROWSER_STOPPED, handoffSurface, stoppedHandoffResult } from "./handoff-browser.ts";it("lets a hand-off ask only for the built-in browser, auto included", () => {expect(handoffSurface("browser")).toBe("browser");expect(handoffSurface("auto")).toBe("browser");for (const asked of ["cloud", "vm", "local", undefined, 3]) expect(handoffSurface(asked)).toBeNull();});++it("reports a hand-off that never continued in the browser as not done, and keeps a real failure", () => {+ expect(stoppedHandoffResult({ ok: true, text: "Moving to the browser." })).toEqual({ ok: false, text: HANDOFF_BROWSER_STOPPED });+ expect(stoppedHandoffResult({ ok: false, text: "engine failed" })).toEqual({ ok: false, text: "engine failed" });+});diff --git a/server/host/handoff-browser.ts b/server/host/handoff-browser.tsindex 100d06c095..09a595904c 100644--- a/server/host/handoff-browser.ts+++ b/server/host/handoff-browser.ts@@ -8,3 +8,11 @@ export const HANDOFF_BROWSER_NOTE = " This is a teammate's hand-off: when it neeexport function handoffSurface(asked: unknown): "browser" | null {return asked === "auto" || asked === "browser" ? "browser" : null;}++export const HANDOFF_BROWSER_STOPPED = "The hand-off stopped before it could continue in the built-in browser (a new message, a stop or another turn came first), so the requested work was not done.";++/** What a hand-off returns when its turn asked to move to the browser but the browser turn never ran: never the+ * reply that only asked to move, as if the work were done. A failed turn keeps its own failure. */+export function stoppedHandoffResult<T extends { ok: boolean; text: string }>(kept: T): T | { ok: false; text: string } {+ return kept.ok ? { ok: false, text: HANDOFF_BROWSER_STOPPED } : kept;+}diff --git a/server/index.ts b/server/index.tsindex 17ede31629..ec91e40d88 100644--- a/server/index.ts+++ b/server/index.ts@@ -271,7 +271,7 @@ import {SendSequencer,} from "./send-idempotency.ts";import { EventBus } from "./harness/bus.ts";-import { ENGINE_LIST_REUSE_MS, engineMemory, enginesByUse, ProviderRegistry } from "./harness/registry.ts"; import { afterFirstEngineRead, holdUntilFirstEngineRead } from "./first-engine-read.ts"; import { HANDOFF_BROWSER_NOTE, HANDOFF_BROWSER_ONLY, handoffSurface } from "./host/handoff-browser.ts";+import { ENGINE_LIST_REUSE_MS, engineMemory, enginesByUse, ProviderRegistry } from "./harness/registry.ts"; import { afterFirstEngineRead, holdUntilFirstEngineRead } from "./first-engine-read.ts"; import { HANDOFF_BROWSER_NOTE, HANDOFF_BROWSER_ONLY, handoffSurface, stoppedHandoffResult } from "./host/handoff-browser.ts";import { ManagedDesktopProviders } from "./managed-desktop.ts";import { mainThread, wasOldestThread } from "./main-thread.ts";import { computerKindForResource, ManagedDesktopPolicy, type ComputerKind } from "./managed-policy.ts"; import { nudgeCloudTeamPolicy, remoteAccessPaths, startCloudTeamPolicy, stopCloudTeamPolicy } from "./cloud-team-policy.ts";@@ -6114,8 +6114,8 @@ function selectTurnPlace(turn: { botId: string; threadId: string; generation: stfunction continueComputerSelection(threadId: string, generation: string | undefined, succeeded: boolean): boolean {const selection = computerSelectionTurns.get(threadId);if (!selection || selection.generation !== generation) return false;- // A hand-off that does not continue still returns the result it kept back.- const giveUp = () => { if (computerSelectionTurns.get(threadId) === selection) computerSelectionTurns.delete(threadId); if (selection.handoff?.outcome) settleDirectCoordination(generation, selection.handoff.outcome); };+ // A hand-off that does not continue reports that its work was not done (or its own failure), never the move request.+ const giveUp = () => { if (computerSelectionTurns.get(threadId) === selection) computerSelectionTurns.delete(threadId); if (selection.handoff?.outcome) settleDirectCoordination(generation, stoppedHandoffResult(selection.handoff.outcome)); };if (!succeeded || !selection.selected || hasQueuedSteeredMessages(selection.botId, threadId)) return giveUp(), false;const surface = selection.selected;setImmediate(() => {diff --git a/server/surface-pins.e2e.test.ts b/server/surface-pins.e2e.test.tsindex b80f1e4fe2..4463f7d3d6 100644--- a/server/surface-pins.e2e.test.ts+++ b/server/surface-pins.e2e.test.ts@@ -509,7 +509,8 @@ describe("surface pin provenance against the real server", () => {expect(savedTask(tester.id, workThread)).toMatchObject({ surface: "browser" });// The asker hears back from the browser turn, never from the turn that only asked to move.const replies = async () => JSON.stringify((await apiOk("GET", `/api/threads/${own.threadId}/messages?limit=60`)).messages);- expect(await until(replies, (text) => text.includes("Continue the handed-off request"))).toBeTruthy();+ // "reply to: ..." is the fixture engine's own answer from the browser turn, not the prompt that started it.+ expect(await until(replies, (text) => /reply to: [^"]*The computer selection is now the built-in browser/.test(text))).toBeTruthy();await idle(tester.id, workThread);await idle(asker.id, own.threadId);await stop();