Spaces:
Running
Running
Sync from felladrin/MiniSearch@190c476
Browse filesFiles changed (7)
1 unmodified line2345678910111213141 unmodified line
Notable changes, grouped by date, most recent first.
## 2026-11-27
- Restoring another search from history while a follow-up is being answered now stops that follow-up. The old chat stayed on screen under the restored search, so sending was blocked until the old answer ended, and that answer was built from the restored search's results and then suggested a question about the old search. The follow-up is now cancelled when the restore switches searches: its question is saved under its own search with "The answer was interrupted.", and the restored chat can be used at once.
## 2026-11-26
- Restoring the search already on screen while a follow-up is being answered keeps the live text results and page excerpts used by that answer.- A search's saved images no longer lose the first search's or a follow-up's images when you leave the search before both arrive. Whichever image search finished last replaced the other's images in history, so restoring that search later showed only one set. Images that arrive after you left a search are now added to the ones it already saved.- A follow-up answer no longer disappears when the same search is restored from history while that answer is still coming. If the answer arrived while the restore was reading the saved chat, the restore put back the older list without it, and the next message sent then removed it from history too. The question being answered also vanished from the chat until its answer arrived. Restoring the search already on screen now leaves a chat that is still answering as it is; restoring any other search still shows that search's saved chat.- A follow-up question no longer disappears when "AI response" is turned off and back on while it is still being answered. Turning the setting off stopped the follow-up and saved the question with "The answer was interrupted.", but the chat shown after turning it back on was rebuilt without it, and the next message sent from that chat then removed it from history too. The question and its note now stay, on screen and in history.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import { act, cleanup, render } from "@testing-library/react";import { type ReactNode, useEffect } from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { getChatSession, getSettings, settingsPubSub, updateChatMessages, updateChatSession, updateResponseImmediately, updateTextGenerationState,} from "@/modules/pubSub";import AiResponseSection from "./AiResponseSection";
const [updateSettings] = settingsPubSub;
vi.mock("@mantine/code-highlight", () => ({ CodeHighlightAdapterProvider: ({ children }: { children: ReactNode }) => children,}));vi.mock("@mantine/code-highlight/styles.css", () => ({}));vi.mock("@/modules/shiki", () => ({ shikiAdapter: {} }));vi.mock("./AiResponseContent", () => ({ default: () => null }));
const chatLifecycle = { mounts: 0, unmounts: 0 };
// What the chat's unmount does (abort the follow-up, save it as interrupted// under its own search, drop the suggestion) is covered in// ChatInterface.test.tsx; this only checks when the chat is remounted.vi.mock("./ChatInterface", () => ({ default: () => { useEffect(() => { chatLifecycle.mounts += 1; return () => { chatLifecycle.unmounts += 1; }; }, []); return null; },}));
beforeEach(() => { chatLifecycle.mounts = 0; chatLifecycle.unmounts = 0; updateSettings({ ...getSettings(), enableAiResponse: true }); updateResponseImmediately("Answer A"); updateChatMessages([]); updateTextGenerationState("completed");});
afterEach(() => { cleanup();});
describe("AiResponseSection", () => { it("remounts the chat for a new chat session, and only then", () => { render(<AiResponseSection />); expect(chatLifecycle).toEqual({ mounts: 1, unmounts: 0 });
act(() => { updateResponseImmediately("Answer B"); updateChatMessages([ { role: "user", content: "A follow-up" }, { role: "assistant", content: "Its answer" }, ]); }); expect(chatLifecycle).toEqual({ mounts: 1, unmounts: 0 });
act(() => updateChatSession(getChatSession() + 1)); expect(chatLifecycle).toEqual({ mounts: 2, unmounts: 1 }); });});3 unmodified lines4567891027 unmodified lines3839404142434418 unmodified lines6364656667686937 unmodified lines1071081091101111123 unmodified linesimport { useScreenWakeLock } from "@/hooks/useScreenWakeLock";import { chatMessagesPubSub, chatSessionPubSub, isRestoringFromHistoryPubSub, modelLoadingProgressPubSub, modelSizeInMegabytesPubSub,27 unmodified lines const [modelSizeInMegabytes] = usePubSub(modelSizeInMegabytesPubSub); const [chatMessages] = usePubSub(chatMessagesPubSub); const [isRestoringFromHistory] = usePubSub(isRestoringFromHistoryPubSub); const [chatSession] = usePubSub(chatSessionPubSub);
useScreenWakeLock(statesKeepingTheScreenAwake.includes(textGenerationState));
18 unmodified lines
{textGenerationState === "completed" && ( <ChatInterface key={chatSession} initialQuery={query} initialResponse={response} initialMessages={37 unmodified lines modelLoadingProgress, modelSizeInMegabytes, isRestoringFromHistory, chatSession, ]);}8 unmodified lines91011121314151617181920212223242526272829109 unmodified lines139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183173 unmodified lines3573583593603613623633643653663673683693703713723733743753763773783793803818 unmodified linesimport { chatGenerationStatePubSub, chatMessagesPubSub, getChatSession, getLlmTextSearchResults, getPageContents, getSuppressNextFollowUp, imageSearchResultsPubSub, imageSearchStatePubSub, isRestoringFromHistoryPubSub, textSearchResultsPubSub, updateImageSearchResults, updateLlmTextSearchResults, updatePageContents, updateSuppressNextFollowUp, updateTextSearchResults,} from "@/modules/pubSub";import type { TextSearchResults } from "@/modules/types";import { useHistoryRestore } from "./useHistoryRestore";
/** A chat turn as history stores it: never a system message. */109 unmodified lines expect(imageSearchStatePubSub[2]()).toBe("completed"); });
it.each([ { searchRunId: "live-run", generating: true, keepsGrounding: true }, { searchRunId: "other-run", generating: true, keepsGrounding: false }, { searchRunId: "live-run", generating: false, keepsGrounding: false }, ])( "restores text grounding for $searchRunId with generating=$generating", async ({ searchRunId, generating, keepsGrounding }) => { const savedText: TextSearchResults = [ ["Saved text", "Saved snippet", "https://example.com/text"], ]; const liveText: TextSearchResults = [ ...savedText, ["Follow-up result", "Fresh snippet", "https://example.com/follow-up"], ]; const excerpts = { "https://example.com/text": "First excerpt", "https://example.com/follow-up": "Fresh excerpt", }; setCurrentSearchRunId("live-run"); updateChatGenerationState({ isGeneratingResponse: generating, isGeneratingFollowUpQuestion: false, }); updateTextSearchResults(liveText); updateLlmTextSearchResults(liveText); updatePageContents(excerpts); vi.mocked(getLatestLlmResponseForEntry).mockResolvedValueOnce( "Saved AI answer.", );
await restoreEntry({ searchRunId, textResults });
const expectedText = keepsGrounding ? liveText : savedText; expect(textSearchResultsPubSub[2]()).toEqual(expectedText); expect(getLlmTextSearchResults()).toEqual(expectedText); expect(getPageContents()).toEqual(keepsGrounding ? excerpts : {}); }, );
it.each([ { name: "image-only entry", payload: { imageResults } }, { name: "legacy image-only entry", payload: { results: imageResults } },173 unmodified lines expect(getChatMessages()).toEqual(savedTurns); }); });
it.each([ { searchRunId: "run-2", startsNewChat: true }, { searchRunId: "run-1", startsNewChat: false }, ])( "starts a new chat session only when another search is restored ($searchRunId)", async ({ searchRunId, startsNewChat }) => { setCurrentSearchRunId("run-1"); updateChatGenerationState({ isGeneratingResponse: true, isGeneratingFollowUpQuestion: false, }); const sessionBefore = getChatSession();
await restoreEntry({ searchRunId });
expect(getChatSession()).toBe( startsNewChat ? sessionBefore + 1 : sessionBefore, ); }, );});13 unmodified lines1415161718192021222341 unmodified lines6566676869707172736970717475747677781 unmodified line808182828384858687888990919293949596979899838485868788899091929394959697989910110010110210313 unmodified linesimport { postMessageToParentWindow } from "../modules/parentWindow";import { getChatGenerationState, getChatSession, updateChatInput, updateChatMessages, updateChatSession, updateFollowUpQuestion, updateImageSearchResults, updateImageSearchState,41 unmodified lines const keepsChat = searchRunId === getCurrentSearchRunId() && getChatGenerationState().isGeneratingResponse; if (searchRunId !== getCurrentSearchRunId()) { updateChatSession(getChatSession() + 1); } setCurrentSearchRunId(searchRunId);
updateIsRestoringFromHistory(true); // Excerpts belong to the search that fetched them; a follow-up on the // restored entry must not be grounded on the live search's pages. updatePageContents({}); updateFollowUpQuestion(""); updateChatInput(""); updateTextSearchStale(false);
const queryString = `q=${encodeURIComponent(selectedQuery)}`; postMessageToParentWindow({ queryString, hash: "" });1 unmodified line
document.title = selectedQuery;
if (hasTextResults(entry)) { const results = getResultsFromEntry(entry); if (results && results.type === "text") { const textTuples: TextSearchResults = results.items.map((it) => [ it.title, it.snippet, it.url, ]); updateTextSearchResults(textTuples); updateTextSearchState("completed"); updateLlmTextSearchResults(textTuples); } else { updateTextSearchResults([]); updateTextSearchState("completed"); updateLlmTextSearchResults([]); } } else { updateTextSearchResults([]); if (!keepsChat) { // Replacing the chat also replaces the source material it can use. updatePageContents({}); updateTextSearchStale(false); const results = hasTextResults(entry) ? getResultsFromEntry(entry) : null; const textTuples: TextSearchResults = results?.type === "text" ? results.items.map(({ title, snippet, url }) => [ title, snippet, url, ]) : []; updateTextSearchResults(textTuples); updateTextSearchState("completed"); updateLlmTextSearchResults([]); updateLlmTextSearchResults(textTuples); }
if (hasImageResults(entry)) {344 unmodified lines345346347348349350351352353354355356357358359344 unmodified lines
export const [updateIsRestoringFromHistory] = isRestoringFromHistoryPubSub;
/** * Changes when a history restore switches to another search, so the chat is * mounted again for it. The old chat's unmount aborts its follow-up and drops * its pending suggestion, which would otherwise land in the restored chat. */export const chatSessionPubSub = createPubSub(0);
export const [updateChatSession, , getChatSession] = chatSessionPubSub;
export const suppressNextFollowUpPubSub = createPubSub(false);
export const [updateSuppressNextFollowUp, , getSuppressNextFollowUp] =55 unmodified lines5657585960616255 unmodified lines| Keyword fallback also returns nothing | Text search state stays `completed` with the no-results alert | `client/modules/textGeneration.degradation.test.ts` || Stop on an internal-API answer, also while the stream is silent, or an error frame | The request is aborted and its stream cancelled, so the server stops streaming and counts the run abandoned | `client/modules/textGenerationWithInternalApi.test.ts` › cancelling the stream || Stop, a new search or closing the chat while another answer is also running | Only that answer's request is aborted, at once even before its first chunk; the other answer finishes | `client/modules/textGenerationWithOpenAi.test.ts` › aborts only the request of the chat whose signal aborts, `client/modules/textGeneration.inference.test.ts` › cancels the previous search's answer, and Stop cancels the current one, `client/components/AiResponse/ChatInterface.test.tsx` › aborts the chat answer when the chat unmounts || Another search is restored from history while a follow-up is being answered | The follow-up is aborted and saved under its own search with the interrupted note, and the restored chat accepts a send at once with no suggestion from the old search | `client/components/AiResponse/AiResponseSection.test.tsx` › remounts the chat for a new chat session, and only then, `client/components/AiResponse/ChatInterface.test.tsx` › aborts the chat answer when the chat unmounts, `client/hooks/useHistoryRestore.test.ts` › starts a new chat session only when another search is restored || SearXNG is down on the client | Text search state becomes `failed`, keyword fallback does not fire | `client/modules/textGeneration.degradation.test.ts` || Client search fails after a previous search populated the LLM channel | The grounding channel is cleared, so the AI can't ground on the previous query's results; when image search is on and it answers, the channel is repopulated with the (image)-tagged titles and URLs instead | `client/modules/textGeneration.degradation.test.ts` || Text search fails and the image search answers | The answer waits for the image results and grounds on their (image)-tagged titles and URLs, and the failed-state alert says so | `client/modules/textGeneration.degradation.test.ts` › search degradation |changelog.md+5
client/components/AiResponse/AiResponseSection.test.tsxAdded+72
client/components/AiResponse/AiResponseSection.tsx+4
client/hooks/useHistoryRestore.test.ts+66
client/hooks/useHistoryRestore.ts+22-23
client/modules/pubSub.ts+9
docs/failure-injection.md+1