Skip to content

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

fix(acp): close Mistral Vibe's live session before re-loading it

AdityaUmaleda246ecec542
diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.ts
index 5e35ad53b7..f4e4bc594f 100644
--- a/server/drivers/acp/core.ts
+++ b/server/drivers/acp/core.ts
@@ -188,7 +188,7 @@ export interface AcpSupport extends AcpDriverHooks {
resendsReasoningReply?: boolean;
/** Threads with the same spawn contract run their sessions in one process (OpenCode 1.19: about 100 MB a session
* instead of about 450 MB a process), up to SHARED_SESSIONS_MAX. */
- shareProcess?: boolean;
+ shareProcess?: boolean; /** mistral-vibe 3.1.2 loads its live session as a second open copy, and both stream every reply. */ closeBeforeLiveLoad?: boolean;
/** Route workspace file access through ACP so edits retain approval cards. */
clientFileSystem?: boolean;
/** Additional server-owned directories this turn may read; writes remain confined to cwd. */
@@ -1225,7 +1225,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
const selectionParams = narrowsNativeTools(turn.toolScope)
? support.toolScopeSessionParams!(turn, init, mcpServers.length > 0, { config: turnConfig, env, cwd }) : {};
let loaded = false;
- if (cursor) {
+ if (cursor && (!support.closeBeforeLiveLoad || liveSessionId !== cursor || await request("session/close", { sessionId: cursor }, 30_000).then(() => true, () => false))) {
try {
await request(
support.resumeMethod === "resume" ? "session/resume" : "session/load",
diff --git a/server/drivers/acp/mistral-vibe.test.ts b/server/drivers/acp/mistral-vibe.test.ts
index fb5bcd2996..8776768b5d 100644
--- a/server/drivers/acp/mistral-vibe.test.ts
+++ b/server/drivers/acp/mistral-vibe.test.ts
@@ -138,6 +138,32 @@ describe("Mistral (Vibe) ACP driver", () => {
expect(JSON.parse(promptRows.at(-1)!)).toMatchObject({ model: "zai-glm-5-3-flash" });
});
+ // A close that fails re-loads in a fresh process instead: one more launch per new bearer.
+ it.each([["1", 1], ["error", 3]])("closes the live session before re-loading it with a new MCP bearer, so vibe-acp streams each reply once (close: %s)", async (close, processes) => {
+ const launches = join(scratch, "launches");
+ const { instance, recorder } = await create({
+ MISTRAL_API_KEY: "engine-fixture-key", FAKE_ACP_LAUNCH_COUNT_FILE: launches,
+ FAKE_ACP_SESSION_CLOSE: String(close), FAKE_ACP_COPY_LIVE_LOAD: "1", FAKE_ACP_TEXT_REPLY: "hello",
+ });
+ const agents = (token: string) => ({
+ command: process.execPath,
+ args: ["/app/dist-server/agents-proxy.js"],
+ env: { OMB_HARNESS_URL: "http://127.0.0.1:8799", OMB_COMMS_TOKEN: token, OMB_BOT_ID: "sprout", OMB_THREAD_ID: "mistral-vibe-bearer" },
+ });
+ const reply = async (text: string, token: string, resume: boolean) => {
+ const { turnId } = await instance.adapter.sendTurn({
+ threadId: "mistral-vibe-bearer", text, model: "mistral-medium-3.5", approvalMode: "ask",
+ ...(resume ? { resumeCursor: "fake-acp-session" } : {}), integrations: { agents: agents(token) },
+ });
+ await recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId);
+ return recorder.events.find((event) => event.turnId === turnId && event.type === "item.completed" && event.itemType === "assistant_text");
+ };
+ expect(await reply("one", "token-one", false)).toMatchObject({ text: "hello" });
+ expect(await reply("two", "token-two", true)).toMatchObject({ text: "hello" });
+ expect(await reply("three", "token-three", true)).toMatchObject({ text: "hello" });
+ expect(Number(readFileSync(launches, "utf8"))).toBe(processes);
+ });
+
it("turns Vibe's session/request_permission into an approval card and answers with the person's choice", async () => {
const answer = join(scratch, "permission.txt");
const { instance, recorder } = await create({ FAKE_ACP_MODE: "permission", FAKE_ACP_PERMISSION_ANSWER: answer });
diff --git a/server/drivers/acp/mistral-vibe.ts b/server/drivers/acp/mistral-vibe.ts
index 14d5bf72df..af5df42afe 100644
--- a/server/drivers/acp/mistral-vibe.ts
+++ b/server/drivers/acp/mistral-vibe.ts
@@ -182,6 +182,7 @@ export const mistralVibeSupport: AcpSupport = {
// Model is a session config option (see header); ids pass through unchanged.
selectModel: { configId: "model" },
shareProcess: true,
+ closeBeforeLiveLoad: true,
resolveModels: resolveMistralVibeModels,
resolveModelsOnCreate: false,
fallbackModel(sessionConfig, catalogDefault) {
diff --git a/server/testing/fake-acp-cli.ts b/server/testing/fake-acp-cli.ts
index b9975cd67e..e7a15d0fd2 100755
--- a/server/testing/fake-acp-cli.ts
+++ b/server/testing/fake-acp-cli.ts
@@ -5,6 +5,8 @@
// FAKE_ACP_REJECT_LIVE_LOAD_FILE while it exists, load/resume of a session live in this process errors
// (FAKE_ACP_REJECT_LIVE_LOAD_DSH=1: with dsh 0.2's -32602 "session is already active" instead of -32000)
// FAKE_ACP_CACHED_LIVE_LOAD a live session/load is acknowledged but keeps the old MCP credentials, like Qwen
+// FAKE_ACP_COPY_LIVE_LOAD=1 a session/load of a session still open adds a second copy, and each open copy streams
+// FAKE_ACP_TEXT_REPLY again, like mistral-vibe 3.1.2; session/close ends every copy
// FAKE_ACP_TEXT_REPLY answer every session/prompt with only this text
// FAKE_STREAM_SCRIPT, FAKE_STREAM_CADENCE a scripted reply chosen by a marker in the prompt (stream-script.ts)
// FAKE_ACP_MODE happy (default) | image | empty-reply | reasoning-only | exit-early | fail-after-text | crash-in-prompt
@@ -587,6 +589,7 @@ async function listMcpTools(entry: AnyMcpEntry, handshake: unknown): Promise<str
});
}
let liveSession: string | null = null;
+const openCopies = new Map<string, number>();
let sessionsOpened = 0;
let rpcFailure: unknown = null;
function emitSessionReports(): void {
@@ -970,6 +973,7 @@ function handle(msg: any) {
sessionsOpened += 1;
const firstSession = process.env.FAKE_ACP_SESSION_ID ?? "fake-acp-session";
liveSession = sessionsOpened === 1 ? firstSession : `${firstSession}-${sessionsOpened}`;
+ openCopies.set(liveSession, 1);
resultAndConfigUpdates(msg.id, {
sessionId: liveSession,
...(opts ? { configOptions: opts } : {}),
@@ -980,6 +984,7 @@ function handle(msg: any) {
}
case "session/close":
endWokenStep(msg.params?.sessionId);
+ openCopies.delete(String(msg.params?.sessionId));
if (mode === "background-wake") detachedSessions.add(String(msg.params?.sessionId));
if (process.env.FAKE_ACP_SESSION_CLOSE === "error") out({ jsonrpc: "2.0", id: msg.id, error: { code: -32603, message: "close failed" } });
else if (process.env.FAKE_ACP_SESSION_CLOSE_MS) setTimeout(() => result(msg.id, {}), Number(process.env.FAKE_ACP_SESSION_CLOSE_MS));
@@ -1029,6 +1034,8 @@ function handle(msg: any) {
const mdls = sessionModels();
liveSession = typeof msg.params?.sessionId === "string" ? msg.params.sessionId : liveSession;
detachedSessions.delete(String(msg.params?.sessionId));
+ const copies = openCopies.get(String(msg.params?.sessionId)) ?? 0;
+ openCopies.set(String(msg.params?.sessionId), process.env.FAKE_ACP_COPY_LIVE_LOAD === "1" ? copies + 1 : 1);
resultAndConfigUpdates(msg.id, { ...(opts ? { configOptions: opts } : {}), ...(mdls ? { models: mdls } : {}) }, "session/load", msg.params.sessionId);
if (mode === "hermes-steer") advertiseHermesCommands(msg.params.sessionId);
break;
@@ -1188,7 +1195,9 @@ function handle(msg: any) {
return;
}
if (process.env.FAKE_ACP_TEXT_REPLY !== undefined) {
- out({ jsonrpc: "2.0", method: "session/update", params: { sessionId: msg.params?.sessionId, update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: process.env.FAKE_ACP_TEXT_REPLY } } } });
+ for (let copy = openCopies.get(String(msg.params?.sessionId)) ?? 1; copy > 0; copy -= 1) {
+ out({ jsonrpc: "2.0", method: "session/update", params: { sessionId: msg.params?.sessionId, update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: process.env.FAKE_ACP_TEXT_REPLY } } } });
+ }
result(msg.id, { stopReason: "end_turn", _meta: { inputTokens: 12, outputTokens: 4 } });
return;
}