Skip to content

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

Re-ask a goal coordinator whose control envelope is malformed

erywim9d7297ac1b19
diff --git a/server/bot-box/env.test.ts b/server/bot-box/env.test.ts
index 9605fdb2d8..e9a277332a 100644
--- a/server/bot-box/env.test.ts
+++ b/server/bot-box/env.test.ts
@@ -37,7 +37,7 @@ const SERVER_ONLY_OMB: ReadonlySet<string> = new Set([
"OMB_DEV_TRUST_LOCAL_BROWSER", "OMB_DISABLE_ANNOUNCEMENTS", "OMB_DISABLE_MODEL_CATALOG_FETCH", "OMB_DISABLE_MODEL_MANIFEST_FETCH", "OMB_DUCKDB_DIR", "OMB_DUCKDB_MAX_TEMP_SIZE",
"OMB_DUCKDB_MEMORY_LIMIT", "OMB_ELEVENLABS_API", "OMB_ENGINE_SESSION_SWEEP", "OMB_ENGINE_TAG", "OMB_ENTERPRISE_DIR", "OMB_ENVIRONMENT_LABEL", "OMB_EOF",
"OMB_FIRST_REPLY_NOTICE_MS", "OMB_FISH_AUDIO_API", "OMB_FISH_AUDIO_API_KEY", "OMB_FISH_LIVE_AGENT_ID", "OMB_FISH_LIVE_URL", "OMB_FLEET_SOCKET", "OMB_GATE_",
- "OMB_GEMINI_API_KEY", "OMB_GEMINI_IMAGE_KEY", "OMB_GEMINI_LIVE_MODEL", "OMB_GEMINI_LIVE_URL", "OMB_GEMINI_TTS_API", "OMB_GOAL_WAIT_MAX_MS",
+ "OMB_GEMINI_API_KEY", "OMB_GEMINI_IMAGE_KEY", "OMB_GEMINI_LIVE_MODEL", "OMB_GEMINI_LIVE_URL", "OMB_GEMINI_TTS_API", "OMB_GOAL_CONTROL_MISSES", "OMB_GOAL_WAIT_MAX_MS",
"OMB_GREENFERENCE_API_KEY", "OMB_GROQ_API_KEY", "OMB_HANDOFF_MAX_FAILURES", "OMB_HANDOFF_MAX_TURNS", "OMB_HELPER_INSTANCE", "OMB_HELPER_MODEL", "OMB_HOOKS", "OMB_HOOK_",
"OMB_HOSTED_", "OMB_HOSTED_MODELS", "OMB_HOSTED_MODEL_TOKEN", "OMB_HOSTED_MODEL_URL", "OMB_IDLE_ENGINES_MAX", "OMB_IMAGE_ENGINES", "OMB_INSTALLATION_CREDENTIAL",
"OMB_JEV_API_KEY", "OMB_LAN", "OMB_LICENSE_KEY", "OMB_LINUX_GPU", "OMB_LIVE_PROVIDER", "OMB_LOCAL_VM_UPDATE_WAIT_MS",
diff --git a/server/group-goal-run-one-on-one.e2e.test.ts b/server/group-goal-run-one-on-one.e2e.test.ts
index 0f05c8eb50..ce1e531dd4 100644
--- a/server/group-goal-run-one-on-one.e2e.test.ts
+++ b/server/group-goal-run-one-on-one.e2e.test.ts
@@ -115,6 +115,7 @@ ${envelope({ status: "completed", detail: "Done." })}`]),
USERPROFILE: home,
OMB_PORT: String(port),
OMB_WEBHOOK_PORT: String(port + 1),
+ OMB_GOAL_CONTROL_MISSES: "3",
},
stdio: ["ignore", "pipe", "pipe"],
});
@@ -212,9 +213,9 @@ describe("one-on-one goal runs (a room of one)", () => {
detailParams: { name: "Patient" },
});
writeFileSync(patientGate, "observed the waiting goal");
- // The fixture's goal turn ends without a marker, so the run stops after exactly the one turn it waited for.
+ // The fixture's goal turn ends without a marker, so the run asks again twice, then stops blocked.
await expect.poll(() => cardIn(bot.threadId), { timeout: hostTimeout(15_000) })
- .toMatchObject({ status: "blocked", turnCount: 1, detail: "Patient did not provide a valid next-step decision." });
+ .toMatchObject({ status: "blocked", turnCount: 3, detail: "Patient did not provide a valid next-step decision after 3 replies." });
expect((await messagesIn(bot.threadId)).filter((message) => message.kind === "goal.run")).toHaveLength(1);
});
diff --git a/server/group-goal-run.test.ts b/server/group-goal-run.test.ts
index 6664770729..bce99aae9d 100644
--- a/server/group-goal-run.test.ts
+++ b/server/group-goal-run.test.ts
@@ -1,8 +1,9 @@
-import { describe, expect, it } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
GROUP_GOAL_CONTROL_CLOSE,
GROUP_GOAL_CONTROL_OPEN,
GROUP_GOAL_MAX_TURNS,
+ goalControlMissLimit,
groupGoalAssignmentKey,
groupGoalCompletionTurnId,
groupGoalCoordinatorInstructions,
@@ -14,6 +15,9 @@ import {
type GoalStepResult,
} from "./group-goal-run.ts";
+beforeEach(() => { delete process.env.OMB_GOAL_CONTROL_MISSES; });
+afterEach(() => vi.unstubAllEnvs());
+
const members = [
{ id: "scout-id", name: "Scout" },
{ id: "chief-id", name: "Miso", chiefOfStaff: true },
@@ -92,6 +96,15 @@ describe("group goal runs", () => {
it("reserves the final bounded turn for coordinator evaluation", () => {
expect(GROUP_GOAL_MAX_TURNS % 2).toBe(1);
});
+
+ it("bounds how many malformed control envelopes are re-asked", () => {
+ expect(goalControlMissLimit(undefined)).toBe(3);
+ expect(goalControlMissLimit("")).toBe(3);
+ expect(goalControlMissLimit("0")).toBe(3);
+ expect(goalControlMissLimit("not-a-number")).toBe(3);
+ expect(goalControlMissLimit("2")).toBe(2);
+ expect(goalControlMissLimit("9")).toBe(5);
+ });
});
describe("groupGoalCoordinatorInstructions harness note", () => {
@@ -206,8 +219,53 @@ describe("one goal-run loop for a room and a one-on-one chat", () => {
it("never takes a reply without a valid marker as done", async () => {
const goal = goalRun({ solo: true, steps: [settled("All done, trust me.")] });
await goal.done;
- expect(goal.calls).toHaveLength(1);
- expect(goal.finished).toEqual([{ status: "blocked", detail: "Solo did not provide a valid next-step decision." }]);
+ expect(goal.calls).toHaveLength(3);
+ expect(goal.finished).toEqual([{ status: "blocked", detail: "Solo did not provide a valid next-step decision after 3 replies." }]);
+ });
+
+ it("asks the coordinator again after a malformed envelope and carries on", async () => {
+ const goal = goalRun({
+ solo: true,
+ steps: [
+ settled("All done, trust me."),
+ settled(envelope({ status: "continue", next: "solo-id", instruction: "Fix the parser test", detail: "Working" })),
+ settled(envelope({ status: "completed", detail: "Every test passes." })),
+ ],
+ });
+ await goal.done;
+ expect(goal.calls).toHaveLength(3);
+ expect(goal.calls[1]!.instructions).toContain("Harness note: Your last reply did not end with exactly one valid control envelope");
+ expect(goal.progress).toContain("Solo's reply did not end with a valid control envelope. Asking again (1/3).");
+ expect(goal.finished).toEqual([{ status: "completed", detail: "Every test passes." }]);
+ });
+
+ it("counts control-envelope misses in a row, not across the run", async () => {
+ const goal = goalRun({
+ solo: true,
+ steps: [
+ settled("All done, trust me."),
+ settled("Still no envelope."),
+ settled(envelope({ status: "continue", next: "solo-id", instruction: "First step", detail: "Working" })),
+ settled("Still no envelope."),
+ settled(envelope({ status: "completed", detail: "Done." })),
+ ],
+ });
+ await goal.done;
+ expect(goal.calls).toHaveLength(5);
+ expect(goal.progress.filter((line) => line.includes("Asking again"))).toEqual([
+ "Solo's reply did not end with a valid control envelope. Asking again (1/3).",
+ "Solo's reply did not end with a valid control envelope. Asking again (2/3).",
+ "Solo's reply did not end with a valid control envelope. Asking again (1/3).",
+ ]);
+ expect(goal.finished).toEqual([{ status: "completed", detail: "Done." }]);
+ });
+
+ it("blocks at a configured miss limit", async () => {
+ vi.stubEnv("OMB_GOAL_CONTROL_MISSES", "2");
+ const goal = goalRun({ solo: true, steps: [settled("All done, trust me.")] });
+ await goal.done;
+ expect(goal.calls).toHaveLength(2);
+ expect(goal.finished).toEqual([{ status: "blocked", detail: "Solo did not provide a valid next-step decision after 2 replies." }]);
});
it("blocks a room of one that repeats the same next step", async () => {
diff --git a/server/group-goal-run.ts b/server/group-goal-run.ts
index 6c131793ef..3e02aeef31 100644
--- a/server/group-goal-run.ts
+++ b/server/group-goal-run.ts
@@ -7,11 +7,23 @@ import type { GroupDefaultResponder } from "./store.ts";
export const GROUP_GOAL_MAX_TURNS = 13;
export const GROUP_GOAL_WAIT_MAX_MS = Math.max(1_000, Number(process.env.OMB_GOAL_WAIT_MAX_MS) || 30 * 60_000);
const GROUP_GOAL_MAX_WAIT_EXHAUSTIONS = 3;
+const GROUP_GOAL_CONTROL_MISSES = 3;
+const GROUP_GOAL_CONTROL_MISSES_MAX = 5;
+/** How many replies in a row may miss the control envelope before the run is blocked (OMB_GOAL_CONTROL_MISSES, 1-5). */
+export function goalControlMissLimit(raw = process.env.OMB_GOAL_CONTROL_MISSES): number {
+ const parsed = Number(raw);
+ return Number.isInteger(parsed) && parsed >= 1 ? Math.min(parsed, GROUP_GOAL_CONTROL_MISSES_MAX) : GROUP_GOAL_CONTROL_MISSES;
+}
export const GROUP_GOAL_CONTROL_OPEN = "<openmaus-goal>";
export const GROUP_GOAL_CONTROL_CLOSE = "</openmaus-goal>";
/** A close tag the model sometimes escapes; it ends an envelope exactly like the plain one. */
const ESCAPED_GOAL_CONTROL_CLOSE = "<\\/openmaus-goal>";
+const controlMissNote = (next: string, instruction: string): string =>
+ "Your last reply did not end with exactly one valid control envelope, so the goal could not take your decision. "
+ + "Do not repeat the work or the assignments you already made. Write one short update, then end with the envelope alone on its own last line: "
+ + `${GROUP_GOAL_CONTROL_OPEN}{"status":"continue","next":"${next}","instruction":"${instruction}","detail":"Short progress note"}${GROUP_GOAL_CONTROL_CLOSE}`;
+
export type GroupGoalDecision =
| { status: "continue"; next: string; instruction: string; detail?: string }
| { status: "completed" | "needs-input" | "blocked"; detail: string };
@@ -310,6 +322,7 @@ export async function runGoalRun<Bot extends GoalRunMember>(deps: GoalRunDeps<Bo
let coordinatorNote: string | undefined;
let waitExhaustions = 0;
+ let controlMisses = 0;
while (!deps.cancelled() && run.turnCount < run.maxTurns) {
const coordinatorTurn = run.turnCount + 1;
const note = coordinatorNote;
@@ -354,9 +367,19 @@ export async function runGoalRun<Bot extends GoalRunMember>(deps: GoalRunDeps<Bo
const decision = parseGroupGoalDecision(coordinatorResult.replyText).decision;
if (!decision) {
- deps.finish("blocked", `${coordinator.name} did not provide a valid next-step decision.`);
- return;
+ controlMisses += 1;
+ const limit = goalControlMissLimit();
+ if (controlMisses >= limit || run.turnCount >= run.maxTurns) {
+ deps.finish("blocked", `${coordinator.name} did not provide a valid next-step decision after ${controlMisses} ${controlMisses === 1 ? "reply" : "replies"}.`);
+ return;
+ }
+ deps.progress(`${coordinator.name}'s reply did not end with a valid control envelope. Asking again (${controlMisses}/${limit}).`);
+ coordinatorNote = deps.solo
+ ? controlMissNote(coordinator.id, "Your next step")
+ : controlMissNote("Exact member id from the roster", "Concrete next assignment");
+ continue;
}
+ controlMisses = 0;
if (decision.status !== "continue") {
deps.finish(decision.status, decision.detail);
return;