Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(chat): retry history searches and scope archived restores

Bingxi Zhao (Frank)0378bc7810ed
diff --git a/web/components/space/ChatHistorySection.tsx b/web/components/space/ChatHistorySection.tsx
index e8e41b05e..9b97da9b4 100644
--- a/web/components/space/ChatHistorySection.tsx
+++ b/web/components/space/ChatHistorySection.tsx
@@ -71,6 +71,7 @@ export default function ChatHistorySection({
const [query, setQuery] = useState("");
const [searchResults, setSearchResults] = useState<SessionSearchResult[]>([]);
const [searchLoading, setSearchLoading] = useState(false);
+ const [searchError, setSearchError] = useState(false);
const [searchVersion, setSearchVersion] = useState(0);
const searchGenerationRef = useRef(0);
const [courseFilter] = useState("all");
@@ -116,6 +117,7 @@ export default function ChatHistorySection({
useEffect(() => {
const generation = ++searchGenerationRef.current;
const term = query.trim();
+ setSearchError(false);
if (!term) {
setSearchResults([]);
setSearchLoading(false);
@@ -137,6 +139,7 @@ export default function ChatHistorySection({
return;
if (generation !== searchGenerationRef.current) return;
setSearchResults([]);
+ setSearchError(true);
})
.finally(() => {
if (generation === searchGenerationRef.current)
@@ -236,7 +239,13 @@ export default function ChatHistorySection({
async (sessionId: string) => {
setRestoringId(sessionId);
try {
- await updateSessionOrganization(sessionId, { archived: false });
+ await updateSessionOrganization(
+ sessionId,
+ { archived: false },
+ sessionWorkspaceId(
+ filteredSessions.find((item) => item.session_id === sessionId),
+ ),
+ );
// Restoring cascades to the tutor threads under the conversation, so
// the server's own list is what says which rows are left.
await reload(true, true);
@@ -245,7 +254,7 @@ export default function ChatHistorySection({
setRestoringId(null);
}
},
- [reload],
+ [filteredSessions, reload],
);
const handleOrganize = useCallback(
@@ -356,6 +365,18 @@ export default function ChatHistorySection({
/>
))}
</div>
+ ) : searchError ? (
+ <div role="alert" className="flex items-center justify-between gap-3 px-2 py-4 text-[12.5px] text-[var(--muted-foreground)]">
+ <p>{t("Could not search chat history. Try again.")}</p>
+ <button
+ type="button"
+ onClick={() => setSearchVersion((version) => version + 1)}
+ className="inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-[var(--border)] px-2.5 py-1.5 text-[12px] font-medium text-[var(--foreground)] transition-colors hover:bg-[var(--muted)]"
+ >
+ <RefreshCw size={13} strokeWidth={1.8} />
+ {t("Retry")}
+ </button>
+ </div>
) : archiveFilter === "archived" ? (
<ArchivedConversations
buckets={archiveBuckets}
diff --git a/web/locales/de/app.json b/web/locales/de/app.json
index a91d2cc4c..9bb3e5673 100644
--- a/web/locales/de/app.json
+++ b/web/locales/de/app.json
@@ -5271,5 +5271,6 @@
"Move this knowledge base with its documents, settings, and indexes. Existing workspace assignments are updated.": "Diese Knowledge Base samt Dokumenten, Einstellungen und Indizes verschieben. Bestehende Workspace-Zuweisungen werden aktualisiert.",
"Review move": "Verschiebung prüfen",
"{{count}} files · {{bytes}} bytes": "{{count}} Dateien · {{bytes}} Bytes",
- "Assignments updated: {{names}}": "Aktualisierte Zuweisungen: {{names}}"
+ "Assignments updated: {{names}}": "Aktualisierte Zuweisungen: {{names}}",
+ "Could not search chat history. Try again.": "Der Chatverlauf konnte nicht durchsucht werden. Versuche es erneut."
}
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index d88102b0b..486b5c9da 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -5271,5 +5271,6 @@
"Move this knowledge base with its documents, settings, and indexes. Existing workspace assignments are updated.": "Move this knowledge base with its documents, settings, and indexes. Existing workspace assignments are updated.",
"Review move": "Review move",
"{{count}} files · {{bytes}} bytes": "{{count}} files · {{bytes}} bytes",
- "Assignments updated: {{names}}": "Assignments updated: {{names}}"
+ "Assignments updated: {{names}}": "Assignments updated: {{names}}",
+ "Could not search chat history. Try again.": "Could not search chat history. Try again."
}
diff --git a/web/locales/fr/app.json b/web/locales/fr/app.json
index 2f4205924..fe6fd19b3 100644
--- a/web/locales/fr/app.json
+++ b/web/locales/fr/app.json
@@ -5714,5 +5714,6 @@
"Move this knowledge base with its documents, settings, and indexes. Existing workspace assignments are updated.": "Déplacer cette base avec ses documents, paramètres et index. Les attributions existantes seront mises à jour.",
"Review move": "Vérifier le déplacement",
"{{count}} files · {{bytes}} bytes": "{{count}} fichiers · {{bytes}} octets",
- "Assignments updated: {{names}}": "Attributions mises à jour : {{names}}"
+ "Assignments updated: {{names}}": "Attributions mises à jour : {{names}}",
+ "Could not search chat history. Try again.": "Impossible de rechercher dans l’historique des conversations. Réessayez."
}
diff --git a/web/locales/uk/app.json b/web/locales/uk/app.json
index fe91bb306..23034fe6b 100644
--- a/web/locales/uk/app.json
+++ b/web/locales/uk/app.json
@@ -5287,5 +5287,6 @@
"Move this knowledge base with its documents, settings, and indexes. Existing workspace assignments are updated.": "Перемістити базу знань разом із документами, налаштуваннями та індексами. Наявні призначення робочих областей буде оновлено.",
"Review move": "Перевірити переміщення",
"{{count}} files · {{bytes}} bytes": "{{count}} файлів · {{bytes}} байтів",
- "Assignments updated: {{names}}": "Оновлені призначення: {{names}}"
+ "Assignments updated: {{names}}": "Оновлені призначення: {{names}}",
+ "Could not search chat history. Try again.": "Не вдалося виконати пошук в історії чатів. Спробуйте ще раз."
}
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 53ba5032d..98f4ee678 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -5271,5 +5271,6 @@
"Move this knowledge base with its documents, settings, and indexes. Existing workspace assignments are updated.": "连同文档、设置和索引一起移动此知识库。现有工作区分配会同步更新。",
"Review move": "检查移动详情",
"{{count}} files · {{bytes}} bytes": "{{count}} 个文件 · {{bytes}} 字节",
- "Assignments updated: {{names}}": "将更新以下工作区的分配:{{names}}"
+ "Assignments updated: {{names}}": "将更新以下工作区的分配:{{names}}",
+ "Could not search chat history. Try again.": "无法搜索聊天记录,请重试。"
}
diff --git a/web/tests/chat-history-search.spec.tsx b/web/tests/chat-history-search.spec.tsx
index 1b8255ac7..4aeb599c7 100644
--- a/web/tests/chat-history-search.spec.tsx
+++ b/web/tests/chat-history-search.spec.tsx
@@ -1,7 +1,7 @@
import { act, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, expect, it, vi } from "vitest";
import ChatHistorySection from "@/components/space/ChatHistorySection";
-import { searchAllSessions } from "@/lib/session-api";
+import { searchAllSessions, updateSessionOrganization } from "@/lib/session-api";
const searchMock = vi.mocked(searchAllSessions);
@@ -40,7 +40,9 @@ vi.mock("@/components/space/SpaceSectionHeader", () => ({
default: ({ title }: { title: string }) => <h1>{title}</h1>,
}));
vi.mock("@/components/space/ArchivedConversations", () => ({
- default: () => null,
+ default: ({ onRestore }: { onRestore: (id: string) => void }) => (
+ <button onClick={() => onRestore("older")}>Unarchive</button>
+ ),
}));
vi.mock("@/components/courses/OrganizedSessionList", () => ({
default: ({
@@ -65,7 +67,7 @@ vi.mock("@/components/courses/OrganizedSessionList", () => ({
),
}));
vi.mock("@/lib/session-api", () => ({
- sessionWorkspaceId: () => "",
+ sessionWorkspaceId: (session?: { content_workspace_id?: string }) => session?.content_workspace_id ?? "",
listAllSessions: vi.fn(async () => [
{
id: "recent",
@@ -105,6 +107,7 @@ vi.mock("@/lib/session-api", () => ({
afterEach(() => {
vi.useRealTimers();
fixture.calls.length = 0;
+ vi.clearAllMocks();
});
it("searches the full account history, then restores the unfiltered index", async () => {
@@ -173,3 +176,35 @@ it("cancels a stale search when the query changes", async () => {
expect(fixture.calls[1].signal?.aborted).toBe(false);
expect(screen.getByText("Older conversation")).toBeInTheDocument();
});
+
+it("reports a failed transcript search and retries the same query", async () => {
+ render(<ChatHistorySection />);
+ await act(async () => { await Promise.resolve(); });
+ vi.useFakeTimers();
+ searchMock.mockRejectedValueOnce(new Error("Network unavailable"));
+ fireEvent.change(screen.getByPlaceholderText("Search chat history..."), { target: { value: "Bayes" } });
+ await act(async () => { vi.advanceTimersByTime(300); });
+ expect(screen.getByRole("alert")).toHaveTextContent("Could not search chat history. Try again.");
+ fireEvent.click(screen.getByRole("button", { name: "Retry" }));
+ await act(async () => { vi.advanceTimersByTime(300); });
+ expect(searchMock).toHaveBeenLastCalledWith("Bayes", expect.any(AbortSignal), { allWorkspaces: true });
+ expect(screen.queryByRole("alert")).toBeNull();
+ expect(screen.getByText("Older conversation")).toBeInTheDocument();
+});
+
+it("restores an archived search match in its own workspace", async () => {
+ render(<ChatHistorySection />);
+ await act(async () => { await Promise.resolve(); });
+ vi.useFakeTimers();
+ searchMock.mockResolvedValueOnce([{
+ id: "older", session_id: "older", title: "Archived chat", created_at: 1, updated_at: 2,
+ message_count: 4, last_message: "", content_workspace_id: "other-workspace",
+ preferences: { archived: true }, match_excerpt: "Bayes", match_role: "user",
+ match_message_id: 7, match_created_at: 1,
+ }]);
+ fireEvent.change(screen.getByLabelText("Filter by archive status"), { target: { value: "archived" } });
+ fireEvent.change(screen.getByPlaceholderText("Search chat history..."), { target: { value: "Bayes" } });
+ await act(async () => { vi.advanceTimersByTime(300); });
+ await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Unarchive" })); });
+ expect(updateSessionOrganization).toHaveBeenCalledWith("older", { archived: false }, "other-workspace");
+});