Skip to content

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

fix: allow verified wait follow-ups to schedule the next stage

fangyuan2034a164f607
diff --git a/docs/verification/waits.md b/docs/verification/waits.md
index d5640acf6e..3cd153fc9a 100644
--- a/docs/verification/waits.md
+++ b/docs/verification/waits.md
@@ -12,9 +12,12 @@ pnpm exec vitest run server/wait-probes.test.ts server/waits.test.ts server/wait
## In a fixture
-The fake engine calls `wait_until` on every turn it runs, the follow-up turn too. That
-turn was started by the wait, not by the person, so its `wait_until` is refused: a wait
-never renews itself.
+The fake engine calls `wait_until` on every turn it runs, including the follow-up.
+A follow-up proved by the server's wait run and fired notice can create its next wait
+in the same bot's direct chat. The multi-stage e2e test exercises two completions and
+registration of the next stage. Scheduled routines and unrelated outside events
+retain their existing refusal. A condition already true returns immediately and
+directs the bot to carry out its follow-up in that turn.
```sh
W=$(mktemp -d)
@@ -45,9 +48,9 @@ Expected:
- After the `touch`: exactly one bot line `the report: done. <W>/report.txt is there now.`
carrying `"wait": { "id": "...", "status": "fired" }`, then a user line
`[Wait finished: the report] Say the report is ready.`, then that turn's `wait_until`
- row with `"ok": false` (refused: "Only the person can set up or stop a wait, in their
- own chat with you; …"), and the fake engine's reply.
-- Still one `options` card: the refused call made no second wait.
+ row with `"ok": true` (the condition already holds, so the result asks it to
+ carry out `follow_up` now), and the fake engine's reply.
+- Still one `options` card because the condition already holds.
- `waits.json` holds `"waits": []`.
- One notification with `"kind": "wait"` and `"title": "Pepper's wait is over"`.
- The last `messages` still shows one fired line.
@@ -61,10 +64,18 @@ internet, and what a real model does with the follow-up (the fake engine replies
## Last exercised
+2026-11-16, macOS arm64, Node 26.5.0. Five focused Vitest files passed with
+60 tests, including successive build, test and package waits in one direct chat.
+The packaged server passed its smoke checks and all four wait and handed-wait
+e2e tests against disposable fixture data. The route tests also cover immediate
+follow-up when the requested condition already holds.
+
+## Earlier fixture transcript
+
2026-10-28, Node 24, branch `feat/bot-waits` at `4fc4ef0bb`, fixture log
`/var/folders/7b/15jj691d4tj_7vq99cqvwgbr0000gn/T/openmausbot-verification-evidence/server-1793162265419-23568.log`.
-Every expectation above held. The lines below are abridged: only these fields of each
-message are kept, and `<W>` stands for the temp dir.
+The lines below record the original continuation refusal. They are abridged to
+selected message fields, and `<W>` stands for the temp dir.
`wait_until` answer in the person's turn:
diff --git a/server/index.ts b/server/index.ts
index 952fb86125..c0e79302c0 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -484,7 +484,7 @@ import { listenWebhookIngress, type WebhookIngress } from "./webhook-ingress.ts"
import { addressFor } from "./webhook-address.ts";
import { assertModelVariantSupported, memberTurnSelection } from "./member-turn.ts";
import { WebhookManager } from "./webhooks.ts";
-import { tieAutomationsToBots } from "./bot-automations.ts"; import { WaitManager } from "./waits.ts"; import { cancelWaitFromCard, createWaitHost, waitRunChat } from "./wait-host.ts"; import { continuedConversation } from "./routine-same-conversation.ts"; import { createWaitRoutes, findWaitPeer, handedAssignment, hostWaitRefusal, waitSourceRefusal, type WaitRouteContext } from "./routes/waits.ts";
+import { tieAutomationsToBots } from "./bot-automations.ts"; import { WaitManager } from "./waits.ts"; import { cancelWaitFromCard, createWaitHost, waitContinuesHere, waitRunChat } from "./wait-host.ts"; import { continuedConversation } from "./routine-same-conversation.ts"; import { createWaitRoutes, findWaitPeer, handedAssignment, hostWaitRefusal, waitSourceRefusal, type WaitRouteContext } from "./routes/waits.ts";
import type { WebhookTrigger } from "../shared/webhooks.ts";
import { AGENTS_NODE_FLAG, SPAWNED_PROXIES } from "./proxy-paths.ts";
import { agentsProxyLaunch, agentsToolBridgeEnv, applyAgentsBridge, bridgedToolTitle, turnEngine } from "./agents-bridge-switch.ts"; import { serverTurnedOff } from "./drivers/agents-tool-groups.ts"; import { availableToolGroups, toolsOffPart } from "./tool-groups.ts"; import { agentsServerEnv, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, roomSkillsRefusal, type TurnKind } from "./agents-turn.ts";
@@ -11118,7 +11118,7 @@ function connectorThread(botId: string, threadId: string) {
}
function directChatOf(botId: string, threadId: string): boolean { const source = connectorThread(botId, threadId); return source !== null && !source.group; }
function waitTurnChecks(capability: InternalCapability, sender: BotRecord): Pick<WaitRouteContext, "sourceRefusal" | "assignmentId" | "hostRefusal" | "guest" | "peer" | "elsewhere"> { const { threadId } = capability, place = () => { const turn = turnPlaces.get(threadId); return turn?.botId === sender.id ? turn.place : null; }, assignmentId = () => handedAssignment(capability.roomHandoffId ?? directCoordinationSettlers.get(capability.generation)?.nodeId, (id) => coordinator.node(id));
- return { assignmentId, sourceRefusal: (op, assignment) => { const source = connectorThread(sender.id, threadId); return waitSourceRefusal({ owned: source !== null, room: Boolean(source?.group), depth: capability.depth, handedOff: Boolean(capability.roomHandoffId), routineRun: Boolean(activeRoutineRunForThread(threadId)), outsideDriven: outsideDrivenThread(threadId), personStarted: turnOrigin(capability).kind === "user", guest: cloudGuestDriven(threadId), op, assignmentId: assignment }); }, hostRefusal: () => hostWaitRefusal({ cloudHome: Boolean(CLOUD_HOME), hosted: HOSTED_WORKSPACE, guest: cloudGuestDriven(threadId), place: place() }), guest: () => cloudGuestDriven(threadId), peer: (name) => findWaitPeer(reachablePeers(store.bots, sender), sender.id, name), elsewhere: placesElsewhere.explain }; }
+ return { assignmentId, sourceRefusal: (op, assignment) => { const source = connectorThread(sender.id, threadId); return waitSourceRefusal({ owned: source !== null, room: Boolean(source?.group), depth: capability.depth, handedOff: Boolean(capability.roomHandoffId), routineRun: Boolean(activeRoutineRunForThread(threadId)), waitContinuation: !capability.externalRuntime && directRequestOwners.get(threadId)?.generations.has(capability.generation) === true && waitContinuesHere(activeRoutineRunForThread(threadId), sender.id, threadId, store), outsideDriven: outsideDrivenThread(threadId), personStarted: turnOrigin(capability).kind === "user", guest: cloudGuestDriven(threadId), op, assignmentId: assignment }); }, hostRefusal: () => hostWaitRefusal({ cloudHome: Boolean(CLOUD_HOME), hosted: HOSTED_WORKSPACE, guest: cloudGuestDriven(threadId), place: place() }), guest: () => cloudGuestDriven(threadId), peer: (name) => findWaitPeer(reachablePeers(store.bots, sender), sender.id, name), elsewhere: placesElsewhere.explain }; }
/** Read fresh every time; a line stamped via the HTTP API does not count, so a bot cannot re-arm the ceiling it just spent. */
function lastHumanRoomMessageAt(group: GroupRecord): number | undefined {
diff --git a/server/routes/waits.test.ts b/server/routes/waits.test.ts
index fd8026a5b2..77286e55d9 100644
--- a/server/routes/waits.test.ts
+++ b/server/routes/waits.test.ts
@@ -63,6 +63,10 @@ describe("the waits route", () => {
it("answers 200 for a condition already true and the manager's status for a refusal, and appends a note", async () => {
waits.create.mockResolvedValueOnce({ state: "already", text: "It exists already." } as never);
expect(await call("POST", "/api/internal/waits", FILE_WAIT)).toMatchObject({ status: 200, payload: { text: "It exists already." } });
+ waits.create.mockResolvedValueOnce({ state: "already", text: "It exists already." } as never);
+ expect(await call("POST", "/api/internal/waits", { ...FILE_WAIT, follow_up: "Read the report and continue." })).toMatchObject({
+ status: 200, payload: { text: "It exists already.\nCarry out follow_up now in this turn: Read the report and continue." },
+ });
waits.create.mockResolvedValueOnce({ state: "refused", status: 409, error: "Too many." } as never);
expect(await call("POST", "/api/internal/waits", FILE_WAIT)).toMatchObject({ status: 409, payload: { error: "Too many." } });
waits.create.mockResolvedValueOnce({ state: "created", wait: { id: "w2", label: "l", expiresAt: 0 }, note: "Slow page." } as never);
@@ -198,6 +202,15 @@ describe("the waits route", () => {
expect(waitSourceRefusal({ ...handed, room: true, op: "create" })).toBe(WAIT_MESSAGES.room);
expect(waitSourceRefusal({ ...handed, owned: false, op: "create" })).toBe(WAIT_MESSAGES.notYours);
});
+
+ it("lets a proved wait continuation create the next wait in its own direct chat", () => {
+ const continuation = { owned: true, room: false, depth: 0, handedOff: false, routineRun: true, outsideDriven: true, personStarted: false, guest: false, waitContinuation: true, op: "create" as const };
+ expect(waitSourceRefusal(continuation)).toBeNull();
+ for (const patch of [
+ { waitContinuation: false }, { owned: false }, { room: true }, { guest: true },
+ { depth: 1 }, { handedOff: true }, { routineRun: false }, { op: "cancel" as const },
+ ]) expect(waitSourceRefusal({ ...continuation, ...patch })).not.toBeNull();
+ });
it("holds a handed-on wait to its running assignment, never a root or one that ended", () => {
const nodes: Record<string, { id: string; parentId?: string; status: string }> = {
child: { id: "child", parentId: "root", status: "running" },
diff --git a/server/routes/waits.ts b/server/routes/waits.ts
index e4ed99c5d5..eaaec3915e 100644
--- a/server/routes/waits.ts
+++ b/server/routes/waits.ts
@@ -15,7 +15,7 @@ const CANCEL = "/api/internal/waits/cancel";
export const WAIT_MESSAGES = {
notYours: "This conversation is not yours.",
room: "Waits are made in a one-to-one chat with the person, not in a room.",
- notPerson: "Only the person can set up or stop a wait, in their own chat with you; a routine or an outside event cannot, and work a bot handed you can set one only when the person's own request started it.",
+ notPerson: "A wait needs the person's own request in this chat or a verified continuation of its completed wait. Scheduled routines and outside events cannot set one. Work handed on by a bot needs the person's original request and can only create a wait.",
handedStop: "Work handed to you by a bot can set one wait but not stop one: it ends on its own, or the person stops it.",
serverHost: "File and program waits look at the computer MausBot runs on, and here that is a server, not the computer you work on. Use url_contains, url_missing or bot_idle.",
guest: "File and program waits are only for the owner of this computer. Use url_contains, url_missing or bot_idle.",
@@ -124,10 +124,11 @@ export function parseWaitRequest(body: unknown, home: string): { ok: true; reque
export function waitSourceRefusal(turn: {
owned: boolean; room: boolean; depth: number; handedOff: boolean; routineRun: boolean; outsideDriven: boolean; personStarted: boolean; guest: boolean;
- op?: "create" | "cancel"; assignmentId?: string;
+ op?: "create" | "cancel"; assignmentId?: string; waitContinuation?: boolean;
}): string | null {
if (!turn.owned) return WAIT_MESSAGES.notYours;
if (turn.room) return WAIT_MESSAGES.room;
+ if (turn.waitContinuation && turn.routineRun && turn.depth === 0 && !turn.handedOff && !turn.guest && turn.op === "create") return null;
if (turn.routineRun || turn.outsideDriven) return WAIT_MESSAGES.notPerson;
if (turn.depth > 0 || turn.handedOff) {
if (!turn.personStarted || turn.guest || !turn.assignmentId) return WAIT_MESSAGES.notPerson;
@@ -246,7 +247,9 @@ export function createWaitRoutes(deps: { waits: Pick<WaitManager, "create" | "li
...(assignmentId ? { assignmentId, stillAllowed: () => (ctx.assignmentId?.() === assignmentId ? null : WAIT_MESSAGES.notPerson) } : {}),
});
if (result.state === "refused") return void json(res, result.status, { error: result.error });
- if (result.state === "already") return void json(res, 200, { text: result.text });
+ if (result.state === "already") return void json(res, 200, { text: request.followUp
+ ? `${result.text}\nCarry out follow_up now in this turn: ${request.followUp}`
+ : result.text });
const { wait, note } = result;
const then = request.followUp ? `, and you will then do what you wrote in follow_up${deps.cloudHome ? " in a run that reports in its own results chat, not this one" : ""}` : "";
const every = WAIT_WAKE_MS / 60_000;
diff --git a/server/wait-host.test.ts b/server/wait-host.test.ts
index 9b1272b064..574e701e5e 100644
--- a/server/wait-host.test.ts
+++ b/server/wait-host.test.ts
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import type { Notification } from "../shared/notification.ts";
import type { Message } from "./store.ts";
-import { cancelWaitFromCard, createWaitHost, waitRunChat, type WaitHostDeps } from "./wait-host.ts";
+import { cancelWaitFromCard, createWaitHost, waitContinuesHere, waitRunChat, type WaitHostDeps } from "./wait-host.ts";
import type { WaitRecord } from "./waits.ts";
const NOW = 1_700_000_000_000;
@@ -110,4 +110,19 @@ describe("the store side of waits", () => {
it("knows a deleted bot from an idle one", () => {
expect([host.botBusy("bot-1"), host.botBusy("gone")]).toEqual([false, undefined]);
});
+
+ it("proves a wait continuation from the run and its fired notice in the same chat", () => {
+ const run = { eventSource: "wait" as const, triggerSource: "webhook" as const, botId: "bot-1", threadId: "t-1", resultsThreadId: "t-1", webhookId: "wait:w1", deliveryId: "w1" };
+ expect(waitContinuesHere(run, "bot-1", "t-1", store)).toBe(false);
+ host.post(wait, { status: "fired", text: "done" });
+ expect(waitContinuesHere(run, "bot-1", "t-1", store)).toBe(true);
+ expect(waitContinuesHere(null, "bot-1", "t-1", store)).toBe(false);
+ for (const patch of [
+ { eventSource: "app" as const }, { eventSource: undefined }, { triggerSource: "schedule" as const },
+ { botId: "other" }, { threadId: "other" }, { resultsThreadId: "other" },
+ { deliveryId: "other" }, { deliveryId: undefined }, { webhookId: "other" },
+ ]) expect(waitContinuesHere({ ...run, ...patch }, "bot-1", "t-1", store)).toBe(false);
+ store.messages[0]!.wait!.status = "expired";
+ expect(waitContinuesHere(run, "bot-1", "t-1", store)).toBe(false);
+ });
});
diff --git a/server/wait-host.ts b/server/wait-host.ts
index 0205f4d010..014636f64b 100644
--- a/server/wait-host.ts
+++ b/server/wait-host.ts
@@ -28,6 +28,19 @@ export function waitRunChat(
return directChat(run.botId, run.resultsThreadId) ? run.resultsThreadId : null;
}
+/** A wait continuation is proved by the server's run and fired notice in the same bot's chat, never its prompt. */
+export function waitContinuesHere(
+ run: Pick<RoutineRun, "eventSource" | "triggerSource" | "botId" | "threadId" | "resultsThreadId" | "webhookId" | "deliveryId"> | null,
+ botId: string,
+ threadId: string,
+ store: Pick<Store, "messagesFor">,
+): boolean {
+ if (!run || run.eventSource !== "wait" || run.triggerSource !== "webhook" || run.botId !== botId
+ || run.threadId !== threadId || run.resultsThreadId !== threadId || !run.deliveryId
+ || run.webhookId !== `wait:${run.deliveryId}`) return false;
+ return store.messagesFor(threadId).some((message) => message.wait?.status === "fired" && message.wait.id === run.deliveryId);
+}
+
type CardStore = Pick<Store, "messagesFor" | "patchMessage">;
function settleWaitCard(store: CardStore, threadId: string, messageId: string, how: "fired" | "expired" | "cancelled"): void {
diff --git a/server/waits.e2e.test.ts b/server/waits.e2e.test.ts
index 66887f2c35..3a19ff885f 100644
--- a/server/waits.e2e.test.ts
+++ b/server/waits.e2e.test.ts
@@ -79,9 +79,9 @@ it("waits for a file with no AI, posts once in the asked chat, notifies, and con
}
}, 120_000);
-it("refuses a new wait in the run a wait's follow-up started, so a wait never renews itself", async () => {
+it("continues successive waits in the same authorized chat after each completion", async () => {
const { folder, gate, api, busy, settledTurn, transcript, send, turnPrompt, turnToken, close } = await scout("renew");
- const build = join(folder, "build.txt");
+ const build = join(folder, "build.txt"), tests = join(folder, "tests.txt"), packageFile = join(folder, "package.txt");
try {
await send("Tell me when the build is done");
const asked = await turnToken();
@@ -92,11 +92,19 @@ it("refuses a new wait in the run a wait's follow-up started, so a wait never re
expect(await busy()).toBe(true);
const followUp = await turnToken();
expect(await api("GET", "/api/internal/waits", undefined, 200, followUp)).toEqual({ text: WAIT_MESSAGES.none });
- const again = { label: "the build", kind: "file_changed", path: build, follow_up: "Wait for the build again." };
- expect(await api("POST", "/api/internal/waits", again, 403, followUp)).toEqual({ error: WAIT_MESSAGES.notPerson });
+ const next = { label: "the tests", kind: "file_exists", path: tests, follow_up: "Wait for the package." };
+ expect((await api("POST", "/api/internal/waits", next, 201, followUp)).text).toContain("Waiting for the tests");
expect(await api("POST", "/api/internal/waits/cancel", { id: "any" }, 403, followUp)).toEqual({ error: WAIT_MESSAGES.notPerson });
writeFileSync(gate, "finish"); await settledTurn();
- expect((await transcript()).filter((m) => m.card?.waitRequest).map((m) => m.card.waitRequest)).toMatchObject([{ label: "the build", settled: "fired" }]);
+ unlinkSync(gate);
+ writeFileSync(tests, "passed");
+ await expect.poll(turnPrompt, { timeout: 40_000 }).toContain("[Wait finished: the tests] Wait for the package.");
+ const afterTests = await turnToken();
+ expect((await api("POST", "/api/internal/waits", { label: "the package", kind: "file_exists", path: packageFile }, 201, afterTests)).text).toContain("Waiting for the package");
+ writeFileSync(gate, "finish"); await settledTurn();
+ expect((await transcript()).filter((m) => m.card?.waitRequest).map((m) => m.card.waitRequest)).toMatchObject([
+ { label: "the build", settled: "fired" }, { label: "the tests", settled: "fired" },
+ ]);
} finally {
await close();
}