Skip to content

Agents window: prompt timeline subscribes to every turn's changeset on each session open, and the agent host recomputes all turn diffs each time #348141

Description

Version: VS Code Insiders 1.147.0-insider (54ab794), Linux x64. Agents window, Copilot CLI agent host session, default sessions.chatTimeline.display (gutter).

Steps to reproduce

  1. Have an agent host session with many turns (I used 100 turns, each editing a few files).
  2. Turn on chat.agentHost.ahpJsonlLoggingEnabled so the protocol traffic is visible.
  3. Open the session in the Agents window, switch to another session, then switch back. Repeat.

What happens

Each time the session is shown, the window subscribes to the turn changeset of every prompt: 100 subscribe requests for changeset/turn/<id> within 9-16 ms. After switching away, all 100 are unsubscribed. Switching back subscribes all 100 again.

On each first subscribe, the agent host recomputes that turn's diffs from the session database (computeTurnChangeset), even when nothing changed since the last time. Each turn then sends a snapshot plus statusChanged and contentChanged actions back to the window.

From the AHP log of one run (100 turns, 3 opens):

Subscribe bursts 3 × 100 subscribes, each burst in 9-16 ms, with 2 × 100 unsubscribes in between
Host time to answer all 100 per open 932 ms, 891 ms, 641 ms after the burst (last statusChanged)
Host → window on changeset/turn/* 300 channel/snapshot (106 KB), 300 changeset/contentChanged (73 KB), 300 changeset/statusChanged (69 KB): 247 KB in 900 messages, about 300 messages per open
Status actions in the whole log 102 computing, 212 recomputing, 312 ready

The work grows with the number of prompts. It's repeated on every switch, and it competes with the session's own restore and rendering on the host and in the window.

Expected

Showing a session shouldn't subscribe to and recompute the diffs of every historical turn. At most, it should fetch what's visible, and reuse results for completed turns that haven't changed.

Where it comes from

  • PromptTimelineWidgetContrib._createRail uses model.promptTicks for the gutter rail: one tick per prompt, uncapped.
  • PromptTimelineModel._withDiffStats creates a derived per tick that calls _statForRequests → _diffsForRequest → IChatResponseFileChangesService.getChangesForRequest(...).read(reader).
  • AgentHostResponseFileChangesProvider._createDiffsObservable reads _subscribeChangeset(turnChangesetUri), so each tick holds a turn changeset subscription.
  • On the host, AgentHostChangesetCoordinator.onFirstSubscriber (Turn branch) calls computeTurnChangeset(..., 'fileEditTracker') whenever the session is loaded. onLastSubscriber only drops the subscription. _computeTurnChangeset always marks the changeset computing and recomputes.

The gutter rail uses tick.stat only in the flyout rows: the +N −M badge, the reviewable class and its tab stop, and the diff button's label. The resting dots don't use it. So the stats of all prompts are fetched while the flyout is usually hidden. The ruler rail does draw stat bars, but it uses the capped model.ticks.

Possible directions

  • Read the per-prompt stats only while the gutter flyout is revealed, or provide them from one session-level per-turn summary instead of one changeset subscription per turn.
  • On the host, reuse a Ready turn changeset for a completed turn on resubscribe instead of recomputing it. While a turn is unsubscribed, _onTrackedEditsChanged and onToolCallEditsApplied skip it, so the host would need to mark such turns stale rather than trust the old result.

🤖 Authored with GitHub Copilot on behalf of Benjamin Christopher Simmonds (@benibenj).

Activity

  1. added
    agent-host
    on Nov 13, 2026
  2. sandy081 commented on Nov 20, 2026

    @sandy081
    Member

    This now also affects editor windows. Since #349181 the same gutter is on by default in editor-window chat views and chat editors, so opening a long agent-host chat there subscribes to every turn's changeset. With about 5,000 prompts the agent host stalled for over 20 seconds, dropped the window, and repeated it on reconnect, hanging every chat meanwhile. #349432 turns the timeline off by default as a stopgap.

    Where it comes from:

    Measured in Code - OSS with a mock agent host (per-turn changeset subscribes when the chat opens, with the timeline on): Agents window, 30 prompts: 30. Editor window, 1,001 prompts: 1,001, and another 1,001 when the chat moves into a chat editor. With the timeline off: 4.

    Suggested fix: compute tick.stat only for the flyout rows that are on screen while the flyout is revealed, and release them when it collapses. The ruler needs the same, since each bucketed tick aggregates all of its prompts (46 subscribes for 30 prompts). A prototype with tests is ready to share: the gutter reports its visible rows and the model computes stats only for those. A contrib test mounts a 500-prompt chat and observes 0 prompts while collapsed and only the on-screen rows when revealed.

    Osvaldo Ortega (@osortega) for the timeline, Bhavya U (@bhavyaus) and Karthik Nadig (@karthiknadig) for review. Benjamin Christopher Simmonds (@benibenj) and roblourens: a stat read probably shouldn't need a live per-turn subscription at all, and tearing down and resubscribing thousands of them on reconnect stalls the host.

    Written by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)

  3. added
    important
    freeze-slow-crash-leak
    on Nov 20, 2026
  4. connor4312 commented on Nov 20, 2026

    @connor4312
    Member

    Suggested fix: compute tick.stat only for the flyout rows that are on screen while the flyout is revealed, and release them when it collapses

    mirroring Slack

    I think the right fix without reintroducing subscriptions is the notion of an ‘outline’ of chats. I want to do this anyway for lazy-loading turns; we support paging in of older turns in AHP but it’s just basic pagination with no additional information, so the scroll indicator would not work as it does today.

    I saw Osvaldo opened microsoft/agent-host-protocol#620 yesterday along these lines but haven’t had a chance to digest it yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agent-hostagents-windowfreeze-slow-crash-leakimportantperf

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions