fix: ensure AI Assistant restart clears conversation history (#3261)#3317
fix: ensure AI Assistant restart clears conversation history (#3261)#3317pierreeurope wants to merge 2 commits intokeplergl:masterfrom
Conversation
…l#3261) Signed-off-by: pierreeurope <pierre.europe@pm.me>
be17358 to
a8ee7ef
Compare
There was a problem hiding this comment.
Pull request overview
Fixes an AI Assistant “Restart Chat” bug where the UI resets but subsequent LLM requests still include the prior conversation history, by ensuring both Redux and the assistant library state are cleared before forcing a remount.
Changes:
- Clear Redux
aiAssistant.messageswhen restarting chat. - Invoke the assistant library’s
restartChatto reset internal state. - Defer the remount trigger (
restartKeyincrement) to the next tick to avoid remounting with staleinitialMessages.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Force remount after state has been cleared | ||
| // Use setTimeout to ensure Redux state update has propagated |
There was a problem hiding this comment.
setTimeout schedules a state update that can still fire after AiAssistantComponent unmounts (e.g., when switching to config view or closing the panel), which can trigger React warnings and unnecessary work. Consider storing the timeout id in a ref and clearing it in a useEffect cleanup (or guarding the callback with an isMounted ref) before calling setRestartKey.
There was a problem hiding this comment.
@copilot check if this comment makes sense and if yes, apply changes based on this feedback
Fixes #3261
This PR fixes a bug where clicking "Restart Chat" in the AI Assistant would clear the UI but continue sending the entire previous conversation history to LLM providers in subsequent API calls.
Problem:
The component was remounting (via the
keyprop) before the Redux state update had fully propagated, causinginitialMessagesto still contain the old conversation when the component re-initialized.Solution:
Wrap the
setRestartKeycall in asetTimeout(0)to ensure it executes after the Redux state update has been applied. This guarantees that when the component remounts,aiAssistant?.messagesis already empty.Impact:
The fix is minimal and preserves all existing functionality while correctly resetting the conversation state.