forge
Explore
Log in

Don't you dare go Hollow

🩹 stop claiming summary work happens in the background

Browse files at this commit

2c2da014d9da61207fa9624a705df2ff9ca89852Ahmet Kaan GümüşParent: a3421b2
  • fix
    • 🩹 stop claiming summary work happens in the background
Show full message
fix: 🩹 stop claiming summary work happens in the background

The AI outputs panel flashed "Summary generation continues in the
background" whenever a reindex poll found no new output. Nothing was
running: the rag service refused the call in milliseconds, so the panel
was telling the user a lie.

Say what is true instead. A poll that ends without a new row now shows
that the summary was not created, that nothing is indexed for the note
yet, and that the button can be pressed again — an inline warning plus a
distinct empty-state line, in both locales. The happy path is unchanged:
a new row still toasts `courseNotes.ragReady` and renders at once.

Also make the button's disabled state honest: `/ai/capabilities` lists
what connected workers actually serve, so the button is live only when
some worker declares `rag.index`. A bridge reported off, or a fleet with
no rag worker, disables it with the reason visible; a discovery failure
still leaves it live so the call itself can report.

`courseNotes.ragQueued` is deleted — nothing may claim it again.
src/components/notes/rag-outputs-panel.test.tsxadded+106 -0
@@ -0,0 +1,106 @@
1+import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library";
2+import { afterEach, describe, expect, it, vi } from "vitest";
3+import { RagOutputsPanel } from "@/components/notes/rag-outputs-panel";
4+import type { NoteFileSource } from "@/lib/note-source";
5+import { PreferencesProvider } from "@/stores/preferences-context";
6+
7+const aiApi = vi.hoisted(() => ({ getAiCapabilities: vi.fn() }));
8+// The panel reports success through a toast; capture the text without a portal.
9+const toastApi = vi.hoisted(() => ({ showToast: vi.fn() }));
10+
11+vi.mock("@/api/ai", () => aiApi);
12+vi.mock("@/components/ui/toast", () => ({ showToast: toastApi.showToast, Toaster: () => null }));
13+
14+const CAPABILITIES_WITH_RAG = {
15+ enabled: true,
16+ protocol: "hab/2",
17+ capabilities: [{ capability: "rag.index", workers: 1, inflight: 0 }],
18+};
19+
20+/** A source whose list stays empty — the state a refused reindex leaves behind. */
21+function stubSource(options: { rag?: boolean } = {}): NoteFileSource {
22+ return {
23+ maxFiles: 10,
24+ listFiles: async () => ({ items: [], total: 0, limit: 10, offset: 0 }),
25+ uploadFile: async () => {
26+ throw new Error("not used by this panel");
27+ },
28+ deleteFile: async () => {},
29+ fileUrl: () => "",
30+ fileBlob: async () => new Blob(),
31+ listRagOutputs: async () => ({ items: [], total: 0, limit: 10, offset: 0 }),
32+ deleteRagOutput: async () => {},
33+ reindexRag: async () => {
34+ if (!options.rag) throw new Error("reindex should not be called without rag.index");
35+ },
36+ };
37+}
38+
39+function renderPanel(source: NoteFileSource) {
40+ render(() => (
41+ <PreferencesProvider>
42+ <RagOutputsPanel noteId="note-1" active source={source} />
43+ </PreferencesProvider>
44+ ));
45+}
46+
47+const generateButton = () => screen.getByRole("button", { name: "Create summary" }) as HTMLButtonElement;
48+
49+describe("RagOutputsPanel", () => {
50+ afterEach(() => {
51+ cleanup();
52+ vi.useRealTimers();
53+ vi.clearAllMocks();
54+ });
55+
56+ it("reports that nothing was indexed when the poll ends without an output", async () => {
57+ vi.useFakeTimers();
58+ aiApi.getAiCapabilities.mockResolvedValue(CAPABILITIES_WITH_RAG);
59+
60+ renderPanel(stubSource({ rag: true }));
61+ fireEvent.click(generateButton());
62+
63+ // 24 polls after the initial 1.5s delay is the panel's own ceiling.
64+ for (let i = 0; i < 24; i += 1) await vi.advanceTimersByTimeAsync(2500);
65+
66+ // The truthful message is on screen, twice: the notice and the empty list.
67+ expect(
68+ screen.getByText("The summary was not created. Nothing is indexed for this note yet — press Create summary to try again."),
69+ ).toBeTruthy();
70+ expect(screen.getByText("Nothing is indexed for this note yet. Press Create summary to try again.")).toBeTruthy();
71+ // The false claim must be gone: nothing is running in the background.
72+ expect(toastApi.showToast).not.toHaveBeenCalledWith({ title: "Summary generation continues in the background." });
73+ // The button can be pressed again.
74+ expect(generateButton().disabled).toBe(false);
75+ });
76+
77+ it("disables the button and names the reason when no worker serves rag.index", async () => {
78+ aiApi.getAiCapabilities.mockResolvedValue({
79+ enabled: true,
80+ protocol: "hab/2",
81+ capabilities: [{ capability: "chat.reply", workers: 1, inflight: 0 }],
82+ });
83+
84+ renderPanel(stubSource());
85+
86+ await waitFor(() => {
87+ expect(
88+ screen.getByText("The AI summary service is not connected right now. Try again when a worker is available."),
89+ ).toBeTruthy();
90+ });
91+ expect(generateButton().disabled).toBe(true);
92+ });
93+
94+ it("keeps the button live when rag.index is advertised", async () => {
95+ aiApi.getAiCapabilities.mockResolvedValue(CAPABILITIES_WITH_RAG);
96+
97+ renderPanel(stubSource({ rag: true }));
98+
99+ await waitFor(() => {
100+ expect(generateButton().disabled).toBe(false);
101+ });
102+ expect(
103+ screen.queryByText("The AI summary service is not connected right now. Try again when a worker is available."),
104+ ).toBeNull();
105+ });
106+});
src/components/notes/rag-outputs-panel.tsxmodified+32 -4
@@ -17,6 +17,13 @@ import { RagOutputContent } from "@/components/notes/rag-output-content";
1717
1818 const RAG_PAGE_SIZE = 10;
1919
20+/**
21+ * The capability a worker must have declared for a reindex call to have any
22+ * chance of being answered. `/ai/capabilities` lists what connected services
23+ * actually serve, so the button stays disabled until some worker serves this.
24+ */
25+const RAG_INDEX_CAPABILITY = "rag.index";
26+
2027 export function RagOutputsPanel(props: {
2128 noteId: string;
2229 active: boolean;
@@ -30,6 +37,8 @@ export function RagOutputsPanel(props: {
3037 const [flash, setFlash] = createFlash();
3138 const [deleteTarget, setDeleteTarget] = createSignal<RagOutput | null>(null);
3239 const [generating, setGenerating] = createSignal(false);
40+ /** Set when a reindex attempt ended without a new output — the truthful state. */
41+ const [missed, setMissed] = createSignal("");
3342 let pollTimer: ReturnType<typeof setTimeout> | undefined;
3443
3544 onCleanup(() => pollTimer && clearTimeout(pollTimer));
@@ -44,11 +53,20 @@ export function RagOutputsPanel(props: {
4453 );
4554
4655 const outputs = () => list()?.items ?? [];
47- const available = () => capabilities.error || capabilities()?.enabled !== false;
56+ // The button is live only when a worker actually serves `rag.index`. A
57+ // discovery failure is not evidence of absence, so leave it live and let the
58+ // call itself report; while the list is still loading we do not know either.
59+ const available = () => {
60+ if (capabilities.error || capabilities.loading) return true;
61+ const caps = capabilities();
62+ if (!caps || caps.enabled === false) return false;
63+ return caps.capabilities.some((c) => c.capability === RAG_INDEX_CAPABILITY);
64+ };
4865
4966 const generate = async () => {
5067 if (!props.source.reindexRag || generating()) return;
5168 setError("");
69+ setMissed("");
5270 setGenerating(true);
5371 const previousId = outputs()[0]?.id;
5472 try {
@@ -62,9 +80,16 @@ export function RagOutputsPanel(props: {
6280 attempts += 1;
6381 const next = await refetch();
6482 const firstId = next?.items?.[0]?.id;
65- if ((firstId && firstId !== previousId) || attempts >= 24) {
83+ if (firstId && firstId !== previousId) {
84+ setGenerating(false);
85+ setFlash(t("courseNotes.ragReady"));
86+ return;
87+ }
88+ if (attempts >= 24) {
89+ // Nothing was produced. Say that plainly: no worker indexed this
90+ // note, and the button runs the whole call again.
6691 setGenerating(false);
67- setFlash(firstId && firstId !== previousId ? t("courseNotes.ragReady") : t("courseNotes.ragQueued"));
92+ setMissed(t("courseNotes.ragNotIndexed"));
6893 return;
6994 }
7095 pollTimer = setTimeout(() => void poll().catch(fail), 2500);
@@ -115,6 +140,9 @@ export function RagOutputsPanel(props: {
115140 <Show when={error()}>
116141 <Alert variant="destructive">{error()}</Alert>
117142 </Show>
143+ <Show when={missed()}>
144+ <Alert variant="warning">{missed()}</Alert>
145+ </Show>
118146 <Show when={!available()}>
119147 <Alert variant="warning">{t("courseNotes.ragUnavailable")}</Alert>
120148 </Show>
@@ -122,7 +150,7 @@ export function RagOutputsPanel(props: {
122150 <Show when={list.error}>
123151 <Alert variant="destructive">{formatApiError(list.error)}</Alert>
124152 </Show>
125- <Show when={outputs().length > 0} fallback={<p class="text-sm text-muted-foreground">{t("courseNotes.ragEmpty")}</p>}>
153+ <Show when={outputs().length > 0} fallback={<p class="text-sm text-muted-foreground">{missed() ? t("courseNotes.ragEmptyFailed") : t("courseNotes.ragEmpty")}</p>}>
126154 <ul class="space-y-3">
127155 <For each={outputs()}>
128156 {(output) => (
src/i18n/messages.tsmodified+6 -3
@@ -875,7 +875,8 @@ export type MessageKey =
875875 | "courseNotes.ragGenerate"
876876 | "courseNotes.ragGenerating"
877877 | "courseNotes.ragReady"
878- | "courseNotes.ragQueued"
878+ | "courseNotes.ragNotIndexed"
879+ | "courseNotes.ragEmptyFailed"
879880 | "courseNotes.ragUnavailable"
880881 | "podcast.title"
881882 | "podcast.description"
@@ -2984,7 +2985,8 @@ const en: Dict = {
29842985 "courseNotes.ragGenerate": "Create summary",
29852986 "courseNotes.ragGenerating": "Creating summary…",
29862987 "courseNotes.ragReady": "The new summary is ready.",
2987- "courseNotes.ragQueued": "Summary generation continues in the background.",
2988+ "courseNotes.ragNotIndexed": "The summary was not created. Nothing is indexed for this note yet — press Create summary to try again.",
2989+ "courseNotes.ragEmptyFailed": "Nothing is indexed for this note yet. Press Create summary to try again.",
29882990 "courseNotes.ragUnavailable": "The AI summary service is not connected right now. Try again when a worker is available.",
29892991 "podcast.title": "Audio workshop",
29902992 "podcast.description": "Turn a lesson note into a listenable episode.",
@@ -5095,7 +5097,8 @@ const tr: Dict = {
50955097 "courseNotes.ragGenerate": "Özet oluştur",
50965098 "courseNotes.ragGenerating": "Özet oluşturuluyor…",
50975099 "courseNotes.ragReady": "Yeni özet hazır.",
5098- "courseNotes.ragQueued": "Özet oluşturma arka planda devam ediyor.",
5100+ "courseNotes.ragNotIndexed": "Özet oluşmadı. Bu not için henüz bir dizin oluşturulmadı — yeniden denemek için Özet oluştur'a basın.",
5101+ "courseNotes.ragEmptyFailed": "Bu not için henüz bir dizin oluşturulmadı. Yeniden denemek için Özet oluştur'a basın.",
50995102 "courseNotes.ragUnavailable": "YZ özet servisi şu anda bağlı değil. Bir worker hazır olduğunda tekrar deneyin.",
51005103 "podcast.title": "Ses Atölyesi",
51015104 "podcast.description": "Bir ders notunu dinlenebilir bir bölüme dönüştürün.",