Repository navigation
Fix: regenerate chat message does not truncate history - #17087
Conversation
When regenerating an answer, the truncated message list was not always sent to the backend: - Regenerating the first question produced an empty history list, which sendMessage treated as 'not provided' and silently replaced with the full untruncated history. The backend then overwrote the session with the full history plus a duplicated question, so the truncation was never persisted and a browser refresh restored (or grew) the list. - The re-sent question was given a new id while the local question kept the old one, diverging the question/answer pair ids between local state and the persisted session and corrupting later delete/regenerate operations. Keep the original message id when regenerating, always pass the truncated history explicitly (even when empty), and only fall back to derivedMessages when no message list is provided.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRegeneration now preserves message IDs and explicitly sends truncated history. Message submission distinguishes an explicitly empty history from an omitted history, allowing existing conversations to fall back to derived history. ChangesChat history handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes a bug where clicking the regenerate (refresh) button on a chat message did not reliably truncate the conversation. Depending on which message was regenerated, the history was either truncated correctly, fully restored after a browser refresh, or even grew by an extra Q&A pair.
Root causes in the web frontend:
messages.slice(0, 0)), whichsendMessagetreated as "not provided" and silently replaced with the full untruncated history. The backend then overwrote the session (pass_all_history_messages: true) with the full history plus a duplicated question, so the truncation was never persisted and a browser refresh restored (or grew) the message list.uuid()while the local question kept its old id, diverging the question/answer pair ids between local state and the persisted session. Subsequent delete/regenerate operations then acted on stale ids, leaving orphan assistant messages whose corrupted order was later persisted by the next full-history submission.Changes:
useRegenerateMessage: always pass the truncated history explicitly (even when empty) and keep the original message id so pair ids stay consistent between local state and the persisted session.use-send-chat-message.ts: an explicitly provided message list is now authoritative even when empty; thederivedMessagesfallback only applies when no list is provided. Normal sends are unaffected (emptycurrentMessagesis passed asundefined).