Skip to content

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

fix: authorize immediate wait follow-ups after probing

fangyuanc305f22e3d92
diff --git a/docs/verification/waits.md b/docs/verification/waits.md
index 3eb5ed31fd..5024302c41 100644
--- a/docs/verification/waits.md
+++ b/docs/verification/waits.md
@@ -15,8 +15,9 @@ pnpm exec vitest run server/wait-probes.test.ts server/waits.test.ts server/wait
The fake engine calls `wait_until` on every turn it runs, including the follow-up.
A follow-up proved by its live turn generation, originating wait run and fired notice
can create its next wait in the same bot's direct chat. Continuation authorization is
-checked again after the initial probe and immediately before persistence. The multi-stage
-e2e test exercises two completions and registration of the next stage. Scheduled routines and unrelated outside events
+checked again after the initial probe, before returning immediate follow-up instructions
+or persisting a wait. 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.
@@ -66,9 +67,9 @@ 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. Twelve targeted Vitest files passed with
-500 tests, including successive build, test and package waits in one direct chat,
-originating-run and live-generation authorization, and rejection before persistence
-when continuation authorization changes during a URL probe.
+505 tests, including successive build, test and package waits in one direct chat,
+originating-run and live-generation authorization, and rejection when continuation
+authorization changes during a URL probe with either a matching or pending condition.
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.
diff --git a/server/waits.e2e.test.ts b/server/waits.e2e.test.ts
index 3a19ff885f..3bf7d11e73 100644
--- a/server/waits.e2e.test.ts
+++ b/server/waits.e2e.test.ts
@@ -92,6 +92,8 @@ it("continues successive waits in the same authorized chat after each completion
expect(await busy()).toBe(true);
const followUp = await turnToken();
expect(await api("GET", "/api/internal/waits", undefined, 200, followUp)).toEqual({ text: WAIT_MESSAGES.none });
+ expect((await api("POST", "/api/internal/waits", { label: "the completed build", kind: "file_exists", path: build, follow_up: "Read the build report." }, 200, followUp)).text)
+ .toContain("Carry out follow_up now in this turn: Read the build report.");
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 });
diff --git a/server/waits.test.ts b/server/waits.test.ts
index cbd9a1a53c..209c7fc014 100644
--- a/server/waits.test.ts
+++ b/server/waits.test.ts
@@ -91,8 +91,12 @@ function harness(options: Partial<WaitManagerOptions> = {}) {
}
describe("WaitManager", () => {
- it.each(["ended", "new generation", "different run"])("refuses to persist a continuation that changed during a URL probe: %s", async (change) => {
+ it.each([
+ ["ended", ""], ["new generation", ""], ["different run", ""],
+ ["ended", "done"], ["new generation", "done"], ["different run", "done"],
+ ])("refuses a revoked continuation after a URL probe (%s, page %j)", async (change, text) => {
const h = harness();
+ h.page = { ok: true, text };
const route = createWaitRoutes({ waits: h.manager });
const json = vi.fn();
const turn = { active: true, generation: "generation-1", runId: "run-1" };
@@ -120,6 +124,23 @@ describe("WaitManager", () => {
expect(h.showCard).not.toHaveBeenCalled();
});
+ it.each([false, true])("returns an immediate follow-up for an authorized request (continuation %s)", async (continuation) => {
+ const h = harness();
+ h.page = { ok: true, text: "done" };
+ const route = createWaitRoutes({ waits: h.manager });
+ const json = vi.fn();
+ await route({
+ method: "POST", path: "/api/internal/waits", res: {} as never, json,
+ botId: "bot-1", threadId: "t-1",
+ readBody: async () => ({ label: "the build", kind: "url_contains", url: "https://example.test/build", text: "done", follow_up: "Run tests." }),
+ sourceRefusal: () => null, continuationAllowed: () => continuation, hostRefusal: () => null, guest: () => false, peer: () => null,
+ });
+ expect(json).toHaveBeenCalledWith(expect.anything(), 200, { text: expect.stringContaining("Carry out follow_up now in this turn: Run tests.") });
+ expect(h.manager.list("bot-1")).toEqual([]);
+ expect(existsSync(h.file)).toBe(false);
+ expect(h.showCard).not.toHaveBeenCalled();
+ });
+
it("keeps work a bot handed on to one open wait per assignment, across a restart, until it ends", async () => {
const h = harness();
const handed = (assignmentId: string) => h.manager.create({ botId: "bot-1", threadId: "t-1", label: "the report", condition: { kind: "file_exists", path: "/r.txt" }, assignmentId });
diff --git a/server/waits.ts b/server/waits.ts
index 3384821e97..b593760b65 100644
--- a/server/waits.ts
+++ b/server/waits.ts
@@ -181,8 +181,8 @@ export class WaitManager {
/**
* Makes a wait once its first check shows the condition is not met yet. Limits are checked before
- * and after that check, and `input.stillAllowed` last of all, since the check can take seconds and
- * the work that asked for the wait can end meanwhile.
+ * and after that check. The work that asked for the wait must still be authorized after the probe,
+ * before returning an already-met result or persisting a wait.
*/
async create(input: NewWait): Promise<CreateWaitResult> {
const full = this.limitRefusal(input);
@@ -192,11 +192,11 @@ export class WaitManager {
if (verdict.gone) return { state: "refused", status: 400, error: `${(condition as { botName: string }).botName} no longer exists. Use a name or id from list_bots.` };
if (verdict.unlisted) return { state: "refused", status: 400, error: NO_PROCESS_LIST };
if (verdict.page && !verdict.page.ok && verdict.page.refused) return { state: "refused", status: 400, error: verdict.page.error };
+ const ended = input.stillAllowed?.();
+ if (ended) return { state: "refused", status: 403, error: ended };
if (verdict.met) return { state: "already", text: `${describeCondition(condition)} already. Nothing was set up: tell the person now.` };
const crowded = this.limitRefusal(input);
if (crowded) return crowded;
- const ended = input.stillAllowed?.();
- if (ended) return { state: "refused", status: 403, error: ended };
const now = this.now();
const wait: WaitRecord = {
id: randomUUID(),