Skip to content

fix: clean up Roundtable UI state after QA/Discussion request failure#128

Merged
wyuc merged 3 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/issue-127-error-cleanup
Mar 24, 2026
Merged

fix: clean up Roundtable UI state after QA/Discussion request failure#128
wyuc merged 3 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/issue-127-error-cleanup

Conversation

@YizukiAme
Copy link
Contributor

Summary

Fixes #127 — When /api/chat fails mid-stream during a QA or Discussion session, the Roundtable live UI (bubble, thinking animation, engine mode) is never cleaned up, leaving the interface stuck until page refresh.

Problem

The catch blocks in resumeSession(), sendMessage(), and startDiscussion() only append an error message to the chat panel. They don't notify Stage to clean up live UI state, nor do they transition the PlaybackEngine out of live mode.

This affects users with unstable networks or when the LLM provider returns server errors mid-stream.

Changes

File Change
use-chat-sessions.ts Add clearLiveSessionAfterError() helper that cleans current buffer, appends error message, and notifies Stage via onLiveSessionError callback
chat-area.tsx Pass through onLiveSessionError callback
stage.tsx Add handleLiveSessionError() to reset all live UI state + call engine.handleDiscussionError(). Also add engine.resume() in doResumeTopic() to sync engine mode after soft-pause
engine.ts Add handleDiscussionError() to exit live mode gracefully without triggering the normal discussion-end flash sequence

How it works

Request fails in catch block
  → clearLiveSessionAfterError()
    → append error message to chat
    → onLiveSessionError callback
      → Stage: resetLiveState() (clear bubble, thinking, streaming flags)
      → Engine: handleDiscussionError() (live → idle, restore lecture cursor)

The session is not hard-closed — it remains retryable.

Verification

  • ✅ ESLint: 0 errors on all 4 files
  • ✅ TypeScript: only pre-existing latex-to-omml.ts error (unrelated)

@YizukiAme YizukiAme closed this Mar 19, 2026
@YizukiAme YizukiAme reopened this Mar 19, 2026
wyuc
wyuc previously approved these changes Mar 22, 2026
Copy link
Contributor

@wyuc wyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean refactor. Consolidates the duplicated error handling into clearLiveSessionAfterError and adds the missing Stage/Engine notification. restoreSavedLectureState extraction is a nice cleanup too. LGTM.

@wyuc
Copy link
Contributor

wyuc commented Mar 22, 2026

Approved. There are merge conflicts with main — could you rebase when you get a chance?

…THU-MAIC#127)

When /api/chat fails mid-stream during QA or Discussion, the catch blocks
only appended an error message to the chat panel. The Roundtable live UI
(bubble, thinking animation, engine mode) was never cleaned up, leaving
the interface stuck until page refresh.

Changes:
- Add clearLiveSessionAfterError() in use-chat-sessions.ts that notifies
  Stage via onLiveSessionError callback on request failure
- Add handleLiveSessionError() in stage.tsx to reset all live UI state
  and transition PlaybackEngine back to idle
- Add handleDiscussionError() in engine.ts to exit live mode without
  triggering the normal discussion-end sequence
- Add engine.resume() in doResumeTopic() to sync engine mode after
  soft-pause resume

Closes THU-MAIC#127
@YizukiAme
Copy link
Contributor Author

Approved. There are merge conflicts with main — could you rebase when you get a chance?

Rebased onto latest main — resolved the conflict with #129's livePausedRef (both additions kept, no logical overlap).
Ready for re-review when you get a chance~

@wyuc wyuc merged commit 2841ce6 into THU-MAIC:main Mar 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Roundtable UI state not cleaned up after QA/Discussion request failure

2 participants