Skip to content

Commit bc66478

Browse files
committed
fix(ui): expose complete cloud failure diagnostics
1 parent 5328856 commit bc66478

14 files changed

Lines changed: 431 additions & 161 deletions

‎docs/web/control-ui.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ Capability toggles stay disabled until the Gateway, session, and runtime config
521521

522522
## Chat behavior
523523

524+
Chat error banners, including cloud runner failures, keep a compact preview. Open **Error details** to read and select the complete diagnostic received by the UI, then use **Copy error** to copy it. The disclosure works with Enter or Space; the expanded text wraps long lines and can be scrolled with the keyboard. Expanding or copying an error does not retry the failed operation.
525+
524526
<AccordionGroup>
525527
<Accordion title="Send and history semantics">
526528
- `chat.send` is **non-blocking**: it acks immediately with `{ runId, status: "started" }` and the response streams via `chat` events. Trusted Control UI clients may also receive optional ACK timing metadata for local diagnostics.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { afterEach, describe, expect, it, vi } from "vitest";
4+
import { COMMAND_PALETTE_TARGET_EVENT } from "../components/command-palette-contract.ts";
5+
import { resetAppHostTestGlobals } from "./app-host.test-support.ts";
6+
import "./app-host.ts";
7+
import type { ShellChromeHost } from "./app-shell-chrome.ts";
8+
import { NATIVE_HISTORY_STATE_EVENT } from "./native-web-chrome.ts";
9+
10+
type ShellLifecycle = {
11+
connectedCallback(): void;
12+
disconnectedCallback(): void;
13+
};
14+
15+
afterEach(resetAppHostTestGlobals);
16+
17+
describe("OpenClaw shell event lifecycle", () => {
18+
it("retires host, window, and document actions on disconnect and reconnects once", () => {
19+
const shell = document.createElement("openclaw-app-shell") as ShellChromeHost & ShellLifecycle;
20+
const navigate = vi.spyOn(shell, "navigate").mockImplementation(() => {});
21+
const onSlashCommand = vi.fn();
22+
const target = { owner: shell, onSlashCommand };
23+
const history = { canGoBack: true, canGoForward: false };
24+
const dispatchActions = () => {
25+
shell.dispatchEvent(new CustomEvent(COMMAND_PALETTE_TARGET_EVENT, { detail: target }));
26+
window.dispatchEvent(new CustomEvent(NATIVE_HISTORY_STATE_EVENT, { detail: history }));
27+
document.dispatchEvent(
28+
new KeyboardEvent("keydown", { code: "Comma", key: ",", ctrlKey: true, shiftKey: true }),
29+
);
30+
};
31+
32+
try {
33+
for (let connection = 1; connection <= 2; connection += 1) {
34+
shell.connectedCallback();
35+
dispatchActions();
36+
expect(shell.commandPaletteTarget).toBe(target);
37+
expect(shell.nativeHistoryState).toBe(history);
38+
expect(navigate).toHaveBeenCalledTimes(connection);
39+
expect(navigate).toHaveBeenLastCalledWith("appearance");
40+
41+
shell.disconnectedCallback();
42+
shell.commandPaletteTarget = undefined;
43+
shell.nativeHistoryState = { canGoBack: false, canGoForward: false };
44+
dispatchActions();
45+
expect(shell.commandPaletteTarget).toBeUndefined();
46+
expect(shell.nativeHistoryState.canGoBack).toBe(false);
47+
expect(navigate).toHaveBeenCalledTimes(connection);
48+
}
49+
} finally {
50+
shell.disconnectedCallback();
51+
navigate.mockRestore();
52+
}
53+
});
54+
});

‎ui/src/app/app-host.test.ts‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import type {
3030
ApplicationGateway,
3131
ApplicationGatewaySnapshot,
3232
} from "./context.ts";
33-
import "./app-host.ts";
3433
import type { LazyCustomElementRequestController } from "./lazy-custom-element.ts";
34+
import "./app-host.ts";
3535
import {
3636
persistLazyShellAction,
3737
readLazyShellAction,
@@ -742,21 +742,6 @@ describe("OpenClaw shell keyboard shortcuts", () => {
742742
).toBe(false);
743743
});
744744

