Skip to content

Fix reasoning text rendering when restoring agent host sessions#312559

Merged
roblourens merged 2 commits intomainfrom
roblou/agents/fix-agent-session-render-order
Apr 25, 2026
Merged

Fix reasoning text rendering when restoring agent host sessions#312559
roblourens merged 2 commits intomainfrom
roblou/agents/fix-agent-session-render-order

Conversation

@roblourens
Copy link
Copy Markdown
Member

When re-opening an agent host session, thinking text rendered all bunched up at the top of the response instead of being properly interspersed with tool calls.

Root cause

The SDK's session.getMessages() history bundles reasoning into each assistant.message as reasoningText, rather than emitting it as a separate event. mapSessionEvents already forwarded reasoningText onto IAgentMessageEvent, but _buildTurnsFromMessages only read content and toolRequests and dropped reasoning entirely. Whatever thinking text users were seeing on resume came from a different path that did not honor stream order, hence the bunching.

Fix

When handling an assistant.message in _buildTurnsFromMessages (and in _buildSubagentTurns), push a Reasoning response part from msg.reasoningText immediately before the Markdown part. Tool calls then naturally interleave because they arrive as separate tool_start / tool_complete events between messages.

This matches the shape the Copilot EH CLI uses for history replay (reasoning + text parts pulled off a single assistant.message).

Added regression tests in agentService.test.ts asserting the response parts come back in the order: reasoning → markdown → tool call → reasoning → markdown.

Also tidied up by introducing a SessionHistoryEvent type alias for the union of events getSessionMessages returns.

(Written by Copilot)

When re-opening an agent host session, thinking text was rendered up
front instead of being properly interspersed with tool calls. The SDK's
`getMessages()` history bundles reasoning into each `assistant.message`
as `reasoningText` rather than emitting it as a separate event.
`_buildTurnsFromMessages` was reading `content` and tool requests but
ignoring `reasoningText` entirely, so reasoning was either dropped or
came from a different code path that did not honor stream order.

Fix: when handling an `assistant.message`, push a Reasoning response
part (from `reasoningText`) immediately before the Markdown part. This
matches the EH CLI's history-replay shape and keeps reasoning, content,
and tool calls interleaved in their original order.

Also applied to subagent inner messages.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 25, 2026 21:16
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

Fixes session restore rendering so assistant “reasoning/thinking” text replays in the correct stream order relative to markdown and tool calls when restoring agent host sessions.

Changes:

  • Introduces SessionHistoryEvent as the canonical event union for IAgent.getSessionMessages() history reconstruction.
  • Updates turn reconstruction to insert ResponsePartKind.Reasoning from IAgentMessageEvent.reasoningText immediately before the markdown part (including subagent turn reconstruction).
  • Adds a regression test asserting reasoning → markdown → tool call ordering on resume.
Show a summary per file
File Description
src/vs/platform/agentHost/common/agentService.ts Adds SessionHistoryEvent and updates IAgent.getSessionMessages() return type.
src/vs/platform/agentHost/node/agentService.ts Replays reasoningText into ResponsePartKind.Reasoning during history-to-turn reconstruction (parent + subagent).
src/vs/platform/agentHost/node/copilot/mapSessionEvents.ts Uses SessionHistoryEvent for mapped history event arrays.
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Updates getMessages() to return SessionHistoryEvent[].
src/vs/platform/agentHost/node/copilot/copilotAgent.ts Updates session message retrieval types to SessionHistoryEvent[].
src/vs/platform/agentHost/test/node/mockAgent.ts Updates mock agent history typing to SessionHistoryEvent[] (note: one implementation still needs updating).
src/vs/platform/agentHost/test/node/agentService.test.ts Adds regression coverage for reasoning/markdown/tool-call ordering on restore.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 1

Comment thread src/vs/platform/agentHost/test/node/mockAgent.ts
@roblourens roblourens changed the title Fix reasoning render order when restoring agent host sessions Fix reasoning text rendering when restoring agent host sessions Apr 25, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens roblourens marked this pull request as ready for review April 25, 2026 21:40
@roblourens roblourens enabled auto-merge (squash) April 25, 2026 21:40
@roblourens roblourens merged commit 3109dfc into main Apr 25, 2026
40 of 41 checks passed
@roblourens roblourens deleted the roblou/agents/fix-agent-session-render-order branch April 25, 2026 23:50
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 25, 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.

3 participants