From 1224036111dda1dec160201bb304d09dfd0841f0 Mon Sep 17 00:00:00 2001 From: unknown <2399365302@qq.com> Date: Wed, 20 May 2026 10:35:11 +0800 Subject: [PATCH] fix: suppress Turn cancelled error during module switch (P1-1) Add moduleSwitchRef set on module_changed, checked in error handler to suppress the "Turn cancelled" error from cancel_turn. Cleared on done so the old turn's auto-advance fires and starts the new module's guided_learning turn. --- web/app/(workspace)/learning/[bookId]/page.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/app/(workspace)/learning/[bookId]/page.tsx b/web/app/(workspace)/learning/[bookId]/page.tsx index 5fc2496b8..80198b655 100644 --- a/web/app/(workspace)/learning/[bookId]/page.tsx +++ b/web/app/(workspace)/learning/[bookId]/page.tsx @@ -33,6 +33,7 @@ export default function LearningBookPage() { const [waitingForLLM, setWaitingForLLM] = useState(false); const [error, setError] = useState(null); const errorRef = useRef(false); + const moduleSwitchRef = useRef(false); const activeTurnRetryRef = useRef(false); const [toast, setToast] = useState(""); const wsRef = useRef(null); @@ -156,6 +157,10 @@ export default function LearningBookPage() { clearTimeout(autoAdvanceTimerRef.current); autoAdvanceTimerRef.current = null; } + // Suppress the "Turn cancelled" error that follows cancel_turn. + moduleSwitchRef.current = true; + errorRef.current = false; + setError(null); const e = evt as unknown as Record; if (e.success !== false) { setCurrentModuleId(typeof e.module_id === "string" ? e.module_id : ""); @@ -241,6 +246,7 @@ export default function LearningBookPage() { fetchProgressRef.current(); } } else if (evt.type === "done") { + moduleSwitchRef.current = false; // Auto-advance after turn completes. // Skip if: terminal "completed" stage exists, any error stage exists, or errorRef is set. const hasCompletedTerminal = stagesRef.current.some(s => s.stage === "completed" && s.status === "completed"); @@ -270,6 +276,10 @@ export default function LearningBookPage() { autoAdvanceTimerRef.current = setTimeout(() => sendContinue(3), 500); } } else if (evt.type === "error") { + // Ignore cancellation errors from the old turn during module switch. + if (moduleSwitchRef.current && evt.content?.includes("cancelled")) { + return; + } setError(evt.content); errorRef.current = true; // Check if this is a recoverable "active turn" error