Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix: never requeue an indeterminate steer through person-first

erywim86e0a270f55f
diff --git a/server/index.ts b/server/index.ts
index e8b24b6a66..b84c161998 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -7201,7 +7201,9 @@ async function acceptDirectSend(
store.setTaskAskedAt(botId, threadId, message.at);
handoffs.steered(threadId, steerTarget, instance?.instanceId, message.id);
signInSettle.answerInChat(botId, threadId);
- if (personsOwn) personFirst.wait(threadId, { requeue: (note) => void queueSteeredMessage(current.id, threadId, text, { prompt: note ? `${queuedPrompt}\n\n${note}` : queuedPrompt, rowId: message.id, first: true, queuedAt: message.at, replyToId: replyTo?.id, dataContext, sender, trigger, via, callId, mentions, aheadOfOthers: runOwners.askerFirst(threadId) }) });
+ // Only a confirmed steer may be queued again: an indeterminate one may already be in the turn. Person-first still
+ // watches it, as it does for a steered message the engine already read, so a long call can still be stopped.
+ if (personsOwn) personFirst.wait(threadId, steered === "steered" ? { requeue: (note) => void queueSteeredMessage(current.id, threadId, text, { prompt: note ? `${queuedPrompt}\n\n${note}` : queuedPrompt, rowId: message.id, first: true, queuedAt: message.at, replyToId: replyTo?.id, dataContext, sender, trigger, via, callId, mentions, aheadOfOthers: runOwners.askerFirst(threadId) }) } : {});
return { ok: true as const, steered: true as const, threadId, message };
}
if (!current.busy) {
diff --git a/server/person-first.e2e.test.ts b/server/person-first.e2e.test.ts
index f9b6be330b..bae29e969c 100644
--- a/server/person-first.e2e.test.ts
+++ b/server/person-first.e2e.test.ts
@@ -5,6 +5,7 @@ import { randomBytes } from "node:crypto";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
+import { DatabaseSync } from "node:sqlite";
import { expect, it } from "vitest";
import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";
@@ -14,6 +15,8 @@ import { hostTimeout } from "./testing/host-timeout.ts";
const POLL = { name: "Bash", input: { command: "gh run view 42; sleep 30" }, hold: true };
const QUESTION = "Is the PR up yet?";
const ANSWER = "Yes: PR #42 is up. CI is still running, and I will tell you when it is done.";
+const HELD_COMMAND = "omb-hold-ci --until-stopped";
+const INDETERMINATE_QUESTION = "Did the steer land yet?";
it("stops a turn that keeps the person's message unread in a long tool call, and answers it next", async () => {
const folder = mkdtempSync(join(tmpdir(), "omb-person-first-"));
@@ -66,3 +69,59 @@ it("stops a turn that keeps the person's message unread in a long tool call, and
await removeTempDir(folder);
}
}, hostTimeout(90_000));
+
+// The codex fake never answers turn/steer (FAKE_CODEX_STEER_HANG), so the driver times out and reports the steer as
+// "indeterminate": the words may already be in the running turn. Person-first still stops the held tool call that kept
+// the person waiting, but must not queue the words again, or the same message runs a second time.
+it("never queues an indeterminate steer again through person-first", async () => {
+ const folder = mkdtempSync(join(tmpdir(), "omb-person-first-indeterminate-"));
+ const gate = join(folder, "hold.never");
+ const owner = randomBytes(32).toString("base64url");
+ const realFetch = globalThis.fetch;
+ globalThis.fetch = (input, init = {}) => realFetch(input, { ...init,
+ headers: { ...Object.fromEntries(new Headers(init.headers)), "x-openmausbot-desktop-owner": owner } });
+ const fixture = await launchVerificationServer({ ...process.env, OMB_TEST_DESKTOP_OWNER_TOKEN: owner, OMB_PERSON_FIRST_MS: "1500",
+ FAKE_CODEX_COMMAND: HELD_COMMAND, FAKE_CODEX_COMMAND_GATE: gate, FAKE_CODEX_STEER_HANG: "1" },
+ undefined, undefined, undefined, undefined, undefined, ["codex"]);
+ try {
+ const api = async (method: string, path: string, body?: unknown) => {
+ const response = await fetch(fixture.info.url + path, { method, headers: { "content-type": "application/json", origin: fixture.info.url },
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
+ return { status: response.status, body: await response.json() as any };
+ };
+ const instances = (await api("GET", "/api/instances")).body.instances as Array<{ instanceId: string; models?: { default?: string } }>;
+ const model = instances.find((entry) => entry.instanceId === "codex")?.models?.default ?? "gpt-fake-default";
+ const created = await api("POST", "/api/bots", { name: "Watcher", modelSelection: { instanceId: "codex", model } });
+ expect(created.status).toBe(201);
+ const bot = created.body.bot as { id: string; threadId: string };
+ const threadId = bot.threadId;
+ const transcript = async (): Promise<any[]> => (await api("GET", `/api/threads/${threadId}/messages?limit=100`)).body.messages;
+ const busy = async () => (await api("GET", "/api/bots?messages=0")).body.bots.find((entry: { id: string }) => entry.id === bot.id)?.busy === true;
+ const held = (rows: any[]) => rows.filter((message) => message.kind === "activity" && JSON.stringify(message.tool ?? {}).includes(HELD_COMMAND));
+ const wasStopped = (rows: any[]) => rows.some((message) => message.kind === "activity" && /^Stopped a step that had run for \d+ s, to answer you first$/.test(message.tool?.name ?? ""));
+ // A re-queue is written to the follow-ups before person-first's stop line is appended, and a queued turn that is
+ // still running keeps its row, so the stop line is the event that makes this read final.
+ const queuedWords = (): string[] => {
+ const db = new DatabaseSync(join(fixture.info.dataDir, "messages.db"), { readOnly: true });
+ try { return (db.prepare("SELECT payload FROM chat_followups WHERE kind = 'bot'").all() as Array<{ payload: string }>).map((row) => JSON.parse(row.payload).text as string); }
+ finally { db.close(); }
+ };
+
+ expect((await api("POST", `/api/bots/${bot.id}/messages`, { text: "Open the PR and watch CI", threadId })).status).toBe(202);
+ await expect.poll(async () => held(await transcript()).length, { timeout: hostTimeout(20_000) }).toBe(1);
+
+ const sent = await api("POST", `/api/bots/${bot.id}/messages`, { text: INDETERMINATE_QUESTION, threadId });
+ expect(sent.status).toBe(202);
+ expect(sent.body.steered).toBe(true);
+
+ await expect.poll(async () => wasStopped(await transcript()), { timeout: hostTimeout(30_000) }).toBe(true);
+ // The person-first stop alone must not start a new turn for words that may already be in the interrupted one.
+ expect(queuedWords(), "the indeterminate steer is not queued again").not.toContain(INDETERMINATE_QUESTION);
+ await expect.poll(busy, { timeout: hostTimeout(15_000) }).toBe(false);
+ expect(held(await transcript()), "the indeterminate steer is not run again").toHaveLength(1);
+ } finally {
+ globalThis.fetch = realFetch;
+ await fixture.close();
+ await removeTempDir(folder);
+ }
+}, hostTimeout(90_000));