Skip to content

fix: exclude synthetic user messages from chat history processing#312018

Merged
DonJayamanne merged 3 commits intomainfrom
don/flaky-canidae
Apr 23, 2026
Merged

fix: exclude synthetic user messages from chat history processing#312018
DonJayamanne merged 3 commits intomainfrom
don/flaky-canidae

Conversation

@DonJayamanne
Copy link
Copy Markdown
Contributor

Co-authored-by: Copilot copilot@github.com

Fixes #310897

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 21:56
@DonJayamanne DonJayamanne self-assigned this Apr 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 1f9cd94d Current: 6175605a

Changed (2)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after
editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after

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

Adjusts Copilot CLI chat-history reconstruction to ignore “synthetic” user.message events (e.g. skill invocations) so the VS Code chat UI doesn’t mis-render or attribute turns incorrectly (fixes #310897).

Changes:

  • Prevent sdkRequestId from being overwritten by subsequent user.message events during a single request.
  • Filter out synthetic user.message events when rebuilding chat turns, including when determining the “last user message”.
  • Introduce isSyntheticUserMessage(...) helper for the filtering logic.
Show a summary per file
File Description
extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSession.ts Keeps the first captured SDK request ID for metadata mapping, avoiding later overwrites.
extensions/copilot/src/extension/chatSessions/copilotcli/common/copilotCLITools.ts Skips synthetic user messages during history building and adds helper used for filtering.

Copilot's findings

Comments suppressed due to low confidence (1)

extensions/copilot/src/extension/chatSessions/copilotcli/common/copilotCLITools.ts:1745

  • isSyntheticUserMessage currently returns true when event.data.source is missing or equals 'user', which will classify normal user messages (including ones emitted by this extension that don't set source) as synthetic. This will cause user turns to be skipped in buildChatHistoryFromEvents and likely break history rendering/tests. Invert the predicate so only explicitly non-user sources (e.g. skill/system) are treated as synthetic, and treat missing/empty source as a regular user message.
export function isSyntheticUserMessage(event: Extract<SessionEvent, { type: 'user.message' }>): boolean {
	return event.type === 'user.message' && (!event.data.source || (event.data.source ?? '').toLowerCase() === 'user');
}
  • Files reviewed: 2/2 changed files
  • Comments generated: 1

@DonJayamanne
Copy link
Copy Markdown
Contributor Author

@copilot fix the test failures in copilotCLITools.spec.ts, copilotCliSessionService.spec.ts

@DonJayamanne DonJayamanne marked this pull request as ready for review April 23, 2026 23:25
@DonJayamanne DonJayamanne enabled auto-merge (squash) April 23, 2026 23:25
@DonJayamanne DonJayamanne merged commit 1cfc083 into main Apr 23, 2026
26 checks passed
@DonJayamanne DonJayamanne deleted the don/flaky-canidae branch April 23, 2026 23:47
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 23, 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.

Bad rendering after skill invocation

3 participants