Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): remove subtask polling and load error UI (#6212)
chengyongrua48228109218
diff --git a/webui/src/components/thread/SubagentTasks.tsx b/webui/src/components/thread/SubagentTasks.tsxindex 72dbf43e6..24477b5e5 100644--- a/webui/src/components/thread/SubagentTasks.tsx+++ b/webui/src/components/thread/SubagentTasks.tsx@@ -32,7 +32,6 @@ function isActive(task: SubagentTaskSnapshot): boolean {interface TaskContext {tasks: ObservedSubagentTask[];- loadError: string | null;stopError: string | null;stoppingId: string | null;open: (task: SubagentTaskSnapshot, trigger: HTMLButtonElement) => void;@@ -59,7 +58,6 @@ export function SubagentTasksProvider({ client, sessionKey, token, enabled, liveconst [tasks, setTasks] = useState<ObservedSubagentTask[]>([]);const [selectedId, setSelectedId] = useState<string | null>(null);const [stoppingId, setStoppingId] = useState<string | null>(null);- const [loadError, setLoadError] = useState<string | null>(null);const [stopError, setStopError] = useState<string | null>(null);const scopeGeneration = useRef(0);const mounted = useRef(true);@@ -72,7 +70,6 @@ export function SubagentTasksProvider({ client, sessionKey, token, enabled, livesetTasks([]);setSelectedId(null);setStoppingId(null);- setLoadError(null);setStopError(null);return () => { scopeGeneration.current += 1; };}, [client, sessionKey]);@@ -98,10 +95,9 @@ export function SubagentTasksProvider({ client, sessionKey, token, enabled, liveconst payload = await fetchSubagentTasks(token, sessionKey);if (!cancelled) {setTasks((current) => mergeSubagentTasks(current, payload.tasks));- setLoadError(null);}} catch {- if (!cancelled) setLoadError(t("thread.subagents.loadFailed"));+ // Background read failures retain the last task snapshot.} finally {refreshing = false;if (refreshPending && !cancelled) {@@ -112,28 +108,22 @@ export function SubagentTasksProvider({ client, sessionKey, token, enabled, live};const unsubscribeChat = liveEvents ? client.onChat(sessionKey.slice("websocket:".length), (event) => {if (cancelled || event.event !== "subagent_task") return;- if (!isSubagentTask(event.task)) {- setLoadError(t("thread.subagents.loadFailed"));- return;- }+ if (!isSubagentTask(event.task)) return;setTasks((current) => mergeSubagentTasks(current, [event.task]));}) : undefined;const unsubscribeStatus = liveEvents ? client.onStatus((status) => {if (status === "open") void refresh();}) : undefined;if (!refreshing) void refresh();- // Protocol 1 hosts may support task reads without the optional event stream.- const timer = liveEvents ? undefined : window.setInterval(() => void refresh(), 3000);const focus = () => void refresh();window.addEventListener("focus", focus);return () => {cancelled = true;- window.clearInterval(timer);unsubscribeChat?.();unsubscribeStatus?.();window.removeEventListener("focus", focus);};- }, [client, enabled, liveEvents, active, sessionKey, token, pageVisible, paneVisible, t]);+ }, [client, enabled, liveEvents, active, sessionKey, token, pageVisible, paneVisible]);const stop = async (task: SubagentTaskSnapshot) => {if (!sessionKey) return;@@ -152,7 +142,7 @@ export function SubagentTasksProvider({ client, sessionKey, token, enabled, live};const selected = enabled && active && paneVisible ? tasks.find((task) => task.task_id === selectedId) : undefined;const value: TaskContext = {- tasks: enabled ? tasks : [], loadError: enabled ? loadError : null,+ tasks: enabled ? tasks : [],stopError: enabled ? stopError : null, stoppingId,open: (task, target) => { trigger.current = target; setSelectedId(task.task_id); }, stop,register: (id, button, previous) => {@@ -261,7 +251,7 @@ function TaskButton({ task }: { task: ObservedSubagentTask }) {export function useHasSubagentContent(): boolean {const context = useContext(TasksContext);- return !!context && (context.tasks.length > 0 || !!context.loadError || !!context.stopError);+ return !!context && (context.tasks.length > 0 || !!context.stopError);}/** Prefer an exact prompt, then its turn's first prompt when replay changed message IDs. */@@ -287,7 +277,7 @@ export function SubagentThreadMessages(props: ComponentProps<typeof ThreadMessagreturn <ThreadMessages {...props}beforeMessages={<SubagentWork tasks={groups.unlinked} unlinked />}afterUserMessage={(message) => <SubagentWork tasks={groups.byMessage.get(message.id) ?? []} />}- afterMessages={<SubagentTaskErrors />} />;+ afterMessages={<SubagentStopError />} />;}function SubagentWork({ tasks, unlinked = false }: { tasks: ObservedSubagentTask[]; unlinked?: boolean }) {@@ -333,11 +323,10 @@ function SubagentWork({ tasks, unlinked = false }: { tasks: ObservedSubagentTask</section>;}-function SubagentTaskErrors() {+function SubagentStopError() {const context = useContext(TasksContext);- if (!context?.loadError && !context?.stopError) return null;+ if (!context?.stopError) return null;return <div className="thread-message-row mt-2 space-y-1 text-xs text-destructive">- {context.loadError ? <p role="alert">{context.loadError}</p> : null}- {context.stopError ? <p role="alert">{context.stopError}</p> : null}+ <p role="alert">{context.stopError}</p></div>;}diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.jsonindex 225d2a9d8..c1f7e68a8 100644--- a/webui/src/i18n/locales/en/common.json+++ b/webui/src/i18n/locales/en/common.json@@ -1819,7 +1819,6 @@},"thread": {"subagents": {- "loadFailed": "Could not load subtasks.","stopFailed": "Could not stop this task.","stopTask": "Stop {{label}}","receiptHelp": "Delivered means the message was included in the subtask’s next model request. It does not mean the instructions have been carried out.",diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.jsonindex bea7868ea..baf2b0171 100644--- a/webui/src/i18n/locales/es/common.json+++ b/webui/src/i18n/locales/es/common.json@@ -1620,7 +1620,6 @@},"thread": {"subagents": {- "loadFailed": "No se pudieron cargar las subtareas.","stopFailed": "No se pudo detener esta tarea.","stopTask": "Detener {{label}}","receiptHelp": "Entregado significa que el mensaje se incluyó en la siguiente solicitud del subagente, sin confirmar su ejecución.",diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.jsonindex 2ba6a4434..042865c44 100644--- a/webui/src/i18n/locales/fr/common.json+++ b/webui/src/i18n/locales/fr/common.json@@ -1619,7 +1619,6 @@},"thread": {"subagents": {- "loadFailed": "Impossible de charger les sous-tâches.","stopFailed": "Impossible d’arrêter cette tâche.","stopTask": "Arrêter {{label}}","receiptHelp": "Livré signifie que le message a été inclus dans la prochaine requête du sous-agent, sans confirmer son exécution.",diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.jsonindex 10bd82b96..09d81d1d5 100644--- a/webui/src/i18n/locales/id/common.json+++ b/webui/src/i18n/locales/id/common.json@@ -1619,7 +1619,6 @@},"thread": {"subagents": {- "loadFailed": "Tidak dapat memuat subtugas.","stopFailed": "Tidak dapat menghentikan tugas ini.","stopTask": "Hentikan {{label}}","receiptHelp": "Terkirim berarti pesan disertakan dalam permintaan model berikutnya dari subagen, bukan konfirmasi bahwa pekerjaan selesai.",diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.jsonindex d6ac72a97..59256a09d 100644--- a/webui/src/i18n/locales/ja/common.json+++ b/webui/src/i18n/locales/ja/common.json@@ -1619,7 +1619,6 @@},"thread": {"subagents": {- "loadFailed": "サブタスクを読み込めませんでした。","stopFailed": "このタスクを停止できませんでした。","stopTask": "{{label}} を停止","receiptHelp": "配信済みは子タスクの次のモデルリクエストにメッセージが含まれたことを示し、実行完了を意味しません。",diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.jsonindex 4e49a4eb5..afc5c4049 100644--- a/webui/src/i18n/locales/ko/common.json+++ b/webui/src/i18n/locales/ko/common.json@@ -1619,7 +1619,6 @@},"thread": {"subagents": {- "loadFailed": "하위 작업을 불러올 수 없습니다.","stopFailed": "이 작업을 중지할 수 없습니다.","stopTask": "{{label}} 중지","receiptHelp": "전달됨은 메시지가 하위 작업의 다음 모델 요청에 포함되었음을 뜻하며, 실행 완료를 의미하지 않습니다.",diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.jsonindex 2692c1f37..b7d234ff3 100644--- a/webui/src/i18n/locales/pt-BR/common.json+++ b/webui/src/i18n/locales/pt-BR/common.json@@ -1633,7 +1633,6 @@},"thread": {"subagents": {- "loadFailed": "Não foi possível carregar as subtarefas.","stopFailed": "Não foi possível interromper esta tarefa.","stopTask": "Interromper {{label}}","receiptHelp": "Entregue significa que a mensagem foi incluída na próxima solicitação do subagente, sem confirmar sua execução.",diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.jsonindex cd1a80a7e..928788d66 100644--- a/webui/src/i18n/locales/vi/common.json+++ b/webui/src/i18n/locales/vi/common.json@@ -1619,7 +1619,6 @@},"thread": {"subagents": {- "loadFailed": "Không thể tải tác vụ con.","stopFailed": "Không thể dừng tác vụ này.","stopTask": "Dừng {{label}}","receiptHelp": "Đã chuyển nghĩa là tin nhắn đã được đưa vào yêu cầu mô hình tiếp theo của tác nhân con, không xác nhận công việc đã hoàn tất.",diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.jsonindex afb7479d5..6ccceb41c 100644--- a/webui/src/i18n/locales/zh-CN/common.json+++ b/webui/src/i18n/locales/zh-CN/common.json@@ -1819,7 +1819,6 @@},"thread": {"subagents": {- "loadFailed": "无法加载子任务。","stopFailed": "无法停止此任务。","stopTask": "停止 {{label}}","receiptHelp": "已送达表示消息已进入子任务的下一次模型请求,不代表已执行完成。",diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.jsonindex df1b6d9c7..a776cf1a3 100644--- a/webui/src/i18n/locales/zh-TW/common.json+++ b/webui/src/i18n/locales/zh-TW/common.json@@ -1619,7 +1619,6 @@},"thread": {"subagents": {- "loadFailed": "無法載入子任務。","stopFailed": "無法停止此任務。","stopTask": "停止 {{label}}","receiptHelp": "已送達表示訊息已進入子任務的下一次模型請求,不代表已執行完成。",diff --git a/webui/src/tests/subagent-tasks.test.tsx b/webui/src/tests/subagent-tasks.test.tsxindex 6ccac4525..8a49ed6b9 100644--- a/webui/src/tests/subagent-tasks.test.tsx+++ b/webui/src/tests/subagent-tasks.test.tsx@@ -272,7 +272,7 @@ describe("session-owned task UI", () => {expect(statusHandlers.size).toBe(0);});- it("keeps load failures visible and keeps stop failures across a successful refresh", async () => {+ it("preserves loaded tasks and stop errors across background snapshot failures", async () => {const user = userEvent.setup();requestMutation.mockRejectedValue(new Error("Cannot stop task"));render(layout());@@ -282,23 +282,26 @@ describe("session-owned task UI", () => {await waitFor(() => expect(fetch).toHaveBeenCalledTimes(2));expect(screen.getByText("Cannot stop task")).toBeVisible();vi.mocked(fetch).mockRejectedValue(new Error("offline"));- fireEvent(window, new Event("focus"));- await screen.findByText("Could not load subtasks.");+ await act(async () => { fireEvent(window, new Event("focus")); });expect(screen.getByRole("button", { name: /Config check Running/ })).toBeVisible();+ expect(screen.getByText("Cannot stop task")).toBeVisible();});- it("shows a read error for malformed or duplicate task records", async () => {+ it("retains the last valid snapshot after malformed reads and recovers on refresh", async () => {+ render(layout());+ await screen.findByRole("button", { name: /Config check Running/ });vi.mocked(fetch).mockImplementation(async () => new Response(JSON.stringify({tasks: [{ ...task(), label: { unexpected: true } }],}), { headers: { "content-type": "application/json" } }));- render(layout());- await screen.findByText("Could not load subtasks.");- expect(screen.queryByText("Config check")).not.toBeInTheDocument();+ await act(async () => { fireEvent(window, new Event("focus")); });+ expect(screen.getByRole("button", { name: /Config check Running/ })).toBeVisible();+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();vi.mocked(fetch).mockImplementation(async () => response([task(), task()]));- fireEvent(window, new Event("focus"));- await waitFor(() => expect(fetch).toHaveBeenCalledTimes(2));- expect(screen.getByText("Could not load subtasks.")).toBeVisible();- expect(screen.queryByText("Config check")).not.toBeInTheDocument();+ await act(async () => { fireEvent(window, new Event("focus")); });+ expect(screen.getByRole("button", { name: /Config check Running/ })).toBeVisible();+ vi.mocked(fetch).mockResolvedValue(response([task({ revision: 2, state: "done", completed_at: 102 })]));+ await act(async () => { fireEvent(window, new Event("focus")); });+ expect(screen.getByRole("button", { name: /Subtasks Finished: 1/ })).toBeVisible();});it("discards reads from the previous session after switching", async () => {@@ -464,17 +467,21 @@ describe("session-owned task UI", () => {expect(screen.getByRole("button", { name: /Config check Cancelled/ })).toBeVisible();expect(fetch).toHaveBeenCalledTimes(3);emitTask({ ...task(), revision: -1 });- expect(screen.getByText("Could not load subtasks.")).toBeVisible();+ expect(screen.getByRole("button", { name: /Config check Cancelled/ })).toBeVisible();+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();});- it("keeps protocol 1 task controls usable on a host without event support", async () => {+ it("reads snapshots without polling on a host without task events", async () => {vi.mocked(fetch).mockImplementation(async () => response([task({ revision: undefined })]));vi.useFakeTimers();const view = render(layout({ liveEvents: false }));await act(async () => { await Promise.resolve(); });expect(screen.getByRole("button", { name: /Config check Running/ })).toBeVisible();vi.mocked(fetch).mockImplementation(async () => response([task({ revision: undefined, state: "done", completed_at: 102 })]));- await act(async () => { await vi.advanceTimersByTimeAsync(3000); });+ await act(async () => { await vi.advanceTimersByTimeAsync(9000); });+ expect(fetch).toHaveBeenCalledTimes(1);+ expect(screen.getByRole("button", { name: /Config check Running/ })).toBeVisible();+ await act(async () => { fireEvent(window, new Event("focus")); });expect(screen.getByRole("button", { name: /Subtasks Finished: 1/ })).toBeVisible();expect(client.onChat).not.toHaveBeenCalled();view.rerender(layout({ liveEvents: false, visible: false }));