Skip to content

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

fix(web): a refused thinking-level pin in the subagent panel keeps its reason

lmliheng5c4aef576fec
diff --git a/changelog/unreleased/2026-11-12-subagent-thinking-refusal.md b/changelog/unreleased/2026-11-12-subagent-thinking-refusal.md
new file mode 100644
index 00000000..b36fbf49
--- /dev/null
+++ b/changelog/unreleased/2026-11-12-subagent-thinking-refusal.md
@@ -0,0 +1,42 @@
+# A refused thinking-level pin in the subagent panel keeps its reason, and the picker stays on the level the child runs
+
+- **Date:** 2026-11-12
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文版](2026-11-12-subagent-thinking-refusal.zh.md)
+
+The subagent panel's thinking-level picker adopted the clicked level before the `PATCH` went out and
+then only toasted the failure. A refused write therefore left two lies at once: a picker reading
+`高` for a child that was still running at `中`, and a reason that dismissed itself after six
+seconds. The main composer has never behaved this way — the draft picker and the session picker both
+adopt the level only once the write has landed, and draw the refusal above the card — and this panel
+pins a child Session through the same route, so it now does the same: the level is adopted when the
+`PATCH` resolves, and a refusal puts `没能切换思考等级:<reason>` in the composer's thinking-refusal
+slot until the next attempt.
+
+## Details
+
+- `packages/web/src/features/chat/subagents-view.tsx`: `pinChildLevel` adopts the level in
+ `.then(...)` and records the refusal in a `levelRefusal` state; that state is handed to the child
+ composer as `thinkingRefusal` (the slot the main composer already uses). The `toastError` — and
+ with it the `apiErrorText` import — is gone: the sentence above the card is the whole account.
+- `packages/web/src/features/chat/thinking-level-refusal.ts`: the module comment now names the
+ panel as the third caller of `thinkingLevelRefused`, so the "adopt only once the write landed"
+ rule it describes covers every picker.
+
+## Tests
+
+- `packages/web/e2e/subagent-thinking-refusal.spec.mjs`: a real server, a real browser and the
+ repository's mock model — the child's `PATCH` is stubbed to a 500; the sentence above the child
+ composer carries the interface's own words for that code (never the wire's English) and does not
+ mention the Agent's default; the picker still reads what the child runs at; nothing is in the
+ notification region; it is still there after seven seconds; with the route restored the next pick
+ lands, the sentence goes and the child's row carries the pin.
+- Unit coverage of the sentence itself is unchanged (`packages/web/test/thinking-level-refusal.test.ts`).
+
+## Compatibility
+
+No wire change, no new dependency, no new string. The panel's pin behaves as before when the write
+succeeds; a child's level is still adopted from the next LLM request.
diff --git a/changelog/unreleased/2026-11-12-subagent-thinking-refusal.zh.md b/changelog/unreleased/2026-11-12-subagent-thinking-refusal.zh.md
new file mode 100644
index 00000000..6407e974
--- /dev/null
+++ b/changelog/unreleased/2026-11-12-subagent-thinking-refusal.zh.md
@@ -0,0 +1,35 @@
+# 子会话面板里思考等级没能钉住时,原因留在输入框上方,选择器仍读这个子会话实际在跑的档
+
+- **日期:** 2026-11-12
+- **类型:** 修复
+- **范围:** `web`
+- **破坏性变更:** 否
+
+[English](2026-11-12-subagent-thinking-refusal.md)
+
+子会话面板的思考等级选择器在 `PATCH` 发出之前就把点中的档记下来了,失败只弹一条通知。于是被拒的写入
+一次留下两处假象:选择器读着 `高`,而那个子会话仍在 `中` 上跑;原因却是一条六秒后自己消失的通知。主输入
+框从来不是这样 —— 起草页的选择器与会话的选择器都是写成功了才采用那一档,被拒时把句子画在卡片上方 ——
+而这个面板钉住的同样是一个会话行、走的是同一条路由,所以现在也照这个形状来:`PATCH` 落地才采用,
+被拒时把 `没能切换思考等级:<原因>` 放进输入框的「思考等级被拒」那一槽,直到下一次尝试。
+
+## 细节
+
+- `packages/web/src/features/chat/subagents-view.tsx`:`pinChildLevel` 在 `.then(...)` 里才采用那一档,
+ 被拒时把句子记进 `levelRefusal`,再由 `thinkingRefusal` 交给子会话的输入框(主输入框一直在用的那一槽)。
+ 那条 `toastError` 删掉了,`apiErrorText` 的导入跟着走 —— 卡片上方那一句就是全部交代。
+- `packages/web/src/features/chat/thinking-level-refusal.ts`:模块注释补上「子会话面板是
+ `thinkingLevelRefused` 的第三个调用方」,让这份注释写的「写成功才采用」覆盖每一个选择器。
+
+## 测试
+
+- `packages/web/e2e/subagent-thinking-refusal.spec.mjs`:真服务端 + 真浏览器 + 仓库自带的 mock 模型 ——
+ 子会话的 `PATCH` 桩成 500;句子在子会话输入框上方、用的是界面自己的译文(绝不是线上英文原文)、不提
+ Agent 的默认档;选择器仍读子会话实际在跑的那一档;通知区没有东西;七秒后仍在;路由放开后下一次点选落地,
+ 句子消失、子会话行上带着这次钉住的档。
+- 句子本身已有单测(`packages/web/test/thinking-level-refusal.test.ts`),没有变化。
+
+## 兼容性
+
+线上接口没变、没有新依赖、没有新文案。写入成功时面板的行为与以前一样;子会话的档仍然从它的下一次 LLM
+请求起生效。
diff --git a/packages/web/e2e/subagent-thinking-refusal.spec.mjs b/packages/web/e2e/subagent-thinking-refusal.spec.mjs
new file mode 100644
index 00000000..20474bd2
--- /dev/null
+++ b/packages/web/e2e/subagent-thinking-refusal.spec.mjs
@@ -0,0 +1,140 @@
+/**
+ * Regression: a thinking level the subagent panel could not pin leaves the reason above the child's
+ * composer, and the picker keeps reading the level the child actually runs at.
+ *
+ * The panel's picker used to adopt the clicked level up front and PATCH afterwards, so a refused
+ * write left two lies on screen at once: a picker showing a level the child was never pinned to,
+ * and a reason that lived only in a six-second notification. The main composer never did this (it
+ * swaps the returned Session row in), and this panel is the same shape — a child Session's level,
+ * pinned through the same route — so it now behaves the same way: adopted once the PATCH landed,
+ * with the sentence in the composer's thinking-refusal slot until the next attempt.
+ *
+ * The child's PATCH is stubbed for the refusal half (the child's own runs are not what is measured),
+ * carrying a code the interface has its own copy for plus an English wire message — that is how the
+ * test tells the localized sentence from the raw one. The second half lets the same route through.
+ */
+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";
+
+/** The refusal: a code the interface translates, plus a message that must not reach the page. */
+const REFUSAL = { code: "internal", message: "RAW ENGLISH SERVER MESSAGE" };
+/** The line the page draws for that code (S.errors.byCode), after what failed. */
+const REASON = "服务器内部错误,请稍后重试。";
+
+/** Every Session write: the panel's pin is the only PATCH this page makes. */
+const PATCH_ROUTE = /\/api\/sessions\/[^/]+$/;
+
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+/** The child composer's picker — the main composer has one with the same name. */
+const picker = (page) => page.locator('[data-testid="dock"] button[aria-label="思考等级"]');
+const refusalLine = (page) => page.getByRole("alert").filter({ hasText: "没能切换思考等级" });
+
+/** Register a user, wire the mock model into their Project, create one session. */
+async function provisionSession(page, username) {
+ await provisionAndLogin(page.request, username, P);
+ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();
+ const projectId = projects.projects[0].projectId;
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ ],
+ },
+ });
+ expect(put.ok(), "put models").toBeTruthy();
+ const created = await page.request.post(
+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,
+ { data: { provider: "custom", modelId: "claude-4-8" } },
+ );
+ expect(created.ok(), `create session: ${await created.text()}`).toBeTruthy();
+ return (await created.json()).session.sessionId;
+}
+
+/** Pick a level from the picker's menu (the trigger carries the plain name, the row the wire value). */
+async function pick(page, row) {
+ await picker(page).click();
+ await page.getByRole("button", { name: row, exact: true }).click();
+}
+
+/** No announcement either: the sentence above the card is the whole account (7.111's rule). */
+async function expectNoToast(page) {
+ await page.waitForTimeout(400);
+ expect(await notifications(page).getByRole("button").count()).toBe(0);
+}
+
+test("a pin the child refuses says why above its composer and leaves the picker on the level it runs", async ({
+ page,
+}) => {
+ const sessionId = await provisionSession(page, "subthinkfail");
+
+ await page.goto(`${BASE}/chat/${sessionId}`);
+ // The MAIN composer: the panel brings a second ChatInput once the agents tab is up.
+ const main = page.locator('textarea:not([data-testid="dock"] textarea)');
+ await main.waitFor();
+ await main.fill("run a subagent");
+ await page.locator('button[aria-label="发送"]:not([data-testid="dock"] *)').click();
+
+ // The panel opens itself on the live spawn; this spec needs the child composer.
+ await expect(
+ page.locator('[data-testid="dock"] [data-tab-id="agents"][data-active="true"]'),
+ ).toBeVisible();
+ // The parent's turn ends, so the child is idle and the pick below is an ordinary pick.
+ await expect(page.getByText("Command finished; the result looks as expected.")).toBeVisible();
+ await expect(picker(page)).toBeVisible();
+ // What the child runs at, resolved by the panel (spawn-pinned level, else the parent's).
+ const ran = await picker(page).innerText();
+
+ const pinned = [];
+ await page.route(PATCH_ROUTE, (route) => {
+ if (route.request().method() !== "PATCH") return route.fallback();
+ pinned.push(route.request().url());
+ return route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await pick(page, "高 (high)");
+
+ // The sentence names the action, carries the interface's own words for that code, and says
+ // nothing about the Agent's default (a child's pin is the child's alone).
+ const line = refusalLine(page);
+ await expect(line).toBeVisible();
+ await expect(line).toHaveText(`没能切换思考等级:${REASON}`);
+ await expect(line).not.toContainText("Agent");
+ await expect(line).not.toContainText("RAW ENGLISH");
+ // The picker never adopted the pick, and nothing was announced twice.
+ await expect(picker(page)).toHaveText(ran);
+ await expectNoToast(page);
+
+ // Past the six seconds a notification lived: the sentence is still above the card.
+ await page.waitForTimeout(7000);
+ await expect(line).toHaveText(`没能切换思考等级:${REASON}`);
+ await expect(picker(page)).toHaveText(ran);
+
+ // The retry from the same picker lands: the sentence goes, and the child carries the pin.
+ expect(pinned).toHaveLength(1);
+ const childId = pinned[0].split("/").pop();
+ await page.unroute(PATCH_ROUTE);
+ await pick(page, "高 (high)");
+ await expect(picker(page)).toContainText("高");
+ await expect(page.getByRole("alert")).toHaveCount(0);
+ await expect
+ .poll(async () => {
+ const row = await (await page.request.get(`${BASE}/api/sessions/${childId}`)).json();
+ return row.session.thinkingLevel;
+ })
+ .toBe("high");
+});
diff --git a/packages/web/src/features/chat/subagents-view.tsx b/packages/web/src/features/chat/subagents-view.tsx
index a18e3231..c9c8bf46 100644
--- a/packages/web/src/features/chat/subagents-view.tsx
+++ b/packages/web/src/features/chat/subagents-view.tsx
@@ -41,14 +41,13 @@ import {
NoticeStrip,
StatusIcon,
Text,
- toastError,
} from "@adelie/ui";
import { abortSubagent, getAgentSkills, messageSubagent, patchSession } from "../../api/endpoints";
-import { apiErrorText } from "../../lib/api-error";
import { S } from "../../lib/strings";
import type { NestedSessionMeta, StreamModel } from "../../lib/omni/stream-model";
import { ChatInput } from "./chat-input";
import type { ComposerControl } from "./chat-input";
+import { thinkingLevelRefused } from "./thinking-level-refusal";
import type { PermissionPick } from "../../lib/permission-level";
import { noteSessionSeen } from "../../lib/session-seen";
import { useProject } from "../../state/project";
@@ -399,12 +398,24 @@ function SubagentComposer({
// The level pinned on the child Session from this panel ("" = untouched, the child runs at
// its own level): mirrors the main composer's per-session pick, scoped to this child —
// written through PATCH on the child; core applies it from the child's next LLM request.
+ // Adopted only once the PATCH has landed, like the main composer (which swaps the returned row
+ // in): adopting a pick up front left the picker reading a level the child was never pinned to
+ // when the write was refused.
const [turnLevel, setTurnLevel] = useState("");
+ /**
+ * A pin the child's PATCH refused. The picker therefore still reads what the child runs at, and
+ * this sentence — drawn above the card, in the composer's thinking-refusal slot — is the only
+ * account of the press (7.95's rule): a toast would be gone after six seconds while the picker
+ * went on showing the old level.
+ */
+ const [levelRefusal, setLevelRefusal] = useState<string | null>(null);
const pinChildLevel = (level: string): void => {
- setTurnLevel(level);
+ setLevelRefusal(null); // The new attempt answers for itself; the old sentence goes.
void patchSession(childSessionId, {
thinkingLevel: level as SessionPatchRequest["thinkingLevel"],
- }).catch((err: unknown) => toastError(apiErrorText(err)));
+ })
+ .then(() => setTurnLevel(level))
+ .catch((err: unknown) => setLevelRefusal(thinkingLevelRefused(err)));
};
const modelRef = meta ? { provider: meta.provider, modelId: meta.modelId } : null;
@@ -488,6 +499,7 @@ function SubagentComposer({
// PATCHed onto the child Session and applies from its next LLM request.
turnThinkingLevel={turnLevel || fallbackThinkingLevel}
onChangeTurnThinkingLevel={pinChildLevel}
+ thinkingRefusal={levelRefusal}
{...(contextWindow !== undefined ? { contextWindow } : {})}
contextNow={contextNow}
vision={false}
diff --git a/packages/web/src/features/chat/thinking-level-refusal.ts b/packages/web/src/features/chat/thinking-level-refusal.ts
index 4c884db8..e1a8a96b 100644
--- a/packages/web/src/features/chat/thinking-level-refusal.ts
+++ b/packages/web/src/features/chat/thinking-level-refusal.ts
@@ -10,6 +10,9 @@
* a notification that dismissed itself after six seconds, leaving a control that looked as though
* it had not registered the click.
*
+ * The subagent panel's picker is the third caller: it pins the level on a child Session and, since
+ * 2026-11-12, adopts it only once that PATCH has landed — the same shape, the same sentence.
+ *
* Which words: `refusalText`, the rule every refusal slot in the app follows (7.19) — an answer
* the server gave is read through its code's own localized sentence, and a value this codebase
* raised itself is shown as it wrote it.