Skip to content

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

Merge pull request #1021 from Zuan0/research-interruption-recovery

Bingxi Zhao (Frank)3c51bb9ed9a1
diff --cc web/app/(workspace)/home/[[...sessionId]]/page.tsx
index 604ce548e,03faeefaa..0578b59cc
--- a/web/app/(workspace)/home/[[...sessionId]]/page.tsx
+++ b/web/app/(workspace)/home/[[...sessionId]]/page.tsx
@@@ -120,9 -125,9 +120,10 @@@ import
} from "@/lib/book-references";
import {
normalizeSelectedText,
+ textFromDomSelection,
type SelectionTutorContext,
} from "@/lib/selection-tutor";
+ import { shouldReturnToChatAfterResearch } from "@/lib/deep-research-report";
const NotebookRecordPicker = dynamic(
() => import("@/components/notebook/NotebookRecordPicker"),
@@@ -600,8 -736,32 +601,32 @@@ export default function ChatPage()
const isQuizMode = activeCap.value === "deep_question";
const isVisualizeMode = activeCap.value === "visualize";
const isResearchMode = activeCap.value === "deep_research";
- const isReadingMode = activeCap.value === "immersive_reading";
+ const isWatchingMode = activeCap.value === "immersive_watching";
const capabilityNeedsConfig = isQuizMode || isVisualizeMode || isResearchMode;
+ const returnedResearchTurnRef = useRef<string | null>(null);
+
+ // Deep Research is a one-shot workflow: once its confirmed-outline turn
+ // reaches a terminal event, ordinary composer messages should discuss the
+ // report in chat context. Keeping the mode selected caused follow-ups such
+ // as "why did this stop?" to become brand-new research outlines. The Retry
+ // button still submits the preserved outline explicitly as deep_research.
+ useEffect(() => {
+ if (state.isStreaming || state.activeCapability !== "deep_research") return;
+ const latestAssistant = [...state.messages]
+ .reverse()
+ .find((message) => message.role === "assistant");
+ if (!latestAssistant || !shouldReturnToChatAfterResearch(latestAssistant.events)) {
+ return;
+ }
+ const terminal = [...(latestAssistant.events ?? [])]
+ .reverse()
+ .find((event) => event.type === "done");
+ const turnKey = String(terminal?.turn_id || latestAssistant.id || "");
+ if (!turnKey || returnedResearchTurnRef.current === turnKey) return;
+ returnedResearchTurnRef.current = turnKey;
+ setCapability(null);
+ setCapabilityConfigConfirmed(false);
+ }, [setCapability, state.activeCapability, state.isStreaming, state.messages]);
// Edit-invalidates-confirm wrappers — flipping any field after the user
// hit *Confirm* should restore the gate so they re-confirm intentionally.
diff --cc web/context/UnifiedChatContext.tsx
index 2741a3fe4,32063d118..754651c20
--- a/web/context/UnifiedChatContext.tsx
+++ b/web/context/UnifiedChatContext.tsx
@@@ -45,11 -40,8 +45,12 @@@ import
import { hasPendingAskUserInMessages } from "@/lib/ask-user-state";
import { notify } from "@/lib/notifications";
import { forwardReaderAction } from "@/lib/reading-reader-action";
-import { readingTurnFields } from "@/lib/reading-turn-state";
+import {
+ normalizeReadingMaterialId,
+ readingTurnFields,
+} from "@/lib/reading-turn-state";
+import { watchingTurnFields } from "@/lib/watching-turn-state";
+ import { decideIdleTurnRecovery } from "@/lib/chat-idle-recovery";
import i18n from "i18next";
import {
normalizeBookReferences,