Repository navigation
Description
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
Chat normally for several turns.
Occasionally, right after streaming completes, the assistant's reply disappears from the view.
Send another message -> the model responds using only the earliest turn(s) as context.
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:
Context loss:
_get_message_path_syncindeeptutor/services/session/sqlite_store.pybuilds the LLM context by walking theparent_message_idchain 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.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
- DeepTutor Version: 1.5.4
- Operating System: Windows 11
- Python Version: 3.11.15
- Node.js Version: v24.15.0
- Browser (if applicable): Edge
- Related Issues: fix: prevent sending messages while AI is streaming response #674
Activity
ImproveRei0 commentedon Jul 26, 2026
same,seems a new bug in v1.5.4
(I updated the system from v1.51)
fix(chat): mint unique optimistic message ids (#698)
pancacake commentedon Jul 26, 2026
Thanks — the
parent_message_idtable in your report was what made this findable.One root cause is fixed on
dev(2faaef9e). Optimistic rows were minted with-Date.now()atUnifiedChatContext.tsx:349(user row) and:435(assistant placeholder), and those two dispatches are back-to-back — so they routinely landed in the same millisecond and shared one id.reconcileTurnIdskeys its optimistic→persisted remap by id, so whendonearrived both rows collapsed onto the user's persisted id. That reproduces every symptom you described, exactly:parent_message_idbecomes the previous user message (your 168→166, 172→170, 180→178);buildVisiblePaththen sees two children under that id and picks the newer optimistic one, so the reply drops out of view;It surfaced in 1.5.4 (@ImproveRei0's observation is consistent): before
308a0606the client refetched the whole session after each turn, which overwrote the collision. Ids are now minted from a single generator that never repeats.A second, independent path is still open, found by @AmirF194 in #706: the
doneevent carrying the ids is published but never persisted, so a client that reconnects after the turn completed gets a synthesizeddonewith no ids and never reconciles at all. I verified that ordering inturn_runtime.py(the flush at:1724runs before the publish at:1745). Keeping this issue open until that one lands too.release: v1.5.5
JonbinC commentedon Jul 26, 2026
I can reproduce the same main-workspace symptom on an arm64 Docker deployment (DeepTutor
v1.5.1, public HTTPS reverse proxy; the proxy is not involved in the data path).A concrete persisted chain from
data/user/chat_history.dbwas:The UI therefore chose the newer branch
29 -> 31 -> 32and hid the valid earlier reply30, exactly as described in this issue. All four user/assistant messages and both turns were persisted successfully.I applied a local hotfix to the compiled home-chat bundle: for ordinary follow-ups, it now omits
parent_message_identirely and lets the backend auto-append to the latest persisted message. Explicit edit/branch operations still provide a parent id. This prevents the bad branch shape in my deployment.I also found a separate Partner chat UI race (not the main-chat issue): the Partner component starts an async history hydration and unconditionally does an equivalent of
setMessages(history). If the user sends a message before that request resolves, WebSocket events append live messages first, then the stale history response replaces the whole local list. The backend JSONL conversation remains intact. A generation/version guard or merge/dedupe by stable message/turn id is needed there.Happy to provide a small diff, but please note the home-chat issue is already covered by #698; this comment is intended as an independent reproduction plus the Partner-specific related race.
pancacake commentedon Aug 4, 2026
Thanks for your comments~ feel free to check v1.5.9