Skip to content

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

Fix DeepSeek Harness "session is already active" when a turn's tools change (#4274)

Aditya Umale743566be0654
diff --git a/server/drivers/acp/deepseek.test.ts b/server/drivers/acp/deepseek.test.ts
index 8b23d00a8b..81b3b2152a 100644
--- a/server/drivers/acp/deepseek.test.ts
+++ b/server/drivers/acp/deepseek.test.ts
@@ -379,3 +379,53 @@ describe("DeepSeek Harness after a provider was added in dsh since its process s
expect(f.launches()).toBe(2);
});
});
+
+// dsh 0.2 refuses session/resume of a session still open in the same process (-32602 "session is already active"),
+// so a turn whose tools changed must not resume on the live process: the message went unanswered.
+describe("DeepSeek Harness when a turn's tools change", () => {
+ const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "testing", "fake-acp-cli.ts");
+ let cleanup: (() => Promise<void>) | null = null;
+ afterEach(async () => {
+ await cleanup?.();
+ cleanup = null;
+ });
+
+ it("resumes the session in a fresh process instead of the one where it is still open", async () => {
+ const scratch = mkdtempSync(join(tmpdir(), "omb-deepseek-active-"));
+ const instance = await DeepSeekAgentDriver.create({
+ instanceId: "deepseek-active", displayName: "DeepSeek Harness", enabled: true,
+ config: { cli: FAKE_CLI, fullAuto: false, workspace: scratch },
+ environment: {
+ HOME: scratch, USERPROFILE: scratch, DSH_HOME: join(scratch, "dsh"), DEEPSEEK_API_KEY: "sk-fixture",
+ FAKE_ACP_REJECT_LIVE_LOAD_FILE: join(scratch, "reject"), FAKE_ACP_REJECT_LIVE_LOAD_DSH: "1",
+ FAKE_ACP_LAUNCH_COUNT_FILE: join(scratch, "launches"), FAKE_ACP_RPC_APPEND_FILE: join(scratch, "rpc.jsonl"),
+ FAKE_ACP_DUMP: join(scratch, "dump"),
+ },
+ });
+ const recorder = recordEvents(instance.adapter);
+ cleanup = async () => {
+ recorder.stop();
+ await instance.dispose();
+ await removeTempDir(scratch);
+ };
+ writeFileSync(join(scratch, "reject"), "1");
+ const agents = (token: string) => ({ agents: { command: process.execPath, args: [FAKE_CLI], env: { OMB_COMMS_TOKEN: token } } });
+ const run = async (text: string, token: string, resumeCursor?: string) => {
+ const { turnId } = await instance.adapter.sendTurn({ threadId: "t-active", text, integrations: agents(token), ...(resumeCursor ? { resumeCursor } : {}) });
+ return recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId);
+ };
+ expect(await run("one", "token-one")).toMatchObject({ ok: true });
+ const second = await run("two", "token-two", "fake-acp-session");
+ expect(recorder.events.filter((event) => event.type === "runtime.error")).toEqual([]);
+ expect(second).toMatchObject({ ok: true });
+ const calls = readFileSync(join(scratch, "rpc.jsonl"), "utf8").trim().split("\n").map((line) => JSON.parse(line) as { pid: number; method: string; sessionId?: string });
+ expect(calls.filter((call) => call.method === "session/new")).toHaveLength(1);
+ expect(calls.filter((call) => call.method === "session/resume").map((call) => call.sessionId)).toEqual(["fake-acp-session"]);
+ expect(calls.filter((call) => call.method === "session/prompt")).toHaveLength(2);
+ expect(Number(readFileSync(join(scratch, "launches"), "utf8"))).toBe(2);
+ const servers = JSON.parse(readFileSync(join(scratch, "dump.mcp.json"), "utf8")) as Array<{ name: string }>;
+ const agentsServer = JSON.stringify(servers.find((server) => server.name === "agents"));
+ expect(agentsServer).toContain("OMB_COMMS_TOKEN");
+ expect(agentsServer).toContain("token-two");
+ });
+});
diff --git a/server/drivers/acp/deepseek.ts b/server/drivers/acp/deepseek.ts
index 6558a5ab5c..627c071edb 100644
--- a/server/drivers/acp/deepseek.ts
+++ b/server/drivers/acp/deepseek.ts
@@ -308,6 +308,9 @@ export const deepseekSupport: AcpSupport = {
selectModel: { configId: "model" },
modelVariants: true,
resumeMethod: "resume",
+ // dsh 0.2 rejects session/resume of a session still open in the same process
+ // ("session is already active"), so a turn with new tools needs a new process.
+ restartOnMcpChange: true,
// Refresh only: a fresh profile boot can take long, and startup must not wait on it.
resolveModels: (env, config) => fetchDeepSeekCatalog(config.cli || "dsh", env, tmpdir()),
resolveModelsOnCreate: false,
diff --git a/server/testing/fake-acp-cli.ts b/server/testing/fake-acp-cli.ts
index e04c898e0a..e641a5b90d 100755
--- a/server/testing/fake-acp-cli.ts
+++ b/server/testing/fake-acp-cli.ts
@@ -3,6 +3,7 @@
// session/prompt and scripted session/update streams) for driver tests. Env knobs:
// FAKE_ACP_LOAD_NULL session/load returns null, so the driver falls through to session/new
// 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_TEXT_REPLY answer every session/prompt with only this text
// FAKE_ACP_MODE happy (default) | image | empty-reply | reasoning-only | exit-early | fail-after-text | crash-in-prompt | hang
@@ -115,6 +116,9 @@ const handoffIdOf = (reply: string): string => /"requestId":"([\w-]+)"/.exec(rep
const statusCall = (id: string): { name: string; args: () => object } => ({ name: "assignment_status", args: () => ({ id }) });
const logFile = process.env.FAKE_ACP_LOG_FILE ?? "";
const rejectLiveLoadFile = process.env.FAKE_ACP_REJECT_LIVE_LOAD_FILE ?? "";
+const liveLoadError = (sessionId: string) => process.env.FAKE_ACP_REJECT_LIVE_LOAD_DSH === "1"
+ ? { code: -32602, message: `Invalid params: session is already active: ${sessionId}` }
+ : { code: -32000, message: "session already active in this agent" };
function fakeLog(line: string): void {
if (!logFile) return;
try {
@@ -381,12 +385,12 @@ const resultAndConfigUpdates = (id: unknown, res: unknown, after: string, sessio
process.stdout.write([{ jsonrpc: "2.0", id, result: res }, ...updates].map((message) => JSON.stringify(message)).join("\n") + "\n");
};
const rpcMethods: string[] = [];
-const recordMethod = (method: string) => {
+const recordMethod = (method: string, sessionId?: unknown) => {
rpcMethods.push(method);
if (process.env.FAKE_ACP_RPC_DUMP) writeFileSync(process.env.FAKE_ACP_RPC_DUMP, JSON.stringify(rpcMethods));
if (process.env.FAKE_ACP_RPC_APPEND_FILE) {
try {
- appendFileSync(process.env.FAKE_ACP_RPC_APPEND_FILE, JSON.stringify({ pid: process.pid, method, cwd: process.cwd() }) + "\n");
+ appendFileSync(process.env.FAKE_ACP_RPC_APPEND_FILE, JSON.stringify({ pid: process.pid, method, cwd: process.cwd(), sessionId }) + "\n");
} catch {}
}
};
@@ -628,7 +632,7 @@ function handle(msg: any) {
}
if (!msg.method) return;
if (msg.method === "session/prompt" && heldByHoldFile(msg)) return;
- recordMethod(msg.method);
+ recordMethod(msg.method, msg.params?.sessionId);
switch (msg.method) {
case "initialize": {
@@ -731,7 +735,7 @@ function handle(msg: any) {
out({
jsonrpc: "2.0",
id: msg.id,
- error: { code: -32000, message: "session already active in this agent" },
+ error: liveLoadError(msg.params.sessionId),
});
break;
}
@@ -757,7 +761,7 @@ function handle(msg: any) {
out({
jsonrpc: "2.0",
id: msg.id,
- error: { code: -32000, message: "session already active in this agent" },
+ error: liveLoadError(msg.params.sessionId),
});
break;
}