Skip to content

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

fix(deepseek): retain model-specific thinking choices in the catalog

mr·hd62e3dc6913c
diff --git a/server/deepseek-variants.e2e.test.ts b/server/deepseek-variants.e2e.test.ts
new file mode 100644
index 0000000000..14473ed646
--- /dev/null
+++ b/server/deepseek-variants.e2e.test.ts
@@ -0,0 +1,94 @@
+import { spawn, type ChildProcess } from "node:child_process";
+import { closeSync, existsSync, openSync, readFileSync, writeFileSync } from "node:fs";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { expect, it } from "vitest";
+import { launchVerificationServer, runControlOmb, verificationServerEnvironment } from "../scripts/control-omb.ts";
+import { waitForExit } from "./testing/cleanup.ts";
+
+it("offers DeepSeek thinking before a prompt and retains catalog and chosen effort across restart", async () => {
+ const fixture = await launchVerificationServer();
+ const { dataDir, url, logPath } = fixture.info;
+ const dump = join(dataDir, "deepseek-selection");
+ const wireModels = ["deepseek-v4-flash", "deepseek-v4-pro"].map(model => JSON.stringify(["deepseek-official", model]));
+ const variants = ["off", "low", "high", "max"];
+ let restarted: ChildProcess | undefined;
+ const evidence: unknown[] = [];
+ const api = async (method: string, path: string, body?: unknown) => {
+ const response = await fetch(`${url}${path}`, {
+ method, headers: { "content-type": "application/json", origin: url },
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }), signal: AbortSignal.timeout(30_000),
+ });
+ const result = await response.json() as any;
+ expect(response.ok, `${method} ${path}: ${JSON.stringify(result)}`).toBe(true);
+ return result;
+ };
+ const control = async (...args: string[]) => {
+ const result = await runControlOmb([...args, "--url", url]) as any;
+ evidence.push({ command: args, result });
+ return result;
+ };
+ const restart = async () => {
+ await waitForExit(restarted ?? fixture.child, { signal: "SIGTERM" });
+ const log = openSync(logPath, "a", 0o600);
+ restarted = spawn(process.execPath, ["--experimental-strip-types", fileURLToPath(new URL("./index.ts", import.meta.url))], {
+ cwd: fileURLToPath(new URL("..", import.meta.url)),
+ env: verificationServerEnvironment({}, dataDir, Number(new URL(url).port)), stdio: ["ignore", log, log],
+ });
+ closeSync(log);
+ await expect.poll(async () => {
+ try { return (await fetch(`${url}/api/health`, { signal: AbortSignal.timeout(1_000) })).ok; } catch { return false; }
+ }, { timeout: 25_000 }).toBe(true);
+ };
+ try {
+ await waitForExit(fixture.child, { signal: "SIGTERM" });
+ const configPath = join(dataDir, "config.json");
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
+ config.instances.deepseek = {
+ driver: "deepseekAgent", displayName: "DeepSeek fixture",
+ config: { cli: fileURLToPath(new URL("./testing/fake-acp-cli.ts", import.meta.url)) },
+ environment: {
+ DEEPSEEK_API_KEY: "fixture-only", DSH_HOME: join(dataDir, "dsh"),
+ FAKE_ACP_MODELS: wireModels.join("\n"), FAKE_ACP_DUMP: dump,
+ FAKE_ACP_VARIANTS: JSON.stringify(Object.fromEntries(wireModels.map(model => [model, {
+ id: "reasoning_effort", currentValue: "high", options: variants.map(value => ({ value, name: value })),
+ }]))),
+ },
+ };
+ writeFileSync(configPath, JSON.stringify(config));
+ await restart();
+ const refreshed = await api("POST", "/api/instances/deepseek/refresh-models", {});
+ const engine = refreshed.instances.find((entry: any) => entry.instanceId === "deepseek");
+ expect(engine.capabilities.modelVariants).toBe(true);
+ expect(engine.models.options.map((model: any) => ({ id: model.id, variants: model.variants }))).toEqual([
+ { id: "deepseek-official/deepseek-v4-flash", variants: variants.map(id => ({ id, label: id })) },
+ { id: "deepseek-official/deepseek-v4-pro", variants: variants.map(id => ({ id, label: id })) },
+ ]);
+ expect(existsSync(`${dump}.selection.json`)).toBe(false);
+ evidence.push({ catalogBeforeFirstPrompt: engine.models });
+ const created = (await control("new-bot", "--name", "DeepSeek Thinking Fixture")).bot;
+ const threadId = created.activeTaskId ?? created.threadId;
+ const selection = { instanceId: "deepseek", model: "deepseek-official/deepseek-v4-flash", variant: "low" };
+ await api("PATCH", `/api/bots/${created.id}/tasks/${threadId}`, {
+ modelSelection: selection, updateBotDefault: true, requireAvailableModel: true,
+ });
+ expect((await control("send", "--bot", created.id, "--task", threadId, "--text", "Fixture selection check.")).success).toBe(true);
+ expect((await control("wait", "--bot", created.id, "--task", threadId, "--timeout", "30")).status).toBe("settled");
+ const receipt = JSON.parse(readFileSync(`${dump}.selection.json`, "utf8"));
+ expect(receipt).toMatchObject({ model: wireModels[0], variant: "low" });
+ evidence.push({ nativePromptSelection: receipt });
+ await restart();
+ const cached = (await api("GET", "/api/instances")).instances.find((entry: any) => entry.instanceId === "deepseek");
+ expect(cached.models).toEqual(engine.models);
+ const saved = (await api("GET", "/api/bots")).bots.find((bot: any) => bot.id === created.id);
+ expect(saved.modelSelection).toEqual(selection);
+ expect(saved.tasks.find((task: any) => task.threadId === threadId).modelSelection).toEqual(selection);
+ evidence.push({ catalogAfterRestart: cached.models, savedSelection: saved.modelSelection });
+ } finally {
+ const evidencePath = `${logPath}.deepseek-variants.json`;
+ writeFileSync(evidencePath, JSON.stringify({ evidence }, null, 2));
+ await waitForExit(restarted, { signal: "SIGTERM" });
+ await fixture.close();
+ console.info(JSON.stringify({ logPath, evidencePath, fixtureRemoved: !existsSync(dataDir) }));
+ }
+}, 120_000);
diff --git a/server/drivers/acp/deepseek.test.ts b/server/drivers/acp/deepseek.test.ts
index 81b3b2152a..e096639b19 100644
--- a/server/drivers/acp/deepseek.test.ts
+++ b/server/drivers/acp/deepseek.test.ts
@@ -209,16 +209,23 @@ describe("DeepSeek live catalog", () => {
const PARSED = {
default: "deepseek-official/deepseek-v4-flash",
options: [
- { id: "deepseek-official/deepseek-v4-flash", label: "deepseek-v4-flash", provider: "DeepSeek" },
+ { id: "deepseek-official/deepseek-v4-flash", label: "deepseek-v4-flash", provider: "DeepSeek", variants: [{ id: "off", label: "Off" }, { id: "high", label: "High" }] },
{ id: "deepseek-official/deepseek-v4-pro", label: "DeepSeek-V4-Pro", provider: "DeepSeek" },
{ id: "anthropic/claude-opus-4.6", label: "Claude Opus 4.6", provider: "Anthropic" },
],
};
+ const DISCOVERED = { ...PARSED, options: PARSED.options.map((model) => ({ ...model, variants: PARSED.options[0].variants })) };
describe("parseDeepSeekCatalog", () => {
it("flattens provider groups into picker ids with dsh's names as labels", () => {
expect(parseDeepSeekCatalog(SESSION_NEW)).toEqual(PARSED);
});
+ it("keeps reasoning choices only on the model the session actually confirmed", () => {
+ const catalog = parseDeepSeekCatalog(SESSION_NEW);
+ expect(catalog.options[0].variants).toEqual([{ id: "off", label: "Off" }, { id: "high", label: "High" }]);
+ expect(catalog.options[1]).not.toHaveProperty("variants");
+ expect(catalog.options[2]).not.toHaveProperty("variants");
+ });
it("falls back to the first model when the current one is not offered", () => {
const session = { ...SESSION_NEW, configOptions: [{ ...SESSION_NEW.configOptions[0], currentValue: '["gone","model"]' }] };
expect(parseDeepSeekCatalog(session).default).toBe("deepseek-official/deepseek-v4-flash");
@@ -256,6 +263,17 @@ process.stdin.on("data", (chunk) => {
authMethods: [] });
} else if (msg.method === "session/new") {
reply(msg.id, JSON.parse(process.env.FAKE_DSH_SESSION));
+ } else if (msg.method === "session/set_config_option") {
+ const result = JSON.parse(process.env.FAKE_DSH_SESSION);
+ const model = result.configOptions.find(option => option.id === "model");
+ if (mode !== "refuse-model") model.currentValue = msg.params.value;
+ const choices = JSON.parse(process.env.FAKE_DSH_VARIANTS || "null");
+ if (choices) {
+ result.configOptions = result.configOptions.filter(option => option.id !== "reasoning_effort");
+ const options = choices[msg.params.value];
+ if (options) result.configOptions.push({ id: "reasoning_effort", category: "thought_level", type: "select", options });
+ }
+ reply(msg.id, result);
} else if (msg.method === "session/close") {
reply(msg.id, {});
}
@@ -282,12 +300,28 @@ process.stdin.on("data", (chunk) => {
const { cli, env, dump } = fakeCli({});
const cwd = mkdtempSync(join(tmpdir(), "omb-dsh-ws-"));
dirs.push(cwd);
- await expect(fetchDeepSeekCatalog(cli, env, cwd)).resolves.toEqual(PARSED);
+ await expect(fetchDeepSeekCatalog(cli, env, cwd)).resolves.toEqual(DISCOVERED);
const calls = JSON.parse(readFileSync(dump, "utf8")) as Array<{ method: string; params: any }>;
- expect(calls.map((c) => c.method)).toEqual(["initialize", "session/new", "session/close"]);
+ expect(calls.map((c) => c.method)).toEqual(["initialize", "session/new", "session/set_config_option", "session/set_config_option", "session/close"]);
expect(calls[0]!.params).toMatchObject({ protocolVersion: 1 });
expect(calls[1]!.params).toEqual({ cwd, mcpServers: [] });
- expect(calls[2]!.params).toEqual({ sessionId: "s1" });
+ expect(calls[2]!.params).toEqual({ sessionId: "s1", configId: "model", value: '["deepseek-official","deepseek-v4-pro"]' });
+ expect(calls[4]!.params).toEqual({ sessionId: "s1" });
+ });
+
+ it("discovers different choices per model and leaves models without reasoning unmarked", async () => {
+ const { cli, env } = fakeCli({ FAKE_DSH_VARIANTS: JSON.stringify({
+ '["deepseek-official","deepseek-v4-pro"]': [{ value: "max", name: "Max" }],
+ }) });
+ const catalog = await fetchDeepSeekCatalog(cli, env, tmpdir());
+ expect(catalog.options[0].variants).toEqual(PARSED.options[0].variants);
+ expect(catalog.options[1].variants).toEqual([{ id: "max", label: "Max" }]);
+ expect(catalog.options[2]).not.toHaveProperty("variants");
+ });
+
+ it("rejects a model switch that was not confirmed instead of assigning another model's choices", async () => {
+ const { cli, env } = fakeCli({ FAKE_DSH_MODE: "refuse-model" });
+ await expect(fetchDeepSeekCatalog(cli, env, tmpdir())).rejects.toThrow(/did not confirm model/);
});
it("rejects within the timeout when dsh never answers", async () => {
@@ -310,12 +344,12 @@ process.stdin.on("data", (chunk) => {
it.each(["not-a-number", "0", "-1", "2147483648"])("ignores invalid timeout %s and keeps the 60 s default", async (timeout) => {
expect(DEEPSEEK_MODELS_DEFAULT_TIMEOUT_MS).toBe(60_000);
const { cli, env } = fakeCli({ [DEEPSEEK_MODELS_TIMEOUT_ENV]: timeout });
- await expect(fetchDeepSeekCatalog(cli, env, tmpdir())).resolves.toEqual(PARSED);
+ await expect(fetchDeepSeekCatalog(cli, env, tmpdir())).resolves.toEqual(DISCOVERED);
});
it("is what Refresh runs, against the instance's own cli", async () => {
const { cli, env } = fakeCli({});
- await expect(deepseekSupport.resolveModels!(env, { cli, fullAuto: false }, "deepseek")).resolves.toEqual(PARSED);
+ await expect(deepseekSupport.resolveModels!(env, { cli, fullAuto: false }, "deepseek")).resolves.toEqual(DISCOVERED);
});
});
diff --git a/server/drivers/acp/deepseek.ts b/server/drivers/acp/deepseek.ts
index f29985641f..b5a7630487 100644
--- a/server/drivers/acp/deepseek.ts
+++ b/server/drivers/acp/deepseek.ts
@@ -32,6 +32,7 @@ import type { ModelCatalog } from "../../contracts.ts";
import { harnessHome } from "../../env-path.ts";
import { resolveCli, spawnCli } from "../../procs.ts";
import { createAcpDriver, type AcpSupport } from "./core.ts";
+import { acpVariantOption } from "./config-options.ts";
export const DEEPSEEK_MODELS: ModelCatalog = {
default: "deepseek-official/deepseek-v4-flash",
@@ -162,6 +163,9 @@ export function parseDeepSeekCatalog(sessionResult: unknown): ModelCatalog {
collect(option?.options, undefined);
if (!out.length) throw new Error("dsh advertised no models");
const current = typeof option?.currentValue === "string" ? deepseekPickerId(option.currentValue) : null;
+ const selected = out.find((model) => model.id === current);
+ const variants = acpVariantOption(sessionResult)?.options;
+ if (selected && variants?.length) selected.variants = variants;
return {
default: current && out.some((row) => row.id === current) ? current : out[0]!.id,
options: out,
@@ -181,7 +185,7 @@ function catalogTimeoutMs(env: Record<string, string | undefined>): number {
}
/** Ask the installed dsh what it offers: initialize, session/new in `cwd`,
- * read the catalog, session/close. Rejects on any failure so the core keeps
+ * read each model's thinking choices, session/close. Rejects on any failure so the core keeps
* the last usable catalog; never resolves to an empty or guessed list. */
export function fetchDeepSeekCatalog(
cli: string,
@@ -243,6 +247,18 @@ export function fetchDeepSeekCatalog(
let sessionReqId = 0;
let closeId = 0;
let catalog: ModelCatalog | null = null;
+ let sessionId: string | null = null;
+ let selectId = 0;
+ let selectedModel: ModelCatalog["options"][number] | undefined;
+ const pendingModels: ModelCatalog["options"] = [];
+ const nextModel = () => {
+ selectedModel = pendingModels.shift();
+ if (selectedModel) {
+ selectId = send("session/set_config_option", { sessionId, configId: "model", value: deepseekWireValue(selectedModel.id) });
+ } else {
+ closeId = send("session/close", { sessionId });
+ }
+ };
child.stdout?.on("data", (chunk) => {
buf += String(chunk);
let nl: number;
@@ -259,7 +275,7 @@ export function fetchDeepSeekCatalog(
if (!msg.result) return finish({ error: new Error(`dsh rejected initialize: ${JSON.stringify(msg.error ?? msg)}`) });
sessionReqId = send("session/new", { cwd, mcpServers: [] });
} else if (sessionReqId && msg?.id === sessionReqId) {
- const sessionId = typeof msg.result?.sessionId === "string" ? msg.result.sessionId : null;
+ sessionId = typeof msg.result?.sessionId === "string" ? msg.result.sessionId : null;
try {
catalog = parseDeepSeekCatalog(msg.result);
} catch (error) {
@@ -268,8 +284,17 @@ export function fetchDeepSeekCatalog(
return finish({ error: error instanceof Error ? error : new Error(String(error)) });
}
if (!sessionId) return finish({ catalog });
- // Leave no half-open session behind in dsh's persisted list.
- closeId = send("session/close", { sessionId });
+ const current = offeredWireValues(msg.result, "model").current;
+ pendingModels.push(...catalog.options.filter((model) => deepseekWireValue(model.id) !== current));
+ nextModel();
+ } else if (selectId && msg?.id === selectId && selectedModel) {
+ if (offeredWireValues(msg.result, "model").current !== deepseekWireValue(selectedModel.id)) {
+ send("session/close", { sessionId });
+ return finish({ error: new Error(`dsh did not confirm model ${selectedModel.id} during discovery`) });
+ }
+ const variants = acpVariantOption(msg.result)?.options;
+ if (variants?.length) selectedModel.variants = variants;
+ nextModel();
} else if (closeId && msg?.id === closeId) {
finish({ catalog: catalog! });
}
diff --git a/src/components/ModelPicker.dom.test.ts b/src/components/ModelPicker.dom.test.ts
index 2060b232ec..278dbb65a2 100644
--- a/src/components/ModelPicker.dom.test.ts
+++ b/src/components/ModelPicker.dom.test.ts
@@ -317,6 +317,33 @@ describe("picking a model that has reasoning levels", () => {
}
});
+describe("DeepSeek thinking choices before a conversation starts", () => {
+ it("offers catalog choices, saves the chosen variant, and restores it after remount without session events", async () => {
+ const model = "deepseek-official/deepseek-v4-flash";
+ const models = { default: model, options: [{ id: model, label: "DeepSeek V4 Flash",
+ variants: ["off", "low", "high", "max"].map(id => ({ id, label: id })) }] };
+ fixture.instances = [{ instanceId: "deepseek", driverKind: "deepseekAgent", displayName: "DeepSeek Harness",
+ snapshot: { state: "available", authenticated: true }, capabilities: { modelVariants: true }, models }];
+ const selected = { ...scout(), modelSelection: { instanceId: "deepseek", model } };
+ render(selected);
+ await openWith("click");
+ const select = document.querySelector<HTMLSelectElement>('select[aria-label="Reasoning variant"]')!;
+ expect(select).not.toBeNull();
+ expect([...select.options].map(option => option.textContent)).toEqual(["Use session setting", "off", "low", "high", "max"]);
+ select.value = "1";
+ flushSync(() => select.dispatchEvent(new Event("change", { bubbles: true })));
+ const saved = fixture.dispatch.mock.lastCall![0];
+ expect(saved).toMatchObject({ type: "setModel", botId: selected.id, threadId: selected.threadId,
+ selection: { instanceId: "deepseek", model, variant: "low" } });
+ flushSync(() => root.unmount());
+ root = createRoot(host);
+ render({ ...selected, modelSelection: saved.selection });
+ await openWith("click");
+ const restored = document.querySelector<HTMLSelectElement>('select[aria-label="Reasoning variant"]')!;
+ expect(restored.selectedOptions[0].textContent).toBe("low");
+ });
+});
+
describe("clearing a search after a pick that keeps the menu open", () => {
it("keeps focus in the Simple menu when Escape removes the picked row, so the next Escape still closes it", async () => {
fixture.instances = [claude(numbered(14))];