Skip to content

Insert paragraph separator between Copilot CLI assistant messages#319727

Merged
ulugbekna merged 2 commits into
mainfrom
ulugbekna/agents/investigate-text-spacing-issue
Jun 4, 2026
Merged

Insert paragraph separator between Copilot CLI assistant messages#319727
ulugbekna merged 2 commits into
mainfrom
ulugbekna/agents/investigate-text-spacing-issue

Conversation

@ulugbekna
Copy link
Copy Markdown
Contributor

@ulugbekna ulugbekna commented Jun 3, 2026

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.add

Root 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, prepend stream.markdown('\n\n') before the new content. Streaming deltas that share a messageId are unaffected, so within-message streaming continues to work as before. Emissions without a defined messageId (rare/legacy) keep their current behavior.

The helper is wired into both the assistant.message_delta and assistant.message handlers 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 in copilotcliSession.spec.ts:

  1. Separator inserted between deltas with different messageIds (the bug)
  2. NO separator between deltas with the same messageId (don't break streaming within one message)
  3. Separator inserted between full assistant.message events with different messageIds
    subsequent full message
  4. NO separator before the very first emission

Verified the 3 bug-exercising tests fail on baseline and all 5 pass with the fix.

Verification

  • tsgo -- cleannoEmit
  • 158/159 relevant tests pass; the 1 failure (preserves order of edit toolCallIds and permissions...) is pre-existing on baseline and unrelated.

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>
Copilot AI review requested due to automatic review settings June 3, 2026 12:40
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

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 messageId and emit requestStream.markdown('\n\n') when a new (defined) messageId is observed.
  • Apply the separator logic to both assistant.message_delta and assistant.message handlers.
  • 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>
@ulugbekna ulugbekna merged commit c04dae2 into main Jun 4, 2026
25 checks passed
@ulugbekna ulugbekna deleted the ulugbekna/agents/investigate-text-spacing-issue branch June 4, 2026 08:30
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone 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.
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