Insert paragraph separator between Copilot CLI assistant messages#319727
Merged
Conversation
When the CLI emits multiple assistant messages in a single turn, each message arrives as its own `assistant.message_delta` / `assistant.message` event with a distinct `messageId`. The handlers forwarded each event to `stream.markdown(...)` with no separator, so consecutive messages fused into a run-on paragraph (e.g. "...wiring:Now add..."). Track the last emitted `messageId` and prepend `\n\n` whenever the incoming event carries a different (defined) id. Streaming deltas sharing the same `messageId` remain unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes run-on paragraphs in the Agents window when the Copilot CLI emits multiple assistant messages within a single turn by inserting a paragraph separator (\n\n) between distinct assistant message IDs during streaming.
Changes:
- Track the last emitted assistant
messageIdand emitrequestStream.markdown('\n\n')when a new (defined)messageIdis observed. - Apply the separator logic to both
assistant.message_deltaandassistant.messagehandlers. - Add a dedicated test suite covering delta-vs-full message separation behavior.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSession.ts | Adds messageId-based paragraph separator emission for Copilot CLI assistant text streaming. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/test/copilotcliSession.spec.ts | Adds unit tests validating separator insertion (and non-insertion) across message/delta scenarios. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
Addresses Copilot review feedback: lock in that legacy SDK emissions without a defined messageId continue to be concatenated without an inserted separator, rather than producing spurious blank paragraphs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
DonJayamanne
approved these changes
Jun 4, 2026
ulugbekna
added a commit
that referenced
this pull request
Jun 4, 2026
…-vscode-iss-f08ea8e8 Resolve conflicts in copilotcli session + spec: keep MarkdownSegmentSeparator helper version (functionally equivalent to #319727 inline impl). Kept the new 'legacy undefined messageId' test from passes against the helpermain because onSegment(undefined) is a no-op.
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.
Problem
In the Agents window, multiple assistant messages emitted by the Copilot CLI in a single turn fuse into a single run-on paragraph. Notice in the screenshot from the original report:
wiring:Now no space, no paragraph break. Each phase boundary is missing its separator.addRoot cause
more text, or back-to-back the markdown chunks concatenate.phases
Structurally identical to the OpenAI Responses API issue fixed in #312173.
Fix
Track
lastEmittedAssistantMessageId; when the incoming event carries a different (defined)messageId, prependstream.markdown('\n\n')before the new content. Streaming deltas that share amessageIdare unaffected, so within-message streaming continues to work as before. Emissions without a definedmessageId(rare/legacy) keep their current behavior.The helper is wired into both the
assistant.message_deltaandassistant.messagehandlers so the protection holds regardless of whether the SDK is streaming deltas or sending whole messages.Tests
New
describe('assistant message text separation')with 5 cases incopilotcliSession.spec.ts:messageIds (the bug)messageId(don't break streaming within one message)assistant.messageevents with differentmessageIdssubsequent full message
Verified the 3 bug-exercising tests fail on baseline and all 5 pass with the fix.
Verification
tsgo -- cleannoEmitpreserves order of edit toolCallIds and permissions...) is pre-existing on baseline and unrelated.