Skip to content

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

fix(web): a Save of the new-chat defaults says which half the Project took

lmliheng84f180b0dd64
diff --git a/changelog/unreleased/2026-11-13-chat-defaults-save-refusal.md b/changelog/unreleased/2026-11-13-chat-defaults-save-refusal.md
new file mode 100644
index 00000000..a8ca5372
--- /dev/null
+++ b/changelog/unreleased/2026-11-13-chat-defaults-save-refusal.md
@@ -0,0 +1,65 @@
+# A refused Save in Project settings says which half the Project took
+
+- **Date:** 2026-11-13
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文版](2026-11-13-chat-defaults-save-refusal.zh.md)
+
+One Save on Project settings → New chat defaults is up to TWO writes: the `[default_chat]` block
+(agent / working directory / approval mode / thinking level) and then the Project's default model.
+They go out in that order, so the second can be refused after the first has already landed — and
+the refusal was a notification carrying the error's own words and nothing else. A Save whose block
+HAD been stored then read exactly like one that never got anywhere, and that sentence was gone six
+seconds later, leaving a reader to guess which half of the form the Project now holds. That is the
+rule every write refusal in the app follows (the sentence belongs where the attempt was made), and
+this section was the next place still sending a toast.
+
+The sentence now sits under the controls that asked, and it names the half the Project took: a
+refused block says the defaults are still the old ones, a refused model write after the block
+landed says the defaults were saved but the model is still the old one, and a refused model write
+on its own says only that — it never claims the defaults were saved. Each attempt clears the
+sentence from the attempt before it, and the Save button is still the retry.
+
+## Details
+
+- `packages/web/src/lib/chat-defaults-save-refusal.ts` (new): `chatDefaultsSaveRefused(attempt,
+ error)` — `{ write: "defaults" | "model"; defaultsLanded: boolean }` plus the sentence, read
+ through `refusalText` (an answer the server gave is spoken through its code's own localized
+ words; a failure this codebase raised is shown as written). The attempt comes back with the
+ sentence, because which write it was is what decides what the Project now holds.
+- `packages/web/src/components/layout/project-dialogs.tsx`: `ChatDefaultsSection` tracks which of
+ the two writes the attempt is on and whether the block already landed, and draws the sentence
+ under the grid (`data-testid="chat-defaults-refusal"`, `role="alert"`, danger ink, two lines
+ with the full text on hover); the `toastError` on this page is gone. Both writes, their order
+ and what lands are untouched.
+- `packages/web/src/lib/strings.ts` / `strings-en.ts`: `chatDefaultsRefused`,
+ `chatDefaultsModelRefused` and `chatDefaultsModelRefusedAfterSave`, in both dictionaries.
+
+## Tests
+
+- `packages/web/test/chat-defaults-save-refusal.test.ts` (new, 6 cases): a refused block says
+ nothing was saved and speaks the server code's own words; a refused model write after the block
+ landed says which half the Project took; the same refusal without the block never claims a save;
+ a failure raised before the request keeps its own words; a value with nothing to say falls back
+ to the generic text; the active dictionary decides the language.
+- `packages/web/e2e/chat-defaults-save-refusal.spec.mjs` (new, 2 cases, real server + a real
+ browser, both refusals the server's own): with both halves dirty and the picked model removed
+ from the Project meanwhile (what another tab's models page does), the default-model route
+ answers 400 — the sentence says the defaults were saved, names the refused model, the block is
+ really stored while the default model is really unchanged, nothing lands in the notification
+ region, the sentence is still there after seven seconds, and the same button lands the model
+ half once the row is back; with only the model changed, the sentence says just that, the stored
+ block is byte-for-byte the read from before, and the same button retries it.
+- Against the section as it was before the change (rebuilt from `HEAD`'s
+ `project-dialogs.tsx`), both cases fail on the missing refusal line; a two-state probe on the
+ same page reads one notification at 1.2 s — the bare `defaultModel must be included in models:
+ …` — and an empty screen at 7.5 s (while the block write had landed server-side), against the
+ sentence at both moments after the change.
+
+## Compatibility
+
+No API change, no new dependency, no stored format change. A Save whose writes both land behaves
+exactly as before; what changed is a Save that only half lands — it can no longer look as if none
+of it did.
diff --git a/changelog/unreleased/2026-11-13-chat-defaults-save-refusal.zh.md b/changelog/unreleased/2026-11-13-chat-defaults-save-refusal.zh.md
new file mode 100644
index 00000000..723e0fd8
--- /dev/null
+++ b/changelog/unreleased/2026-11-13-chat-defaults-save-refusal.zh.md
@@ -0,0 +1,49 @@
+# 项目设置里的一次保存被拒时,说清哪一半已经存进了项目
+
+- **日期:** 2026-11-13
+- **类型:** 修复
+- **范围:** `web`
+- **破坏性变更:** 否
+
+[English](2026-11-13-chat-defaults-save-refusal.md)
+
+项目设置「默认值」页的一次保存最多写两处:先是 `[default_chat]` 那一块(Agent、工作目录、审批模式、思考
+等级),再是这个项目的默认模型。它们按这个顺序发出,所以第二次可以在这第一次已经落地之后被拒 —— 而那条拒绝
+只落在一句通知里,念的是错误自己的话,别的什么都没有。于是「那一块已经存进去了」的一次保存,与「哪儿都没去成」
+的那一次读起来一模一样,而这句话六秒后就自己消失,留下读者去猜项目现在拿着哪一半。这正是全应用那条「被拒的
+原因留在发问的地方」的规则,而这一页是还在发通知的下一处。
+
+现在这句话画在发问的那组控件下方,并且说清项目拿走了哪一半:那一块被拒时说默认值仍是原来的;默认模型被拒而
+那一块已经落地时,说默认值已保存、模型仍是原来的;只有模型被拒(那一块没动)时只说这一件 —— 绝口不提「已
+保存」。每次尝试先清掉上一次那句,保存按钮仍然是重试。
+
+## 细节
+
+- `packages/web/src/lib/chat-defaults-save-refusal.ts`(新增):`chatDefaultsSaveRefused(attempt,
+ error)` —— `{ write: "defaults" | "model"; defaultsLanded: boolean }` 加上那句话,经 `refusalText`
+ 读出(服务端答的按错误码自己那句本地化文案念;本仓库自己抛出的失败原样显示)。那次尝试随句子一起回来,
+ 因为被拒的是哪一次写,正是「项目现在拿着什么」的答案。
+- `packages/web/src/components/layout/project-dialogs.tsx`:`ChatDefaultsSection` 记住这次尝试在写哪一处、
+ 那一块是否已经落地,并把句子画在控件网格下方(`data-testid="chat-defaults-refusal"`、`role="alert"`、
+ 危险色、限两行、悬停看全文);这一页的 `toastError` 撤掉。两处写本身、它们的顺序与谁会落地一个字节都没改。
+- `packages/web/src/lib/strings.ts` / `strings-en.ts`:`chatDefaultsRefused`、`chatDefaultsModelRefused`、
+ `chatDefaultsModelRefusedAfterSave`,中英各三句。
+
+## 测试
+
+- `packages/web/test/chat-defaults-save-refusal.test.ts`(新增,6 条):那一块被拒时说没有保存、并念错误码
+ 自己那句;那一块已落地而模型被拒时说清哪一半进了项目;同样的模型拒绝在那一块没动时绝不声称保存过;没走到
+ 请求就失败的保留它自己的话;什么都没得说时落通用文案;当前词典决定语言。
+- `packages/web/e2e/chat-defaults-save-refusal.spec.mjs`(新增,2 条,真服务端 + 真浏览器,两次拒绝都是
+ 服务端自己给的):两半都动过、而挑中的模型同时被另一个标签页的模型页从这个项目里删掉 —— 默认模型路由答
+ 400,句子说默认值已保存、点名被拒的模型,那一块真的存进去了而默认模型真的没变,通知区一条都没有,七秒后
+ 那句仍在,把模型加回去后按同一个按钮就让模型那一半落地;只改了模型的那一次,句子只说这一件,存下来的那一块
+ 与之前读到的逐字节相同,同一个按钮重试即落地。
+- 拿改动前的这一页(`HEAD` 的 `project-dialogs.tsx` 重新构建)跑同一份新用例,两条都死在找不到那行拒绝句;
+ 同一页上的两态探针:改前 1.2 s 是通知区一条只有 `defaultModel must be included in models: …` 的通知、
+ 7.5 s 屏幕上一片空白(而那一块在服务端已经存进去了),改后两刻都是控件下方那句话。
+
+## 兼容性
+
+线上接口没变、没有新依赖、已存数据格式没变。两处都落地的保存与以前一模一样;变的是只落地一半的那一次 ——
+它再也不能看起来像哪儿都没去成。
diff --git a/packages/web/e2e/chat-defaults-save-refusal.spec.mjs b/packages/web/e2e/chat-defaults-save-refusal.spec.mjs
new file mode 100644
index 00000000..dc7e530d
--- /dev/null
+++ b/packages/web/e2e/chat-defaults-save-refusal.spec.mjs
@@ -0,0 +1,231 @@
+/**
+ * Regression: a refused Save on Project settings → New chat defaults keeps its reason under the
+ * controls that asked, and says which of the Save's two writes the Project took.
+ *
+ * One Save is up to two writes — the `[default_chat]` block (agent / workspace / approval /
+ * thinking) and then the Project's default model. Before, a refusal was a six-second
+ * notification carrying the error's own words and nothing else, so a Save whose block HAD been
+ * stored (and whose model half was then refused) looked exactly like one that never got
+ * anywhere: the reader had to guess which half of the form the Project now holds.
+ *
+ * Both refusals here are the server's own: the narrow default-model route answers 400
+ * `bad_request` ("defaultModel must be included in models: …") when the pair is no longer in the
+ * Project's table. That is what another tab's models page does between the dialog loading its
+ * snapshot and the Save — so the spec makes that same edit through the API, exactly as the
+ * members spec has somebody else revoke a membership.
+ */
+import { test, expect } from "@playwright/test";
+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+
+/** The shared notification region: a refusal must not also land in it. */
+const notices = (page) => page.getByRole("region", { name: "通知" });
+
+const refOf = (m) => (m ? `${m.provider}/${m.modelId}` : null);
+
+/** The trigger labels of the thinking-level select, by wire value. */
+const THINKING_LABEL = {
+ low: "低",
+ medium: "中",
+ high: "高",
+ xhigh: "极高",
+ max: "最高",
+};
+
+async function projectIdOf(page) {
+ return (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0].projectId;
+}
+
+async function modelsOf(page, projectId) {
+ return (await page.request.get(`${BASE}/api/projects/${projectId}/models`)).json();
+}
+
+async function chatDefaultsOf(page, projectId) {
+ return (await page.request.get(`${BASE}/api/projects/${projectId}/chat-defaults`)).json();
+}
+
+/**
+ * The row's tooltip — the picker's own way of telling two rows apart, and the only handle a
+ * spec has on one: it carries the upstream id, since a display name repeats across gateways
+ * (the same `deepseek-v4-pro-0813` is offered by the vendor group and by a gateway under the
+ * same name).
+ */
+const tooltipOf = (m) =>
+ (m.displayName ? m.displayName : m.modelId) === m.modelId
+ ? m.modelId
+ : `${m.displayName} · ${m.modelId}`;
+
+/**
+ * Two models the picker offers that are NOT the current default, both from the default's own
+ * provider group where possible — the dialog's picker opens on that group, so a same-group row
+ * is the one a reader reaches without touching the rail. Counted rather than pinned: this data
+ * root outlives a rerun and the preset list can grow. Only rows whose tooltip is unique across
+ * the whole table qualify: a duplicate would make "click that row" ambiguous.
+ */
+function targetsOf(models) {
+ const dflt = models.defaultModel;
+ const isDefault = (m) => m.provider === dflt.provider && m.modelId === dflt.modelId;
+ const seenOnce = (m) => models.models.filter((x) => tooltipOf(x) === tooltipOf(m)).length === 1;
+ const usable = models.models.filter((m) => seenOnce(m) && !isDefault(m));
+ const sameGroup = usable.filter((m) => m.provider === dflt.provider);
+ const [a, b] = [...sameGroup, ...usable];
+ expect(a, "the picker must offer a model that is not the default").toBeTruthy();
+ expect(b, "and a second one, for the second case").toBeTruthy();
+ return [a, b];
+}
+
+/** Opens Project settings → New chat defaults through the sidebar, the way a user gets there. */
+async function openDefaults(page) {
+ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();
+ const project = projects.projects[0];
+ const sidebar = page.getByRole("complementary");
+ await expect(sidebar).toBeVisible({ timeout: 20000 });
+ await sidebar.getByRole("button", { name: project.name ?? project.projectId }).click();
+ // Same DOM click as the members spec: the row closes its menu as it opens the dialog.
+ await page.getByRole("button", { name: "项目设置" }).evaluate((el) => el.click());
+ const dialog = page.getByRole("dialog", { name: "项目设置" });
+ await expect(dialog).toBeVisible();
+ await dialog.getByRole("button", { name: "默认值" }).click();
+ // The section arrives with both its reads (the block and the models).
+ await expect(dialog.getByRole("button", { name: "选择模型" })).toBeVisible();
+ return dialog;
+}
+
+/** Picks `target` through the section's own model picker (search, then the row). */
+async function pickModel(page, dialog, target) {
+ const label = target.displayName ? target.displayName : target.modelId;
+ await dialog.getByRole("button", { name: "选择模型" }).click();
+ await page.getByPlaceholder(/搜索模型/).fill(target.modelId);
+ const row = page.getByRole("listbox").locator(`button[data-tooltip="${tooltipOf(target)}"]`);
+ await expect(row).toHaveCount(1);
+ await row.click();
+ // The pick is what makes the section dirty: the Save button proves the form took it.
+ await expect(dialog.getByRole("button", { name: "保存" })).toBeEnabled();
+ await expect(dialog.getByRole("button", { name: "选择模型" })).toHaveText(label);
+}
+
+/** Sets the thinking level to `level` through that select (its accessible name is the label). */
+async function setThinking(page, dialog, level) {
+ await dialog.getByRole("button", { name: "思考等级" }).click();
+ await page.getByRole("option", { name: THINKING_LABEL[level], exact: true }).click();
+ await expect(dialog.getByRole("button", { name: "思考等级" })).toHaveText(THINKING_LABEL[level]);
+ await expect(dialog.getByRole("button", { name: "保存" })).toBeEnabled();
+}
+
+/** The whole-table PUT's entry list: what this route takes, against the models it already holds. */
+function tableOf(models, extra) {
+ const rows = models.models.map((m) => ({ provider: m.provider, modelId: m.modelId }));
+ return [...rows, ...(extra ? [{ provider: extra.provider, modelId: extra.modelId }] : [])];
+}
+
+/** Another tab's models page drops `target` from the Project: the narrow default route then refuses it. */
+async function dropModel(page, projectId, target) {
+ const models = await modelsOf(page, projectId);
+ const rows = tableOf(models).filter(
+ (r) => !(r.provider === target.provider && r.modelId === target.modelId),
+ );
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: { models: rows },
+ });
+ expect(put.ok()).toBeTruthy();
+ const after = await modelsOf(page, projectId);
+ expect(after.models.some((m) => refOf(m) === refOf(target))).toBe(false);
+}
+
+/** Puts it back, so the same Save button can be the retry. */
+async function restoreModel(page, projectId, target) {
+ const models = await modelsOf(page, projectId);
+ if (models.models.some((m) => refOf(m) === refOf(target))) return;
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: { models: tableOf(models, target) },
+ });
+ expect(put.ok()).toBeTruthy();
+}
+
+test("a Save refused at its model half says the defaults were saved, and the same button retries", async ({
+ page,
+}) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const projectId = await projectIdOf(page);
+ const [target] = targetsOf(await modelsOf(page, projectId));
+ const storedBefore = await chatDefaultsOf(page, projectId);
+ const modelsBefore = await modelsOf(page, projectId);
+
+ await page.goto(`${BASE}/chat`);
+ const dialog = await openDefaults(page);
+
+ // Both halves of the Save are dirty: the block (thinking level) and the default model.
+ const level = storedBefore.thinkingLevel === "high" ? "xhigh" : "high";
+ await setThinking(page, dialog, level);
+ await pickModel(page, dialog, target);
+
+ // Another tab removes that model meanwhile — the dialog's snapshot still offers it, and the
+ // pick the form holds is what the Save will send.
+ await dropModel(page, projectId, target);
+ await expect(dialog.getByRole("button", { name: "选择模型" })).toHaveText(
+ target.displayName ? target.displayName : target.modelId,
+ );
+ await expect(dialog.getByRole("button", { name: "保存" })).toBeEnabled();
+
+ await dialog.getByRole("button", { name: "保存" }).click();
+
+ const refusal = dialog.getByTestId("chat-defaults-refusal");
+ await expect(refusal).toBeVisible();
+ await expect(refusal).toHaveAttribute("role", "alert");
+ // The sentence names the half the Project took, then the server's own reason.
+ await expect(refusal).toContainText("新对话默认值已保存,但默认模型没能改");
+ await expect(refusal).toContainText(
+ `defaultModel must be included in models: (provider=${target.provider}, model_id=${target.modelId})`,
+ );
+ // Nothing was reported through a notification instead.
+ await expect(notices(page).getByRole("button")).toHaveCount(0);
+
+ // The block really is stored, and the default model really is the old one.
+ const storedAfter = await chatDefaultsOf(page, projectId);
+ expect(storedAfter.thinkingLevel).toBe(level);
+ const modelsAfter = await modelsOf(page, projectId);
+ expect(refOf(modelsAfter.defaultModel)).toBe(refOf(modelsBefore.defaultModel));
+
+ // Six seconds is how long a toast lives: the sentence has to outlive it.
+ await page.waitForTimeout(7000);
+ await expect(refusal).toBeVisible();
+
+ // Put the row back and press the same button: the model half lands, the sentence goes away.
+ await restoreModel(page, projectId, target);
+ await dialog.getByRole("button", { name: "保存" }).click();
+ await expect(refusal).toHaveCount(0);
+ const retried = await modelsOf(page, projectId);
+ expect(refOf(retried.defaultModel)).toBe(refOf(target));
+});
+
+test("a Save whose block was not touched does not claim the defaults were saved", async ({
+ page,
+}) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const projectId = await projectIdOf(page);
+ const [, target] = targetsOf(await modelsOf(page, projectId));
+ const storedBefore = await chatDefaultsOf(page, projectId);
+
+ await page.goto(`${BASE}/chat`);
+ const dialog = await openDefaults(page);
+ await pickModel(page, dialog, target);
+ await dropModel(page, projectId, target);
+ await dialog.getByRole("button", { name: "保存" }).click();
+
+ const refusal = dialog.getByTestId("chat-defaults-refusal");
+ await expect(refusal).toBeVisible();
+ await expect(refusal).toContainText("没能改默认模型,项目里仍是原来的模型");
+ // The block was never part of this attempt, so nothing may say it was saved.
+ await expect(refusal).not.toContainText("已保存");
+ await expect(notices(page).getByRole("button")).toHaveCount(0);
+ // And nothing was written: the stored block is byte-for-byte the read from before.
+ expect(await chatDefaultsOf(page, projectId)).toEqual(storedBefore);
+
+ // The same button retries it once the row is back.
+ await restoreModel(page, projectId, target);
+ await dialog.getByRole("button", { name: "保存" }).click();
+ await expect(refusal).toHaveCount(0);
+ const retried = await modelsOf(page, projectId);
+ expect(refOf(retried.defaultModel)).toBe(refOf(target));
+});
diff --git a/packages/web/src/components/layout/project-dialogs.tsx b/packages/web/src/components/layout/project-dialogs.tsx
index 8f9847f0..fa54d361 100644
--- a/packages/web/src/components/layout/project-dialogs.tsx
+++ b/packages/web/src/components/layout/project-dialogs.tsx
@@ -33,6 +33,10 @@ import {
import * as api from "../../api/endpoints";
import { S } from "../../lib/strings";
import { apiErrorText } from "../../lib/api-error";
+import {
+ chatDefaultsSaveRefused,
+ type ChatDefaultsWrite,
+} from "../../lib/chat-defaults-save-refusal";
import { memberWriteRefused, type MemberRefusal } from "../../lib/member-write-refusal";
import { toneInk } from "../../lib/tone";
import {
@@ -553,9 +557,11 @@ function MembersSection({ projectId, isOwner }: { projectId: string; isOwner: bo
* the same top-level `default_model` (via the narrow PUT /models/default route), never a
* second key; changing it also releases the draft-cached model pin exactly as the models
* page does (shared clearDraftModelRef helper). Owner edits with ONE explicit Save for the
- * whole section (dialog convention: failures toast, success is silent — the refreshed
- * values are the confirmation); members see the values read-only. Mounted per dialog open
- * (the Modal unmounts its children when closed), so reopening always refetches.
+ * whole section; that Save is up to two writes, so a refusal says which of them the Project
+ * took under the controls that asked (7.125, `chat-defaults-save-refusal.ts`) instead of
+ * leaving a sentence that cannot tell a half-saved form from an unsaved one. Members see the
+ * values read-only. Mounted per dialog open (the Modal unmounts its children when closed), so
+ * reopening always refetches.
*/
function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwner: boolean }) {
const { user } = useAuth();
@@ -571,6 +577,8 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
const [thinking, setThinking] = useState("");
/** The default-model pick (paired reference; seeded from the models response's defaultModel). */
const [modelRef, setModelRef] = useState<ModelRefDto | null>(null);
+ /** The sentence the last refused Save left, drawn under the controls that asked. */
+ const [saveRefusal, setSaveRefusal] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
@@ -614,7 +622,9 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
/**
* One Save persists both writes: the `[default_chat]` block (whole-block PUT — a field
* left "not set" is simply omitted, which clears it) and, when changed, the default
- * model via the narrow route. Failures toast and keep the edits for retry.
+ * model via the narrow route. A refusal leaves its sentence under the controls and keeps
+ * the edits for retry; because these are two writes in that order, the sentence also says
+ * whether the block ahead of the refused one landed (see `chat-defaults-save-refusal.ts`).
*
* Each landed write also resets the saving user's new-conversation draft so new chats
* pick the change up instead of being shadowed by the values a previous /chat/new visit
@@ -626,12 +636,20 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
const save = async () => {
if (busy || (!blockDirty && !modelDirty)) return;
setBusy(true);
+ // A new question starts here: the sentence from the attempt before it is about edits that
+ // may well be stored by now, or an edit the user has since changed.
+ setSaveRefusal(null);
// Collected per landed write, dispatched in `finally`: when the block PUT lands but the
// model PUT throws, the block change still happened server-side and live views must
// still reseed from it.
let changed: ChatDefaultsChangedDetail | null = null;
+ // Which of the two writes this attempt is on. The block goes first, so a refused model
+ // write can arrive with the block already stored — the one thing the sentence has to say
+ // and the one thing a bare error message cannot.
+ let writing: ChatDefaultsWrite = "model";
try {
if (blockDirty) {
+ writing = "defaults";
const body: ChatDefaultsDto = {
...(agentId ? { agentId } : {}),
...(workspace.trim() ? { workspace: workspace.trim() } : {}),
@@ -647,6 +665,7 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
if (user) clearDraftChatDefaults(user.userId, projectId);
changed = { projectId, defaults: stored };
}
+ writing = "model";
if (modelDirty && modelRef) {
const res = await api.putDefaultModel(projectId, {
provider: modelRef.provider,
@@ -663,7 +682,14 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
// anything was actually written (the early-return above guards the no-op case).
if (changed) toastSuccess(S.common.saved);
} catch (e) {
- toastError(apiErrorText(e));
+ setSaveRefusal(
+ chatDefaultsSaveRefused(
+ // `changed` non-null here means the block write already landed: the model write is
+ // the only one that can be refused after it.
+ { write: writing, defaultsLanded: changed !== null },
+ e,
+ ).text,
+ );
} finally {
if (changed) dispatchChatDefaultsChanged(changed);
setBusy(false);
@@ -775,6 +801,20 @@ function ChatDefaultsSection({ projectId, isOwner }: { projectId: string; isOwne
/>
</div>
</div>
+ {/* A refused Save belongs under the controls that asked, saying which of its two
+ writes the Project took (chat-defaults-save-refusal.ts): the toast this replaced
+ could not tell a half-saved form from an unsaved one. */}
+ {saveRefusal !== null && (
+ <p
+ role="alert"
+ data-testid="chat-defaults-refusal"
+ data-tooltip={saveRefusal}
+ data-tooltip-content="text"
+ className={`mt-3 line-clamp-2 break-words text-xs ${toneInk.danger}`}
+ >
+ {saveRefusal}
+ </p>
+ )}
<div className="mt-3 flex justify-end">
<Button
size="sm"
diff --git a/packages/web/src/lib/chat-defaults-save-refusal.ts b/packages/web/src/lib/chat-defaults-save-refusal.ts
new file mode 100644
index 00000000..2c86dbbe
--- /dev/null
+++ b/packages/web/src/lib/chat-defaults-save-refusal.ts
@@ -0,0 +1,53 @@
+/**
+ * The "New chat defaults" page of the Project settings dialog
+ * (`components/layout/project-dialogs.tsx`) and the sentence one refused Save leaves under its
+ * controls.
+ *
+ * One Save is up to TWO writes: the `[default_chat]` block (agent / working directory /
+ * approval mode / thinking level) through the declarative whole-block PUT, and — when the model
+ * pick changed — the Project's default model through the narrow route. They go out in that
+ * order, so a refusal can arrive after the first one has already landed. The notification that
+ * used to carry the reason could not say so: it read the error's own words and nothing else, so
+ * a Save whose Agent / workspace / approval / thinking change HAD been stored looked exactly
+ * like one that never got anywhere — and the reader had to guess which half of the form the
+ * Project now holds (7.19's rule, app-wide: the sentence belongs where the attempt was made).
+ *
+ * The sentence therefore says what the Project stores now: which write was refused, and
+ * whether the block before it landed. `refusalText` decides the words for the reason — an answer
+ * the server gave is spoken through its code's own localized sentence.
+ */
+import { refusalText } from "./api-error";
+import { S } from "./strings";
+
+/** The write of a Save that was refused: the `[default_chat]` block, or the default model. */
+export type ChatDefaultsWrite = "defaults" | "model";
+
+/** Which write was refused, and whether the block write ahead of it had already landed. */
+export interface ChatDefaultsSaveAttempt {
+ readonly write: ChatDefaultsWrite;
+ /** The `[default_chat]` block is stored — only a refused model write can leave this true. */
+ readonly defaultsLanded: boolean;
+}
+
+/** The sentence one refused Save left, and the attempt it was for. */
+export interface ChatDefaultsSaveRefusal {
+ readonly attempt: ChatDefaultsSaveAttempt;
+ readonly text: string;
+}
+
+/** The sentence: which write of the Save was refused, and what the Project holds now. */
+export function chatDefaultsSaveRefused(
+ attempt: ChatDefaultsSaveAttempt,
+ error: unknown,
+): ChatDefaultsSaveRefusal {
+ const reason = refusalText(error);
+ return {
+ attempt,
+ text:
+ attempt.write === "defaults"
+ ? S.project.chatDefaultsRefused(reason)
+ : attempt.defaultsLanded
+ ? S.project.chatDefaultsModelRefusedAfterSave(reason)
+ : S.project.chatDefaultsModelRefused(reason),
+ };
+}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index b64fea3d..49021e8d 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -1612,6 +1612,17 @@ export const en: Strings = {
chatDefaultsThinkingNotSet: "Not set (follow the agent's config)",
/** The model default is single-sourced with the Models page (the same default_model); this is just another entry point. */
chatDefaultsModelHint: "Same default model as the Models page",
+ /**
+ * A Save this section was refused (chat-defaults-save-refusal.ts), drawn under the controls
+ * that asked: one Save writes the block AND the default model, so the sentence has to say
+ * which half the Project now holds.
+ */
+ chatDefaultsRefused: (reason: string): string =>
+ `Could not save the new-chat defaults; the Project still holds the old ones: ${reason}`,
+ chatDefaultsModelRefused: (reason: string): string =>
+ `Could not change the default model; the Project still holds the old one: ${reason}`,
+ chatDefaultsModelRefusedAfterSave: (reason: string): string =>
+ `The new-chat defaults were saved, but the default model could not be changed (the Project still holds the old one): ${reason}`,
/** Settings dialog tab rail. */
settingsTabGeneral: "General",
settingsTabMembers: "Members",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 7a032301..8f1f0486 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -1658,6 +1658,17 @@ export const zh = {
chatDefaultsThinkingNotSet: "未设置(跟随智能体配置)",
/** The model default shares its source with the Models page (the same default_model); this is just another entry point. */
chatDefaultsModelHint: "与模型页的默认模型同步",
+ /**
+ * A Save this section was refused (chat-defaults-save-refusal.ts), drawn under the controls
+ * that asked: one Save writes the block AND the default model, so the sentence has to say
+ * which half the Project now holds.
+ */
+ chatDefaultsRefused: (reason: string): string =>
+ `没能保存新对话默认值,项目里仍是原来的值:${reason}`,
+ chatDefaultsModelRefused: (reason: string): string =>
+ `没能改默认模型,项目里仍是原来的模型:${reason}`,
+ chatDefaultsModelRefusedAfterSave: (reason: string): string =>
+ `新对话默认值已保存,但默认模型没能改(项目里仍是原来的模型):${reason}`,
/** Settings dialog tab rail. */
settingsTabGeneral: "通用",
settingsTabMembers: "成员",
diff --git a/packages/web/test/chat-defaults-save-refusal.test.ts b/packages/web/test/chat-defaults-save-refusal.test.ts
new file mode 100644
index 00000000..50021728
--- /dev/null
+++ b/packages/web/test/chat-defaults-save-refusal.test.ts
@@ -0,0 +1,80 @@
+/**
+ * A Save the Project settings dialog refused (src/lib/chat-defaults-save-refusal.ts): the
+ * sentence the new-chat-defaults page draws under its controls.
+ *
+ * One Save is up to two writes — the `[default_chat]` block, then the default model — so the
+ * sentence's whole job is to say what the Project holds now: a refused block wrote nothing, a
+ * refused model write may have arrived after the block landed. Three things it has to get right:
+ * an answer the server gave speaks the interface's own language rather than the wire message
+ * where a code is mapped (7.19's rule), a failure this codebase raised itself keeps what it
+ * knows, and the two halves are never described as the same thing.
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { ApiError } from "../src/api/client";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { en as EN } from "../src/lib/strings-en";
+import { chatDefaultsSaveRefused } from "../src/lib/chat-defaults-save-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("chatDefaultsSaveRefused", () => {
+ it("a refused block says nothing was saved, and reads the reason through its code", () => {
+ const refusal = chatDefaultsSaveRefused(
+ { write: "defaults", defaultsLanded: false },
+ new ApiError(404, "agent_not_found", "Agent does not exist: ghost."),
+ );
+ expect(refusal.attempt).toEqual({ write: "defaults", defaultsLanded: false });
+ expect(refusal.text).not.toContain("Agent does not exist");
+ expect(refusal.text).toBe(
+ S.project.chatDefaultsRefused(S.errors.byCode.agent_not_found as string),
+ );
+ });
+
+ it("a refused model write after the block landed says which half the Project took", () => {
+ const refusal = chatDefaultsSaveRefused(
+ { write: "model", defaultsLanded: true },
+ new ApiError(400, "bad_request", "defaultModel must be included in models."),
+ );
+ // The sentence says the block was saved — the one thing a bare error message cannot.
+ expect(refusal.text).toBe(
+ S.project.chatDefaultsModelRefusedAfterSave("defaultModel must be included in models."),
+ );
+ expect(refusal.text).toContain("已保存");
+ expect(refusal.text).toContain("defaultModel must be included in models.");
+ });
+
+ it("a refused model write on its own does not claim anything else was saved", () => {
+ const refusal = chatDefaultsSaveRefused(
+ { write: "model", defaultsLanded: false },
+ new ApiError(400, "bad_request", "defaultModel must be included in models."),
+ );
+ expect(refusal.text).toBe(
+ S.project.chatDefaultsModelRefused("defaultModel must be included in models."),
+ );
+ expect(refusal.text).not.toContain("已保存");
+ });
+
+ it("keeps what a failure that never reached the route has to say", () => {
+ expect(
+ chatDefaultsSaveRefused(
+ { write: "defaults", defaultsLanded: false },
+ new Error("Failed to fetch"),
+ ).text,
+ ).toBe(S.project.chatDefaultsRefused("Failed to fetch"));
+ });
+
+ it("falls back to the generic text when the value has nothing to say", () => {
+ expect(chatDefaultsSaveRefused({ write: "model", defaultsLanded: true }, undefined).text).toBe(
+ S.project.chatDefaultsModelRefusedAfterSave(S.common.unknownError),
+ );
+ });
+
+ it("speaks the language the interface is in, not the one it was built in", () => {
+ setActiveStrings(EN);
+ expect(
+ chatDefaultsSaveRefused({ write: "model", defaultsLanded: true }, new Error("boom")).text,
+ ).toBe(EN.project.chatDefaultsModelRefusedAfterSave("boom"));
+ });
+});