Skip to content

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

fix(web): a refused permission pick keeps its reason above the input card

lmlihengf493a86acf78
diff --git a/changelog/unreleased/2026-11-12-permission-refusal.md b/changelog/unreleased/2026-11-12-permission-refusal.md
new file mode 100644
index 00000000..48a5a39b
--- /dev/null
+++ b/changelog/unreleased/2026-11-12-permission-refusal.md
@@ -0,0 +1,49 @@
+# A refused permission pick keeps its reason above the input card
+
+- **Date:** 2026-11-12
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文版](2026-11-12-permission-refusal.zh.md)
+
+The composer's permission button writes both halves of a Session's permission in one PATCH — the
+approval mode and the Session's own sandbox policy. The button shows the pick straight away and then
+re-reads the Session once the write settles, so a refusal changes nothing on screen: the button goes
+back to the level it read before, and nothing was written (the route checks every field before it
+writes any). The reason used to live only in a notification above the page that dismissed itself
+after six seconds — a click that looked as though it had never registered.
+
+Now the sentence is drawn above the input card, in the thinking level's slot:
+`没能切换权限(会话仍是原来的权限):<reason>`. It stays until the next pick — that permission button is
+the retry — and nothing is toasted for it any more.
+
+## Details
+
+- `packages/web/src/features/chat/permission-refusal.ts` (new): `permissionRefused(error)` builds the
+ sentence through `refusalText` (the app-wide refusal rule, 7.19) and says the Session still holds
+ the permission it had — the fact a reverted button cannot show on its own.
+- `packages/web/src/features/chat/chat-page.tsx`: `onChangePermission` records the refusal in
+ `permissionRefusal` (keyed by sessionId, so switching conversations never carries it over) and
+ clears it at the start of every attempt; this path no longer calls `toastError`.
+- `packages/web/src/features/chat/chat-input.tsx`: `ChatInput` takes an optional `permissionRefusal`
+ and draws it above the card (`role="alert"`, danger colour, two lines, the whole sentence on
+ hover), beside `thinkingRefusal`.
+- `packages/web/src/lib/strings{,-en}.ts`: one sentence per language.
+
+## Tests
+
+- `packages/web/test/permission-refusal.test.ts`: the sentence goes through `refusalText` rather than
+ the wire message, keeps what a write that never reached the route has to say, falls back to the
+ generic text, names the unchanged permission, and follows the active language.
+- `packages/web/e2e/permission-refusal.spec.mjs`: a real server and a real browser — the refused pick
+ leaves the sentence above the card with nothing in the notification region, still there after seven
+ seconds, with the button back on "always ask" and the stored Session still `always-ask`; the same
+ button retried writes, the sentence goes, the button reads "allow all" and the server follows.
+
+## Compatibility
+
+No wire change, no new dependency, no Project config change. The thinking level's sentence on the
+same page, successful writes and every other notification are untouched. A pick made from the Agents
+dock panel is the same write, so its refusal lands in the same place; while the panel covers the
+composer, that control still reads the old level and is the retry.
diff --git a/changelog/unreleased/2026-11-12-permission-refusal.zh.md b/changelog/unreleased/2026-11-12-permission-refusal.zh.md
new file mode 100644
index 00000000..437308d0
--- /dev/null
+++ b/changelog/unreleased/2026-11-12-permission-refusal.zh.md
@@ -0,0 +1,40 @@
+# 换权限档被拒时,原因留在输入框上方,不再只活六秒
+
+- **日期:** 2026-11-12
+- **类型:** 修复
+- **范围:** `web`
+- **破坏性变更:** 否
+
+[English](2026-11-12-permission-refusal.md)
+
+输入框里的权限按钮一次写两半 —— 审批模式与会话自己的沙盒策略 —— 按钮先把选中的那一档画出来,写入落定后再回读
+会话。所以被拒时屏幕上什么都不变:按钮退回它原来读到的等级,而那一档**没有写成**、会话上的权限一处没动;这条
+路由又是先把每个字段都验过才写,被拒时什么都不落库。此前这个原因只在页面顶部一条六秒后自己消失的通知里,留下
+一次看起来根本没被记下的点击。
+
+现在那句话画在**输入框卡片上方**(与思考等级被拒时同一个位置):`没能切换权限(会话仍是原来的权限):<原因>`。
+它留到下一次选择为止 —— 那个权限按钮就是重试;这件事不再另弹通知。
+
+## 细节
+
+- `packages/web/src/features/chat/permission-refusal.ts`(新增):`permissionRefused(error)` 按 `refusalText`
+ (全应用统一的拒绝口径,7.19)造句,并说清「会话仍是原来的权限」—— 一个退回原位的按钮自己说不出来的事实。
+- `packages/web/src/features/chat/chat-page.tsx`:`onChangePermission` 的拒绝写进 `permissionRefusal`
+ (按 sessionId 归属,切换会话不会串),每次尝试开始先清掉上一句;这一处不再 `toastError`。
+- `packages/web/src/features/chat/chat-input.tsx`:`ChatInput` 多一个可选的 `permissionRefusal`,画在卡片上方
+ (`role="alert"`、危险色、限两行、整句挂悬停),与 `thinkingRefusal` 并排。
+- `packages/web/src/lib/strings{,-en}.ts`:两种语言各一句。
+
+## 测试
+
+- `packages/web/test/permission-refusal.test.ts`:句子走 `refusalText` 而不是线上原话、保留没到路由的失败、
+ 没话说时回落到通用文案、说明会话仍是原来的权限、跟随当前语言。
+- `packages/web/e2e/permission-refusal.spec.mjs`:真服务端 + 真浏览器 —— 被拒的选择把句子留在卡片上方、通知区
+ 没有东西、七秒后仍在、按钮退回「总是询问」、服务端那一行仍是 `always-ask`;同一次重试写成功后句子归零、按钮
+ 变成「全部放行」、服务端跟上。
+
+## 兼容性
+
+线上接口没变、没有新依赖、Project 配置没变。同一页面上思考等级被拒的那一句、成功的写入、以及其余通知都一字未改。
+从「智能体」停靠面板里改权限走的是同一个写入,因此它的拒绝也落在同一处;面板挡住输入框时,那颗控件自己仍读着
+原来的等级,就是重试。
diff --git a/packages/web/e2e/permission-refusal.spec.mjs b/packages/web/e2e/permission-refusal.spec.mjs
new file mode 100644
index 00000000..38f2eef3
--- /dev/null
+++ b/packages/web/e2e/permission-refusal.spec.mjs
@@ -0,0 +1,119 @@
+/**
+ * Regression: a permission preset the write refused keeps the reason above the input card instead
+ * of in a notification that dismisses itself after six seconds.
+ *
+ * The permission button shows the pick at once, then re-reads the Session once the PATCH settles —
+ * so a refusal puts the old level back and that button is the retry. The route checks every field
+ * before writing any, so a refusal stores nothing. Before this, the reason lived only in a toast:
+ * the press looked as though it had never registered, and six seconds later nothing said why.
+ * This is the thinking level's slot (7.95) and the same shape; the sentence says the Session kept
+ * the permission it had, because a reverted button cannot show that on its own.
+ *
+ * The write is stubbed with a 500 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.
+ */
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const AGENT = "default_agent";
+
+/** 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 = "服务器内部错误,请稍后重试。";
+
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+/** The permission button: icon-only, its accessible name carries the level it reads. */
+const permissionBtn = (page) => page.locator('button[aria-label^="权限: "]');
+const refusalLine = (page) => page.getByTestId("permission-refusal");
+
+/**
+ * Provision a user, give the Project a model (without one the onboarding overlay covers the page),
+ * and create one Session whose approval mode this file then tries to change. No model is called.
+ */
+async function sessionWithModel(page, userId) {
+ await provisionAndLogin(page.request, userId, "password123");
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const models = 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(models.ok(), "put models").toBeTruthy();
+ const created = await page.request.post(
+ `${BASE}/api/projects/${projectId}/agents/${AGENT}/sessions`,
+ { data: { provider: "custom", modelId: "claude-4-8", approvalMode: "always-ask" } },
+ );
+ expect(created.ok(), `create session: ${await created.text()}`).toBeTruthy();
+ return (await created.json()).session.sessionId;
+}
+
+/** The Session's stored approval mode, as the server holds it. */
+async function storedApprovalMode(page, sessionId) {
+ const row = await (await page.request.get(`${BASE}/api/sessions/${sessionId}`)).json();
+ return row.session.approvalMode;
+}
+
+test("a refused permission pick keeps the reason above the card and leaves the Session as it was", async ({
+ page,
+}) => {
+ const sessionId = await sessionWithModel(page, "r226permrefuse");
+ await page.goto(`${BASE}/chat/${sessionId}`);
+ await expect(permissionBtn(page)).toHaveAttribute("aria-label", "权限: 总是询问");
+ await expect(refusalLine(page)).toHaveCount(0);
+
+ const writes = [];
+ let refuse = true;
+ await page.route(`**/api/sessions/${sessionId}`, async (route) => {
+ if (route.request().method() !== "PATCH") return route.fallback();
+ writes.push(route.request().postDataJSON());
+ if (!refuse) return route.fallback();
+ return route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await permissionBtn(page).click();
+ await page.getByRole("menuitemradio", { name: /全部放行/ }).click();
+
+ // The sentence is above the card, in the interface's own words, and stays past the six seconds
+ // an error notification lived.
+ const text = `没能切换权限(会话仍是原来的权限):${REASON}`;
+ await expect(refusalLine(page)).toHaveCount(1);
+ await expect(refusalLine(page)).toHaveText(text);
+ await expect(refusalLine(page)).not.toContainText("RAW ENGLISH");
+ await expect(notifications(page)).not.toContainText("RAW ENGLISH");
+ await page.waitForTimeout(7000);
+ await expect(refusalLine(page)).toHaveCount(1);
+ await expect(refusalLine(page)).toHaveText(text);
+
+ // The refusal wrote nothing: the button reads the level it read before (the retry) and the
+ // Session on the server still holds the old approval mode.
+ await expect(permissionBtn(page)).toHaveAttribute("aria-label", "权限: 总是询问");
+ expect(await storedApprovalMode(page, sessionId)).toBe("always-ask");
+ expect(writes).toHaveLength(1);
+
+ // The retry is the same button: this time the write lands, the sentence goes, and the Session
+ // carries the pick.
+ refuse = false;
+ await permissionBtn(page).click();
+ await page.getByRole("menuitemradio", { name: /全部放行/ }).click();
+ await expect(refusalLine(page)).toHaveCount(0);
+ await expect(permissionBtn(page)).toHaveAttribute("aria-label", "权限: 全部放行");
+ await expect.poll(async () => storedApprovalMode(page, sessionId)).toBe("allow-all");
+ expect(writes).toHaveLength(2);
+});
diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsx
index 30c639df..c7ed4f6c 100644
--- a/packages/web/src/features/chat/chat-input.tsx
+++ b/packages/web/src/features/chat/chat-input.tsx
@@ -595,6 +595,7 @@ export function ChatInput({
thinkingLevel,
onChangeThinkingLevel,
thinkingRefusal,
+ permissionRefusal,
turnThinkingLevel,
onChangeTurnThinkingLevel,
contextWindow,
@@ -756,6 +757,15 @@ export function ChatInput({
* hands it over only while it still describes the Agent / Session on screen.
*/
thinkingRefusal?: string | null;
+ /**
+ * A picked permission preset the write refused — the sentence drawn above the card, next to the
+ * thinking level's, or null/absent. Same reasoning: the permission button re-reads the Session
+ * once the PATCH settles, so a refusal puts the old level back and the button is the retry; a
+ * notification would be the only trace of a click that visibly did nothing. The parent owns the
+ * sentence because it owns the write, and hands it over only while it still describes the
+ * Session on screen.
+ */
+ permissionRefusal?: string | null;
/**
* Session state: the Session's thinking level to DISPLAY — the parent resolves it as "the
* user's pick for this session, else the Agent config's level" ("" = neither known yet),
@@ -2526,6 +2536,22 @@ export function ChatInput({
</p>
)}
+ {/* A permission preset the write refused: same slot, same reason — the button inside the
+ card re-read the Session and went back to the level it had, and the route wrote nothing.
+ The sentence therefore names the fact the reverted button cannot show (the Session keeps
+ what it had) and stays until the next pick. */}
+ {permissionRefusal != null && permissionRefusal !== "" && (
+ <p
+ role="alert"
+ data-testid="permission-refusal"
+ data-tooltip={permissionRefusal}
+ data-tooltip-content="text"
+ className={`anim-fade mb-1 line-clamp-2 break-words text-xs ${toneInk.danger}`}
+ >
+ {permissionRefusal}
+ </p>
+ )}
+
{/* Unified input card: the multi-line text body occupies the top area, with all controls
collected onto a single bottom row that never shares a line with the text. The card
collapses its toolbar by its own width (help text and button text hide under its
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index 2a7a87cb..54b00f98 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -115,6 +115,7 @@ import {
} from "./thinking-level";
import type { StagedThinkingSwitch } from "./thinking-level";
import { thinkingLevelRefused } from "./thinking-level-refusal";
+import { permissionRefused } from "./permission-refusal";
import { ChatDropRegion } from "./drop-zone";
import { ConversationOutline, OutlineMenuButton, useOutlineRailFit } from "./conversation-outline";
import { DraftView } from "./draft-view";
@@ -1734,20 +1735,30 @@ export function ChatPage() {
// A preset from the permission button: the approval mode and the Session's own sandbox
// policy in one PATCH, applied from the next tool call and command. A refused change (a
// non-admin loosening past the server's settings) stores nothing — the route checks every
- // field before writing any — so the Session is as it was, and the toast says why.
+ // field before writing any — so the Session is as it was and the button goes back to the
+ // level it read before: it is the retry, and the sentence saying why lives above the card
+ // (7.95's slot, same shape) instead of in a notification that outlives nothing.
+ const [permissionRefusal, setPermissionRefusal] = useState<{
+ sessionId: string;
+ text: string;
+ } | null>(null);
const onChangePermission = useCallback(
(pick: PermissionPick) => {
if (!selected || modeSaving) return;
+ const sessionId = selected.sessionId;
setModeSaving(true);
+ setPermissionRefusal(null); // One attempt, one reason: the new pick answers for itself.
// Returned so the permission button keeps the pick on screen until the save settles.
return api
- .patchSession(selected.sessionId, {
+ .patchSession(sessionId, {
approvalMode: pick.approvalMode,
// Absent for an approval-mode pick: the Session's policy is left as it is.
...(pick.sandbox !== undefined ? { sandbox: pick.sandbox } : {}),
})
.then((res) => replace(res.session))
- .catch((e: unknown) => toastError(apiErrorText(e)))
+ .catch((e: unknown) => {
+ setPermissionRefusal({ sessionId, text: permissionRefused(e) });
+ })
.finally(() => setModeSaving(false));
},
[selected, modeSaving, replace],
@@ -2238,6 +2249,9 @@ export function ChatPage() {
thinkingRefusal={
thinkingRefusal?.sessionId === selected.sessionId ? thinkingRefusal.text : null
}
+ permissionRefusal={
+ permissionRefusal?.sessionId === selected.sessionId ? permissionRefusal.text : null
+ }
{...(contextWindow !== undefined ? { contextWindow } : {})}
{...(compactionLimit !== undefined ? { compactionLimit } : {})}
onChangeCompactionLimit={onChangeCompactionLimit}
diff --git a/packages/web/src/features/chat/permission-refusal.ts b/packages/web/src/features/chat/permission-refusal.ts
new file mode 100644
index 00000000..2fc059d0
--- /dev/null
+++ b/packages/web/src/features/chat/permission-refusal.ts
@@ -0,0 +1,27 @@
+/**
+ * The permission picker: the sentence a refused write leaves above the input card, and why it is
+ * drawn there instead of arriving as a toast.
+ *
+ * A preset (or, with the Sandbox switch off, an approval mode) is written straight through as one
+ * PATCH on the Session — the approval mode and the Session's own sandbox policy together. The
+ * button shows the pick at once and then re-reads the Session once the write settles, so a refusal
+ * reverts it to the level it read before: nothing else on screen changes, and that button is the
+ * retry. The route checks every field before it writes any, so a refusal stores nothing either.
+ * A notification was therefore the only trace of the press, and it dismissed itself after six
+ * seconds — leaving a control that looked as though the click had never registered.
+ *
+ * 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.
+ */
+import { refusalText } from "../../lib/api-error";
+import { S } from "../../lib/strings";
+
+/**
+ * The line the composer draws above the card after a refused permission change. It says the
+ * Session still holds the permission it had — that is the fact a reverted button cannot show on
+ * its own, and the reason nothing was written.
+ */
+export function permissionRefused(error: unknown): string {
+ return S.chat.permissionRefused(refusalText(error));
+}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 29a8fed6..f50af4e9 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -3439,6 +3439,13 @@ export const en: Strings = {
forAgent
? `Could not change the thinking level (also the Agent's default, unchanged): ${reason}`
: `Could not change the thinking level: ${reason}`,
+ /**
+ * A picked permission preset (or approval mode) was refused: the button re-reads the Session and
+ * therefore shows the old level again, so the sentence says the pick did not take and that the
+ * Session kept what it had — the route writes nothing at all when it refuses.
+ */
+ permissionRefused: (reason: string) =>
+ `Could not change the permission (the Session keeps the one it had): ${reason}`,
/** Second tooltip line on a shortcut row: the click fills the composer, it does not send. */
shortcutFillHint: "Click to fill the composer — edit it if you like, then send",
/** The draft screen's saved-prompt folder: prompts the user wrote and saved, stored per user on the server. */
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 094c269c..0995f62a 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -3529,6 +3529,12 @@ export const zh = {
forAgent
? `没能切换思考等级(同时是 Agent 的默认档,没有改动):${reason}`
: `没能切换思考等级:${reason}`,
+ /**
+ * A picked permission preset (or approval mode) was refused: the button re-reads the Session and
+ * therefore shows the old level again, so the sentence says the pick did not take and that the
+ * Session kept what it had — the route writes nothing at all when it refuses.
+ */
+ permissionRefused: (reason: string) => `没能切换权限(会话仍是原来的权限):${reason}`,
/** Second tooltip line on a shortcut row: the click fills the composer, it does not send. */
shortcutFillHint: "点击填入输入框,可修改后自行发送",
/** The draft screen's saved-prompt folder: prompts the user wrote and saved, stored per user on the server. */
diff --git a/packages/web/test/permission-refusal.test.ts b/packages/web/test/permission-refusal.test.ts
new file mode 100644
index 00000000..c70e33f6
--- /dev/null
+++ b/packages/web/test/permission-refusal.test.ts
@@ -0,0 +1,53 @@
+/**
+ * A permission preset the write refused (src/features/chat/permission-refusal.ts): which words the
+ * sentence above the input card uses.
+ *
+ * The permission button shows the pick at once and then re-reads the Session once the PATCH
+ * settles, so a refusal puts the old level back and the button is the retry — the sentence is the
+ * only thing saying why the press changed nothing. Three things it must get right: a server answer
+ * speaks the interface's own language rather than the wire message, a write that never reached the
+ * route keeps what it knows (7.19's rule), and it says out loud that the Session kept the
+ * permission it had (the route writes nothing at all when it refuses).
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { ApiError } from "../src/api/client";
+import { en as EN } from "../src/lib/strings-en";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { permissionRefused } from "../src/features/chat/permission-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("permissionRefused", () => {
+ it("reads a refusal through the code's own sentence, not the wire message", () => {
+ const line = permissionRefused(new ApiError(500, "internal", "RAW ENGLISH"));
+ expect(line).not.toContain("RAW ENGLISH");
+ expect(line).toBe(S.chat.permissionRefused(S.errors.byCode.internal as string));
+ });
+
+ it("keeps what a write that never reached the route has to say", () => {
+ expect(permissionRefused(new Error("Failed to fetch"))).toBe(
+ S.chat.permissionRefused("Failed to fetch"),
+ );
+ });
+
+ it("falls back to the generic text when the value has nothing to say", () => {
+ expect(permissionRefused(undefined)).toBe(S.chat.permissionRefused(S.common.unknownError));
+ });
+
+ it("says the Session kept the permission it had", () => {
+ // A non-admin loosening past the server's ceiling is the ordinary refusal of this write.
+ const line = permissionRefused(new ApiError(403, "admin_required", "RAW"));
+ expect(line).toBe(S.chat.permissionRefused(S.errors.byCode.admin_required as string));
+ expect(line).toContain("会话仍是原来的权限");
+ });
+
+ it("speaks the active language", () => {
+ setActiveStrings(EN);
+ expect(permissionRefused(new Error("boom"))).toBe(
+ "Could not change the permission (the Session keeps the one it had): boom",
+ );
+ expect(permissionRefused(new Error("boom"))).toBe(EN.chat.permissionRefused("boom"));
+ });
+});