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): link automation history to the recorded chat
Xubin Ren5719ed6e1695
diff --git a/nanobot/webui/session_automations.py b/nanobot/webui/session_automations.pyindex dfe309690..1c4bcab16 100644--- a/nanobot/webui/session_automations.py+++ b/nanobot/webui/session_automations.py@@ -14,6 +14,7 @@ from nanobot.session.manager import (_metadata_title, # pyright: ignore[reportPrivateUsage])from nanobot.triggers.local_types import LocalTrigger+from nanobot.webui.session_identity import is_webui_session_keyAutomationJob = CronJob | LocalTrigger@@ -176,19 +177,21 @@ def _serialize_job(payload["created_at_ms"] = job.created_at_mspayload["updated_at_ms"] = job.updated_at_mspayload["payload"].update({"kind": job.payload.kind})+ run_history: list[dict[str, Any]] = []+ for record in job.state.run_history[-5:]:+ session_key = record.session_key or job.payload.session_key or ""+ run_history.append({+ "run_at_ms": record.run_at_ms,+ "status": record.status,+ "duration_ms": record.duration_ms,+ "error": record.error,+ "webui_session_key": session_key if is_webui_session_key(session_key) else None,+ })payload["state"].update({"last_run_at_ms": job.state.last_run_at_ms,"last_error": job.state.last_error,- "run_history": [- {- "run_at_ms": record.run_at_ms,- "status": record.status,- "duration_ms": record.duration_ms,- "error": record.error,- }- for record in job.state.run_history[-5:]- ],+ "run_history": run_history,})payload["origin"] = _origin_payload(job, session_manager)diff --git a/tests/webui/test_automation_chat_binding.py b/tests/webui/test_automation_chat_binding.pyindex 3d3c5d8c8..b1bf4f756 100644--- a/tests/webui/test_automation_chat_binding.py+++ b/tests/webui/test_automation_chat_binding.py@@ -24,6 +24,7 @@ from nanobot.session.manager import SessionManagerfrom nanobot.webui.automation_chats import automation_chatsfrom nanobot.webui.automation_results import cron_run_responsefrom nanobot.webui.gateway_services import build_gateway_services+from nanobot.webui.session_automations import serialize_automation_jobsfrom nanobot.webui.workspaces import WebUIWorkspaceController@@ -277,6 +278,13 @@ async def test_real_gateway_move_run_reload_and_previous_result(tmp_path):moved = CronService(cron.store_path).get_job(job.id)for run in moved.state.run_history:assert cron_run_response(cron.store_path.parent / "runs", moved, run) == "Synthetic result"+ history = serialize_automation_jobs([moved], include_details=True)[0]["state"]["run_history"]+ assert [run["webui_session_key"] for run in history] == ["websocket:source", None]+ cron.change_binding(job.id, revision=binding_revision(moved),+ binding=CronBinding("websocket:source", "websocket", "source", {}), message="Back")+ # Moving back must not turn the external run's link into the current chat.+ history = serialize_automation_jobs([cron.get_job(job.id)], include_details=True)[0]["state"]["run_history"]+ assert [run["webui_session_key"] for run in history] == ["websocket:source", None]finally:if client is not None:await client.close()diff --git a/webui/proposals/automation-chat/README.md b/webui/proposals/automation-chat/README.mdindex 0fa479eae..18e9037e8 100644--- a/webui/proposals/automation-chat/README.md+++ b/webui/proposals/automation-chat/README.md@@ -41,6 +41,8 @@ is pending, so the PR remains a draft.- Each run retains its session identity. Before the first supported move, olderrun records are stamped with the known unchanged original binding. Audit resultchecks still verify job, run, session, status, and file path.+ History links use that run's WebUI chat key, not the task's current chat.+ External runs expose no recipient key and have no WebUI chat link.No new execution path, agent-loop policy, dependencies, or separate CSS systemare added. The dialog uses the existing Select, Dialog, Button, Textarea, channeldiff --git a/webui/src/components/settings/system/AutomationRunDialog.tsx b/webui/src/components/settings/system/AutomationRunDialog.tsxindex 2fc019cdc..5fbe244e2 100644--- a/webui/src/components/settings/system/AutomationRunDialog.tsx+++ b/webui/src/components/settings/system/AutomationRunDialog.tsx@@ -56,8 +56,9 @@ export function AutomationRunDialog({ token = "", job, run, locale, open, onOpen: run.status === "skipped" ? t("settings.automations.skipped"): t("settings.automations.calendar.recorded");const duration = run.duration_ms;- const chatHref = job.origin?.channel === "websocket" && job.origin.session_key- ? `#/chat/${encodeURIComponent(job.origin.session_key)}` : null;+ const chatKey = run.webui_session_key !== undefined ? run.webui_session_key+ : job.origin?.channel === "websocket" ? job.origin.session_key : null;+ const chatHref = chatKey ? `#/chat/${encodeURIComponent(chatKey)}` : null;return (<Dialog open={open} onOpenChange={onOpenChange}>diff --git a/webui/src/lib/types.ts b/webui/src/lib/types.tsindex aa06a50b4..74f0e6d9a 100644--- a/webui/src/lib/types.ts+++ b/webui/src/lib/types.ts@@ -252,6 +252,7 @@ export interface SessionAutomationJob {status: "ok" | "error" | "skipped" | string;duration_ms?: number;error?: string | null;+ webui_session_key?: string | null; // null: external chat; absent: older host.}>;};origin?: {diff --git a/webui/src/tests/automations-settings.test.tsx b/webui/src/tests/automations-settings.test.tsxindex 4f0ea8563..841f0c558 100644--- a/webui/src/tests/automations-settings.test.tsx+++ b/webui/src/tests/automations-settings.test.tsx@@ -323,6 +323,22 @@ describe("Automation task list and detail sheet", () => {expect(within(screen.getByRole("dialog", { name: "PR watch" })).getByRole("button", { name: "Edit" })).toBeVisible();});+ it.each(["websocket:original-chat", null])("uses the recorded chat for a historical run (%s), not the task's current chat", async (webuiSessionKey) => {+ const user = userEvent.setup();+ render(<Harness payload={{ jobs: [{ ...task, state: { run_history: [{+ run_at_ms: now - 60_000, status: "ok", webui_session_key: webuiSessionKey,+ }] } }] }} />);+ await user.click(screen.getByRole("button", { name: /PR watch.*Completed/ }));+ const dialog = within(screen.getByRole("dialog", { name: "PR watch" }));+ if (webuiSessionKey) {+ expect(dialog.getByRole("link", { name: "Open a chat" })).toHaveAttribute(+ "href", "#/chat/websocket%3Aoriginal-chat",+ );+ } else {+ expect(dialog.queryByRole("link", { name: "Open a chat" })).not.toBeInTheDocument();+ }+ });+it("keeps the selected historical result across refreshes and restores focus when its day button disappears", async () => {const user = userEvent.setup();const start = new Date(new Date(now).setHours(8, 0, 0, 0)).getTime();