Skip to content

agentHost: open, navigate, and search long chats on demand - #349287

Draft
Osvaldo Ortega (osortega) wants to merge 2 commits into
mainfrom
agents/can-you-work-on-the-fix
Draft

Osvaldo Ortega (osortega) wants to merge 2 commits into
mainfrom
agents/can-you-work-on-the-fix

Conversation

@osortega

@osortega Osvaldo Ortega (osortega) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Opening a long chat could disconnect the relay before it displayed the first reply. The client now opens at the latest messages (up to ten completed turns, with a byte budget) rather than requesting every reply. The gutter can still list every prompt, and Find can reach older replies. Neither requires downloading the rest of the transcript in the background.

Companion protocol draft: microsoft/agent-host-protocol#620. listChatTurns, readChatTurns, and searchChatTurns are optional reads. They do not move the live subscription. The client uses them only when the chat advertises historyNavigation; without it, Find reports results for loaded messages only.

How to review and test

Use a client and host built from this branch and a remote chat with at least 100 turns retained by the host. Pick a word that appears only in an early reply.

  1. Open at the latest reply. The opening page is bounded; opening the gutter lists prompt previews, not reply bodies.
  2. Select turn 45. It opens with its real neighbors: scrolling forward shows 46, not 90. At the edge of the reading window, the next page starts from the turn on screen. Scroll to Latest returns to the live chat.
  3. While reading 45, a reply arriving from another client should not move you. Sending a new prompt from this widget returns to latest only once the send is accepted. Old rows are read-only; a truncation must not leave a deleted turn in the gutter or Find.
  4. Open Find and search for the word unique to the early reply. Choosing the match should reveal and highlight it without fetching the intervening replies.

Verification

  • Local 100-turn fixture with 45 MiB of retained reply text: the unpaged response was 47,200,941 bytes and rejected by the relay encoder. The opening response contained turns 93–100 in 3,776,205 bytes. The entire title index was 3,929 bytes. A one-turn read returned 45, its successor was 46, and search found the only marker in reply 3 (6,023 bytes of search results across 50 pages).
  • Combined Electron run of the changed test suites: 3,287 passed, 5 pending. Client type-check, scoped lint, and full repository hygiene passed.
  • The 45 MiB check exercised the host queries and relay encoder offline. The new gutter and Find still need a human pass over a live relay, including keyboard and screen-reader testing. A fixture that generates replies only when paging cannot validate host-side Find.

Limits

The transcript remains virtualized. Manually visited neighboring pages are kept until another jump or return to latest; this is not a fixed-size cache. Opening the gutter builds all title rows. Search reports incomplete results if it hits the worker time or concurrency limit. This change does not raise the relay limit or change authentication.

Page older turns on demand so opening a long chat does not exceed the relay message limit. Keep each subscriber's history window independent and preserve the transcript, checkpoints, and pending sends across reconnects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues can start canceled prompts after reauthentication, prevent paginated subagent calls from opening child chats, and leave turns completed during disconnection without restore checkpoints.

3 open issues
What changed in this PR

This PR adds on-demand history paging to Agent Host relay chats, reducing opening payloads that can exceed the relay’s message limit. Local subscriptions continue to load full history.

Changes:

  • Request the latest 10 completed turns over the relay, with subscription-specific cursors and byte-bounded pages.
  • Load older turns through scrolling or keyboard navigation while preserving reading position, focus, and active responses.
  • Update reconnect recovery and checkpoint handling, with regression tests and accessibility guidance.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​common/​chatService/​chatService.test.ts Tests prepending history and reconciling local requests.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​widget/​chatListWidget.test.ts Tests paging gestures, scroll anchoring, and focus preservation.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostChatContribution.test.ts Tests page loading, reconnect history, and checkpoint boundaries.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentHost/​agentHostSnapshotController.test.ts Tests checkpoint prepends during undo and restoration.
src/​vs/​workbench/​contrib/​chat/​common/​model/​chatViewModel.ts Distinguishes historical insertions from new sends.
src/​vs/​workbench/​contrib/​chat/​common/​model/​chatModel.ts Exposes paging and preserves pending edit events during insertions.
src/​vs/​workbench/​contrib/​chat/​common/​chatSessionsService.ts Adds paging and history-ownership contracts.
src/​vs/​workbench/​contrib/​chat/​common/​chatService/​remoteChatSessionRestorer.ts Prepends older history without disrupting live responses.
src/​vs/​workbench/​contrib/​chat/​browser/​widget/​chatWidget.ts Avoids new-send UI effects for historical insertions.
src/​vs/​workbench/​contrib/​chat/​browser/​widget/​chatListWidget.ts Triggers paging from navigation and preserves scroll position.
src/​vs/​workbench/​contrib/​chat/​browser/​remoteAgentHost/​cloudSandboxSessionHandler.ts Forwards paging through cloud-session wrappers.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSnapshotController.ts Adds older checkpoints while preserving undo boundaries.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSessionHandler.ts Coordinates paging, history reconciliation, and safe truncation.
src/​vs/​workbench/​contrib/​chat/​browser/​actions/​chatAccessibilityHelp.ts Documents keyboard navigation for older messages.
src/​vs/​platform/​agentHost/​test/​node/​protocolServerHandler.test.ts Tests cursor isolation, size limits, authorization, and replay.
src/​vs/​platform/​agentHost/​test/​electron-browser/​agentHostProtocolClient.test.ts Tests paged subscriptions and pending-prompt recovery.
src/​vs/​platform/​agentHost/​node/​protocolServerHandler.ts Serves subscription-specific pages and bounded reconnect responses.
src/​vs/​platform/​agentHost/​node/​chatHistoryView.ts Implements cursor tracking and count- and byte-bounded pages.
src/​vs/​platform/​agentHost/​node/​agentHostStateManager.ts Allocates distinct sequence numbers for subscription baselines.
src/​vs/​platform/​agentHost/​common/​state/​agentSubscription.ts Tracks pending starts and checks delivery across history pages.
src/​vs/​platform/​agentHost/​common/​agentService.ts Adds an optional connection API for fetching older turns.
src/​vs/​platform/​agentHost/​browser/​agentHostProtocolClient.ts Requests relay pages and verifies pending sends during recovery.
src/​vs/​platform/​agentHost/​AGENTS.md Documents paging and reconnect invariants.

