Skip to content

Commit 32ddbb3

Browse files
authored
fix(ui): chat send failures were invisible when the session pane was hidden (#124473)
* fix(ui): always surface terminal chat send failures Terminal chat send failures were recorded only on the queue item when the owning pane was not visible (reconnect, alias drift, split-pane routing), so the operator saw nothing at all — an action ending in silence. Root cause: every error surface in the send/drain path was gated on visibleSessionMatches(...), and the FIFO outbox drain treated every chat.history reconcile rejection as a silent retryable "blocked", so a non-retryable rejection (e.g. auth loss) wedged the head — and everything behind it — permanently with no visible outcome. Fix, at the owner: - New surfaceChatDeliveryFailure() in steer-lifecycle.ts (the shared error-text owner): visible pane keeps the inline chat error; otherwise the failure routes through the existing global toast host, naming the session. All terminal failure sites in chat-send-delivery, chat-outbox-drain, chat-send-queue-state, and steer-lifecycle now use it. - reconcileStoredChatOutboxHead: a non-retryable GatewayRequestError on the head now terminally fails a never-attempted head (unblocking the lane) or parks an attempted head as unconfirmed — both with a visible outcome — instead of blocking the lane forever. - Composer disabled-reason: the reason now also renders while a draft hides the placeholder, and the cloud-startup-pending gate gets a reason instead of a silently disabled composer. Regression tests: hidden-pane terminal failure surfaces via toast; wedged head fails visibly and the lane drains the next message; attempted head parks unconfirmed; disabled reason visible with draft text present. * fix(ci): raise startup JS baseline for global failure surfacing and pin workspace-sync test clock The chat send path now imports session-display naming for the global failure toast, adding ~1 KiB gzip to startup JS (335452 B on CI's Linux builder, still well under the 358400 B committed cap). workspace-sync "never commands" asserted the exact dispatch timeoutMs (777) but the impl derives it from a Date.now() deadline, so any elapsed ms between admission and dispatch failed the exact-equality assertion on a loaded runner. Pin the clock like the sibling timeout tests do. * fix(ui): surface route-switched command failures and agent-scope global toast naming ClawSweeper review findings on #124473: - A queued local command failing after the operator navigated away hit failCommand(error) with expose=false; the dispatcher's stale-scope guard had already withheld the inline error, so a successful state write recorded the failure invisibly — the silent class this PR removes. Expose it globally when the scope is stale and the owning pane is hidden; a stale scope with the pane still visible keeps the failed queue chip (the new connection owns the inline surface). - Global session rows are agent-scoped behind one shared "global" key, so the toast row lookup could borrow another agent's label. Match the row's agentId to the failed outbox's agent for global keys. Both regression tests fail pre-fix (stash-verified).
1 parent b097aaa commit 32ddbb3

10 files changed

Lines changed: 404 additions & 57 deletions
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"startupJsGzipBytes": 334391,
3-
"reason": "cumulative 2026-08-15 UI growth plus folder group defaults catalog and lazy New Session route resolution",
4-
"updatedAt": "2026-08-15"
2+
"startupJsGzipBytes": 335452,
3+
"reason": "chat delivery failures surface globally: toast + session-display naming joins startup chat path",
4+
"updatedAt": "2026-08-16"
55
}

‎src/gateway/worker-environments/workspace-sync.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ function createWorkspaceActions(
5757

5858
describe("worker workspace command transport retry", () => {
5959
it("runs never commands once without changing the selected port", async () => {
60+
// Pin the clock: the impl derives the dispatch timeout from a Date.now()
61+
// deadline, so real elapsed ms between admission and dispatch would turn
62+
// the exact 777 assertion below into a loaded-runner flake.
63+
vi.spyOn(Date, "now").mockReturnValue(1_000);
6064
const run = vi.fn(async (argv: string[], _options: CommandOptions) =>
6165
argv.at(-1)?.includes("never-command") ? result(255) : result(),
6266
);

‎ui/src/lib/toast.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class OpenClawToastHost extends OpenClawLightDomContentsElement {
113113
}
114114

115115
export function showToast(options: ToastOptions): boolean {
116+
if (typeof document === "undefined") {
117+
return false;
118+
}
116119
const host = document.querySelector<OpenClawToastHost>("openclaw-toast-host");
117120
if (!host) {
118121
queuedToast = options;
@@ -136,7 +139,8 @@ export function showToast(options: ToastOptions): boolean {
136139
return true;
137140
}
138141

139-
if (!customElements.get("openclaw-toast-host")) {
142+
// Guarded so DOM-free (node) consumers of send-failure surfacing can load this module.
143+
if (typeof customElements !== "undefined" && !customElements.get("openclaw-toast-host")) {
140144
customElements.define("openclaw-toast-host", OpenClawToastHost);
141145
}
142146

‎ui/src/pages/chat/chat-composer.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ describe("renderChatComposer controls", () => {
234234
expect(container.querySelector<HTMLTextAreaElement>("textarea")?.disabled).toBe(true);
235235
});
236236

237+
it("shows the disabled reason even when draft text hides the placeholder", () => {
238+
const reason = "This session is read-only.";
239+
const { container } = renderComposer({
240+
canSend: false,
241+
disabledReason: reason,
242+
draft: "a draft that hides the placeholder",
243+
});
244+
245+
// The placeholder carries the reason only for an empty composer; the
246+
// dedicated reason row must keep the explanation visible alongside a draft.
247+
expect(container.querySelector(".agent-chat__disabled-reason")?.textContent).toContain(reason);
248+
expect(container.querySelector<HTMLTextAreaElement>("textarea")?.disabled).toBe(true);
249+
});
250+
237251
it("switches the primary action between voice, send, queue, and stop", () => {
238252
const onToggleRealtimeTalk = vi.fn();
239253
let view = renderComposer({ onToggleRealtimeTalk });

‎ui/src/pages/chat/chat-outbox-drain.ts‎

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import {
3030
type StoredChatOutbox,
3131
type StoredChatOutboxScope,
3232
} from "./composer-persistence.ts";
33+
import { formatConnectError } from "./connect-error.ts";
3334
import { isQueuedMessageBeingEdited } from "./queued-message-edit.ts";
3435
import { isChatBusy } from "./run-lifecycle.ts";
3536
import {
3637
chatMessagesContainQueuedSend,
3738
OFFLINE_QUEUE_STORAGE_ERROR,
3839
preserveQueuedUserTurn,
40+
surfaceChatDeliveryFailure,
3941
} from "./steer-lifecycle.ts";
4042

4143
export type QueuedChatSendResult = "sent" | "pending" | "failed";
@@ -179,16 +181,43 @@ async function readCurrentStoredChatHistory(
179181
limit: 1000,
180182
});
181183
} catch (err) {
184+
const connectionCurrent =
185+
host.client === client && host.connectionEpoch === connectionEpoch && host.connected;
182186
const retryDelayMs = retryableGatewayDelayMs(err);
183-
if (
184-
retryDelayMs !== null &&
185-
host.client === client &&
186-
host.connectionEpoch === connectionEpoch &&
187-
host.connected
188-
) {
189-
scheduleStoredChatOutboxRetry(host, outbox, retryDelayMs, dependencies);
187+
if (retryDelayMs !== null) {
188+
if (connectionCurrent) {
189+
scheduleStoredChatOutboxRetry(host, outbox, retryDelayMs, dependencies);
190+
}
191+
return "blocked";
190192
}
191-
return "blocked";
193+
// An authoritative non-retryable rejection (auth loss, revoked scope) will
194+
// repeat on every drain wakeup; leaving the head silently "blocked" wedges
195+
// the whole FIFO lane forever. Fail or park it visibly so the operator sees
196+
// the outcome and the lane can move past a never-attempted head.
197+
if (!connectionCurrent || !(err instanceof GatewayRequestError)) {
198+
return "blocked";
199+
}
200+
const attempted =
201+
(item.sendAttempts ?? 0) > 0 ||
202+
item.sendRequestStartedAtMs !== undefined ||
203+
item.sendState === "unconfirmed";
204+
const error = attempted ? UNCONFIRMED_CHAT_SEND_ERROR : formatConnectError(err);
205+
const targetState = attempted ? ("unconfirmed" as const) : ("failed" as const);
206+
if (item.sendState === targetState && item.sendError === error) {
207+
return "blocked";
208+
}
209+
const parked = updateQueuedMessageForSession(host, outbox.sessionKey, item.id, (entry) => ({
210+
...entry,
211+
sendError: error,
212+
sendState: targetState,
213+
}));
214+
surfaceChatDeliveryFailure(
215+
host,
216+
outbox.sessionKey,
217+
outbox.agentId,
218+
parked ? error : OFFLINE_QUEUE_STORAGE_ERROR,
219+
);
220+
return parked && !attempted ? "continue" : "blocked";
192221
}
193222
const currentOutbox = readStoredChatOutbox(host, outbox);
194223
const currentItem = currentOutbox?.queue.find((entry) => entry.id === item.id);
@@ -272,8 +301,13 @@ async function reconcileStoredChatOutboxHead(
272301
sendError: UNCONFIRMED_CHAT_SEND_ERROR,
273302
sendState: "unconfirmed",
274303
}));
275-
if (parked && visibleSessionMatches(host, outbox.sessionKey, outbox.agentId)) {
276-
dependencies.setChatError(host, UNCONFIRMED_CHAT_SEND_ERROR);
304+
if (parked) {
305+
surfaceChatDeliveryFailure(
306+
host,
307+
outbox.sessionKey,
308+
outbox.agentId,
309+
UNCONFIRMED_CHAT_SEND_ERROR,
310+
);
277311
}
278312
return "blocked";
279313
}
@@ -411,12 +445,13 @@ async function drainStoredChatOutbox(
411445
visibleSessionMatches(host, outbox.sessionKey, outbox.agentId);
412446
const failCommand = (error: string, expose = false): "blocked" => {
413447
const updated = setCommandState("failed", error);
414-
if (commandScopeIsCurrent()) {
415-
if (!updated) {
416-
dependencies.setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
417-
} else if (expose) {
418-
dependencies.setChatError(host, error);
419-
}
448+
if (!updated || expose) {
449+
surfaceChatDeliveryFailure(
450+
host,
451+
outbox.sessionKey,
452+
outbox.agentId,
453+
updated ? error : OFFLINE_QUEUE_STORAGE_ERROR,
454+
);
420455
}
421456
return "blocked";
422457
};
@@ -435,11 +470,17 @@ async function drainStoredChatOutbox(
435470
return "blocked";
436471
}
437472
if (dispatchResult === "failed") {
473+
// A still-current scope already saw the dispatcher's inline error.
474+
// After a route switch the dispatcher withholds it and the pane is
475+
// gone, so the terminal failure must surface globally. A stale scope
476+
// with the pane still visible (connection replaced) keeps the failed
477+
// queue chip instead: the new connection owns the inline surface.
438478
const commandStillCurrent = commandScopeIsCurrent();
439479
const error =
440480
(commandStillCurrent ? host.lastError : null) ??
441481
`Command /${item.localCommandName} failed.`;
442-
return failCommand(error);
482+
const paneHidden = !visibleSessionMatches(host, outbox.sessionKey, outbox.agentId);
483+
return failCommand(error, !commandStillCurrent && paneHidden);
443484
}
444485
if (dispatchResult === "uncertain") {
445486
const currentOutbox = readStoredChatOutbox(host, outbox);
@@ -466,9 +507,12 @@ async function drainStoredChatOutbox(
466507
}
467508
}
468509
if (!removeQueuedMessageWithoutReleasing(host, item.id, outbox.sessionKey)) {
469-
if (commandScopeIsCurrent()) {
470-
dependencies.setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
471-
}
510+
surfaceChatDeliveryFailure(
511+
host,
512+
outbox.sessionKey,
513+
outbox.agentId,
514+
OFFLINE_QUEUE_STORAGE_ERROR,
515+
);
472516
return "blocked";
473517
}
474518
if (dispatchResult === "uncertain") {

‎ui/src/pages/chat/chat-pane-render.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,15 @@ export class ChatPane extends ChatPaneBrowserAnnotationRender {
207207
selectedSession.sharingRole === "viewer" &&
208208
isGatewayMethodAdvertised(gatewaySnapshot, "session.suggestions.add") === true &&
209209
isGatewayMethodAdvertised(gatewaySnapshot, "session.suggestions.list") === true;
210+
// Every composer-disabling gate needs a visible reason here or a banner in
211+
// sessionDisabledBanner; a silently disabled composer is a silent failure.
210212
const disabledReason = modelUnavailable
211213
? `${t("modelSetup.failure.auth")}. ${t("modelSetup.failureGuidance.auth")}`
212214
: sessionParticipationBlocked && !suggestionViewer
213215
? t("chat.sessionSharing.readOnlyNotice")
214-
: null;
216+
: cloudStartupPending
217+
? t("newSession.starting")
218+
: null;
215219
const typingEnabled =
216220
multiIdentity &&
217221
hasOperatorWriteAccess(gatewaySnapshot.hello?.auth ?? null) &&

‎ui/src/pages/chat/chat-send-delivery.ts‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ import { resetChatInputHistoryNavigation } from "./input-history.ts";
6363
import { controlUiNowMs, roundedControlUiDurationMs } from "./performance.ts";
6464
import { hasAbortableSessionRun, isChatBusy, reconcileChatRunLifecycle } from "./run-lifecycle.ts";
6565
import { resetChatScroll, scheduleChatScroll } from "./scroll.ts";
66-
import { formatTerminalChatSendAckError, OFFLINE_QUEUE_STORAGE_ERROR } from "./steer-lifecycle.ts";
66+
import {
67+
formatTerminalChatSendAckError,
68+
OFFLINE_QUEUE_STORAGE_ERROR,
69+
surfaceChatDeliveryFailure,
70+
} from "./steer-lifecycle.ts";
6771
import { resetToolStream } from "./tool-stream.ts";
6872
import { buildUserChatMessageContentBlocks } from "./user-message-content.ts";
6973

@@ -224,9 +228,7 @@ async function sendQueuedChatMessage(
224228
const access = readChatResetTargetAccess(host, options.target);
225229
if (!access.allowed) {
226230
setState("failed", access.reason);
227-
if (visibleSessionMatches(host, sessionKey, prepared.agentId)) {
228-
setChatError(host, access.reason);
229-
}
231+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, access.reason);
230232
return "failed";
231233
}
232234
}
@@ -245,9 +247,7 @@ async function sendQueuedChatMessage(
245247
}
246248
if (!waiting) {
247249
setState("failed", OFFLINE_QUEUE_STORAGE_ERROR);
248-
if (visibleSessionMatches(host, sessionKey, prepared.agentId)) {
249-
setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
250-
}
250+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, OFFLINE_QUEUE_STORAGE_ERROR);
251251
}
252252
return "pending";
253253
}
@@ -267,9 +267,7 @@ async function sendQueuedChatMessage(
267267
agentId: prepared.agentId,
268268
}));
269269
if (!sendingItem) {
270-
if (visibleSessionMatches(host, sessionKey, prepared.agentId)) {
271-
setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
272-
}
270+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, OFFLINE_QUEUE_STORAGE_ERROR);
273271
return "pending";
274272
}
275273
registerChatSendTiming(host, sendingItem, runId, requestStartedAtMs);
@@ -349,9 +347,9 @@ async function sendQueuedChatMessage(
349347
publishRunStatus: false,
350348
armLocalTerminalReconcile: ack.runId === runId,
351349
});
352-
setChatError(host, error);
353350
restoreComposer(host, options ?? {});
354351
}
352+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, error);
355353
recordChatSendTiming(host, sendingItem, "failed", sendingItem.sendSubmittedAtMs, {
356354
error,
357355
ackStatus: ack.status,
@@ -431,9 +429,7 @@ async function sendQueuedChatMessage(
431429
}
432430
discardChatAttachmentDataUrls(excludeComposerAttachments(host, attachments));
433431
if (retirementFailed) {
434-
if (isVisible()) {
435-
setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
436-
}
432+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, OFFLINE_QUEUE_STORAGE_ERROR);
437433
return "pending";
438434
}
439435
return retireOnAck ? "sent" : "pending";
@@ -478,9 +474,12 @@ async function sendQueuedChatMessage(
478474
sendState: safelyRejected ? "failed" : "unconfirmed",
479475
}));
480476
}
481-
if (isVisible()) {
482-
setChatError(host, restore ? error : OFFLINE_QUEUE_STORAGE_ERROR);
483-
}
477+
surfaceChatDeliveryFailure(
478+
host,
479+
sessionKey,
480+
prepared.agentId,
481+
restore ? error : OFFLINE_QUEUE_STORAGE_ERROR,
482+
);
484483
recordChatSendTiming(host, prepared, "failed", prepared.sendSubmittedAtMs, {
485484
error: restore ? error : OFFLINE_QUEUE_STORAGE_ERROR,
486485
});
@@ -503,9 +502,7 @@ async function sendQueuedChatMessage(
503502
sendState: "failed",
504503
}));
505504
}
506-
if (isVisible()) {
507-
setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
508-
}
505+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, OFFLINE_QUEUE_STORAGE_ERROR);
509506
recordChatSendTiming(host, prepared, "failed", prepared.sendSubmittedAtMs, {
510507
error: OFFLINE_QUEUE_STORAGE_ERROR,
511508
});
@@ -534,12 +531,12 @@ async function sendQueuedChatMessage(
534531
}
535532
setState("failed", error);
536533
if (isVisible()) {
537-
setChatError(host, error);
538534
restoreComposer(host, options ?? {});
539535
if (activeLeafChanged) {
540536
void Promise.all([loadChatHistory(host), loadChatBranches(host)]);
541537
}
542538
}
539+
surfaceChatDeliveryFailure(host, sessionKey, prepared.agentId, error);
543540
recordChatSendTiming(host, prepared, "failed", prepared.sendSubmittedAtMs, { error });
544541
return "failed";
545542
} finally {

‎ui/src/pages/chat/chat-send-queue-state.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { storedChatOutboxScopeKey, type StoredChatOutboxScope } from "./composer
2020
import { controlUiNowMs } from "./performance.ts";
2121
import { hasAbortableSessionRun, isChatBusy } from "./run-lifecycle.ts";
2222
import { scheduleChatScroll } from "./scroll.ts";
23-
import { OFFLINE_QUEUE_STORAGE_ERROR } from "./steer-lifecycle.ts";
23+
import { OFFLINE_QUEUE_STORAGE_ERROR, surfaceChatDeliveryFailure } from "./steer-lifecycle.ts";
2424

2525
const SKILL_WORKSHOP_CONNECTION_CHANGED_ERROR =
2626
"Skill Workshop revision request cancelled because the Gateway connection changed.";
@@ -132,9 +132,12 @@ export function failSkillWorkshopRevisionConnectionChange(
132132
sessionKey,
133133
item.id,
134134
)("failed", SKILL_WORKSHOP_CONNECTION_CHANGED_ERROR);
135-
if (visibleSessionMatches(host, sessionKey, item.agentId)) {
136-
setChatError(host, SKILL_WORKSHOP_CONNECTION_CHANGED_ERROR);
137-
}
135+
surfaceChatDeliveryFailure(
136+
host,
137+
sessionKey,
138+
item.agentId,
139+
SKILL_WORKSHOP_CONNECTION_CHANGED_ERROR,
140+
);
138141
return "failed";
139142
}
140143

0 commit comments

Comments
 (0)