Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Chat engine: a bot that worked around a failed tool call ends its turn ok, on every model
milind-soni1d927396a3ec
diff --git a/server/drivers/openai-chat-local-model.test.ts b/server/drivers/openai-chat-local-model.test.tsindex 386b33fbd4..f2dc933f47 100644--- a/server/drivers/openai-chat-local-model.test.ts+++ b/server/drivers/openai-chat-local-model.test.ts@@ -240,6 +240,35 @@ describe("a local model repeating itself", () => {expect(f.effects()).toEqual([]);});+ it("a hosted model that went on to use more tools after a failed call ends ok, and the failed step still shows failed", async () => {+ // Real HTTP and a real MCP server: one bad call mid-turn, then the bot works around it and answers.+ const f = await fixture((_body, response, round) => {+ if (round === 1) structured(response, "audit_write", "call-1");+ else if (round === 2) structured(response, "audit_fail", "call-2");+ else if (round === 3) structured(response, "audit_write", "call-3");+ else say(response, "Done another way.");+ }, "hosted");+ await f.start();+ expect(await f.completed()).toMatchObject({ ok: true });+ expect(f.recorder.events.some((event) => event.type === "runtime.error")).toBe(false);+ const steps = f.recorder.events.flatMap((event) => event.type === "item.completed" && event.itemType === "tool" ? [[event.itemId, (event as { ok?: boolean }).ok]] : []);+ expect(steps).toEqual([["call-1", true], ["call-2", false], ["call-3", true]]);+ expect(f.effects().map((effect) => effect.name)).toEqual(["same", "same", "same"]);+ expect(f.replies()).toEqual(["Done another way."]);+ });++ it("a hosted model whose last calls failed still ends failed, after any earlier recovery", async () => {+ const f = await fixture((_body, response, round) => {+ if (round === 1) structured(response, "audit_fail", "call-1");+ else if (round === 2) structured(response, "audit_write", "call-2");+ else if (round === 3) structured(response, "audit_fail", "call-3");+ else say(response, "It is finished.");+ }, "hosted");+ await f.start();+ expect(await f.completed()).toMatchObject({ ok: false, stopReason: "tool_error" });+ expect(f.requests).toHaveLength(4);+ });+it("a hosted model's failed turn ends as before", async () => {let id = 0;const f = await fixture((_body, response, round) => round === 1 ? structured(response, "audit_fail", `call-${++id}`) : say(response, "It is finished."), "hosted");diff --git a/server/drivers/openai-chat.test.ts b/server/drivers/openai-chat.test.tsindex e7877b76c3..77bdbbda83 100644--- a/server/drivers/openai-chat.test.ts+++ b/server/drivers/openai-chat.test.ts@@ -416,8 +416,11 @@ describe("createOpenAIChatRuntime tool approvals", () => {.toEqual({ requests: 5, corrective: 1, ok: false, stopReason: "tool_error" });}, 20_000);- it("without rounds, a later call that succeeds does not clear the failure", async () => {+ it("without rounds, a bot that went on to run tools after a failure ends ok; one whose last calls failed does not", async () => {+ // Seen on a hosted model: 137 turns in a week ended failed for one bad query the bot had already worked around.expect(await run([toolCall("c1", "nope"), toolCall("c2", "fx_write"), answer], undefined, { custom: { fx: toolServer() } }))+ .toEqual({ requests: 3, corrective: 0, ok: true, stopReason: null });+ expect(await run([toolCall("c1", "fx_write"), toolCall("c2", "nope"), answer], undefined, { custom: { fx: toolServer() } })).toEqual({ requests: 3, corrective: 0, ok: false, stopReason: "tool_error" });}, 20_000);});diff --git a/server/drivers/openai-chat.ts b/server/drivers/openai-chat.tsindex fec49d69df..fb2a1eb55d 100644--- a/server/drivers/openai-chat.ts+++ b/server/drivers/openai-chat.ts@@ -782,9 +782,10 @@ export function createOpenAIChatRuntime<Config>(options: RuntimeOptions<Config>)}if (seenCalls.size > MAX_TURN_TOOL_CALLS) throw new ChatProtocolError(stoppedAfter(`${MAX_TURN_TOOL_CALLS} tool calls`));messages.push(assistantReply(model, completion, completion.text || null, completion.toolCalls));- // After a corrective round, the failure stays pending only until the bot runs tools again. A local model that- // went on to use more tools has already reacted: a wrong guess, a search, then the right call is not a failed turn.- if ((correctiveRounds || options.localModel) && !denials.length) { toolFailed = false; failedCalls.length = 0; }+ // A failure stays pending only until the bot runs tools again: one that went on to use more tools has read the error+ // and reacted (a wrong guess, a bad query, then the right call), so its turn is not failed for it, on any model. The+ // failed step still shows as failed; a failure in the last calls before the answer, or a person's no, still ends it.+ if (!denials.length) { toolFailed = false; failedCalls.length = 0; }const screenshotParts: ChatContentPart[] = [];for (const call of completion.toolCalls) {abort.signal.throwIfAborted();