Skip to content

Commit 19b2d6c

Browse files
committed
fix(ui): keep failed history refreshes actionable over cached transcripts
A refresh failure with cached messages rendered nothing: the failure panel only replaced an empty thread, so stale content sat with no error or Retry. Render the same failure surface as a compact non-displacing banner above the transcript when content exists, sharing one builder with the empty-state panel. Adds the cached-refresh browser regression with screenshot proof.
1 parent f7aca53 commit 19b2d6c

3 files changed

Lines changed: 87 additions & 17 deletions

File tree

‎ui/src/e2e/chat-flow.history-issuance.e2e.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,54 @@ suite.define(() => {
119119
await suite.closeBrowserContext(context);
120120
}
121121
});
122+
it("keeps cached history visible and actionable when a refresh fails", async () => {
123+
const context = await suite.newBrowserContext({
124+
locale: "en-US",
125+
serviceWorkers: "block",
126+
viewport: { height: 900, width: 1280 },
127+
});
128+
const page = await context.newPage();
129+
const gateway = await installMockGateway(page, {
130+
historyMessages: [
131+
{
132+
content: [{ text: "Cached transcript stays visible.", type: "text" }],
133+
role: "assistant",
134+
timestamp: Date.now(),
135+
},
136+
],
137+
});
138+
139+
try {
140+
await page.goto(`${suite.server.baseUrl}chat`);
141+
const cachedMessage = page
142+
.locator(".chat-thread")
143+
.getByText("Cached transcript stays visible.");
144+
await cachedMessage.waitFor({ state: "visible" });
145+
146+
await gateway.deferNext("chat.startup");
147+
await gateway.setOnline(false);
148+
await gateway.setOnline(true);
149+
await gateway.waitForRequest("chat.startup", { after: 1 });
150+
await gateway.rejectDeferred("chat.startup", {
151+
code: "GATEWAY_ERROR",
152+
message: "History refresh failed.",
153+
retryable: false,
154+
});
155+
156+
const inlineError = page.locator(".chat-history-error--inline");
157+
await inlineError.waitFor({ state: "visible", timeout: 5_000 });
158+
expect(await inlineError.textContent()).toContain("History refresh failed.");
159+
// The stale transcript must not be displaced by the failure surface.
160+
await cachedMessage.waitFor({ state: "visible" });
161+
await captureHistoryIssuanceProof(page, "04-history-refresh-failed-cached");
162+
163+
const startupCount = (await gateway.getRequests("chat.startup")).length;
164+
await inlineError.getByRole("button", { name: "Retry" }).click();
165+
await gateway.waitForRequest("chat.startup", { after: startupCount });
166+
await inlineError.waitFor({ state: "hidden", timeout: 5_000 });
167+
await cachedMessage.waitFor({ state: "visible" });
168+
} finally {
169+
await suite.closeBrowserContext(context);
170+
}
171+
});
122172
});

‎ui/src/pages/chat/chat-view.ts‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -536,26 +536,35 @@ export function renderChat(props: ChatProps) {
536536
: nothing;
537537
const historyState = props.historyState;
538538
const historyLoadState = historyState ? getChatHistoryLoadState(historyState) : undefined;
539-
const historyError =
540-
historyState &&
539+
const historyFailed =
540+
historyState !== undefined &&
541541
historyLoadState?.phase === "failed" &&
542-
historyLoadState.sessionKey === props.sessionKey &&
542+
historyLoadState.sessionKey === props.sessionKey;
543+
const transcriptEmpty =
543544
props.messages.length === 0 &&
544545
props.toolMessages.length === 0 &&
545546
props.streamSegments.length === 0 &&
546547
!props.stream &&
547-
props.queue.length === 0
548-
? html`<div class="chat-history-error" role="alert">
549-
<span>${historyLoadState.message}</span>
550-
<button
551-
class="btn btn--sm"
552-
type="button"
553-
@click=${() => retryChatHistoryLoad(historyState)}
554-
>
555-
${t("common.retry")}
556-
</button>
557-
</div>`
558-
: nothing;
548+
props.queue.length === 0;
549+
// A failed load with cached content must stay visible without displacing the
550+
// transcript; only an empty pane may replace the thread with the error panel.
551+
const renderHistoryFailure = (inline: boolean) =>
552+
html`<div
553+
class="chat-history-error${inline ? " chat-history-error--inline" : ""}"
554+
role=${inline ? "status" : "alert"}
555+
>
556+
<span>${historyLoadState?.phase === "failed" ? historyLoadState.message : ""}</span>
557+
<button
558+
class="btn btn--sm"
559+
type="button"
560+
@click=${() => historyState && retryChatHistoryLoad(historyState)}
561+
>
562+
${t("common.retry")}
563+
</button>
564+
</div>`;
565+
const historyError = historyFailed && transcriptEmpty ? renderHistoryFailure(false) : nothing;
566+
const historyRefreshNotice =
567+
historyFailed && !transcriptEmpty ? renderHistoryFailure(true) : nothing;
559568

560569
return html`
561570
<section
@@ -610,8 +619,8 @@ export function renderChat(props: ChatProps) {
610619
})}
611620
${renderTranscriptSearch(props.paneId, requestUpdate)}
612621
<div class="chat-main__conversation">
613-
${historyError === nothing ? thread : historyError} ${earlierHistoryButton}
614-
${scrollToBottomButton}
622+
${historyRefreshNotice} ${historyError === nothing ? thread : historyError}
623+
${earlierHistoryButton} ${scrollToBottomButton}
615624
${props.inlineApproval && props.onApprovalDecision
616625
? html`<div class="chat-inline-approval">
617626
${renderExecApprovalCard({

‎ui/src/styles/chat/layout.css‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,17 @@ openclaw-chat-page {
632632
text-align: center;
633633
}
634634

635+
/* Failed refresh with cached history keeps the transcript and shows a compact
636+
banner instead; displacing content would hide the stale-but-useful messages. */
637+
.chat-history-error--inline {
638+
flex: 0 0 auto;
639+
flex-direction: row;
640+
justify-content: center;
641+
gap: 10px;
642+
padding: 8px 12px;
643+
border-block-end: 1px solid var(--border);
644+
}
645+
635646
.chat-history-available {
636647
position: absolute;
637648
z-index: 10;

0 commit comments

Comments
 (0)