Repository navigation
chat: refactor input state to be central - #278683
Conversation
- Add a public created `timestamp` on the IChatModel
- Add a started `timestamp` and optional `completedAt` timestamp on
the IChatResponseModel
- Make `isPendingConfirmation<{startedWaitingAt: number}> | undefined`
to encode the time when the response started waiting for confirmation.
- Add a `confirmationAdjustedTimestamp` that can be used to reflect the
duration a chat response was waiting for user input vs working.
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Benjamin Pasero (@bpasero)Matched files:
Johannes Rieken (@jrieken)Matched files:
|
There was a problem hiding this comment.
Pull Request Overview
This PR centralizes chat input state management by moving it from the ChatWidget/ChatInputPart into the ChatModel itself. This enables automatic serialization, restoration, and transfer of input state (attachments, mode, selected model, input text, and cursor selections) when moving chats between different locations (editor, sidebar, panel, window).
Key Changes
- New
InputModelclass: Manages input state as an observable that syncs bidirectionally with the UI - State migration: Updated history service to migrate old
IChatHistoryEntryformat to newIChatModelInputStateformat - Simplified transfer: Removed manual state extraction code in move actions, relying on automatic model serialization
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
chatModel.ts |
Added IInputModel interface, InputModel class, and IChatModelInputState with serialization support |
chatInputPart.ts |
Implemented bidirectional sync between input UI and model, added debouncing for text changes |
chatWidget.ts |
Passes input model reference to input part, simplified getViewState() |
chatViewPane.ts |
Updated to use model's input state instead of manual state passing |
chatEditor.ts |
Removed manual view state management, relying on model's input state |
chatQuick.ts |
Sets empty input state when initializing model |
chatWidgetHistoryService.ts |
Added migration logic from old IChatHistoryEntry to IChatModelInputState |
chatMoveActions.ts |
Simplified move actions by using model's automatic state preservation |
chatExecuteActions.ts |
Updated mode toggle to support session resource lookup |
inlineChatWidget.ts |
Updated to use new input state interface |
chatDynamicVariables.ts |
Updated to read/write contrib state from model's input state |
mainThreadChatAgents2.ts |
Updated session transfer to use model's input state |
modePickerActionItem.ts |
Added session resource to mode picker delegate |
Comments suppressed due to low confidence (2)
src/vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables.ts:51
- [nitpick] Potential race condition: The
onDidChangeViewModelhandler at lines 46-51 attempts to read state fromwidget.viewModel?.model.inputModel.state.get()synchronously. However, when the view model changes, the input model reference might not be set yet in the ChatInputPart (which happens at line 2176 in chatWidget.ts). This could cause the contrib state to not be restored properly. Consider deferring this read or adding a check to ensure the input model is initialized.
this._register(widget.inputEditor.onDidChangeModelContent(e => {
const removed: IDynamicVariable[] = [];
let didChange = false;
// Don't mutate entries in _variables, since they will be returned from the getter
src/vs/workbench/contrib/chat/browser/chatQuick.ts:407
- [nitpick] The
setStatecall at line 406 is clearing theinputTextandselectionsimmediately before callingsetModel, which will sync from the model state. This seems redundant and potentially confusing. If the intention is to ensure the input starts empty for quick chat, this should be done aftersetModelis called, or the comment should explain why this is necessary before model assignment.
| @@ -2182,21 +2267,17 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge | |||
| }; | |||
There was a problem hiding this comment.
[nitpick] The historyKeyFn uses spread operators that don't exclude all fields that should be ignored for history comparison. Specifically, it excludes selectedModel but includes contrib, selections, and inputText which may cause duplicate history entries if these fields differ but the core input is the same. Consider whether selections and contrib should also be excluded from the history key comparison.
|
|
||
| setChatModel(chatModel: IChatModel, state?: IChatViewState) { | ||
| this._chatWidget.setModel(chatModel, { ...state, inputValue: undefined }); | ||
| setChatModel(chatModel: IChatModel) { |
There was a problem hiding this comment.
[nitpick] The setChatModel method is creating a new object with spread operator and then overriding inputText and selections to empty values. This logic seems counterintuitive - if a state is provided, why would we want to clear the input text and selections? This might be intentional for inline chat context, but it should be documented or reconsidered. If the intention is to preserve other state but clear the text, this should be explained in a comment.
| setChatModel(chatModel: IChatModel) { | |
| setChatModel(chatModel: IChatModel) { | |
| // Intentionally clear input text and selections when setting a new chat model. | |
| // This ensures the input area is reset for the new session/context in the inline chat widget. |
| @@ -262,7 +270,7 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { | |||
| this.updateActions(); | |||
| } | |||
There was a problem hiding this comment.
The viewState parameter in loadSession is declared but never used (line 271). The input state should be applied to the model if provided, similar to how it's done in chatViewPane.ts lines 248-250. This parameter should either be removed if not needed, or the input state should be set on the model before calling updateModel.
|
FYI this broke the chat input as the tools were suddenly missing:
Martin Aeschlimann (@aeschli) fixed it with #278761 |
|
Ah, sorry 🙈 I think the change Martin made in that PR is an overall improvement |

This is a big PR that centralizes input state into an aptly named
inputStateon the model. This allows state to be passed around and transferred more completely and consistently.Model, agent, input, and selection is transferred between panel chat, editor chat, and even quick chat, and also in session history and in sessions transferred between workspaces.
More stuff can be cleaned up after #278476 is in because there is still some explicit state passing to make it work with empty sessions.
I also want to do some work on history cleanup/unification. Additionally, this code basically syncs UI state back and forth with the input model, but I want to do a little more work to actually have the model as the point of truth for some of this data. For example, instead of updating your model in the chat picker which triggers and update to save state in the model, instead have the picker take an
IObservable<ChatModel>and emit an event to update the chat model and observe that change.But that should be a less wide-reaching change.
cc roblourens
refs #277318