Skip to content

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

fix(web): 频道的离开与归档确认框被拒时留着,原因也留在框里(7.38)

lmlihenge427e0305153
diff --git a/changelog/unreleased/2026-10-24-channel-refusal.md b/changelog/unreleased/2026-10-24-channel-refusal.md
new file mode 100644
index 00000000..8123dc7e
--- /dev/null
+++ b/changelog/unreleased/2026-10-24-channel-refusal.md
@@ -0,0 +1,38 @@
+# Channels: a refused leave or archive keeps its question — and the reason
+
+- **Date:** 2026-10-24
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-24-channel-refusal.zh.md)
+
+A channel's header asks before the two writes that change who is in it and whether it takes
+messages: leaving removes the reader from the roster, archiving makes the channel read-only.
+Both cards stayed open when the server refused — but the reason went into a toast that dismissed
+itself after a few seconds and sat over the card rather than in it, so the reader was left looking
+at an unchanged channel with nothing to read.
+
+Both cards now close only once their write landed. A refusal leaves the card standing with the
+server's words drawn under its sentence (`ConfirmModal`'s `refusal` slot, the app's existing
+"Refused:" lead-in), so the retry is the button that was pressed; cancelling decides nothing, and
+opening either card again drops the previous reason, which belonged to the attempt it named.
+Un-archiving is a single menu row with no card to keep, so its refusal stays a toast.
+
+## Details
+
+- `features/company/channel-header.tsx`: `leave()` keeps the server's words in `leaveRefusal`
+ instead of only toasting them, and closes the card on the success path alone; `setArchived()`
+ takes whether it was asked in a card — the archive card's refusal goes into `archiveRefusal`,
+ the un-archive menu row's stays a toast. Both writes bail out while one is in flight (the cards'
+ buttons are already disabled by `busy`). The leave button and the archive menu row clear the
+ refusal of the card they are about to open, and a channel switch clears both.
+- New browser test `e2e/channel-refusal.spec.mjs` (2 cases, one per card): with the write refused
+ at `page.route` 500, the card, its sentence and the channel's stored state all stay (nothing to
+ dismiss in the notification region); reopening shows no stale reason; the retry on the same card
+ writes it — the card goes, and the reader is off the roster / the channel reads as archived.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *when* the two cards close and
+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.
diff --git a/changelog/unreleased/2026-10-24-channel-refusal.zh.md b/changelog/unreleased/2026-10-24-channel-refusal.zh.md
new file mode 100644
index 00000000..af53104f
--- /dev/null
+++ b/changelog/unreleased/2026-10-24-channel-refusal.zh.md
@@ -0,0 +1,32 @@
+# 频道:离开或归档被拒时,框留着,原因也留在框里
+
+- **Date:** 2026-10-24
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-24-channel-refusal.md)
+
+频道的页头在两种写入之前各问一句:离开会把读者从成员名册里去掉,归档会让频道变成只读。被拒时两张框其实
+都还开着 —— 但原因落进一条几秒后自己消失、还浮在框上方的通知里,于是读者面对的仍是一个没变的频道,
+却没有一句话可读。
+
+现在两张框都只在自己的写入落地之后才关。被拒时框留着,服务端的原话画在它自己那句话下面(`ConfirmModal`
+的 `refusal` 槽,用的是应用既有的「操作被拒绝:」前缀),重试就是刚才按下的那个按钮;取消不决定任何事,
+重开任何一张框都会先清掉上一次的原因 —— 那句话属于上次那次尝试。取消归档没有框(只是菜单里的一行),
+它的失败仍用通知。
+
+## 细节
+
+- `features/company/channel-header.tsx`:`leave()` 把服务端原话留在 `leaveRefusal` 里,不再只弹通知;
+ 关框只发生在成功那条路径上。`setArchived()` 多收一个「这次是不是在框里问的」—— 归档那张框的失败进
+ `archiveRefusal`,取消归档那一行的失败仍是通知。两个写入在另一个在途时都不再发(框上两个按钮本来就被
+ `busy` 置灰)。离开按钮与归档菜单行在打开各自的框之前先清掉旧原因,切换频道时两个原因一起清。
+- 新增浏览器用例 `e2e/channel-refusal.spec.mjs`(2 条,一张框一条):用 `page.route` 把写入拒成 500 之后,
+ 框、框里那句话与服务端上的频道状态都不变(通知区没有可点的按钮),重开不带旧原因;在同一张框上重试才
+ 真正写入 —— 框关掉,读者已不在名册上 / 频道读作已归档。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了这两张框「什么时候关」与「原因画在哪」。除既有的
+ `S.common.refused` 前缀外没有新文案。
diff --git a/packages/web/e2e/channel-refusal.spec.mjs b/packages/web/e2e/channel-refusal.spec.mjs
new file mode 100644
index 00000000..37659a67
--- /dev/null
+++ b/packages/web/e2e/channel-refusal.spec.mjs
@@ -0,0 +1,239 @@
+/**
+ * Regression: leaving a channel and archiving it are asked in a confirmation card, and a refused
+ * write keeps that question — with the server's words inside it — instead of leaving only a toast.
+ *
+ * Both cards in `features/company/channel-header.tsx` used to stay open while their reason fell
+ * into a toast that dismissed itself after a few seconds and sat over the card rather than in it.
+ * They now close only once their write landed; a refusal leaves the card standing with the reason
+ * drawn under its sentence (`ConfirmModal`'s `refusal` slot), so the retry is the button that was
+ * pressed and cancelling decides nothing. Un-archiving has no card — one menu row — and keeps its
+ * toast, which is what this spec checks it does NOT do for the two cards.
+ *
+ * The organization, its channel and the invited CEO are made through the API rather than through
+ * the dialogs: this spec is about the two confirmations, not about creation. Company mode is off
+ * on a fresh server, so each test turns the admin master switch on first (idempotent), and the
+ * Project gets the mock as its model so the onboarding overlay stays off the page.
+ */
+import { test, expect, request } from "@playwright/test";
+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const ORG = "chanrefuse";
+const CHANNEL = "site";
+const NAME = "站点上线";
+
+/** The writes the page makes; a 500 with its own words proves the reason came back. */
+const LEAVE_REFUSAL = {
+ code: "channel_members_locked",
+ message: "the channel roster is mid-rewrite",
+};
+const ARCHIVE_REFUSAL = { code: "channel_store_locked", message: "channel store is locked" };
+
+/** The admin master switch, off by default: turned on server-wide before the flow starts. */
+async function enableCompanyMode() {
+ const adminCtx = await request.newContext();
+ try {
+ await login(adminCtx, ADMIN_ID, ADMIN_PASSWORD);
+ const res = await adminCtx.put(`${BASE}/api/admin/settings`, { data: { companyMode: true } });
+ if (!res.ok()) {
+ throw new Error(`enable company mode failed: ${res.status()} ${await res.text()}`);
+ }
+ } finally {
+ await adminCtx.dispose();
+ }
+}
+
+/**
+ * A fresh user with mock-model credentials, an organization with its CEO, and one invited channel
+ * holding both the reader and the CEO. Returns the ids and a reader over the channel as stored.
+ */
+async function setUp(page, tag) {
+ await enableCompanyMode();
+ const user = `${tag}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
+ await provisionAndLogin(page.request, user, P);
+ const project = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0];
+ const projectId = project.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 ${projectId}`).toBeTruthy();
+
+ const orgBase = `${BASE}/api/projects/${projectId}/organizations`;
+ const created = await page.request.post(orgBase, {
+ data: { orgId: ORG, mission: "Publish the plugin marketplace and reach the top of search." },
+ });
+ expect(created.ok(), "create organization").toBeTruthy();
+
+ // The creator is the channel's first member; the CEO is invited so leaving really removes one
+ // person from a channel others are in.
+ const channel = await page.request.post(`${orgBase}/${ORG}/channels`, {
+ data: { channelId: CHANNEL, name: NAME, purpose: "站点从零到上线的一切" },
+ });
+ expect(channel.ok(), "create channel").toBeTruthy();
+ const invited = await page.request.post(`${orgBase}/${ORG}/channels/${CHANNEL}/members`, {
+ data: { principal: `agent:${ORG}_ceo` },
+ });
+ expect(invited.ok(), "invite the CEO").toBeTruthy();
+
+ const channelUrl = `${orgBase}/${ORG}/channels/${CHANNEL}`;
+ /** The channel as the server holds it: its roster and whether it is archived. */
+ const stored = async () => {
+ const res = await page.request.get(channelUrl);
+ return res.status() === 200 ? await res.json() : null;
+ };
+ const detail = await stored();
+ const me = detail.members.map((m) => m.principal).find((p) => p.startsWith("user:"));
+ expect(me, "the reader is a member").toBeTruthy();
+ return { projectId, channelUrl, me, stored };
+}
+
+/** Open the channel: the header sits above its stream. */
+async function openChannel(page, projectId) {
+ await page.goto(`/org/${projectId}/${ORG}/channels/${CHANNEL}`);
+ await expect(page.getByRole("heading", { name: new RegExp(NAME) })).toBeVisible();
+}
+
+/**
+ * The card's own text with the refusal line dropped: a refused write adds one line under the
+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal may change.
+ */
+async function cardText(card) {
+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");
+}
+
+test("a refused leave keeps the card, its sentence and the roster", async ({ page }) => {
+ const { projectId, channelUrl, me, stored } = await setUp(page, "r123leave");
+ expect((await stored())?.members.map((m) => m.principal)).toContain(me);
+
+ await openChannel(page, projectId);
+ await page.getByRole("button", { name: "离开", exact: true }).click();
+ const card = page.getByRole("dialog", { name: "离开频道" });
+ await expect(card).toBeVisible();
+ const sentence = await card.innerText();
+ expect(sentence).toContain(`确认离开「${NAME}」`);
+
+ const deletes = [];
+ await page.route(
+ `**/api/projects/${projectId}/organizations/${ORG}/channels/${CHANNEL}/members/**`,
+ async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ deletes.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: LEAVE_REFUSAL }),
+ });
+ },
+ );
+
+ await card.getByRole("button", { name: "离开", exact: true }).click();
+
+ // The reason is in the card that asked, and it is not a toast: the notification region (which
+ // may still hold the company beta's own notice) never carries the server's words, and the card
+ // reads exactly as before plus the one line.
+ await expect(card.getByText(LEAVE_REFUSAL.message)).toBeVisible();
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(LEAVE_REFUSAL.message);
+ expect(deletes).toHaveLength(1);
+ await expect(card).toBeVisible();
+ expect(await cardText(card)).toBe(sentence);
+
+ // Nothing was written: the reader is still on the roster (the card hides the page behind it, so
+ // the header's own button is not readable here — the roster is).
+ expect((await stored())?.members.map((m) => m.principal)).toContain(me);
+
+ // Closing the card decides nothing, and reopening it does not carry the old reason.
+ await card.getByRole("button", { name: "取消" }).click();
+ await expect(card).toHaveCount(0);
+ await page.getByRole("button", { name: "离开", exact: true }).click();
+ const again = page.getByRole("dialog", { name: "离开频道" });
+ await expect(again).toBeVisible();
+ await expect(again.getByText(LEAVE_REFUSAL.message)).toHaveCount(0);
+ expect(await again.innerText()).toBe(sentence);
+
+ // The retry lands: the card goes, and the roster on the server no longer holds the reader.
+ await page.unroute(
+ `**/api/projects/${projectId}/organizations/${ORG}/channels/${CHANNEL}/members/**`,
+ );
+ await again.getByRole("button", { name: "离开", exact: true }).click();
+ await expect(again).toHaveCount(0);
+ await expect
+ .poll(async () => (await stored())?.members.map((m) => m.principal).includes(me))
+ .toBe(false);
+ // Left is left: the header no longer offers to leave (nor to invite), and says so in a notice.
+ await expect(page.getByRole("button", { name: "离开", exact: true })).toHaveCount(0);
+ await expect(page.getByText("你还不是这个频道的成员", { exact: false })).toBeVisible();
+ expect((await (await page.request.get(channelUrl)).json()).isMember).toBe(false);
+});
+
+test("a refused archive keeps the card, its sentence and the channel open", async ({ page }) => {
+ const { projectId, stored } = await setUp(page, "r123archive");
+ expect((await stored())?.archived).toBe(false);
+
+ await openChannel(page, projectId);
+ await page.getByRole("button", { name: new RegExp(`^频道操作: ${NAME}`) }).click();
+ await page.getByRole("menuitem", { name: "归档" }).click();
+ const card = page.getByRole("dialog", { name: "归档频道" });
+ await expect(card).toBeVisible();
+ const sentence = await card.innerText();
+ expect(sentence).toContain(`确认归档「${NAME}」`);
+
+ const patches = [];
+ await page.route(
+ `**/api/projects/${projectId}/organizations/${ORG}/channels/${CHANNEL}`,
+ async (route) => {
+ if (route.request().method() !== "PATCH") return route.fallback();
+ patches.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: ARCHIVE_REFUSAL }),
+ });
+ },
+ );
+
+ await card.getByRole("button", { name: "归档", exact: true }).click();
+
+ // A refusal over a card is the card's news, never a toast (the notification region is where the
+ // company beta's own notice lives, so this checks the words rather than the region being empty).
+ await expect(card.getByText(ARCHIVE_REFUSAL.message)).toBeVisible();
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(
+ ARCHIVE_REFUSAL.message,
+ );
+ expect(patches).toHaveLength(1);
+ await expect(card).toBeVisible();
+ expect(await cardText(card)).toBe(sentence);
+
+ // Nothing was written: the channel still takes messages, and its menu still offers to archive.
+ expect((await stored())?.archived).toBe(false);
+ await expect(page.getByRole("textbox", { name: /输入消息/ })).toBeVisible();
+
+ // Closing the card decides nothing, and reopening it does not carry the old reason.
+ await card.getByRole("button", { name: "取消" }).click();
+ await expect(card).toHaveCount(0);
+ await page.getByRole("button", { name: new RegExp(`^频道操作: ${NAME}`) }).click();
+ await page.getByRole("menuitem", { name: "归档" }).click();
+ const again = page.getByRole("dialog", { name: "归档频道" });
+ await expect(again).toBeVisible();
+ await expect(again.getByText(ARCHIVE_REFUSAL.message)).toHaveCount(0);
+ expect(await again.innerText()).toBe(sentence);
+
+ // The retry lands: the card goes, the channel is archived, and the page says it is read-only.
+ await page.unroute(`**/api/projects/${projectId}/organizations/${ORG}/channels/${CHANNEL}`);
+ await again.getByRole("button", { name: "归档", exact: true }).click();
+ await expect(again).toHaveCount(0);
+ await expect.poll(async () => (await stored())?.archived).toBe(true);
+ await expect(page.getByText("这个频道已归档,只读")).toBeVisible();
+});
diff --git a/packages/web/src/features/company/channel-header.tsx b/packages/web/src/features/company/channel-header.tsx
index 58dd3d10..fb10828a 100644
--- a/packages/web/src/features/company/channel-header.tsx
+++ b/packages/web/src/features/company/channel-header.tsx
@@ -12,6 +12,11 @@
* itself enforces — it cannot be left, archived, or have its membership edited, so those
* controls are simply absent, the missing archive row named by one muted line in the menu.
* What that channel is stays in the header's "?", said once.
+ *
+ * Leaving and archiving are asked in a confirmation card, and the card is the answer's home: it
+ * closes only once its write landed, and a refusal draws the server's words under the card's own
+ * sentence (the retry is the button that was pressed). Un-archiving has no card — it is one menu
+ * row — so its refusal is a toast, like every other write here without a question of its own.
*/
import { useEffect, useState } from "react";
import { createPortal } from "react-dom";
@@ -281,6 +286,10 @@ export function ChannelHeader({
const [leaveOpen, setLeaveOpen] = useState(false);
const [archiveOpen, setArchiveOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
+ // The reason the last leave / archive was refused, drawn inside the card that asked for it:
+ // both writes are questions, so a toast would dismiss itself out of the card still on screen.
+ const [leaveRefusal, setLeaveRefusal] = useState<string | null>(null);
+ const [archiveRefusal, setArchiveRefusal] = useState<string | null>(null);
const [query, setQuery] = useState("");
const [busy, setBusy] = useState(false);
const [openingDesk, setOpeningDesk] = useState<string | null>(null);
@@ -294,6 +303,8 @@ export function ChannelHeader({
setArchiveOpen(false);
setMenuOpen(false);
setQuery("");
+ setLeaveRefusal(null);
+ setArchiveRefusal(null);
}, [channelId]);
if (detail === null) {
@@ -345,28 +356,42 @@ export function ChannelHeader({
};
const leave = async (principal: string) => {
+ if (busy) return;
setBusy(true);
try {
await api.removeOrgChannelMember(projectId, orgId, detail.channelId, principal);
+ // The card goes with its own write landing, never before: a refusal has to stay readable
+ // next to the button that retries it.
setLeaveOpen(false);
+ setLeaveRefusal(null);
toastSuccess(S.company.channels.left);
onChanged();
} catch (e) {
- toastError(apiErrorText(e));
+ setLeaveRefusal(apiErrorText(e));
} finally {
setBusy(false);
}
};
- const setArchived = async (archived: boolean) => {
+ /**
+ * Archives or un-archives the channel. Archiving is asked in a card, so its refusal belongs in
+ * that card (`inCard`); un-archiving is a single menu row with nothing to keep open.
+ */
+ const setArchived = async (archived: boolean, inCard: boolean) => {
+ if (busy) return;
setBusy(true);
try {
await api.patchOrgChannel(projectId, orgId, detail.channelId, { archived });
- setArchiveOpen(false);
+ if (inCard) {
+ setArchiveOpen(false);
+ setArchiveRefusal(null);
+ }
toastSuccess(archived ? S.company.channels.archived : S.company.channels.unarchived);
onChanged();
} catch (e) {
- toastError(apiErrorText(e));
+ const text = apiErrorText(e);
+ if (inCard) setArchiveRefusal(text);
+ else toastError(text);
} finally {
setBusy(false);
}
@@ -440,7 +465,15 @@ export function ChannelHeader({
/>
)}
{!allHands && detail.isMember && !detail.archived && (
- <Button size="sm" disabled={busy} onClick={() => setLeaveOpen(true)}>
+ <Button
+ size="sm"
+ disabled={busy}
+ onClick={() => {
+ // A new question, not the one just refused: the old reason goes.
+ setLeaveRefusal(null);
+ setLeaveOpen(true);
+ }}
+ >
<span className={`flex items-center ${ICON_GAP.tight}`}>
<GlyphIcon d={LEAVE_ICON} size={ICON_SIZE.inlineGlyph} />
{S.company.channels.leave}
@@ -497,7 +530,7 @@ export function ChannelHeader({
label={S.company.channels.unarchive}
onSelect={() => {
setMenuOpen(false);
- void setArchived(false);
+ void setArchived(false, false);
}}
/>
) : (
@@ -506,6 +539,8 @@ export function ChannelHeader({
label={S.company.channels.archive}
onSelect={() => {
setMenuOpen(false);
+ // A new question, not the one just refused: the old reason goes.
+ setArchiveRefusal(null);
setArchiveOpen(true);
}}
/>
@@ -548,6 +583,7 @@ export function ChannelHeader({
confirmLabel={S.company.channels.leave}
cancelLabel={S.common.cancel}
busy={busy}
+ refusal={leaveRefusal === null ? undefined : S.common.refused(leaveRefusal)}
onClose={() => (busy ? undefined : setLeaveOpen(false))}
onConfirm={() => void leave(me)}
>
@@ -561,8 +597,9 @@ export function ChannelHeader({
confirmLabel={S.company.channels.archive}
cancelLabel={S.common.cancel}
busy={busy}
+ refusal={archiveRefusal === null ? undefined : S.common.refused(archiveRefusal)}
onClose={() => (busy ? undefined : setArchiveOpen(false))}
- onConfirm={() => void setArchived(true)}
+ onConfirm={() => void setArchived(true, true)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">
{S.company.channels.archiveConfirm(label)}