Merged
Conversation
wenxi-onyx
approved these changes
Jan 12, 2026
Contributor
Greptile OverviewGreptile SummaryWhat ChangedThis PR fixes an edge case bug when editing the first message in a chat session after a browser refresh. The Problem:
The Solution:
Impact:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Frontend
participant Backend as process_message.py
participant DB as Database
Note over Frontend: User edits first message<br/>after browser refresh
Frontend->>Backend: sendMessage(parent_message_id=root_message.id)
Note over Frontend: Frontend now knows<br/>root message ID after refresh
Backend->>DB: get_or_create_root_message()
DB-->>Backend: root_message (id=X, parent=None)
Backend->>DB: create_chat_history_chain()
DB-->>Backend: chat_history[]
alt parent_message_id == AUTO_PLACE_AFTER_LATEST_MESSAGE
Backend->>Backend: parent_message = chat_history[-1] or root_message
else parent_message_id is None OR parent_message_id == root_message.id
Note over Backend: NEW: Added root_message.id check<br/>to handle refresh edge case
Backend->>Backend: parent_message = root_message
Backend->>Backend: chat_history = [] (truncate)
else specific parent_message_id
Backend->>Backend: Find parent in chat_history
Backend->>Backend: Truncate history to parent
end
Backend->>DB: create_new_chat_message(parent=parent_message)
DB-->>Backend: user_message
Backend->>Backend: Continue with LLM loop
Backend-->>Frontend: Stream response
|
jessicasingh7
pushed a commit
that referenced
this pull request
Jan 12, 2026
jessicasingh7
pushed a commit
that referenced
this pull request
Jan 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Edge case bug with editing the first message after having refreshed the browser. Usually with the first message sent, the frontend does not know about the root node. After a refresh though, it passes the root node id to the backend as the parent. Which is fine honestly and the logic should handle that. So added a handling for that.
How Has This Been Tested?
Works for sure
Additional Options
Summary by cubic
Fixes editing the first message after a browser refresh by treating a root-message parent as a root regeneration. If parent_message_id is None or equals the root id, we start from the root and correctly truncate history to prevent misplacement.
Written for commit f7bf612. Summary will update on new commits.