Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Antigravity cleanup: keep stops confirmed before a timeout; list the new env names as server-only
AdityaUmale83536594fa9c
diff --git a/server/bot-box/env.test.ts b/server/bot-box/env.test.tsindex c7d914be48..6c9d6dc38e 100644--- a/server/bot-box/env.test.ts+++ b/server/bot-box/env.test.ts@@ -9,7 +9,7 @@ import { BOX_ENV_NAMES, BOX_ENV_NEVER, BOX_ENV_OMB_NAMES, BOX_ENV_OMB_PREFIXES,const SERVER_ONLY_OMB: ReadonlySet<string> = new Set(["OMB_ACP_LIMIT_QUIET_MS", "OMB_ACP_NO_SIGNS_STOP_MS", "OMB_ACP_PLAN_LINES", "OMB_ACP_QUIET_NOTICE_MS","OMB_ACP_QUIET_TICK_MS", "OMB_TASK_WORKSPACE_RETENTION", "OMB_CONVERSATION_FOLDER_CLEANUP", "OMB_ORPHAN_SWEEP", "OMB_ORPHAN_SWEEP_MAX_SHARE", "OMB_IDLE_RECLAIM", "OMB_ACP_SESSION_IDLE_", "OMB_ACP_SHARED_RECYCLE_MS", "OMB_ADMIN_", "OMB_ADMIN_MEMBERSHIP",- "OMB_ADMIN_URL", "OMB_ADMIN_WORKSPACE", "OMB_AGENT_BROWSER_PATH", "OMB_AI_CHECKS", "OMB_ANTHROPIC_API_KEY", "OMB_ANTIGRAVITY_NATIVE_CLI",+ "OMB_ADMIN_URL", "OMB_ADMIN_WORKSPACE", "OMB_AGENT_BROWSER_PATH", "OMB_AGY_RUNTIMES", "OMB_AGY_STOP", "OMB_AI_CHECKS", "OMB_ANTHROPIC_API_KEY", "OMB_ANTIGRAVITY_NATIVE_CLI","OMB_ANTHROPIC_API_URL", "OMB_APP_VERSION", "OMB_ATTACHMENTS_MAX_BYTES", "OMB_AZURE_OPENAI_LIVE_DEPLOYMENT","OMB_AZURE_OPENAI_LIVE_ENDPOINT", "OMB_BACKGROUND_TEXT_MAX", "OMB_BENCH", "OMB_BOAT_API", "OMB_CLOUD_FOCUS_WAKE", "OMB_ENGINE_PRESTART", "OMB_BOTS_FULL_SAVE", "OMB_BOTS_SAVE_CHECK", "OMB_BOT_BOX", "OMB_BOT_MEMORY_MAX_MB", "OMB_BOX_CANARY", "OMB_BRAND_FILE","OMB_BROWSER_CGROUP", "OMB_BROWSER_CONNECTION", "OMB_BROWSER_HOLD_IDLE_MS", "OMB_BROWSER_IDLE_HANDOVER_MS", "OMB_BROWSER_LANG", "OMB_BROWSER_LEGACY_SHELL",diff --git a/server/drivers/antigravity-processes.test.ts b/server/drivers/antigravity-processes.test.tsindex 651cb84bf4..160b86db72 100644--- a/server/drivers/antigravity-processes.test.ts+++ b/server/drivers/antigravity-processes.test.ts@@ -1,10 +1,15 @@-import { spawn } from "node:child_process";+import { execFile, spawn } from "node:child_process";import { sep } from "node:path";import { afterEach, describe, expect, it, vi } from "vitest";import * as procs from "../procs.ts";import { AntigravityProcesses, orphanedRuntimeProcesses, stopOrphanedAntigravityRuntimes } from "./antigravity-processes.ts";+vi.mock("node:child_process", async (importOriginal) => {+ const actual = await importOriginal<typeof import("node:child_process")>();+ return { ...actual, execFile: vi.fn(actual.execFile) };+});+const children: ReturnType<typeof spawn>[] = [];afterEach(() => {@@ -92,6 +97,16 @@ describe("runtimes an earlier server left running on Windows", () => {expect(run).toHaveBeenCalledTimes(2);});+ it("counts the stops PowerShell confirmed before it ran out of time, not a pid it was still writing", async () => {+ const listed = (pid: number) => ({ ProcessId: pid, ExecutablePath: `${release}\\agy_acp_server.exe`, Started: "2026-11-21T08:00:00.0000000Z", ParentStarted: null });+ type Done = (error: Error | null, stdout: string) => void;+ const ran = vi.mocked(execFile as unknown as (file: string, args: string[], options: { timeout: number }, done: Done) => void);+ ran.mockImplementationOnce((_file, _args, _options, done) => done(null, JSON.stringify([listed(41), listed(4), listed(43)])))+ .mockImplementationOnce((_file, _args, _options, done) => done(Object.assign(new Error("timed out"), { killed: true }), "41\r\n4"));+ expect(await stopOrphanedAntigravityRuntimes({ platform: "win32", dataDir })).toBe(1);+ expect(ran.mock.calls[1]![2].timeout).toBeGreaterThan(3 * 10_000);+ });+it("stops nothing when no orphan is listed or the listing fails", async () => {for (const listing of [null, "", "[]"]) {const run = vi.fn(async () => listing);diff --git a/server/drivers/antigravity-processes.ts b/server/drivers/antigravity-processes.tsindex 67d12bab41..b728ca867f 100644--- a/server/drivers/antigravity-processes.ts+++ b/server/drivers/antigravity-processes.ts@@ -87,12 +87,13 @@ const WINDOWS_STOP_PROCESSES = "foreach ($e in $env:OMB_AGY_STOP.Split(' ')) { $+ "; if ($p -and $p.CreationDate -and $p.CreationDate.ToUniversalTime().ToString('o') -eq $s) { taskkill /PID $id /T /F | Out-Null"+ "; if ($LASTEXITCODE -eq 0) { Wait-Process -Id $id -Timeout 10 -ErrorAction SilentlyContinue; if (-not (Get-Process -Id $id -ErrorAction SilentlyContinue)) { $id } } } }; exit 0";-type PowerShell = (script: string, env: NodeJS.ProcessEnv) => Promise<string | null>;+type PowerShell = (script: string, env: NodeJS.ProcessEnv, timeoutMs?: number) => Promise<string | null>;-const powershell: PowerShell = (script, env) => new Promise((done) => {+/** A script that fails or runs out of time still gives the lines it wrote in full; a line it was writing is dropped. */+const powershell: PowerShell = (script, env, timeoutMs = 30_000) => new Promise((done) => {execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {- encoding: "utf8", timeout: 30_000, windowsHide: true, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, ...env },- }, (error, stdout) => done(error ? null : stdout));+ encoding: "utf8", timeout: timeoutMs, windowsHide: true, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, ...env },+ }, (error, stdout) => done(error ? stdout.slice(0, stdout.lastIndexOf("\n") + 1) || null : stdout));});function listedRows(listing: string | null): RuntimeProcessRow[] {@@ -119,7 +120,8 @@ export async function stopOrphanedAntigravityRuntimes(options: OrphanStopOptionsconst root = antigravityRuntimesRoot(options.dataDir ?? DATA_DIR);const orphans = orphanedRuntimeProcesses(listedRows(await run(WINDOWS_RUNTIME_PROCESSES, { OMB_AGY_RUNTIMES: root })), root);if (!orphans.length) return 0;- const stopped = await run(WINDOWS_STOP_PROCESSES, { OMB_AGY_STOP: orphans.map(({ pid, started }) => `${pid}=${started}`).join(" ") });+ // Each stop may wait up to 10 s for its runtime to exit.+ const stopped = await run(WINDOWS_STOP_PROCESSES, { OMB_AGY_STOP: orphans.map(({ pid, started }) => `${pid}=${started}`).join(" ") }, 30_000 + orphans.length * 15_000);const gone = new Set(stopped?.split(/\s+/));return orphans.filter(({ pid }) => gone.has(String(pid))).length;}