Fix reasoning text rendering when restoring agent host sessions#312559
Merged
roblourens merged 2 commits intomainfrom Apr 25, 2026
Merged
Fix reasoning text rendering when restoring agent host sessions#312559roblourens merged 2 commits intomainfrom
roblourens merged 2 commits intomainfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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
SessionHistoryEventas the canonical event union forIAgent.getSessionMessages()history reconstruction. - Updates turn reconstruction to insert
ResponsePartKind.ReasoningfromIAgentMessageEvent.reasoningTextimmediately 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
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bhavyaus
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 eachassistant.messageasreasoningText, rather than emitting it as a separate event.mapSessionEventsalready forwardedreasoningTextontoIAgentMessageEvent, but_buildTurnsFromMessagesonly readcontentandtoolRequestsand 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.messagein_buildTurnsFromMessages(and in_buildSubagentTurns), push aReasoningresponse part frommsg.reasoningTextimmediately before theMarkdownpart. Tool calls then naturally interleave because they arrive as separatetool_start/tool_completeevents 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.tsasserting the response parts come back in the order: reasoning → markdown → tool call → reasoning → markdown.Also tidied up by introducing a
SessionHistoryEventtype alias for the union of eventsgetSessionMessagesreturns.(Written by Copilot)