Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(pi): end the turn when omp fails a prompt before the agent starts
AdityaUmale6a5aa2d6ab8f
diff --git a/server/drivers/pi.test.ts b/server/drivers/pi.test.tsindex ce85186750..d602f5de21 100644--- a/server/drivers/pi.test.ts+++ b/server/drivers/pi.test.ts@@ -834,6 +834,17 @@ describe("PiDriver turns (fake CLI)", () => {expect(instance.adapter.hasSession("t-exit")).toBe(false);});+ it("fails the turn when omp reports the prompt failed before the agent started", async () => {+ await create("omp-start-fail");+ const { turnId } = await instance.adapter.sendTurn({ threadId: "t-omp-start-fail", text: "hi" });+ const done = await recorder.until((e) => e.type === "turn.completed" && e.turnId === turnId);+ expect(done).toMatchObject({ ok: false, stopReason: "failed" });+ expect(recorder.events.find((e) => e.type === "runtime.error")).toMatchObject({+ message: "System prompt changed repeatedly during before_agent_start; original input was not delivered.",+ });+ expect(instance.adapter.hasSession("t-omp-start-fail")).toBe(false);+ });+it("surfaces a pi turn error instead of reporting an empty success", async () => {await create("turn-error");const { turnId } = await instance.adapter.sendTurn({ threadId: "t-turn-error", text: "hi" });diff --git a/server/drivers/pi.ts b/server/drivers/pi.tsindex e97552ecad..b88d2270e9 100644--- a/server/drivers/pi.ts+++ b/server/drivers/pi.ts@@ -276,6 +276,9 @@ interface PiEvent {usage?: PiUsage;isTerminal?: boolean;willRetry?: boolean;+ agentInvoked?: boolean;+ status?: string;+ error?: { message?: string };id?: string;method?: string;options?: unknown[];@@ -722,6 +725,13 @@ export const PiDriver: ProviderDriver<PiConfig> = {finishRun();return;}+ case "prompt_result":+ // agentInvoked false: omp failed the prompt before the agent ran, so no turn_end or agent_end follows.+ if (evt.agentInvoked !== false) return;+ endStopReason = evt.status;+ endErrorMessage = evt.error?.message;+ finishRun();+ return;case "agent_settled": {// upstream pi's explicit fully-settled guarantee: no retry or queued continuation remains.if (agentEndTimer) {diff --git a/server/testing/fake-pi-cli.ts b/server/testing/fake-pi-cli.tsindex 48f63513d8..65db38cb8e 100755--- a/server/testing/fake-pi-cli.ts+++ b/server/testing/fake-pi-cli.ts@@ -4,6 +4,7 @@// FAKE_PI_MODE happy (default) | tooluse | priced | priced-stop | permission | interleave | question-select | question-input// | turn-error | no-models | exit-early | compaction | compaction-recovery// | compaction-recovery-upstream | prompt-reject | omp-chunk+// | omp-start-fail (omp accepts the prompt, then fails it before the agent starts: prompt_result agentInvoked false)// | session-slow (answers new_session after FAKE_PI_SESSION_DELAY_MS, default 800, and dumps {sessionReplied})// FAKE_PI_MODELS provider/model pairs (default "ollama-cloud/glm-5.2,openai/gpt-4o")// FAKE_PI_DUMP path to append {argv, env} JSON to@@ -441,6 +442,12 @@ function handle(cmd: any) {} catch {}}send({ type: "response", command: "prompt", success: true });+ if (mode === "omp-start-fail") {+ const error = "System prompt changed repeatedly during before_agent_start; original input was not delivered.";+ send({ type: "response", command: "prompt", success: false, error });+ send({ type: "prompt_result", agentInvoked: false, status: "error", error: { message: error, retryable: false }, sessionSettled: true });+ return;+ }if (streamScript(String(cmd.message ?? ""))) streamScriptTurn(streamScript(String(cmd.message ?? ""))!);else if (mode === "tooluse") streamToolTurn();else if (mode === "priced") streamPricedTurn();