Skip to content

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

fix(web): 定时任务 tab 的启用/停用被拒时,原因留在那一行的徽标下面

lmliheng5131988d1346
diff --git a/changelog/unreleased/2026-10-31-agent-schedule-toggle-refusal.md b/changelog/unreleased/2026-10-31-agent-schedule-toggle-refusal.md
new file mode 100644
index 00000000..f3588539
--- /dev/null
+++ b/changelog/unreleased/2026-10-31-agent-schedule-toggle-refusal.md
@@ -0,0 +1,45 @@
+# A refused 启用 / 停用 on the Agent settings tab says why under that row's status badge
+
+- **Date:** 2026-10-31
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-31-agent-schedule-toggle-refusal.zh.md)
+
+The Agent settings page's Schedule tab lists one Agent's tasks as a table with a text button per
+row (启用 / 停用), and that button writes nothing optimistically: it sends the whole file back with
+`enabled` flipped, and until the write lands the row keeps the state the server has. So a **refused**
+flip used to leave the table exactly as it was — the button did not move, the badge did not move —
+with the reason only in a toast that dismissed itself after six seconds: a button that seemed to do
+nothing, and no sentence left saying why.
+
+The two surfaces that list tasks with the shared `ScheduleRow` (the scheduled-tasks page and the
+chat dock's panel) gained this line for their switch one round ago; this tab is the third list of
+the same thing, and it now draws its reason under the row's status badge: the shared lead-in
+`S.common.refused`, in the danger ink, as `role="alert"`, clamped to two lines with the whole
+sentence on hover. The row it belongs to is picked by the same rule the other two use
+(`scheduleRefusalFor`) — a task is named by its Agent's directory plus its file name — and the next
+flip clears it, since it is that attempt's answer and not the row's standing state. No new copy was
+written.
+
+## Details
+
+- `packages/web/src/features/agents/schedules-tab.tsx`: a `toggleRefusal` state, filled from the
+ failed `updateSchedule` (via `apiErrorText`) instead of `toastError`, cleared at the start of the
+ next flip; a `ToggleRefusal` block under the status badge, so the sentence sits where the reader
+ was looking when the button did not move. The rest of the file is untouched — a successful flip
+ still says so with its toast and still reloads the table.
+
+## Tests
+
+- `packages/web/e2e/agent-schedule-toggle-refusal.spec.mjs` (new, two browser cases against the
+ real server): a refused flip leaves the reason under that row's badge and nothing on the
+ neighbouring row, the notification region without a dismissible toast, the button and the badge
+ where the server still has them, and the line still there seven seconds later; then, with the
+ refusal lifted, the same button lands — the line goes, the button becomes 启用 and the badge 停用.
+
+## Compatibility
+
+- No API, on-disk or request-shape change: the PUT body is exactly the one `toggleBody` built
+ before. Only the failed path stopped using a toast.
diff --git a/changelog/unreleased/2026-10-31-agent-schedule-toggle-refusal.zh.md b/changelog/unreleased/2026-10-31-agent-schedule-toggle-refusal.zh.md
new file mode 100644
index 00000000..1d965627
--- /dev/null
+++ b/changelog/unreleased/2026-10-31-agent-schedule-toggle-refusal.zh.md
@@ -0,0 +1,38 @@
+# Agent 设置页的定时任务 tab:启用 / 停用被拒时,原因留在那一行的状态徽标下面
+
+- **日期:** 2026-10-31
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 无
+
+[English](2026-10-31-agent-schedule-toggle-refusal.md)
+
+Agent 设置页的「定时任务」tab 把某个 Agent 的任务列成一张表,每行靠一个文字按钮「启用 / 停用」
+来翻转。这个按钮同样不做乐观写入:它把整份文件连同翻转后的 `enabled` 一起发回去,写入落地之前
+行里显示的一直是服务端记着的那个状态。所以**被拒**时,这张表此前什么都不会变 —— 按钮没动、徽标
+没动 —— 原因只剩一条六秒后自己消失的 toast:一颗看起来点了没反应的按钮,以及一句已经看不见的解释。
+
+用共用 `ScheduleRow` 的那两个界面(定时任务页与对话停靠栏里的定时任务面板)上一轮已经给它们的开关
+加上了这一行;这里是同一件东西的第三处列表,现在把原因画在那一行的状态徽标下面:共享引子
+`S.common.refused`、danger 色、`role="alert"`、限两行、整句挂悬停。它属于哪一行沿用另外两处的那条
+规则(`scheduleRefusalFor`)—— 任务的名字 = Agent 目录 + 文件名 —— 下一次翻转会把它清掉,因为它是
+那一次点击的答复,不是这一行的长期状态。没有新增文案。
+
+## 细节
+
+- `packages/web/src/features/agents/schedules-tab.tsx`:多一个 `toggleRefusal` 状态,由失败的
+ `updateSchedule` 经 `apiErrorText` 填上(不再走 `toastError`),下一次翻转开始时清空;状态徽标
+ 下面多一块 `ToggleRefusal`,让这句话正落在「按钮没动」时读者看的那一格。文件其余部分未动 ——
+ 成功的翻转照旧弹一条提示并重新拉表。
+
+## 测试
+
+- `packages/web/e2e/agent-schedule-toggle-refusal.spec.mjs`(新,真服务端两条):被拒的翻转把原因
+ 留在那一行的徽标下面、旁边那一行没有,通知区里没有可点的 toast,按钮与徽标仍停在服务端记着的
+ 位置,并且 toast 该消失的七秒之后那一行还在;随后放开拒绝,同一颗按钮真的落地 —— 那一行消失、
+ 按钮变成「启用」、徽标变成「停用」。
+
+## 兼容
+
+- 接口、磁盘格式、请求体都没变:PUT 的正文仍是 `toggleBody` 原本拼的那一份。只有失败那条路不再用
+ toast。
diff --git a/packages/web/e2e/agent-schedule-toggle-refusal.spec.mjs b/packages/web/e2e/agent-schedule-toggle-refusal.spec.mjs
new file mode 100644
index 00000000..f58a2521
--- /dev/null
+++ b/packages/web/e2e/agent-schedule-toggle-refusal.spec.mjs
@@ -0,0 +1,166 @@
+/**
+ * Regression: the Agent settings tab's 启用 / 停用 button says why a flip did not settle, under
+ * that row's status badge, and the sentence outlives the six seconds a toast lives.
+ *
+ * That tab lists one Agent's tasks as a table with a text button per row (not the shared
+ * `ScheduleRow`, whose switch gained this line first), and its toggle writes nothing
+ * optimistically either — the row keeps the state the server has — so a refused flip used to
+ * leave the table exactly as it was with the reason in a toast that dismissed itself: a button
+ * that did not move and, six seconds later, no sentence saying why.
+ *
+ * The refusal is a real one the server answers — `schedule_not_found`, the task file gone (another
+ * window deleted it between the list read and the flip) — taken over by a route so the test does
+ * not race the store's own refetch. The app has its own sentence for that code, so the line on
+ * screen is the localized one.
+ *
+ * Every test seeds through the API: a `startAt` in the future keeps the scheduler out of the way,
+ * and the seed drops a leftover file of the same name first, since a rerun of this file alone
+ * shares one data root with earlier runs.
+ */
+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 AGENT = "default_agent";
+
+/** What the server answers when the task file is gone by the time the flip is written. */
+const REFUSAL = { code: "schedule_not_found", message: "Schedule does not exist: tab_probe" };
+/** The line the row draws: the shared lead-in plus the app's own sentence for that code. */
+const REFUSED_LINE = "操作被拒绝:该定时任务已不存在。";
+
+/**
+ * Provision the user, give the Project a model (the onboarding overlay covers the page without
+ * one), and seed one armed future task per name.
+ */
+async function projectWithTasks(page, user, names) {
+ 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: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ ],
+ },
+ });
+ expect(put.ok(), "put models").toBeTruthy();
+
+ const base = `${BASE}/api/projects/${projectId}/agents/${AGENT}/schedules`;
+ for (const name of names) {
+ await page.request.delete(`${base}/${name}`);
+ const created = await page.request.post(base, {
+ data: {
+ name,
+ prompt: "tab toggle refusal probe",
+ enabled: true,
+ startAt: new Date(Date.now() + 86_400_000).toISOString(),
+ },
+ });
+ expect(created.status(), `seed ${name}`).toBe(201);
+ }
+
+ /** The Project's list as the server holds it: what the table reads. */
+ const listed = async () =>
+ (await (await page.request.get(`${BASE}/api/projects/${projectId}/schedules`)).json())
+ .schedules;
+ return { projectId, listed };
+}
+
+/** Refuse every schedule write with the "the file is gone" answer; the flips that reach it are counted. */
+async function refuseFlips(page, seen) {
+ let refuse = true;
+ await page.route("**/api/projects/*/agents/*/schedules/*", async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ seen.push(route.request().url());
+ if (!refuse) return route.fallback();
+ await route.fulfill({
+ status: 404,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+ return () => {
+ refuse = false;
+ };
+}
+
+/** One task's row in the settings tab's table (a `tr`, unlike the two list surfaces' `li`). */
+function rowOf(page, name) {
+ return page.locator("main").locator("tr").filter({ hasText: name });
+}
+
+/** The row's status cell: the one column that draws the badge, and the refusal under it. */
+function statusCell(row) {
+ return row.locator("td").nth(1);
+}
+
+test("a refused flip on the Agent settings tab keeps the reason under that row, and only that row", async ({
+ page,
+}) => {
+ const { listed } = await projectWithTasks(page, "r170page", ["tab_probe", "tab_quiet"]);
+ const before = await listed();
+
+ await page.goto(`/agents/${AGENT}?tab=schedules`);
+ const row = rowOf(page, "tab_probe");
+ await expect(row).toBeVisible();
+ const other = rowOf(page, "tab_quiet");
+ await expect(other).toBeVisible();
+
+ const flips = [];
+ await refuseFlips(page, flips);
+ await row.getByRole("button", { name: "停用", exact: true }).click();
+
+ // The reason is in the row that asked, under its badge, and it is not a toast: the notification
+ // region holds no dismissible button, and the neighbouring row says nothing.
+ await expect(statusCell(row).getByRole("alert")).toHaveText(REFUSED_LINE);
+ await expect(statusCell(row)).toContainText("生效");
+ await expect(row.getByRole("alert")).toHaveCount(1);
+ await expect(other.getByRole("alert")).toHaveCount(0);
+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);
+ expect(flips).toHaveLength(1);
+
+ // The button did not move, because the task did not: it is still armed on the server.
+ await expect(row.getByRole("button", { name: "停用", exact: true })).toBeVisible();
+ const armed = (await listed()).find((s) => s.name === "tab_probe");
+ expect(armed?.enabled).toBe(true);
+ expect((await listed()).length).toBe(before.length);
+
+ // Six seconds is how long a toast lives; this line has to still be there after it.
+ await page.waitForTimeout(7_000);
+ await expect(statusCell(row).getByRole("alert")).toHaveText(REFUSED_LINE);
+});
+
+test("the next flip clears the line, and a flip that lands moves the button and the badge", async ({
+ page,
+}) => {
+ const { listed } = await projectWithTasks(page, "r170retry", ["tab_retry"]);
+
+ await page.goto(`/agents/${AGENT}?tab=schedules`);
+ const row = rowOf(page, "tab_retry");
+ await expect(row).toBeVisible();
+
+ const flips = [];
+ const letThrough = await refuseFlips(page, flips);
+ await row.getByRole("button", { name: "停用", exact: true }).click();
+ await expect(statusCell(row).getByRole("alert")).toHaveText(REFUSED_LINE);
+
+ // Same button, second click: this time the write lands, so the sentence goes and the row moves
+ // to the position the server now has — the button's name with it (停用 → 启用) and the badge
+ // (生效 → 停用).
+ letThrough();
+ await row.getByRole("button", { name: "停用", exact: true }).click();
+ await expect(row.getByRole("alert")).toHaveCount(0);
+ await expect(row.getByRole("button", { name: "启用", exact: true })).toBeVisible();
+ await expect(statusCell(row)).toContainText("停用");
+ expect(flips).toHaveLength(2);
+ expect((await listed()).find((s) => s.name === "tab_retry")?.enabled).toBe(false);
+});
diff --git a/packages/web/src/features/agents/schedules-tab.tsx b/packages/web/src/features/agents/schedules-tab.tsx
index 2c914297..69b98fa8 100644
--- a/packages/web/src/features/agents/schedules-tab.tsx
+++ b/packages/web/src/features/agents/schedules-tab.tsx
@@ -12,6 +12,9 @@
* below the table's min width.
* Readable by any member; toggle/edit/delete are owner-only — PUT has whole-file
* replace semantics, so toggling also resends every field and only flips `enabled`.
+ * A refused flip draws its reason under that row's status badge (`ToggleRefusal`, the same
+ * rule the shared row's switch uses); the other row actions report via toast or the dialog
+ * that asked for them.
*
* Prompt-injection controls (usePromptInjection): the schedules.enabled switch, the
* {{SCHEDULES}}-placeholder alert and the editable schedules.prompt section, mirroring the
@@ -33,7 +36,6 @@ import {
TableHead,
TableHeaderCell,
TableRow,
- toastError,
toastSuccess,
} from "@adelie/ui";
import type { BadgeStyle } from "@adelie/ui";
@@ -46,7 +48,10 @@ import { AiCreateModal } from "../ai-create";
import { AiCreateButtons } from "../ai-create/ai-create-buttons";
import { ScheduleFormModal } from "../schedules/schedule-form-modal";
import { ScheduleSuggestions, scheduleExamples } from "../schedules/schedule-suggestions";
+import { scheduleRefusalFor } from "../schedules/schedule-toggle";
+import type { ScheduleToggleRefusal } from "../schedules/schedule-toggle";
import { toggleBody } from "../schedules/schedule-upsert";
+import { toneInk } from "../../lib/tone";
import { usePromptInjection } from "./prompt-injection-controls";
/** Display status → badge. A finished one-off is settled: a neutral tag, solid so it still reads. */
@@ -59,6 +64,27 @@ const STATUS_BADGE: Record<ScheduleStatus, BadgeStyle> = {
invalid: { tone: "danger" },
};
+/**
+ * The sentence under a row's status badge for a flip of its 启用 / 停用 the server refused —
+ * `null` for every other row, and for a flip that has not been refused (the host picks the row
+ * with `scheduleRefusalFor`). A `nowrap` cell still wraps this one block (`whitespace-normal`),
+ * and `line-clamp-2` keeps a long server sentence from stretching the column; the whole text is
+ * on hover, the way the shared row's own line carries it.
+ */
+function ToggleRefusal({ refusal }: { refusal: string | null }) {
+ if (refusal === null) return null;
+ return (
+ <p
+ role="alert"
+ data-tooltip={S.common.refused(refusal)}
+ data-tooltip-content="text"
+ className={`mt-1 line-clamp-2 max-w-56 whitespace-normal break-words text-xs ${toneInk.danger}`}
+ >
+ {S.common.refused(refusal)}
+ </p>
+ );
+}
+
export function SchedulesTab({
agentId,
onConfigChanged,
@@ -80,7 +106,8 @@ export function SchedulesTab({
});
const [data, setData] = useState<SchedulesResponse | null>(null);
- // Tab-level error is only the initial list load failure; row/edit actions report via toast.
+ // Tab-level error is only the initial list load failure; a refused flip keeps its reason under
+ // that row, the other row actions report via toast.
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
// Form dialog: non-null means open (editing that row, or null for a new task).
@@ -92,6 +119,13 @@ export function SchedulesTab({
// The server's words for a delete it refused, drawn inside that same confirmation: the toast
// that used to carry them dismissed itself while the retry was still the next thing to do.
const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);
+ // The server's words for a flip of a row's 启用 / 停用 it refused. That button writes nothing
+ // optimistically (the row keeps the state the server has), so a refusal leaves no trace at all —
+ // and the reason was a toast, gone six seconds later, beside a button that had not moved. Same
+ // rule as the shared row's switch about which row may draw it (`scheduleRefusalFor`), since a
+ // task is named the same way here: this tab lists one Agent's tasks, but the row the sentence
+ // belongs to is still decided by the rule the other two surfaces use.
+ const [toggleRefusal, setToggleRefusal] = useState<ScheduleToggleRefusal | null>(null);
const load = useCallback(async () => {
if (!projectId || !agentId) return;
@@ -124,12 +158,14 @@ export function SchedulesTab({
const toggle = async (item: ScheduleItem) => {
if (!projectId) return;
setBusy(true);
+ // This flip's answer replaces the last one's: the line belongs to the attempt, not the row.
+ setToggleRefusal(null);
try {
await api.updateSchedule(projectId, agentId, item.name, toggleBody(item, !item.enabled));
toastSuccess(item.enabled ? S.schedule.toastDisabled : S.schedule.toastEnabled);
await load();
} catch (e) {
- toastError(apiErrorText(e));
+ setToggleRefusal({ agentId, name: item.name, text: apiErrorText(e) });
} finally {
setBusy(false);
}
@@ -216,6 +252,12 @@ export function SchedulesTab({
{S.schedule.statusNames[item.status] ?? item.status}
</Badge>
</span>
+ {/* Under the badge the button would have moved: the same alert shape (and the
+ same shared lead-in) the shared row, the dialogs and the other switches use
+ for a refused write. */}
+ <ToggleRefusal
+ refusal={scheduleRefusalFor(toggleRefusal, { agentId, name: item.name })}
+ />
</TableCell>
<TableCell nowrap className="text-xs text-gray-500 dark:text-gray-400">
{item.period !== undefined ? (