Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): 换模型的确认框正文跟着「放弃摘要」那个勾选框走

lmliheng282ce7352226
diff --git a/changelog/unreleased/2026-10-31-model-switch-body-follows-discard.md b/changelog/unreleased/2026-10-31-model-switch-body-follows-discard.md
new file mode 100644
index 00000000..e51318b4
--- /dev/null
+++ b/changelog/unreleased/2026-10-31-model-switch-body-follows-discard.md
@@ -0,0 +1,46 @@
+# The switch dialog's sentence follows its "switch even if it cannot be compacted" box
+
+- **Date:** 2026-10-31
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-31-model-switch-body-follows-discard.zh.md)
+
+In-conversation model switching compacts the context on the model being left first, and that model
+is the one that has to write the summary — so a model whose every request fails (quota exhausted, a
+rejected credential) could never be left. The confirm dialog therefore carries one opt-in box,
+"switch even if it cannot be compacted": with it ticked a failed compaction drops the context and
+the conversation moves anyway.
+
+The dialog's own sentence did not follow that box: ticked, it still promised *"if the compaction
+fails, it stays on the current model"* — the exact opposite of what the box says one line below and
+of what the switch then does. Two promises in one dialog, and the wrong one read first.
+
+The body now follows the box: unticked it keeps the original promise, ticked it says the
+conversation moves to the target and gives up the summary. Nothing else about the switch changed.
+
+## Details
+
+- `packages/web/src/lib/strings.ts` / `strings-en.ts`: one new key pair,
+ `modelSwitchInSessionBodyDiscard(from, to)` — the compacting body for the ticked case.
+- `packages/web/src/features/chat/chat-page.tsx`: the dialog's body moves out of the JSX into one
+ `modelSwitchBody` value that reads the shape and the box; a comment says why the plain sentence
+ cannot stand beside a ticked box.
+
+## Tests
+
+- `packages/web/test/model-switch.test.ts`: the new sentence is exact in Chinese, and neither
+ locale's discard body still promises to stay.
+- `packages/web/e2e/model-switch-discard.spec.mjs` (new, three browser cases against the mock
+ model): unticked, the box starts off, the body promises to stay, and the request carries only
+ `{provider, modelId}`; ticked, the body switches to the discard sentence and the request carries
+ `onCompactionFailure: "discard"`; a conversation with nothing to compact offers no box at all
+ (its dialog reads 切换).
+- Counter-proof: reverting just `chat-page.tsx` and rebuilding the Web bundle turns exactly the
+ ticked case red — red on "the body still says it stays on the current model" — with the other
+ two green.
+
+## Compatibility
+
+- No API, on-disk or request-shape change; the switch itself and its refusals are untouched.
diff --git a/changelog/unreleased/2026-10-31-model-switch-body-follows-discard.zh.md b/changelog/unreleased/2026-10-31-model-switch-body-follows-discard.zh.md
new file mode 100644
index 00000000..4b28e1bb
--- /dev/null
+++ b/changelog/unreleased/2026-10-31-model-switch-body-follows-discard.zh.md
@@ -0,0 +1,40 @@
+# 换模型的确认框:正文跟着「压缩失败就直接切换」那个勾选框走
+
+- **日期:** 2026-10-31
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 无
+
+[English](2026-10-31-model-switch-body-follows-discard.md)
+
+会话内换模型会先用**要离开的那个模型**压缩上下文 —— 而摘要正是它自己写的。于是模型一旦整个
+不可用(额度用尽、凭据被拒),这个会话就永远离不开它。为此确认框里有一个默认不勾的选项
+「压缩失败就直接切换(放弃摘要)」:勾上之后压不动就丢掉上下文,对话照常切过去。
+
+但对话框自己的那句话没有跟着这个勾选框走:勾上以后,正文仍写着「压缩失败则保持『当前模型』」
+—— 与紧挨着它的勾选框、以及接下来真正发生的事**正好相反**。同一个框里两句相反的承诺,而先读到
+的是错的那句。
+
+现在正文跟着勾选框:不勾照旧那么说,勾上就写明「压缩失败则放弃摘要,直接以目标模型继续」。
+换模型本身的行为一个字节没改。
+
+## 细节
+
+- `packages/web/src/lib/strings.ts` / `strings-en.ts`:新增一对键
+ `modelSwitchInSessionBodyDiscard(from, to)`,即「勾上时」那一种正文。
+- `packages/web/src/features/chat/chat-page.tsx`:确认框的正文从 JSX 里挪出来成一个
+ `modelSwitchBody` 值,读形状与勾选状态;注释写明为什么那一句不能与勾上的框并排出现。
+
+## 测试
+
+- `packages/web/test/model-switch.test.ts`:中文新句逐字断言;两种语言里「放弃摘要」那一版都不再
+ 出现「保持」的说法。
+- `packages/web/e2e/model-switch-discard.spec.mjs`(新,真浏览器三条,对 mock 模型):不勾时框关着、
+ 正文照旧承诺「保持」、请求体只有 `{provider, modelId}`;勾上后正文换成放弃摘要那句、请求体带上
+ `onCompactionFailure: "discard"`;没有上下文可压的会话根本不出现这个勾选框(它的按钮写「切换」)。
+- 反证:只把 `chat-page.tsx` 退回、重建 Web 产物,同一条套件里**只有**「勾上」那条红 —— 红在
+ 「正文仍写着保持当前模型」,另两条照旧绿。
+
+## 兼容
+
+- 接口、磁盘格式、请求体形状都没变;换模型本身与它的几种拒绝也没有改动。
diff --git a/packages/web/e2e/model-switch-discard.spec.mjs b/packages/web/e2e/model-switch-discard.spec.mjs
new file mode 100644
index 00000000..c8d5ecdf
--- /dev/null
+++ b/packages/web/e2e/model-switch-discard.spec.mjs
@@ -0,0 +1,161 @@
+/**
+ * The in-session model switch's escape hatch: "switch even if it cannot be compacted".
+ *
+ * A switch always compacts the context on the model being left, and that model is the one that
+ * has to write the summary — so a model whose every request fails (quota exhausted, credential
+ * rejected) could never be left, and the in-session picker is the only way to change the model
+ * of an existing conversation. The confirm dialog therefore offers one extra choice, off by
+ * default, that drops the context when the compaction cannot complete.
+ *
+ * What this pins, in a real browser against the mock model:
+ * - the box is offered only where a compaction really runs (not on an empty conversation, whose
+ * switch is immediate and whose dialog reads "切换") and starts off;
+ * - the dialog's own sentence follows the box — unticked it promises to stay on the current
+ * model, ticked it says the conversation moves anyway (two promises in one dialog would be
+ * the defect the box itself was meant to remove);
+ * - the request the page sends carries `onCompactionFailure: "discard"` only when the box was
+ * ticked, which is the whole effect the user sees: the server does the discarding.
+ */
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const FROM = "claude-4-8";
+const TO = "claude-4-7";
+/** The mock's turn-2 answer (mock-llm.mjs): the conversation is over and the Session idle. */
+const REPLY = "Command finished; the result looks as expected.";
+
+/** Log in, and give the new user's Project the two mock models this spec switches between. */
+async function setUp(page, user) {
+ await provisionAndLogin(page.request, user, P);
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: FROM },
+ models: [
+ {
+ provider: "custom",
+ modelId: FROM,
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ {
+ provider: "custom",
+ modelId: TO,
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 100000,
+ },
+ ],
+ },
+ });
+ expect(put.ok(), "put models").toBeTruthy();
+ return projectId;
+}
+
+async function createSession(page, projectId) {
+ const sess = await (
+ await page.request.post(`${BASE}/api/projects/${projectId}/agents/default_agent/sessions`, {
+ data: { provider: "custom", modelId: FROM, approvalMode: "allow-all" },
+ })
+ ).json();
+ return sess.session.sessionId;
+}
+
+/** A Session with one finished round, so a switch has something to compact. */
+async function sessionWithConversation(page, projectId) {
+ const sessionId = await createSession(page, projectId);
+ await page.goto(`${BASE}/chat/${sessionId}`);
+ const composer = page.getByPlaceholder(/输入消息/);
+ await composer.waitFor();
+ await composer.fill("hello");
+ await page.getByRole("button", { name: "发送" }).click();
+ await expect(page.getByText(REPLY).first()).toBeVisible();
+ return sessionId;
+}
+
+/** Open the composer's model picker, pick the other model, and hand back the confirm dialog. */
+async function askToSwitch(page) {
+ // Disabled while the round runs and while a compaction is under way: waiting for it to be
+ // enabled is waiting for the Session to be idle, without reading any internal state.
+ const trigger = page.getByRole("button", { name: "选择模型" }).first();
+ await expect(trigger).toBeEnabled();
+ await trigger.click();
+ const picker = page.getByRole("dialog", { name: "选择模型" });
+ await expect(picker).toBeVisible();
+ await picker.locator('li[role="option"]').filter({ hasText: TO }).locator("button").click();
+ const dialog = page.getByRole("dialog", { name: "切换模型" });
+ await expect(dialog).toBeVisible();
+ return dialog;
+}
+
+/** Every `/switch-model` body the page posted, in order. */
+function recordSwitches(page) {
+ const bodies = [];
+ page.on("request", (req) => {
+ if (req.method() === "POST" && req.url().includes("/switch-model")) {
+ bodies.push(req.postDataJSON() ?? {});
+ }
+ });
+ return bodies;
+}
+
+test("unticked, the dialog promises to stay and the request says nothing about compaction", async ({
+ page,
+}) => {
+ const projectId = await setUp(page, "swdiscardoff");
+ await sessionWithConversation(page, projectId);
+ const bodies = recordSwitches(page);
+
+ const dialog = await askToSwitch(page);
+ const box = dialog.getByRole("checkbox", { name: "压缩失败就直接切换(放弃摘要)" });
+ await expect(box).not.toBeChecked();
+ await expect(dialog).toContainText(`压缩失败则保持「${FROM}」`);
+
+ await dialog.getByRole("button", { name: "压缩并切换" }).click();
+ await expect(page.getByText(`正在用「${FROM}」压缩上下文`).first()).toBeVisible();
+ expect(bodies).toHaveLength(1);
+ expect(bodies[0]).toEqual({ provider: "custom", modelId: TO });
+});
+
+test("ticked, the body says the conversation moves anyway and the request carries the discard", async ({
+ page,
+}) => {
+ const projectId = await setUp(page, "swdiscardon");
+ await sessionWithConversation(page, projectId);
+ const bodies = recordSwitches(page);
+
+ const dialog = await askToSwitch(page);
+ const box = dialog.getByRole("checkbox", { name: "压缩失败就直接切换(放弃摘要)" });
+ await expect(box).not.toBeChecked();
+ await box.check();
+ await expect(box).toBeChecked();
+ // The body follows the box: the plain sentence's "stays on the current model" is gone, and
+ // the dialog says what will happen instead.
+ await expect(dialog).not.toContainText(`压缩失败则保持「${FROM}」`);
+ await expect(dialog).toContainText(`压缩失败则放弃摘要,直接以「${TO}」继续`);
+
+ await dialog.getByRole("button", { name: "压缩并切换" }).click();
+ await expect(page.getByText(`正在用「${FROM}」压缩上下文`).first()).toBeVisible();
+ expect(bodies).toHaveLength(1);
+ expect(bodies[0]).toEqual({ provider: "custom", modelId: TO, onCompactionFailure: "discard" });
+});
+
+test("a conversation with no context to compact offers no escape hatch at all", async ({
+ page,
+}) => {
+ const projectId = await setUp(page, "swdiscardempty");
+ const sessionId = await createSession(page, projectId);
+ await page.goto(`${BASE}/chat/${sessionId}`);
+ await page.getByPlaceholder(/输入消息/).waitFor();
+
+ const dialog = await askToSwitch(page);
+ // Nothing is compacted, so the switch is immediate and there is nothing to fail at.
+ await expect(dialog.getByRole("button", { name: "切换" })).toBeVisible();
+ await expect(dialog.getByRole("checkbox")).toHaveCount(0);
+ await expect(dialog).not.toContainText("放弃摘要");
+});
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index a3f39edd..d4100fe0 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -2277,6 +2277,29 @@ export function ChatPage() {
/** Background tasks the conversation still owns — the same live count the sidebar row's mark carries. */
const backgroundCount = selected === null ? 0 : sessionBackgroundTasks(selected);
+ /**
+ * The in-session switch dialog's sentence — each shape promises what the switch will do to
+ * the context and nothing more. The escape hatch changes the compacting shape: with the box
+ * ticked a failed compaction switches anyway, so the plain body's "it stays on the current
+ * model" would be the opposite of what the dialog is about to do.
+ */
+ const modelSwitchBody =
+ modelSwitchAsk === null || selected === null
+ ? null
+ : modelSwitchAsk.shape === "empty"
+ ? S.chat.modelSwitchInSessionDirectBody(modelDisplay(modelSwitchAsk.to))
+ : modelSwitchAsk.shape === "compacted"
+ ? S.chat.modelSwitchInSessionCompactedBody(modelDisplay(modelSwitchAsk.to))
+ : modelSwitchAsk.discardIfCompactionFails
+ ? S.chat.modelSwitchInSessionBodyDiscard(
+ modelDisplay({ provider: selected.provider, modelId: selected.modelId }),
+ modelDisplay(modelSwitchAsk.to),
+ )
+ : S.chat.modelSwitchInSessionBody(
+ modelDisplay({ provider: selected.provider, modelId: selected.modelId }),
+ modelDisplay(modelSwitchAsk.to),
+ );
+
return (
// data-dock-host: the docks' edge bands, drop preview and the bottom dock's height
// ratio all measure this column (dock-drag.tsx / dock-panel.tsx).
@@ -2877,18 +2900,7 @@ export function ChatPage() {
if (!modelSwitchPosting) setModelSwitchAsk(null);
}}
>
- <p className="text-sm text-gray-600 dark:text-gray-300">
- {modelSwitchAsk === null || selected === null
- ? null
- : modelSwitchAsk.shape === "empty"
- ? S.chat.modelSwitchInSessionDirectBody(modelDisplay(modelSwitchAsk.to))
- : modelSwitchAsk.shape === "compacted"
- ? S.chat.modelSwitchInSessionCompactedBody(modelDisplay(modelSwitchAsk.to))
- : S.chat.modelSwitchInSessionBody(
- modelDisplay({ provider: selected.provider, modelId: selected.modelId }),
- modelDisplay(modelSwitchAsk.to),
- )}
- </p>
+ <p className="text-sm text-gray-600 dark:text-gray-300">{modelSwitchBody}</p>
{stream.taskState !== "idle" && (
<p className="mt-2 text-sm text-gray-500 dark:text-gray-400">
{S.chat.thinkingSwitchBusyHint}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 7799974b..e9ece75c 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -3083,6 +3083,9 @@ export const en: Strings = {
modelSwitchInSessionDirectConfirm: "Switch",
modelSwitchInSessionBody: (from: string, to: string): string =>
`The context is compacted on the current model "${from}" first, and this conversation then continues on "${to}". If the compaction fails, it stays on "${from}".`,
+ /** Body while the escape hatch is ticked: it contradicts the plain body's "stays on the current model", so the sentence follows the box. */
+ modelSwitchInSessionBodyDiscard: (from: string, to: string): string =>
+ `The context is compacted on the current model "${from}" first, and this conversation then continues on "${to}". If the compaction fails, the conversation still moves to "${to}", without a summary.`,
modelSwitchInSessionDiscardFails: "Switch even if it cannot be compacted",
modelSwitchInSessionDiscardFailsHint:
"If the current model cannot compact this conversation (quota exhausted, credential rejected), switch to the model above anyway. The cost is the summary: the transcript stays, but the new model does not inherit the conversation's working memory.",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 8cce291d..87feccdd 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -3109,6 +3109,13 @@ export const zh = {
modelSwitchInSessionDirectConfirm: "切换",
modelSwitchInSessionBody: (from: string, to: string): string =>
`将先用当前模型「${from}」压缩上下文,成功后以「${to}」继续本对话;压缩失败则保持「${from}」。`,
+ /**
+ * Body while the escape hatch below is ticked: the plain body promises that a failed
+ * compaction keeps the current model, which a ticked box contradicts — so the sentence
+ * follows the box rather than leaving two promises in one dialog.
+ */
+ modelSwitchInSessionBodyDiscard: (from: string, to: string): string =>
+ `将先用当前模型「${from}」压缩上下文,成功后以「${to}」继续本对话;压缩失败则放弃摘要,直接以「${to}」继续。`,
/**
* The escape hatch, offered only where a compaction really runs: the model to leave is the
* one that has to summarize, so a model whose every request fails (no quota left, a rejected
diff --git a/packages/web/test/model-switch.test.ts b/packages/web/test/model-switch.test.ts
index 58cbb373..49a9817c 100644
--- a/packages/web/test/model-switch.test.ts
+++ b/packages/web/test/model-switch.test.ts
@@ -114,6 +114,18 @@ describe("/model copy", () => {
expect(en.chat.modelSwitchInSessionBody("A", "B")).toContain('"B"');
});
+ it("the body follows the discard box instead of promising to stay beside it", () => {
+ // Ticking "switch even if it cannot be compacted" makes a failed compaction switch anyway,
+ // so the plain body's "it stays on the current model" would contradict the very box.
+ expect(zh.chat.modelSwitchInSessionBodyDiscard("A", "B")).toBe(
+ "将先用当前模型「A」压缩上下文,成功后以「B」继续本对话;压缩失败则放弃摘要,直接以「B」继续。",
+ );
+ expect(zh.chat.modelSwitchInSessionBodyDiscard("A", "B")).not.toContain("保持");
+ expect(en.chat.modelSwitchInSessionBodyDiscard("A", "B")).toContain('"B"');
+ expect(en.chat.modelSwitchInSessionBodyDiscard("A", "B")).toMatch(/without a summary/);
+ expect(en.chat.modelSwitchInSessionBodyDiscard("A", "B")).not.toMatch(/stays on/);
+ });
+
it("right after a compaction, neither the dialog nor the toast promises a compaction", () => {
// The server runs no compaction for a just-compacted Session (design: no second pair), so
// the copy for that shape must not say "compact".