Review effort: Balanced

Comment on lines +2874 to +2876
for (const { channel, clientSeq, action } of this._subscriptionManager.getPendingActions()) {
if (action.type === ActionType.ChatTurnStarted && (expired.pendingTurns.has(clientSeq) || expired.unsentTurns.has(clientSeq))) {
this.dispatchAction(channel, action, this._clientId, clientSeq);
Comment on lines +854 to +855
const previousIds = reason === 'page' ? new Set(previous.map(turn => turn.id)) : undefined;
const older = previousIds ? window.filter(turn => !previousIds.has(turn.id)) : [];
Comment on lines +3096 to +3101
const older = chatSession.reconcileHistory(chat, turns => turnsToHistory(backendSession, turns, this._config.agentId, this._config.connectionAuthority,
this._createTurnModelLookup(sessionResource, lastTurnModelSelection(state)?.id), this._chatErrorContext(sessionResource),
this._config.connection.initializeResult.get()?.terminalCommandPrefix, this._config.connection.resourceUris,
turn => this._getTurnErrorDetails(sessionResource, turn, allowTurnResume),
turns.at(-1) === chat.turns.at(-1) ? readAgentContextUsage(state, chat.turns.at(-1)?.usage) : undefined,
this._managedPluginRetryTarget(backendSession, chatURI)), reason);
List prompt previews without transferring replies. Open a contiguous, read-only window around a gutter or Find selection while leaving the live chat subscribed. Fall back to the loaded transcript when the host does not advertise history navigation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@osortega Osvaldo Ortega (osortega) changed the title agentHost: load recent chat turns first over the relay agentHost: open, navigate, and search long chats on demand Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 1dedb183 Current: 454a05d1

Changed (15)

editor/inlineChatAffordance/InlineChatAffordance/Light
Before After
before after
editor/inlineCompletions/views/SideBySideViewSmall/Light
Before After
before after
editor/inlineCompletions/views/SideBySideViewWide/Light
Before After
before after
editor/inlineCompletions/views/WordReplacementView/Light
Before After
before after
editor/inlineCompletions/views/LineReplacementView/Light
Before After
before after
editor/multiDiffEditor/loading/IncrementalPending/Light
Before After
before after
editor/multiDiffEditor/loading/IncrementalResolved/Light
Before After
before after
editor/multiDiffEditor/loading/DocumentSwapAfter/Light
Before After
before after
editor/multiDiffEditor/variants/cards/ChatInputChanges/Light
Before After
before after
editor/multiDiffEditor/variants/cards/StickyHorizontalOverflow/Light
Before After
before after
editor/multiDiffEditor/withFileList/WithFileList/Light
Before After
before after
editor/multiDiffEditor/withFileList/WithFileListTree/Light
Before After
before after
editor/multiDiffEditor/withFileList/WithFileListOnLeft/Light
Before After
before after
editor/multiDiff/multiDiffEditorScroll/RealWidget/Light
Before After
before after
peekReference/PeekReferences/Light
Before After
before after

Errored (1)

Fixtures that failed to render — no screenshot was produced.

chat/promptTimelineGutter/promptTimelineGutter/ActivePromptHover/Light — Cannot read properties of undefined (reading 'classList')
TypeError: Cannot read properties of undefined (reading 'classList')
    at Object.renderPromptTimelineGutter [as render] (file:///home/runner/work/vscode/vscode/src/vs/workbench/test/browser/componentFixtures/chat/promptTimelineGutter.fixture.ts:46:13)
    at actualRender (file:///home/runner/work/vscode/vscode/src/vs/workbench/test/browser/componentFixtures/fixtureUtils.ts:1372:29)
    at Object.render (file:///home/runner/work/vscode/vscode/src/vs/workbench/test/browser/componentFixtures/fixtureUtils.ts:1422:5)
    at To.waitForRendering (file:///home/runner/work/vscode/vscode/build/node_modules/.pnpm/@vscode+component-explorer@0.2.1-161/node_modules/@vscode/component-explorer/dist/viewer.js:3683:1)
    at Ss.renderFixture (file:///home/runner/work/vscode/vscode/build/node_modules/.pnpm/@vscode+component-explorer@0.2.1-161/node_modules/@vscode/component-explorer/dist/viewer.js:6904:1)
    at async <anonymous>:329:30

This branch has not been deployed

No deployments
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.

2 participants