Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(handoff-browser): report a hand-off given up before its outcome arrived as stopped; softer stopped wording
AdityaUmale3d2a287e5de3
diff --git a/server/host/handoff-browser.test.ts b/server/host/handoff-browser.test.tsindex af1e0a79c3..97d149c936 100644--- a/server/host/handoff-browser.test.ts+++ b/server/host/handoff-browser.test.ts@@ -1,5 +1,5 @@import { expect, it } from "vitest";-import { HANDOFF_BROWSER_STOPPED, handoffSurface, stoppedHandoffResult } from "./handoff-browser.ts";+import { HANDOFF_BROWSER_STOPPED, handoffSurface, StoppedHandoffs, stoppedHandoffResult } from "./handoff-browser.ts";it("lets a hand-off ask only for the built-in browser, auto included", () => {expect(handoffSurface("browser")).toBe("browser");@@ -11,3 +11,14 @@ it("reports a hand-off that never continued in the browser as not done, and keepexpect(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" });});++it("reports a hand-off given up before its outcome arrived as stopped, once, and leaves others alone", () => {+ const stopped = new StoppedHandoffs(2);+ stopped.stop("g1");+ expect(stopped.settle("g1", { ok: true, text: "Moving to the browser." })).toEqual({ ok: false, text: HANDOFF_BROWSER_STOPPED });+ expect(stopped.settle("g1", { ok: true, text: "later" })).toEqual({ ok: true, text: "later" });+ expect(stopped.settle("g2", { ok: true, text: "done" })).toEqual({ ok: true, text: "done" });+ stopped.stop("a"); stopped.stop("b"); stopped.stop("c");+ expect(stopped.settle("a", { ok: true, text: "x" })).toEqual({ ok: true, text: "x" });+ expect(stopped.settle("c", { 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 09a595904c..876856d8f3 100644--- a/server/host/handoff-browser.ts+++ b/server/host/handoff-browser.ts@@ -9,10 +9,26 @@ export 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.";+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 request may be incomplete: check what was already done before relying on it.";/** 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;}++/** Hand-offs given up before their turn's outcome arrived (an adapter can finish before dispatch returns): that late+ * outcome is reported as stopped too, never as the move request. Bounded so ids that never settle cannot pile up. */+export class StoppedHandoffs {+ readonly #ids = new Set<string>();+ readonly limit: number;+ constructor(limit = 1_024) { this.limit = limit; }+ stop(generation: string): void {+ this.#ids.add(generation);+ while (this.#ids.size > this.limit) this.#ids.delete(this.#ids.values().next().value!);+ }+ /** The outcome to report for `generation`: as stopped when it was given up early (once), else unchanged. */+ settle<T extends { ok: boolean; text: string }>(generation: string, outcome: T): T | { ok: false; text: string } {+ return this.#ids.delete(generation) ? stoppedHandoffResult(outcome) : outcome;+ }+}diff --git a/server/index.ts b/server/index.tsindex ec91e40d88..d9ce694c38 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, stoppedHandoffResult } 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, StoppedHandoffs, 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";@@ -1922,7 +1922,7 @@ const gmailDrafts = createGmailDrafts({ node: (id) => coordinator.node(id), endetype DirectTurnOutcome = HostTurnResult;const directFollowupTurns = new ProviderTurnGenerationRegistry<DirectTurnOutcome>();const directFollowupSettlers = new Map<string, { threadId: string; settle?: () => void }>();-const directCoordinationSettlers = new Map<string, { nodeId: string; settle: (outcome: DirectTurnOutcome) => void }>();+const directCoordinationSettlers = new Map<string, { nodeId: string; settle: (outcome: DirectTurnOutcome) => void }>(); const stoppedHandoffs = new StoppedHandoffs();const computerParks = new Map<string, string>();const parkedSeats = new Map<string, string>();const COMPUTER_FREE_NOTE = "OpenMausBot computer update: the computer this conversation waited for is free again. Continue the task that parked waiting for it.";@@ -2009,8 +2009,8 @@ function hostTurnResult(node: HandoffView | undefined, generation: string, outcoreturn { ...result, cards: { question: `Waiting on the person: ${cards.map((card) => card.waits).join("; ")}`, ids: cards.map((card) => card.id) } };}-function settleDirectCoordination(generation: string | undefined, outcome: DirectTurnOutcome) {- if (!generation) return;+function settleDirectCoordination(generation: string | undefined, settled: DirectTurnOutcome) {+ if (!generation) return; const outcome = stoppedHandoffs.settle(generation, settled); // a hand-off given up before its outcome arrivedconst moving = [...computerSelectionTurns.values()].find(turn => turn.generation === generation && turn.handoff && turn.selected); if (moving && directCoordinationSettlers.has(generation)) { moving.handoff!.outcome ??= outcome; return; } // kept for the turn continuing in the browserconst settler = directCoordinationSettlers.get(generation);directCoordinationSettlers.delete(generation);@@ -6115,7 +6115,7 @@ function continueComputerSelection(threadId: string, generation: string | undeficonst selection = computerSelectionTurns.get(threadId);if (!selection || selection.generation !== generation) return false;// 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)); };+ const giveUp = () => { if (computerSelectionTurns.get(threadId) === selection) computerSelectionTurns.delete(threadId); if (selection.handoff?.outcome) settleDirectCoordination(generation, stoppedHandoffResult(selection.handoff.outcome)); else if (selection.handoff && generation && directCoordinationSettlers.has(generation)) stoppedHandoffs.stop(generation); };if (!succeeded || !selection.selected || hasQueuedSteeredMessages(selection.botId, threadId)) return giveUp(), false;const surface = selection.selected;setImmediate(() => {