Skip to content

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

fix: let the reasoning level change while a bot is working

AdityaUmale6dddcb5554dd
diff --git a/server/index.test.ts b/server/index.test.ts
index 262094cf5a..3fa970e87a 100644
--- a/server/index.test.ts
+++ b/server/index.test.ts
@@ -5522,7 +5522,7 @@ describe("harness HTTP API", () => {
}
});
- it("refuses paired model changes while the bot is working", async () => {
+ it("refuses paired model changes while the bot is working but saves a reasoning level", async () => {
const instances = (await api("GET", "/api/instances")).body.instances;
const claude = instances.find((instance: { instanceId: string }) => instance.instanceId === "claude");
const selection = { instanceId: claude.instanceId, model: claude.models.default };
@@ -5539,16 +5539,23 @@ describe("harness HTTP API", () => {
return current?.busy;
}).toBe(true);
- const blocked = await api("PATCH", `/api/bots/${bot.id}/model`, {
- ...selection,
- effort: "high",
- });
+ const otherModel = claude.models.options.find((option: { id: string }) => option.id !== selection.model).id;
+ const blocked = await api("PATCH", `/api/bots/${bot.id}/model`, { ...selection, model: otherModel });
expect(blocked.status).toBe(409);
expect(blocked.body.error).toMatch(/working.*stop it before changing models/i);
const unchanged = (await api("GET", "/api/bots?messages=0")).body.bots.find(
(candidate: { id: string }) => candidate.id === bot.id,
);
expect(unchanged.modelSelection).toEqual(selection);
+
+ // The reasoning level is read when each turn starts, so it can change while the bot works.
+ const effort = await api("PATCH", `/api/bots/${bot.id}/model`, { ...selection, effort: "high" });
+ expect(effort.status).toBe(200);
+ const saved = (await api("GET", "/api/bots?messages=0")).body.bots.find(
+ (candidate: { id: string }) => candidate.id === bot.id,
+ );
+ expect(saved.modelSelection).toEqual({ ...selection, effort: "high" });
+ expect(saved.busy).toBe(true);
} finally {
await api("POST", `/api/bots/${bot.id}/interrupt`, {});
await expect.poll(async () => {
diff --git a/server/index.ts b/server/index.ts
index 8104d276fa..a93e622de4 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -2682,13 +2682,9 @@ function checkedModelSelection(
}
selection.variant = value.variant;
}
- const changed = current && (
- selection.instanceId !== current.selection.instanceId ||
- selection.model !== current.selection.model ||
- selection.effort !== current.selection.effort ||
- selection.variant !== current.selection.variant
- );
- if (current?.busy && changed) {
+ // Each turn reads its reasoning level when it starts, so effort or variant may change while the bot works; the model may not.
+ const modelChanged = current && (selection.instanceId !== current.selection.instanceId || selection.model !== current.selection.model);
+ if (current?.busy && modelChanged) {
return { ok: false, status: 409, error: "the bot is working — stop it before changing models" };
}
const target = registry.get(selection.instanceId);
diff --git a/src/components/ModelPicker.dom.test.ts b/src/components/ModelPicker.dom.test.ts
index ce26766b86..8ff528bf24 100644
--- a/src/components/ModelPicker.dom.test.ts
+++ b/src/components/ModelPicker.dom.test.ts
@@ -435,3 +435,32 @@ describe("a model the organization turned off", () => {
expect((focused() as HTMLButtonElement).disabled).toBe(false);
});
});
+
+describe("while the bot is working", () => {
+ it("opens to the reasoning level only, saves a pick for the next message, and keeps the model locked", async () => {
+ const busy = { ...scout(), busy: true };
+ fixture.bots = [busy];
+ render(busy);
+ expect(chip().disabled).toBe(false);
+ await openWith("click");
+ const panel = menu()!.querySelector<HTMLElement>("[data-model-busy]")!;
+ expect(panel.textContent).toContain("Reasoning level applies from the next message");
+ expect(panel.textContent).toContain("Stop this thread's turn before changing its model");
+ expect(menu()!.textContent).not.toContain("Claude Sonnet 5.5");
+ const effort = panel.querySelector<HTMLSelectElement>("select")!;
+ effort.value = "high";
+ flushSync(() => effort.dispatchEvent(new Event("change", { bubbles: true })));
+ expect(fixture.dispatch).toHaveBeenLastCalledWith(expect.objectContaining({
+ type: "setModel", botId: "scout", threadId: "thread-scout",
+ selection: { instanceId: "claude", model: "claude-opus-5-5", effort: "high" },
+ }));
+ });
+
+ it("stays locked when the engine has no reasoning level to change", () => {
+ fixture.instances = [{ ...claude(three), capabilities: {} }];
+ const busy = { ...scout(), busy: true };
+ fixture.bots = [busy];
+ render(busy);
+ expect(chip().disabled).toBe(true);
+ });
+});
diff --git a/src/components/ModelPicker.test.ts b/src/components/ModelPicker.test.ts
index 413a1af221..e2544228cf 100644
--- a/src/components/ModelPicker.test.ts
+++ b/src/components/ModelPicker.test.ts
@@ -158,7 +158,8 @@ describe("OpenCode model variants", () => {
selection: { instanceId: "opencode", model: "provider/model", ...(variant !== undefined ? { variant } : {}) } });
}
const markup = renderToStaticMarkup(createElement(ModelVariantRow, { bot: { ...selected("removed"), busy: true }, compact: true }));
- expect(markup).toContain('disabled=""');
+ // A reasoning variant is read when each turn starts, so it stays changeable while the bot works.
+ expect(markup).not.toMatch(/<select[^>]* disabled=/);
expect(markup).toContain("removed (unverified)");
expect(markup).toContain("Use session setting");
});
diff --git a/src/components/ModelPicker.tsx b/src/components/ModelPicker.tsx
index bb322d1236..7695a75cf0 100644
--- a/src/components/ModelPicker.tsx
+++ b/src/components/ModelPicker.tsx
@@ -151,7 +151,7 @@ export function ModelVariantRow({ bot, threadId, updateBotDefault, className, la
<div className={className}>
<label className="flex items-center justify-between gap-3">
{label}
- <Select size="sm" variant={quiet ? "quiet" : "field"} aria-label={t("model.variant.label")} disabled={bot.busy} className={wide ? "flex-1" : "max-w-[65%]"}
+ <Select size="sm" variant={quiet ? "quiet" : "field"} aria-label={t("model.variant.label")} className={wide ? "flex-1" : "max-w-[65%]"}
value={selection.variant === undefined ? "unset" : missing ? "missing" : String(options.findIndex((option) => option.id === selection.variant))}
onChange={(event) => choose(options[Number(event.target.value)]?.id)}>
<option value="unset">{t("model.variant.session")}</option>
@@ -173,9 +173,9 @@ export function ModelVariantRow({ bot, threadId, updateBotDefault, className, la
</p>
)}
{selection.variant !== undefined && (
- <button type="button" disabled={bot.busy} onClick={() => choose()}
+ <button type="button" onClick={() => choose()}
title={t("model.variant.clearHint")}
- className="mt-2 block text-[12px] text-ink-secondary underline underline-offset-2 hover:text-ink disabled:opacity-50">
+ className="mt-2 block text-[12px] text-ink-secondary underline underline-offset-2 hover:text-ink">
{t("model.variant.clear")}
</button>
)}
@@ -185,12 +185,11 @@ export function ModelVariantRow({ bot, threadId, updateBotDefault, className, la
<button
key={option.id}
type="button"
- disabled={bot.busy}
aria-pressed={selection.variant === option.id}
title={t("model.variant.use", { variant: variantLabel(option, instance.driverKind) })}
onClick={() => choose(option.id)}
className={cn(
- "rounded-full border px-2.5 py-1 text-[12px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 disabled:opacity-50",
+ "rounded-full border px-2.5 py-1 text-[12px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70",
selection.variant === option.id ? "border-accent/60 bg-control text-ink" : "border-hairline/40 text-ink-secondary hover:bg-control/60 hover:text-ink",
)}
>
@@ -226,7 +225,10 @@ export function ModelPicker({
const { state, dispatch: storeDispatch, refreshInstances, refreshModels: refreshInstanceModels } = useStore();
const [open, setOpen] = useState(false);
const { bot, dispatch } = useAiSwitch({ bot: shown, threadId, contained, dispatch: storeDispatch, setOpen: (next) => (next ? openMenu() : setOpen(false)) });
- const motion = useMenuMotion(open && !bot.busy);
+ // While the bot works the menu still opens to its reasoning level, which applies from the next turn; the model stays locked.
+ const busyInstance = bot.busy && !contained ? state.instances.find((instance) => instance.instanceId === bot.modelSelection.instanceId) : undefined;
+ const locked = Boolean(bot.busy) && !(busyInstance && offersReasoning(state, busyInstance, bot.modelSelection, threadId ?? bot.threadId));
+ const motion = useMenuMotion(open && !locked);
const [railId, setRailId] = useState<string | null>(null);
const [query, setQuery] = useState("");
const [showAll, setShowAll] = useState(false);
@@ -417,7 +419,7 @@ export function ModelPicker({
};
const openMenu = () => {
- if (bot.busy) return;
+ if (locked) return;
if (active && isClaudeAccount(active)) lastClaudeIdRef.current = active.instanceId;
if (active && signInFamily(active) === "openai") lastOpenaiIdRef.current = active.instanceId;
const initial = pickerInstances.find((instance) => instance.instanceId === selection.instanceId) ?? pickerInstances[0];
@@ -591,7 +593,7 @@ export function ModelPicker({
ref: triggerRef,
"data-tour": "model",
type: "button" as const,
- disabled: Boolean(bot.busy),
+ disabled: locked,
onClick: () => (open ? close(false) : openMenu()),
onKeyDown: (event: ReactKeyboardEvent<HTMLButtonElement>) => {
if (event.key === "Escape" && open) {
@@ -603,7 +605,7 @@ export function ModelPicker({
openMenu();
}
},
- "aria-expanded": open && !bot.busy,
+ "aria-expanded": open && !locked,
"aria-haspopup": "dialog" as const,
"aria-controls": open ? menuId : undefined,
title: `${summary}${followLine}${attentionLine}${busyLine}`,
@@ -969,7 +971,20 @@ export function ModelPicker({
} : { width: popoverWidth }}
className={cn("menu-surface z-[80] flex flex-col overflow-hidden", motion.className)}
>
- {simpleMenu ? (
+ {bot.busy ? (
+ <div data-model-busy className="flex flex-col py-1">
+ <EffortRow
+ compact
+ bot={shown}
+ threadId={threadId}
+ updateBotDefault={Boolean(threadId) && (simpleView ? simpleUpdatesBotDefault : scope === "bot")}
+ className="px-3.5 py-[5px]"
+ label={<span className="text-[13px] leading-[18px] text-ink">{active?.capabilities?.modelVariants ? t("model.simple.reasoning") : t("model.section.effort")}</span>}
+ />
+ <p className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">{t("model.reasoningNextTurn")}</p>
+ <p className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">{t(threadId ? "model.threadBusy" : "model.busy")}</p>
+ </div>
+ ) : simpleMenu ? (
<SimpleModelMenu
menu={simpleMenu}
query={query}
diff --git a/src/locales/en.json b/src/locales/en.json
index 7686f3f943..42b5762b8f 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2844,6 +2844,7 @@
"model.searchLocal": "Search local models",
"model.busy": "Stop this bot's turn before changing its model",
"model.threadBusy": "Stop this thread's turn before changing its model",
+ "model.reasoningNextTurn": "Reasoning level applies from the next message",
"model.choose": "Choose model",
"model.customSwitchOnHost": "This thread uses Custom approval. Switch its model in the app on the host computer, so leaving Custom can be confirmed there.",
"model.providerSwitch.title": "Switch model with Ask permissions?",