Skip to content

[Bug]:Assistant replies intermittently disappear from chat; next turn loses context (orphaned branch via stale parent_message_id) #698

Description

@Vincent-LJP

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

In the unified chat workspace, after an assistant reply finishes streaming, the reply sometimes disappears from the conversation view. If I then send another message, the model answers as if it only saw the first turn of the conversation. Switching to another conversation and back makes the missing replies reappear, and subsequent context works again.

Environment

  • DeepTutor version: 1.5.4 (pip install, deeptutor start)
  • OS: Windows 11
  • Browser: Chrome (latest)
  • Deployment: local, single user

Steps to reproduce

  1. Chat normally for several turns.

  2. Occasionally, right after streaming completes, the assistant's reply disappears from the view.

  3. Send another message -> the model responds using only the earliest turn(s) as context.

  4. Switch to another conversation and back -> the full history reappears.

Investigation / likely root cause

I inspected the local data/user/chat_history.db. All messages (user + assistant) are persisted correctly — nothing is lost server-side, and all turns have status = completed.

However, several user messages have parent_message_id pointing to the previous user message instead of the assistant reply that came in between (anonymized real data):

  • msg 168 (user): parent = 166 (previous user msg), expected 167 (the assistant reply in between)

  • msg 172 (user): parent = 170 (previous user msg), expected 171 (the assistant reply in between)

  • msg 180 (user): parent = 178 (previous user msg), expected 179 (the assistant reply in between)

Consequences:

  1. Context loss: _get_message_path_sync in deeptutor/services/session/sqlite_store.py builds the LLM context by walking the parent_message_id chain from the current message. Orphaned assistant replies are excluded — e.g. when msg 168 was sent, the model only saw the first round + the new question.

  2. Display loss: the web UI renders only the active branch, so the orphaned reply is invisible until a full reload (switching conversations) re-fetches the session from the DB.

The frontend sends parentMessageId with each new message (verified in the compiled web bundle), so it appears the frontend sometimes fails to adopt the completed assistant message as the active leaf after streaming finishes, then attaches the next user message to a stale parent — creating an orphan branch.

Expected Behavior

After a turn completes, the assistant reply stays visible and becomes the active leaf; the next user message's parent_message_id points to it.

Related Module

Frontend/Web

Configuration Used

  • Install: pip install deeptutor==1.5.4
    • OS: Windows 11
    • LLM provider/model:
    • Otherwise default settings

Logs and screenshots

No response

Additional Information

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions