-
Notifications
You must be signed in to change notification settings - Fork 228
[dev] [tofikwest] tofik/agent-chat-history-clears-on-close #1964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR SummaryIntroduces ephemeral assistant chat history persistence and UI integration.
Written by Cursor Bugbot for commit 6adab96. This will update automatically on new commits. Configure here. |
Graphite Automations"Auto-assign PRs to Author" took an action on this PR • (01/02/26)1 reviewer was added to this PR based on Mariano Fuentes's automation. |
| role: m.role, | ||
| text, | ||
| createdAt: Date.now(), | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message timestamps reset on every chat load
The save effect always sets createdAt: Date.now() for all messages, overwriting the original timestamps loaded from the server. When the hydration effect completes, it sets lastSavedJsonRef.current to the server's JSON (with original timestamps), then sets isHydratingRef.current = false. The save effect then runs with messages that have new Date.now() timestamps, causing the JSON comparison to fail and triggering an immediate re-save. This means every time a user opens the chat, all historical message timestamps are replaced with the current time, causing progressive data loss without any user action.
Additional Locations (1)
| status: res.status, | ||
| error: res.error, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GET failure allows overwrites causing server data loss
When the GET request for chat history fails (error or non-200 status), the code logs the error but continues execution without returning early. It then sets lastSavedJsonRef.current = "[]" and isHydratingRef.current = false, which allows the save effect to run when the user types new messages. If the user sends a message after a GET failure, the subsequent PUT request will overwrite the server's existing history with only the new message, causing permanent data loss. The error handler needs to return early to prevent saves when the initial load fails.
| return () => { | ||
| controller.abort(); | ||
| }; | ||
| }, [resolvedOrganizationId, setMessages, userId]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Messages sent during hydration are lost from UI
If a user sends a message while the hydration fetch is in progress, the message will be lost from the UI. The sequence is: hydration starts and sets isHydratingRef.current = true, user sends a message via sendMessage, the message is added to the useChat internal state and sent to the AI, then the GET request completes and setMessages(uiMessages) overwrites the state with server history, removing the user's newly sent message. The AI will still process and respond to the message, but the user's original message disappears from the conversation UI, causing a confusing mismatch between the displayed conversation and the AI's response.
|
🎉 This PR is included in version 1.72.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This is an automated pull request to merge tofik/agent-chat-history-clears-on-close into dev.
It was created by the [Auto Pull Request] action.