Skip to content

Scope Agents Window chat input history per session#319345

Merged
federicobrancasi merged 2 commits into
mainfrom
attachment-chat-attachment-cards
Jun 4, 2026
Merged

Scope Agents Window chat input history per session#319345
federicobrancasi merged 2 commits into
mainfrom
attachment-chat-attachment-cards

Conversation

@federicobrancasi
Copy link
Copy Markdown
Member

@federicobrancasi federicobrancasi commented Jun 1, 2026

Fixes #319341

Scopes chat input history by session id, so Up/Down history navigation only shows prompts from the current session.

What Changed

  • Added scoped history keys to the shared chat widget history service.
  • Updated chat history navigators so they only react to changes for their own location/history scope.
  • Scoped Agents Window chat inputs by ISession.sessionId.
  • Preserved history when a temporary session is replaced by its committed session.
  • Added unit tests for scoped history separation and history moves.
  • Documented the Agents Window history behavior in SESSIONS.md.

Demo

Before/after video attached below:

Before

wrong.mov

After

correct.mov

@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented Jun 1, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@benibenj

Matched files:

  • src/vs/sessions/browser/parts/chatView.ts
  • src/vs/sessions/browser/parts/sessionView.ts

@lszomoru

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsManagementService.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ChatWidgetHistoryService to support per-historyKey histories and moving history between keys, and updated ChatHistoryNavigator to 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

Comment on lines +56 to +58
const store = new DisposableStore();
store.add(widget.onDidChangeViewModel(() => this._applyHistoryKeys()));
this._widgetDisposables.add(store);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Copilot ;)

fixed in 6280c9f

Copy link
Copy Markdown
Member

@connor4312 connor4312 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@federicobrancasi federicobrancasi force-pushed the attachment-chat-attachment-cards branch from e4f92ca to 6280c9f Compare June 1, 2026 15:37
@federicobrancasi
Copy link
Copy Markdown
Member Author

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.

@connor4312 Fixed in 6280c9f.

I added chat.agentSessions.scopedInputHistory: it defaults to true for the new per-session history behavior, and setting it to false restores the old shared input history across Agents Window sessions.

Screenshot 2026-06-01 at 5 36 14 PM


export const AGENT_SESSIONS_SCOPED_INPUT_HISTORY_SETTING = 'chat.agentSessions.scopedInputHistory';

export class SessionsChatHistoryContribution extends Disposable implements IWorkbenchContribution {
Copy link
Copy Markdown
Member

@connor4312 connor4312 Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@federicobrancasi federicobrancasi force-pushed the attachment-chat-attachment-cards branch from f2e50f0 to 1b0fc49 Compare June 4, 2026 11:14
@federicobrancasi federicobrancasi merged commit 2abf948 into main Jun 4, 2026
39 of 40 checks passed
@federicobrancasi federicobrancasi deleted the attachment-chat-attachment-cards branch June 4, 2026 12:15
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents Window chat input history is shared across sessions

3 participants