- run(): remove exception text from user-visible error message
- error_diagnosis: remove exc from metadata and ai_confirmation
- RAG retrieval: remove exception detail from warning string
- All exception details now only go to logs with exc_info=True
- Wrap user content in <notebook_records> XML tags for trust boundary
- Strengthen system prompt to explicitly treat tagged content as data
- Sanitize LLM output: strip, truncate to 200 chars, skip names < 2 chars
When LLM evaluation fails in feynman_check, the user's explanation text
is now saved to progress.feynman_explanations[kp_id] instead of being
lost. Cleared on successful evaluation. New field: feynman_explanations.
stage_failure_counts was previously write-only. Now _call_llm_with_degradation
checks cumulative failures at entry — if a stage has failed >= 4 times across
turns, it skips directly without attempting LLM calls. Users can reset via /redo.
- Rename passRate variable to masteryPercent in ModuleTree to match average mastery semantics
- Remove module name requirement from CreateModuleDialog (only KP count matters)
- Sync i18n strings for updated validation message
- Add stage_failure_counts/stage_failure_notes to LearningProgress for persistent failure tracking
- Wrap RAG retrieval with 10s independent timeout in _call_llm_impl
- Add _call_llm_with_timeout (default 60s) and _call_llm_with_degradation (bounded retry + skip)
- Apply degradation to all 12 stage handlers with stage-specific fallback paths
- Extract _run_interactive_quiz_loop shared helper for practice/practice_quiz
- Extract StructuredStageContent component from page.tsx
- Add TypeError to JSON parse except clauses across 7 files
- Simplify _record_attempt_and_update_mastery to single save exit
- Move import logging to module top in service.py
- Replace shared self._call_llm monkeypatch with a contextvars.ContextVar
so concurrent guided-learning turns get isolated RAG warning tracking.
- Extract _call_llm_impl for the raw LLM+RAG logic; _call_llm delegates
to the context-var wrapper when present, avoiding recursion.
- Break the ERROR_DIAGNOSIS ↔ MODULE_TEST loop: when modules are empty
and no active errors remain, advance to COMPLETED instead of cycling.
_call_llm now returns (response, rag_error) tuple. run() wraps it with a
tracking shim that collects warnings into a local list, eliminating shared
mutable _last_rag_error on the singleton capability instance.
_build_question_meta accepts default_kp_id parameter. When LLM omits or
misspells knowledge_point_id, resolved value falls back to kps[0].id
instead of storing empty string.
Codex P2 review items.
fetchProgress catch block logs warning instead of silently swallowing.
Submit button protected by submittingRef to prevent double-sends.
Four hardcoded English strings replaced with i18n keys.
fetchAllProgress adapted to new {summaries, errors} API format.
book/page.tsx updated for new fetchAllProgress return type.
P2-4, P2-5, P2-6
LearningProgress model_config changed from extra="allow" to extra="ignore"
to reject unknown fields (P1-9). All stage handlers now guard against empty
modules to avoid wasted LLM calls (P2-1). list_progress returns
{summaries, errors} instead of silently swallowing load failures (P2-3).
P1-9, P2-1, P2-3
Block A: parse structured JSON from error_diagnosis LLM call and write back
error_type + ai_confirmation to ErrorRecord. Surface RAG retrieval failures
via stream metadata instead of silent warning. Skip LLM call when no active
error records exist.
Block B: request per-question knowledge_point_id from LLM in practice_quiz
and practice stages. Build kp_id_map from LLM response to attribute each
question to its correct KP instead of defaulting all to kps[0].id. Old
format question files with empty kp_id continue to work via fallback.
P1-4, P1-5, P1-10
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.
The per-instance _cas_lock only serialized save_cas on the same
LearningStore instance. save() was unprotected and request handlers
create fresh instances. Moving to a module-level _cas_lock ensures
compare-and-semantics hold across concurrent requests.
Reorder change_module handler: send module_changed first, then cancel
the active turn, then save progress. This ensures the frontend processes
the module switch before receiving any cancellation error, preventing
the UI from getting stuck on a "Turn cancelled" dead end.
The previous check-then-write was not atomic — two concurrent callers
with the same expected_version could both pass the version check and
write, with the last writer silently dropping the first update.
The WS change_module path cancels active turns to prevent stale
progress overwrites, but the HTTP /replace-modules endpoint was
missing this protection. A concurrent turn's finally block could
restore old modules after replacement.
subscribe_session re-checks for a running turn on the server, so if the
turn finishes between check_active_turn and subscribe, the page misses
the terminal done event. subscribe_turn targets the specific turn and
replays its backlog regardless of current status.
Store modulesLength, moduleSelected, currentModuleId in refs synced on
render. connect() reads refs instead of closing over state, keeping the
guard correct without adding those values as useCallback deps — which
would teardown the socket on every progress fetch or module selection.
replace_modules now filters review_queue to remove tasks whose
knowledge points no longer exist, preventing users from receiving
review tasks for deleted content.
Removing modules.length, moduleSelected, and currentModuleId from the
connect dependency array prevents the socket from closing when progress
loads multiple modules with none selected, allowing change_module to
be sent from the module picker.
- Add replace_modules() that cleans stale KP state (mastery, repetition, errors, feynman)
- Rename init_modules to merge_modules, keep alias for backward compat
- Add /replace-modules API endpoint for full module replacement
- Add check_active_turn WS message handler returning turn_id + status
- Frontend sends check_active_turn on connect instead of start_turn
- If active turn exists, subscribe_session to resume; otherwise start_turn
- Add modules.length, moduleSelected, currentModuleId to connect() useCallback deps
- Add version field to LearningProgress and CAS save to LearningStore
- Cancel active turn before change_module (await task completion)
- Clear pending auto-advance timer on module_changed event
Issue 1: Add waitingForLLM state — show spinner with
'Generating diagnostic questions...' text while waiting for LLM
response after WS connect, instead of silent 'Ready to start learning'.
Issue 2: Module picker — when multiple modules exist and none
selected, show module selection cards before auto-connecting WS.
Single-module books still auto-start. ModuleTree clickable after.
Issue 3: Git rm middleware.ts, git add proxy.ts (Next.js 16 compat).
92/92 tests passing.
Issue #2: Add knowledgePointsLabel locale key for standalone label usage
instead of reusing number-suffix key ('个知识点' → '知识点').
Issue #3: Delete 9 empty auto-generated test modules cluttering /learning
page (retain 'default' with 3 modules and 'init3').
Issue #4: Default manual book ID to empty string instead of 'manual'
to avoid leaking implementation detail to users.
Backend: list_progress() derives display name from first module name,
falling back to book_id for empty-module books.
Frontend: ProgressSummary gains 'name' field, card heading uses
card.name || card.book_id instead of raw book_id.
Tests: 2 new negative tests (name from module, empty-module fallback).
92/92 passing.