Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
serve: honor OMB_SERVE_READY_TIMEOUT_MS instead of a fixed minute
skygunner16f686f4d59c
diff --git a/server/cli.test.ts b/server/cli.test.tsindex 3287e0ebed..92e8fa115e 100644--- a/server/cli.test.ts+++ b/server/cli.test.ts@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { applyStartupPreferences, parseArgs, runAccess, runLogin, runOnboardingCommand, serverEntry, type CliOptions, verifyPhoneEndpoint } from "./cli.ts";+import { serveReadyTimeoutMs } from "./headless/args.ts";import { browserSignInLines, formatSessions, pairingBlock, qrToString, untilText } from "./cli-pairing.ts";import { reachableAddresses } from "./lan-address.ts";import { readAdminActivityRange } from "./admin-activity.ts";@@ -696,3 +697,13 @@ describe.skipIf(process.platform === "win32")("serve --domain", () => {}}, 120_000);});++describe("serve readiness wait", () => {+ it("defaults to a minute, honors OMB_SERVE_READY_TIMEOUT_MS, and keeps the default on a bad value", () => {+ expect(serveReadyTimeoutMs({})).toBe(60_000);+ expect(serveReadyTimeoutMs({ OMB_SERVE_READY_TIMEOUT_MS: "10m" })).toBe(600_000);+ expect(serveReadyTimeoutMs({ OMB_SERVE_READY_TIMEOUT_MS: "nonsense" })).toBe(60_000);+ expect(serveReadyTimeoutMs({ OMB_SERVE_READY_TIMEOUT_MS: "1s" })).toBe(60_000);+ expect(serveReadyTimeoutMs({ OMB_SERVE_READY_TIMEOUT_MS: " 5m " })).toBe(300_000);+ });+});diff --git a/server/cli.ts b/server/cli.tsindex 6b04ca3d16..a2244bdd3c 100644--- a/server/cli.ts+++ b/server/cli.ts@@ -45,7 +45,7 @@ import { cliCommand, cliPrefix } from "./cli-invocation.ts"; import { defaultDatimport { checkReach, envPublicUrl, lanProblem, localLinkBase, noRouteLines, publicUrlProblem, reachLines, waitForReach, type Route } from "./cli-reach.ts";import { lanUrl } from "./lan-address.ts";import { isLoopbackHost } from "../electron/server-address.mjs";-import { parseDuration } from "./headless/args.ts";+import { describeMs, parseDuration, serveReadyTimeoutMs } from "./headless/args.ts";import { signInFromEnv, type AppConfig } from "./config.ts";import {cleanupTunnelOrigin,@@ -805,10 +805,9 @@ export async function runServe(options: CliOptions, log: (line: string) => voidprocess.on("SIGTERM", onSignal);try {- const deadline = Date.now() + 60_000;- while (Date.now() < deadline && exited === null && !stopping) {+ const readyTimeoutMs = serveReadyTimeoutMs(env);+ for (const deadline = Date.now() + readyTimeoutMs; Date.now() < deadline && exited === null && !stopping; await new Promise((r) => setTimeout(r, 250))) {if (await serverUp(options.port, child.pid)) break;- await new Promise((r) => setTimeout(r, 250));}if (exited !== null) {if (exited !== 0) log(`OpenMausBot could not start.${logPath ? ` Details: ${logPath}` : " See the output above."}`);@@ -816,7 +815,7 @@ export async function runServe(options: CliOptions, log: (line: string) => void}if (stopping) return await childExit;if (!(await serverUp(options.port, child.pid))) {- console.error(`OpenMausBot did not become ready within a minute.${logPath ? ` Details: ${logPath}` : " See its output above."}`);+ console.error(`OpenMausBot did not become ready within ${describeMs(readyTimeoutMs)}.${logPath ? ` Details: ${logPath}` : " See its output above."}`);await stop();return 1;}diff --git a/server/headless/args.ts b/server/headless/args.tsindex 192bb7a62b..13a6f6a129 100644--- a/server/headless/args.ts+++ b/server/headless/args.ts@@ -262,3 +262,12 @@ export function oneOf<T extends string>(raw: string | undefined, name: string, aif (!(allowed as readonly string[]).includes(raw)) throw usageError(`${name} must be one of: ${allowed.join(", ")}`);return raw as T;}++/** How long `serve` waits for the server's HTTP health before giving up: `OMB_SERVE_READY_TIMEOUT_MS`,+ * else 60s. An unreadable value keeps the default; a machine with a cold start needs this without a rebuild. */+export function serveReadyTimeoutMs(env: NodeJS.ProcessEnv): number {+ const raw = env.OMB_SERVE_READY_TIMEOUT_MS?.trim();+ if (!raw) return 60_000;+ try { return parseDuration(raw, "OMB_SERVE_READY_TIMEOUT_MS", { min: 5_000, max: 3_600_000 }); }+ catch { return 60_000; }+}