chat: fix last response state stored as active in the session index#288161
chat: fix last response state stored as active in the session index#288161connor4312 merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where chat sessions with active (Pending or NeedsInput) response states were being stored incorrectly in the session index. The fix ensures that when session metadata is persisted, any transient active states (Pending/NeedsInput) are converted to Cancelled state, preventing inconsistent state in persisted data.
Changes:
- Modified
getSessionMetadatafunction to normalize transient response states before storing session metadata
| let lastResponseState = session instanceof ChatModel ? | ||
| (session.lastRequest?.response?.state ?? ResponseModelState.Complete) : | ||
| ResponseModelState.Complete; |
There was a problem hiding this comment.
The conditional expression spans multiple lines making it harder to read. Consider extracting this into a helper function or restructuring for clarity. The same pattern also appears in chatServiceImpl.ts line 361, suggesting an opportunity for shared logic.
| if (lastResponseState === ResponseModelState.Pending || lastResponseState === ResponseModelState.NeedsInput) { | ||
| lastResponseState = ResponseModelState.Cancelled; | ||
| } |
There was a problem hiding this comment.
The state normalization logic (converting Pending/NeedsInput to Cancelled) lacks test coverage. Consider adding tests in chatSessionStore.test.ts that verify sessions with Pending or NeedsInput states are stored with Cancelled state in the session index.
Guard old sessions from Insiders that may have Pending or NeedsInput states, converting them to Complete state for consistency. This ensures proper handling of sessions migrated from pre-PR #288161 versions. - Added check to convert Pending/NeedsInput states to Complete state - Preserves backward compatibility with old session data - Prevents state display issues in migrated sessions (Commit message generated by Copilot)
Guard old sessions from Insiders that may have Pending or NeedsInput states, converting them to Complete state for consistency. This ensures proper handling of sessions migrated from pre-PR #288161 versions. - Added check to convert Pending/NeedsInput states to Complete state - Preserves backward compatibility with old session data - Prevents state display issues in migrated sessions (Commit message generated by Copilot)
No description provided.