745-
it("wires merged header window events for the shell lifecycle", () => {
746-
const addEventListener = vi.spyOn(window, "addEventListener");
747-
const shell = document.createElement("openclaw-app-shell") as unknown as ShellChromeEventState;
748-
749-
shell.connectedCallback();
750-
751-
expect(addEventListener).toHaveBeenCalledWith(COMMAND_PALETTE_OPEN_EVENT, expect.any(Function));
752-
expect(addEventListener).toHaveBeenCalledWith(
753-
SHELL_NAV_DRAWER_TOGGLE_EVENT,
754-
expect.any(Function),
755-
);
756-
shell.disconnectedCallback();
757-
addEventListener.mockRestore();
758-
});
759-
760745
it("prevents unhandled window file drops without overriding accepted targets", () => {
761746
const shell = document.createElement("openclaw-app-shell") as unknown as ShellChromeEventState;
762747
const acceptedDropTarget = document.createElement("div");

‎ui/src/app/app-shell-chrome.ts‎

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface ShellChromeHost extends HTMLElement {
121121

122122
export class ShellChromeOwner {
123123
private pendingLazyAction = readLazyShellAction();
124+
private listeners: AbortController | undefined;
124125

125126
constructor(private readonly host: ShellChromeHost) {}
126127

@@ -133,56 +134,62 @@ export class ShellChromeOwner {
133134
}
134135

135136
connect(): void {
137+
this.disconnect();
138+
this.listeners = new AbortController();
139+
// One connection owns all three targets; abort removes exactly its listeners.
140+
const options = { signal: this.listeners.signal };
136141
const host = this.host;
137142
host.nativeHistoryState = readNativeHistoryState();
138-
host.addEventListener(COMMAND_PALETTE_TARGET_EVENT, this.handleCommandPaletteTarget);
139-
window.addEventListener(COMMAND_PALETTE_OPEN_EVENT, this.handleCommandPaletteOpen);
140-
window.addEventListener(SHELL_NAV_DRAWER_TOGGLE_EVENT, this.handleShellNavDrawerToggle);
141-
window.addEventListener(DEBUG_OVERLAY_REQUEST_EVENT, this.handleDebugOverlayRequest);
142-
window.addEventListener(KEYBOARD_SHORTCUTS_REQUEST_EVENT, this.handleKeyboardShortcutsRequest);
143-
document.addEventListener("keydown", this.handleDocumentKeydown);
144-
window.addEventListener("resize", this.handleWindowResize);
145-
window.addEventListener("dragover", this.handleUnhandledFileDrag);
146-
window.addEventListener("drop", this.handleUnhandledFileDrag);
147-
window.addEventListener(NATIVE_HISTORY_STATE_EVENT, this.handleNativeHistoryState);
143+
host.addEventListener(COMMAND_PALETTE_TARGET_EVENT, this.handleCommandPaletteTarget, options);
144+
window.addEventListener(COMMAND_PALETTE_OPEN_EVENT, this.handleCommandPaletteOpen, options);
145+
window.addEventListener(
146+
SHELL_NAV_DRAWER_TOGGLE_EVENT,
147+
this.handleShellNavDrawerToggle,
148+
options,
149+
);
150+
window.addEventListener(DEBUG_OVERLAY_REQUEST_EVENT, this.handleDebugOverlayRequest, options);
151+
window.addEventListener(
152+
KEYBOARD_SHORTCUTS_REQUEST_EVENT,
153+
this.handleKeyboardShortcutsRequest,
154+
options,
155+
);
156+
document.addEventListener("keydown", this.handleDocumentKeydown, options);
157+
window.addEventListener("resize", this.handleWindowResize, options);
158+
window.addEventListener("dragover", this.handleUnhandledFileDrag, options);
159+
window.addEventListener("drop", this.handleUnhandledFileDrag, options);
160+
window.addEventListener(NATIVE_HISTORY_STATE_EVENT, this.handleNativeHistoryState, options);
148161
// Shipped Mac hosts use these same events even when native web chrome is absent.
149-
window.addEventListener("openclaw:native-toggle-sidebar", this.handleNativeToggleSidebar);
150-
window.addEventListener("openclaw:native-open-search", this.handleNativeOpenSearch);
151-
window.addEventListener("openclaw:native-toggle-search", this.handleNativeToggleSearch);
152-
window.addEventListener("openclaw:native-new-session", this.handleNativeNewSession);
153-
window.addEventListener("openclaw:native-navigate", this.handleNativeNavigate);
154-
window.addEventListener(TERMINAL_PANEL_TOGGLE_EVENT, this.handleDeferredTerminalToggle);
155-
window.addEventListener(BROWSER_PANEL_TOGGLE_EVENT, this.handleDeferredBrowserToggle);
156-
window.addEventListener(DESKTOP_PANEL_TOGGLE_EVENT, this.handleDeferredDesktopToggle);
157-
window.addEventListener(CUSTODIAN_PANEL_TOGGLE_EVENT, this.handleDeferredCustodianToggle);
158-
window.addEventListener(SHELL_APPROVALS_OPEN_EVENT, this.handleApprovalsOpen);
162+
window.addEventListener(
163+
"openclaw:native-toggle-sidebar",
164+
this.handleNativeToggleSidebar,
165+
options,
166+
);
167+
window.addEventListener("openclaw:native-open-search", this.handleNativeOpenSearch, options);
168+
window.addEventListener(
169+
"openclaw:native-toggle-search",
170+
this.handleNativeToggleSearch,
171+
options,
172+
);
173+
window.addEventListener("openclaw:native-new-session", this.handleNativeNewSession, options);
174+
window.addEventListener("openclaw:native-navigate", this.handleNativeNavigate, options);
175+
window.addEventListener(
176+
TERMINAL_PANEL_TOGGLE_EVENT,
177+
this.handleDeferredTerminalToggle,
178+
options,
179+
);
180+
window.addEventListener(BROWSER_PANEL_TOGGLE_EVENT, this.handleDeferredBrowserToggle, options);
181+
window.addEventListener(DESKTOP_PANEL_TOGGLE_EVENT, this.handleDeferredDesktopToggle, options);
182+
window.addEventListener(
183+
CUSTODIAN_PANEL_TOGGLE_EVENT,
184+
this.handleDeferredCustodianToggle,
185+
options,
186+
);
187+
window.addEventListener(SHELL_APPROVALS_OPEN_EVENT, this.handleApprovalsOpen, options);
159188
}
160189

161190
disconnect(): void {
162-
const host = this.host;
163-
host.removeEventListener(COMMAND_PALETTE_TARGET_EVENT, this.handleCommandPaletteTarget);
164-
window.removeEventListener(COMMAND_PALETTE_OPEN_EVENT, this.handleCommandPaletteOpen);
165-
window.removeEventListener(SHELL_NAV_DRAWER_TOGGLE_EVENT, this.handleShellNavDrawerToggle);
166-
window.removeEventListener(DEBUG_OVERLAY_REQUEST_EVENT, this.handleDebugOverlayRequest);
167-
window.removeEventListener(
168-
KEYBOARD_SHORTCUTS_REQUEST_EVENT,
169-
this.handleKeyboardShortcutsRequest,
170-
);
171-
document.removeEventListener("keydown", this.handleDocumentKeydown);
172-
window.removeEventListener("resize", this.handleWindowResize);
173-
window.removeEventListener("dragover", this.handleUnhandledFileDrag);
174-
window.removeEventListener("drop", this.handleUnhandledFileDrag);
175-
window.removeEventListener(NATIVE_HISTORY_STATE_EVENT, this.handleNativeHistoryState);
176-
window.removeEventListener("openclaw:native-toggle-sidebar", this.handleNativeToggleSidebar);
177-
window.removeEventListener("openclaw:native-open-search", this.handleNativeOpenSearch);
178-
window.removeEventListener("openclaw:native-toggle-search", this.handleNativeToggleSearch);
179-
window.removeEventListener("openclaw:native-new-session", this.handleNativeNewSession);
180-
window.removeEventListener("openclaw:native-navigate", this.handleNativeNavigate);
181-
window.removeEventListener(TERMINAL_PANEL_TOGGLE_EVENT, this.handleDeferredTerminalToggle);
182-
window.removeEventListener(BROWSER_PANEL_TOGGLE_EVENT, this.handleDeferredBrowserToggle);
183-
window.removeEventListener(DESKTOP_PANEL_TOGGLE_EVENT, this.handleDeferredDesktopToggle);
184-
window.removeEventListener(CUSTODIAN_PANEL_TOGGLE_EVENT, this.handleDeferredCustodianToggle);
185-
window.removeEventListener(SHELL_APPROVALS_OPEN_EVENT, this.handleApprovalsOpen);
191+
this.listeners?.abort();
192+
this.listeners = undefined;
186193
}
187194

188195
toggleNavigationSurface(trigger?: HTMLElement): void {

‎ui/src/e2e/chat-flow.queue-edit.e2e.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ suite.define(() => {
262262

263263
await page
264264
.getByRole("alert")
265+
.locator("summary")
265266
.getByText("Could not store this message for reconnect.", { exact: false })
266267
.waitFor({ timeout: 10_000 });
267268
await row.waitFor();

‎ui/src/e2e/chat-flow.streaming.e2e.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ suite.define(() => {
374374
await page.screenshot({ path: path.join(artifactDir, `terminal-partial-${label}.png`) });
375375
}
376376
const alert = page.locator(".chat-error");
377-
await alert.getByText(errorText).waitFor({ timeout: 10_000 });
378-
expect(await alert.locator("button").count()).toBe(0);
377+
await alert.locator("summary").getByText(errorText).waitFor({ timeout: 10_000 });
378+
expect(await alert.getByRole("button", { name: "Dismiss error" }).count()).toBe(0);
379+
expect(await alert.getByRole("button", { name: "Retry", exact: true }).count()).toBe(0);
379380
expect(await page.locator(".chat-thread-inner").getByText(errorText).count()).toBe(0);
380381
const [alertBox, composerBox] = await Promise.all([
381382
alert.boundingBox(),

‎ui/src/e2e/chat-header-session-outcomes.e2e.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ suite.define(() => {
213213
),
214214
)
215215
.toBe(sessionA);
216-
await visiblePane.getByText(message, { exact: true }).waitFor();
216+
await visiblePane
217+
.getByRole("alert")
218+
.locator("summary")
219+
.getByText(message, { exact: true })
220+
.waitFor();
217221

218222
await page.getByRole("button", { name: "Runs on Cloud" }).click();
219223
await page.getByText("Stop cloud worker…", { exact: true }).waitFor();

0 commit comments

Comments
 (0)