Skip to content

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

Fix 3 P2 bugs from Codex global review: manual module id collision, stale chapters on book switch, stage not reset on module switch

whfd086a06b90e6
diff --git a/deeptutor/api/routers/unified_ws.py b/deeptutor/api/routers/unified_ws.py
index 524fb82c6..9a7ca7bdc 100644
--- a/deeptutor/api/routers/unified_ws.py
+++ b/deeptutor/api/routers/unified_ws.py
@@ -246,6 +246,7 @@ async def unified_websocket(ws: WebSocket) -> None:
continue
from deeptutor.learning.service import LearningService
from deeptutor.learning.storage import LearningStore
+ from deeptutor.learning.models import LearningStage
store = LearningStore()
service = LearningService(store)
@@ -254,6 +255,7 @@ async def unified_websocket(ws: WebSocket) -> None:
if found:
progress.current_module_id = module_id
progress.current_kp_index = 0
+ progress.current_stage = LearningStage.PRETEST
service.save(progress)
await safe_send({"type": "module_changed", "module_id": module_id, "success": found})
continue
diff --git a/web/components/learning/CreateModuleDialog.tsx b/web/components/learning/CreateModuleDialog.tsx
index 7954ad2df..672649143 100644
--- a/web/components/learning/CreateModuleDialog.tsx
+++ b/web/components/learning/CreateModuleDialog.tsx
@@ -86,6 +86,7 @@ export default function CreateModuleDialog({
// Load chapters when book selected
useEffect(() => {
if (!selectedBookId) { setBookChapters([]); return; }
+ setBookChapters([]);
setLoadingChapters(true);
import("@/lib/book-api").then(({ bookApi }) =>
bookApi.get(selectedBookId)
@@ -136,16 +137,17 @@ export default function CreateModuleDialog({
setError(null);
try {
const bookId = manualBookId.trim() || "manual";
+ const moduleId = `${bookId}_m${Date.now()}`;
const modules: ModuleInit[] = [{
- id: `${bookId}_m0`,
+ id: moduleId,
name: moduleName.trim() || t("guidedLearning.untitledModule"),
order: 0,
pass_threshold: 0.7,
knowledge_points: validKps.map((kp, j) => ({
- id: `${bookId}_m0_kp${j}`,
+ id: `${moduleId}_kp${j}`,
name: kp.name.trim(),
type: kp.type,
- module_id: `${bookId}_m0`,
+ module_id: moduleId,
})),
}];
await initModules(bookId, modules);