Skip to content

Commit b90d7ef

Browse files
authored
fix(ui): surface command-palette chat search failures (#124648)
The palette's session search swallowed every gateway error and rendered the plain "No results" empty state — a failed search (e.g. sessions.list rejecting with a store-needs-doctor migration error) was indistinguishable from a successful search with zero matches. Silent failure on a default path is the worst bug class in this repo. Track a sessionSearchFailed flag (set only for the current request id while the palette is open, cleared on every new query/clear), and render "Chat search failed — check the gateway logs and retry" in the empty state instead. Navigation commands stay usable throughout.
1 parent 9873b0f commit b90d7ef

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎ui/src/components/command-palette.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ describe("CommandPalette lifecycle", () => {
204204
expect(palette.textContent).not.toContain("Stale chat");
205205
});
206206

207+
it("shows a search failure instead of a false empty result", async () => {
208+
const { gateway } = createGateway(true);
209+
const list = vi
210+
.fn<ApplicationContext<RouteId>["sessions"]["list"]>()
211+
.mockRejectedValueOnce(new Error("store needs doctor migration"))
212+
.mockResolvedValueOnce(createSessionResult("agent:main:zz", "Recovered chat"));
213+
const { palette } = await mountPalette(createContext(gateway, list));
214+
// The query matches no navigation item, so a swallowed search failure
215+
// would render the plain "No results" empty state.
216+
await enterQuery(palette, "zzz-unmatched");
217+
await vi.advanceTimersByTimeAsync(250);
218+
await palette.updateComplete;
219+
220+
expect(list).toHaveBeenCalledOnce();
221+
expect(palette.textContent).toContain("Chat search failed");
222+
expect(palette.textContent).not.toContain("No results");
223+
224+
// A new keystroke clears the failure state and retries cleanly.
225+
await enterQuery(palette, "zz");
226+
await palette.updateComplete;
227+
expect(palette.textContent).not.toContain("Chat search failed");
228+
await vi.advanceTimersByTimeAsync(250);
229+
await palette.updateComplete;
230+
expect(palette.textContent).toContain("Recovered chat");
231+
});
232+
207233
it("navigates to the plugin manager from search", async () => {
208234
const { gateway } = createGateway(true);
209235
const { palette } = await mountPalette(

‎ui/src/components/command-palette.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type CommandPaletteProps = {
124124
query: string;
125125
activeIndex: number;
126126
sessionItems: readonly PaletteItem[];
127+
sessionSearchFailed: boolean;
127128
onToggle: () => void;
128129
onQueryChange: (query: string) => void;
129130
onActiveIndexChange: (index: number) => void;
@@ -315,7 +316,11 @@ function renderCommandPalette(props: CommandPaletteProps) {
315316
<span class="nav-item__icon" style="opacity:0.3;width:20px;height:20px"
316317
>${icons.search}</span
317318
>
318-
<span>${t("palette.noResults")}</span>
319+
<span
320+
>${props.sessionSearchFailed
321+
? t("palette.searchFailed")
322+
: t("palette.noResults")}</span
323+
>
319324
</div>`
320325
: grouped.map(
321326
([category, groupedItems]) => html`
@@ -369,6 +374,7 @@ export class CommandPalette extends OpenClawLightDomContentsElement {
369374
@state() private query = "";
370375
@state() private activeIndex = 0;
371376
@state() private sessionItems: readonly PaletteItem[] = [];
377+
@state() private sessionSearchFailed = false;
372378

373379
private readonly subscriptions = new SubscriptionsController(this);
374380
private sessionSearchTimer: ReturnType<typeof globalThis.setTimeout> | null = null;
@@ -458,6 +464,7 @@ export class CommandPalette extends OpenClawLightDomContentsElement {
458464
}
459465
this.sessionSearchId += 1;
460466
this.sessionItems = [];
467+
this.sessionSearchFailed = false;
461468
}
462469

463470
private scheduleSessionSearch(query: string) {
@@ -469,6 +476,7 @@ export class CommandPalette extends OpenClawLightDomContentsElement {
469476
// repopulate selectable stale rows during the debounce window.
470477
this.sessionSearchId += 1;
471478
this.sessionItems = [];
479+
this.sessionSearchFailed = false;
472480
const search = normalizeOptionalString(query);
473481
if (!this.open || !search || !this.onSelectSession) {
474482
return;
@@ -551,7 +559,13 @@ export class CommandPalette extends OpenClawLightDomContentsElement {
551559
}));
552560
this.activeIndex = 0;
553561
} catch {
554-
// Session search is best-effort; navigation commands stay usable.
562+
// Session search is best-effort; navigation commands stay usable. But a
563+
// failed search must not render as "No results" — that reads as a
564+
// successful search with zero matches and hides gateway-side failures
565+
// (e.g. a store needing doctor migration) from the operator.
566+
if (requestId === this.sessionSearchId && this.open) {
567+
this.sessionSearchFailed = true;
568+
}
555569
}
556570
}
557571

@@ -573,6 +587,7 @@ export class CommandPalette extends OpenClawLightDomContentsElement {
573587
query: this.query,
574588
activeIndex: this.activeIndex,
575589
sessionItems: this.sessionItems,
590+
sessionSearchFailed: this.sessionSearchFailed,
576591
desktopAvailable: this.desktopAvailable,
577592
onToggle: this.togglePalette,
578593
onQueryChange: (query) => {

‎ui/src/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,6 +3857,7 @@ export const en: TranslationMap = {
38573857
palette: {
38583858
placeholder: "Search chats and commands…",
38593859
noResults: "No results",
3860+
searchFailed: "Chat search failed — check the gateway logs and retry",
38603861
categories: {
38613862
search: "Search",
38623863
navigation: "Navigation",

0 commit comments

Comments
 (0)