Skip to content

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

test(cursor): a routine retry that fails too, end to end

Absterrg0081acd2475f0
diff --git a/docs/verification/engines.md b/docs/verification/engines.md
index ad04ba5b9c..fb905e6f7b 100644
--- a/docs/verification/engines.md
+++ b/docs/verification/engines.md
@@ -81,7 +81,7 @@ cursor-agent 2026.10.22 (`cursor-release.ts`) catches a failed model call inside
pnpm exec vitest run server/cursor-reply-failure.e2e.test.ts server/drivers/acp/cursor.test.ts
```
-The end-to-end test launches the isolated fixture (`launchVerificationServer`), adds a `cursorAgent` instance backed by `server/testing/fake-acp-cli.ts` that replays that wire sequence, and drives it with the control verbs and the routines API. A chat turn settles as failed with "Cursor had a temporary server problem (HTTP 503)…" and no message carries the raw failure line. A routine run started by hand is queued for one automatic retry (`retried: "provider"`) and completes once the fake stops failing. On a build without the fix, the same turn settles as completed. These checks replay the pinned build's output; they do not prove a live Cursor account or a later Cursor release's wording.
+The end-to-end test launches the isolated fixture (`launchVerificationServer`), adds a `cursorAgent` instance backed by `server/testing/fake-acp-cli.ts` that replays that wire sequence, and drives it with the control verbs and the routines API. A chat turn settles as failed with "Cursor had a temporary server problem (HTTP 503)…" and no message carries the raw failure line. A routine run started by hand is queued for one automatic retry (`retried: "provider"`) and completes once the fake stops failing. When the retry fails too, the run ends failed with "Failed after one automatic retry: …", the routine's failure streak is 1, the owner is notified and the Chief opens its Problems to look at thread. On a build without the fix, the turn and both runs settle as completed. These checks replay the pinned build's output; they do not prove a live Cursor account or a later Cursor release's wording.
## Slow or empty CLI version responses
diff --git a/server/cursor-reply-failure.e2e.test.ts b/server/cursor-reply-failure.e2e.test.ts
index deb03b0582..df379782bf 100644
--- a/server/cursor-reply-failure.e2e.test.ts
+++ b/server/cursor-reply-failure.e2e.test.ts
@@ -1,25 +1,41 @@
+// A failed model call Cursor sends as its reply, on the real server: the isolated fixture with a cursorAgent instance backed
+// by the fake ACP CLI, which replays cursor-agent 2026.10.22's sequence from an updates file it re-reads at each prompt.
import { spawn, type ChildProcess } from "node:child_process";
import { closeSync, openSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
-import { expect, it } from "vitest";
-import { launchVerificationServer, runControlOmb, verificationServerEnvironment } from "../scripts/control-omb.ts";
+import { afterEach, expect, it } from "vitest";
+import { launchVerificationServer, runControlOmb, verificationServerEnvironment, type VerificationServer } from "../scripts/control-omb.ts";
+import { INCIDENTS_THREAD_TITLE } from "./incidents.ts";
import { waitForExit } from "./testing/cleanup.ts";
+import { openSse, type SseRecorder } from "./testing/sse.ts";
const engineId = "cursor-fixture";
-// cursor-agent 2026.10.22 sends a failed model call as this one chunk, then waits on a backgrounded shell, then end_turn.
+// The failure chunk, a backgrounded shell Cursor waits on, then end_turn.
const FAILED_CALL = [
{ update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "\n\nError: RetriableError: [unavailable] HTTP 503" } } },
{ update: { sessionUpdate: "tool_call", toolCallId: "watch-1", title: "Watching: wait until 06:15", kind: "other" } },
{ update: { sessionUpdate: "tool_call_update", toolCallId: "watch-1", status: "completed" } },
];
+const TEMPORARY_PROBLEM = "Cursor had a temporary server problem (HTTP 503)";
-it("fails a Cursor turn and retries its routine run when Cursor reports a failed model call as its reply", async () => {
- const fixture = await launchVerificationServer();
+let fixture: VerificationServer | undefined;
+let restarted: ChildProcess | undefined;
+let events: SseRecorder | undefined;
+let evidence: unknown[] = [];
+afterEach(async () => {
+ events?.close();
+ if (fixture) writeFileSync(`${fixture.info.logPath}.cursor-reply-failure.json`, JSON.stringify({ evidence }, null, 2));
+ await waitForExit(restarted, { signal: "SIGTERM" });
+ fixture = restarted = events = undefined;
+ evidence = [];
+});
+
+async function cursorServer({ keepChief }: { keepChief: boolean }) {
+ fixture = await launchVerificationServer();
const { dataDir, url, logPath } = fixture.info;
const updatesFile = join(dataDir, "cursor-updates.json");
- const evidence: unknown[] = [{ fixture: fixture.info, provider: "fake cursor-agent ACP, no network" }];
- let restarted: ChildProcess | undefined;
+ evidence.push({ fixture: fixture.info, provider: "fake cursor-agent ACP, no network" });
const api = async (method: string, path: string, body?: unknown, status = 200) => {
const response = await fetch(`${url}${path}`, {
method, headers: { "content-type": "application/json", origin: url },
@@ -34,55 +50,75 @@ it("fails a Cursor turn and retries its routine run when Cursor reports a failed
evidence.push({ command: args, result });
return result;
};
- try {
- await waitForExit(fixture.child, { signal: "SIGTERM" });
- const configPath = join(dataDir, "config.json");
- const config = JSON.parse(readFileSync(configPath, "utf8"));
- config.instances[engineId] = { driver: "cursorAgent", displayName: "Cursor fixture",
- config: { cli: fileURLToPath(new URL("./testing/fake-acp-cli.ts", import.meta.url)) },
- environment: { FAKE_ACP_VERSION: "2026.10.22-27dcf5f", FAKE_ACP_MODELS_LIST: "auto-only", FAKE_ACP_UPDATES_FILE: updatesFile } };
- writeFileSync(configPath, JSON.stringify(config));
- writeFileSync(updatesFile, JSON.stringify(FAILED_CALL));
- const log = openSync(logPath, "a", 0o600);
- restarted = spawn(process.execPath, ["--experimental-strip-types", fileURLToPath(new URL("./index.ts", import.meta.url))], {
- cwd: fileURLToPath(new URL("..", import.meta.url)),
- env: verificationServerEnvironment({}, dataDir, Number(new URL(url).port)), stdio: ["ignore", log, log],
- });
- closeSync(log);
- await expect.poll(async () => {
- try { return (await fetch(`${url}/api/health`, { signal: AbortSignal.timeout(1_000) })).ok; } catch { return false; }
- }, { timeout: 25_000 }).toBe(true);
+ await waitForExit(fixture.child, { signal: "SIGTERM" });
+ const configPath = join(dataDir, "config.json");
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
+ config.instances[engineId] = { driver: "cursorAgent", displayName: "Cursor fixture",
+ config: { cli: fileURLToPath(new URL("./testing/fake-acp-cli.ts", import.meta.url)) },
+ environment: { FAKE_ACP_VERSION: "2026.10.22-27dcf5f", FAKE_ACP_MODELS_LIST: "auto-only", FAKE_ACP_UPDATES_FILE: updatesFile } };
+ writeFileSync(configPath, JSON.stringify(config));
+ writeFileSync(updatesFile, JSON.stringify(FAILED_CALL));
+ const log = openSync(logPath, "a", 0o600);
+ restarted = spawn(process.execPath, ["--experimental-strip-types", fileURLToPath(new URL("./index.ts", import.meta.url))], {
+ cwd: fileURLToPath(new URL("..", import.meta.url)),
+ env: verificationServerEnvironment({}, dataDir, Number(new URL(url).port)), stdio: ["ignore", log, log],
+ });
+ closeSync(log);
+ await expect.poll(async () => {
+ try { return (await fetch(`${url}/api/health`, { signal: AbortSignal.timeout(1_000) })).ok; } catch { return false; }
+ }, { timeout: 25_000 }).toBe(true);
- for (const starter of (await api("GET", "/api/bots")).bots.filter((bot: any) => bot.chiefOfStaff)) {
- await api("PATCH", `/api/bots/${starter.id}`, { chiefOfStaff: false });
- }
- const bot = (await control("new-bot", "--name", "Cursor routine")).bot;
- const threadId: string = bot.activeTaskId ?? bot.threadId;
- await api("PATCH", `/api/bots/${bot.id}/tasks/${threadId}`, {
- modelSelection: { instanceId: engineId, model: "auto" }, updateBotDefault: true,
- });
-
- expect((await control("send", "--bot", bot.id, "--task", threadId, "--text", "Post the queue.")).success).toBe(true);
- expect((await control("wait", "--bot", bot.id, "--task", threadId, "--timeout", "30")).state).toBe("failed");
- const { messages } = await control("messages", "--bot", bot.id, "--task", threadId, "--limit", "20");
- expect(messages.some((message: any) => JSON.stringify(message).includes("RetriableError"))).toBe(false);
- expect(messages).toContainEqual(expect.objectContaining({ kind: "activity", tool: expect.objectContaining({
- ok: false, name: expect.stringContaining("Cursor had a temporary server problem (HTTP 503)") }) }));
+ const chief = (await api("GET", "/api/bots")).bots.find((bot: any) => bot.chiefOfStaff);
+ if (!keepChief && chief) await api("PATCH", `/api/bots/${chief.id}`, { chiefOfStaff: false });
+ const bot = (await control("new-bot", "--name", "Cursor routine")).bot;
+ const threadId: string = bot.activeTaskId ?? bot.threadId;
+ await api("PATCH", `/api/bots/${bot.id}/tasks/${threadId}`, { modelSelection: { instanceId: engineId, model: "auto" }, updateBotDefault: true });
+ events = await openSse(`${url}/api/events`, { origin: url });
+ const runRoutine = async () => {
const { routine } = await api("POST", "/api/routines", { name: "Morning post", prompt: "Post the queue.", botId: bot.id,
schedule: { type: "interval", everyMinutes: 1440, anchorAt: Date.now() + 86_400_000 } }, 201);
const { run } = await api("POST", `/api/routines/${routine.id}/run`, {}, 201);
- const current = async () => {
- const found = (await api("GET", "/api/routines")).runs.find((candidate: any) => candidate.id === run.id);
- evidence.push({ at: Date.now(), run: found });
- return found;
+ return async () => {
+ const { routines, runs } = await api("GET", "/api/routines");
+ const current = { routine: routines.find((candidate: any) => candidate.id === routine.id), run: runs.find((candidate: any) => candidate.id === run.id) };
+ evidence.push({ at: Date.now(), ...current });
+ return current;
};
- await expect.poll(async () => { const { status, retried } = await current(); return { status, retried }; }, { timeout: 30_000, interval: 500 })
- .toEqual({ status: "queued", retried: "provider" });
- writeFileSync(updatesFile, "[]");
- await expect.poll(async () => (await current()).status, { timeout: 60_000, interval: 1_000 }).toBe("completed");
- } finally {
- writeFileSync(`${logPath}.cursor-reply-failure.json`, JSON.stringify({ evidence }, null, 2));
- if (restarted) await waitForExit(restarted, { signal: "SIGTERM" });
- }
+ };
+ const notified = () => events!.frames.filter((frame) => frame.kind === "notify").map((frame) => frame.notification as { kind: string; title: string; body: string });
+ return { api, control, bot, threadId, chief, updatesFile, runRoutine, notified };
+}
+
+it("fails a Cursor turn on the failed call it sends as its reply, and never shows the raw line", async () => {
+ const s = await cursorServer({ keepChief: false });
+ expect((await s.control("send", "--bot", s.bot.id, "--task", s.threadId, "--text", "Post the queue.")).success).toBe(true);
+ expect((await s.control("wait", "--bot", s.bot.id, "--task", s.threadId, "--timeout", "30")).state).toBe("failed");
+ const { messages } = await s.control("messages", "--bot", s.bot.id, "--task", s.threadId, "--limit", "20");
+ expect(messages.some((message: any) => JSON.stringify(message).includes("RetriableError"))).toBe(false);
+ expect(messages).toContainEqual(expect.objectContaining({ kind: "activity", tool: expect.objectContaining({
+ ok: false, name: expect.stringContaining(TEMPORARY_PROBLEM) }) }));
+}, 120_000);
+
+it("retries a routine run once on that failure, and it completes when the retry succeeds", async () => {
+ const s = await cursorServer({ keepChief: false });
+ const state = await s.runRoutine();
+ await expect.poll(async () => { const { status, retried } = (await state()).run; return { status, retried }; }, { timeout: 30_000, interval: 500 })
+ .toEqual({ status: "queued", retried: "provider" });
+ writeFileSync(s.updatesFile, "[]");
+ await expect.poll(async () => (await state()).run.status, { timeout: 60_000, interval: 1_000 }).toBe("completed");
+ expect(s.notified().filter((notification) => notification.kind === "routine-failed")).toEqual([]);
+}, 120_000);
+
+it("fails a routine run whose retry fails too, counts it, and tells the Chief", async () => {
+ const s = await cursorServer({ keepChief: true });
+ const state = await s.runRoutine();
+ await expect.poll(async () => (await state()).run.status, { timeout: 60_000, interval: 1_000 }).toBe("failed");
+ const { routine, run } = await state();
+ expect(run).toMatchObject({ retried: "provider", error: expect.stringMatching(/^Failed after one automatic retry: Cursor had a temporary server problem \(HTTP 503\)/) });
+ expect(routine.failureStreak).toBe(1);
+ await expect.poll(() => s.notified().filter((notification) => notification.kind === "routine-failed"), { timeout: 15_000 })
+ .toEqual([expect.objectContaining({ title: "Cursor routine's routine failed", body: `Morning post: ${run.error}` })]);
+ await expect.poll(async () => (await s.api("GET", "/api/bots")).bots.find((bot: any) => bot.id === s.chief.id).tasks
+ .map((task: any) => task.title), { timeout: 15_000 }).toContain(INCIDENTS_THREAD_TITLE);
}, 120_000);