Skip to content

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

fix(grok): skip session/set_model when Grok already runs the picked model (#3641)

Aditya Umaleafbc78c5c2d5
diff --git a/server/drivers/acp/acp.test.ts b/server/drivers/acp/acp.test.ts
index 027921684a..dc92902cc9 100644
--- a/server/drivers/acp/acp.test.ts
+++ b/server/drivers/acp/acp.test.ts
@@ -1852,6 +1852,29 @@ describe("ACP turns (fake CLI)", () => {
},
);
+ it("sends Grok session/set_model only when the session runs another model", async () => {
+ await create(GrokAgentDriver);
+ process.env.FAKE_ACP_SESSION_MODELS = "grok-4.7|Grok 4.7,grok-4.6|Grok 4.6";
+ try {
+ const configCalls = async (threadId: string, model: string) => {
+ const dump = join(scratch, `${threadId}.json`);
+ process.env.FAKE_ACP_DUMP = dump;
+ const { turnId } = await instance.adapter.sendTurn({
+ threadId, text: "use a skill", model, approvalMode: "auto",
+ integrations: { agents: { command: "node", args: ["/fixture/agents-proxy.mjs"], env: {} } },
+ });
+ await recorder.until((e) => e.type === "turn.completed" && e.turnId === turnId);
+ return existsSync(`${dump}.config.json`) ? JSON.parse(readFileSync(`${dump}.config.json`, "utf8")) : [];
+ };
+ expect(await configCalls("t-grok-same-model", "grok-4.7")).toEqual([]);
+ expect(await configCalls("t-grok-other-model", "grok-4.6")).toEqual([
+ { method: "session/set_model", params: { sessionId: "fake-acp-session", modelId: "grok-4.6" } },
+ ]);
+ } finally {
+ delete process.env.FAKE_ACP_SESSION_MODELS;
+ }
+ });
+
it.each([
["ask", true, "default"],
["full", true, "bypassPermissions"],
diff --git a/server/drivers/acp/grok.ts b/server/drivers/acp/grok.ts
index 7be8abb85c..7b316aa7a4 100644
--- a/server/drivers/acp/grok.ts
+++ b/server/drivers/acp/grok.ts
@@ -452,13 +452,10 @@ const support: AcpSupport = {
await delay(50);
}
}
- if (!turn.model) return;
+ // Repeating set_model can rebuild the harness, dropping its MCP catalog, or reject a valid resumed profile.
+ if (!turn.model || currentModelId === turn.model) return;
if (narrowsNativeTools(turn.toolScope)) {
- if (currentModelId !== turn.model) {
- throw new Error("Grok could not confirm the selected model without replacing its tool profile. Start a new conversation or choose a model with a supported Grok profile. No prompt was sent.");
- }
- // Repeating set_model can rebuild the harness or reject a valid resumed profile.
- return;
+ throw new Error("Grok could not confirm the selected model without replacing its tool profile. Start a new conversation or choose a model with a supported Grok profile. No prompt was sent.");
}
try {
await request("session/set_model", { sessionId, modelId: turn.model });