Scope Agents Window chat input history per session#319345
Conversation
There was a problem hiding this comment.
Pull request overview
Scopes Agents Window chat input history by ISession.sessionId so Up/Down navigation only traverses prompts previously submitted within the same session (and preserves history when a temporary session is replaced by its committed session).
Changes:
- Extended the shared
ChatWidgetHistoryServiceto support per-historyKeyhistories and moving history between keys, and updatedChatHistoryNavigatorto react only to its scoped history. - Wired Agents Window chat inputs to a session-scoped
historyKey(including handling session replacement) via a new sessions workbench contribution and updates to new-session input widgets. - Added unit tests covering scoped separation and history moves, and documented the Agents Window behavior.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/common/widget/chatWidgetHistoryService.test.ts | Adds tests for per-key separation, moving history, and navigator scoping behavior. |
| src/vs/workbench/contrib/chat/common/widget/chatWidgetHistoryService.ts | Adds historyKey support + moveHistory, extends change events, and scopes ChatHistoryNavigator updates. |
| src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts | Exposes setHistoryKey to allow session-scoped history in chat widget inputs. |
| src/vs/sessions/SESSIONS.md | Documents Agents Window chat input history scoping and session replacement behavior. |
| src/vs/sessions/services/sessions/common/sessionsManagement.ts | Adds onDidReplaceSession event to surface provider-driven session replacement. |
| src/vs/sessions/services/sessions/browser/sessionsManagementService.ts | Fires onDidReplaceSession after handling provider session replacement. |
| src/vs/sessions/contrib/chat/browser/sessionsChatHistoryContribution.ts | New contribution that applies session-scoped history keys to chat widgets and moves history on session replacement. |
| src/vs/sessions/contrib/chat/browser/newChatWidget.ts | Passes historyKey (sessionId) into new-session chat input. |
| src/vs/sessions/contrib/chat/browser/newChatInSessionWidget.ts | Passes historyKey (sessionId) into in-session “new chat” input. |
| src/vs/sessions/contrib/chat/browser/newChatInput.ts | Plumbs optional observable historyKey into ChatHistoryNavigator. |
| src/vs/sessions/contrib/chat/browser/chat.contribution.ts | Registers the new history scoping contribution for the Agents Window. |
Copilot's findings
- Files reviewed: 11/11 changed files
- Comments generated: 1
| const store = new DisposableStore(); | ||
| store.add(widget.onDidChangeViewModel(() => this._applyHistoryKeys())); | ||
| this._widgetDisposables.add(store); |
1d52260 to
e4f92ca
Compare
connor4312
left a comment
There was a problem hiding this comment.
I would at least want a setting to turn this back to the old behavior. Not infrequently I send a message to a session and then decide for whatever reason (context size, concurrency, or just giving the same prompt to multiple models to compare them) to actually start a new session with that message or a derivation of that message. A manual copy+paste isn't always sufficient for this as it does not include the attachments like history does.
e4f92ca to
6280c9f
Compare
@connor4312 Fixed in 6280c9f. I added
|
|
|
||
| export const AGENT_SESSIONS_SCOPED_INPUT_HISTORY_SETTING = 'chat.agentSessions.scopedInputHistory'; | ||
|
|
||
| export class SessionsChatHistoryContribution extends Disposable implements IWorkbenchContribution { |
There was a problem hiding this comment.
I'm a bit confused why we need this new contribution
- This applies the session key to inputs parts when the active session changes. But input parts are already well aware of the session they have via the
_inputModelSessionResource, having a service tell them this separately seems to add more moving parts and complexity - Moving history via
moveHistory. But in a world where the history of a chat is per session, do we even need to store history separately? Could we instead just iterate through past user requests to the model to hydrate the history navigator when it's loaded?
There was a problem hiding this comment.
You are right, this was more indirect than needed.
Fixed in f2e50f0. I removed the extra SessionsChatHistoryContribution widget-scanning path and now pass the session id through the normal SessionView -> ChatView flow.
I kept stored history because it preserves full input state, including attachments, and still supports chat.agentSessions.scopedInputHistory: false for the old shared-history behavior.
Pass Agents session ids through the chat view binding path instead of using a workbench contribution to scan chat widgets. Move temporary-session history preservation into the session replacement handler.
f2e50f0 to
1b0fc49
Compare

Fixes #319341
Scopes chat input history by session id, so Up/Down history navigation only shows prompts from the current session.
What Changed
ISession.sessionId.SESSIONS.md.Demo
Before/after video attached below:
Before
wrong.mov
After
correct.mov