Skip to content

chat: enhance final response rendering with pinning logic and repositioning#293597

Merged
justschen merged 1 commit intomicrosoft:mainfrom
tamuratak:move_last_response_b
Feb 15, 2026
Merged

chat: enhance final response rendering with pinning logic and repositioning#293597
justschen merged 1 commit intomicrosoft:mainfrom
tamuratak:move_last_response_b

Conversation

@tamuratak
Copy link
Contributor

This PR ensures the final answer part is properly detached from the thinking container by enforcing a re-render if it was previously nested within the thought process. Fix #291423

Copilot AI review requested due to automatic review settings February 7, 2026 07:31
Copy link
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 addresses a VS Code Chat rendering issue where the final response content can end up nested inside the “thinking” container (leading to collapsing/cutoff), by forcing a re-render when the final answer markdown is detected inside the thinking DOM and by avoiding pinning behavior for that final answer part.

Changes:

  • Detect the “final answer” markdown part during progressive rendering and avoid pinning/combining it into thinking content.
  • Update diffing to force re-render of the final answer markdown if its rendered DOM is currently inside a .chat-thinking-box.
  • Add a DOM helper to detect whether an existing rendered part is nested under the thinking container.

private renderChatContentDiff(partsToRender: ReadonlyArray<IChatRendererContent | null>, contentForThisTurn: ReadonlyArray<IChatRendererContent>, element: IChatResponseViewModel, elementIndex: number, templateData: IChatListItemTemplate): void {
const renderedParts = templateData.renderedParts ?? [];
templateData.renderedParts = renderedParts;
const lastMarkdownIndex = partsToRender.findLastIndex(part => part?.kind === 'markdownContent');
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastMarkdownIndex is computed from partsToRender, which is the diff array containing many null entries. When the final markdown part is already rendered (so it’s null in the diff) but an earlier markdown part updates in this tick, this will incorrectly treat that earlier part as the “final answer” and disable pinning/combining for it. Compute the last markdown index from the full contentForThisTurn (or pass the lastMarkdownContentIndex from diff(...)) so the final-answer check is stable across ticks.

Suggested change
const lastMarkdownIndex = partsToRender.findLastIndex(part => part?.kind === 'markdownContent');
const lastMarkdownIndex = contentForThisTurn.findLastIndex(part => part.kind === 'markdownContent');

Copilot uses AI. Check for mistakes.
Comment on lines +1385 to +1391
const elementIsComplete = isResponseVM(element) && element.isComplete;
const lastMarkdownContentIndex = contentToRender.findLastIndex(part => part.kind === 'markdownContent');
for (let i = 0; i < contentToRender.length; i++) {
const content = contentToRender[i];
const renderedPart = renderedParts[i];
const isFinalAnswerPart = content.kind === 'markdownContent' && i === lastMarkdownContentIndex && elementIsComplete;

Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s now duplicated “final answer” detection logic (findLastIndex + isFinalAnswerPart) in both renderChatContentDiff and diff. This increases the risk of the two drifting (and producing different pin/detach behavior). Consider extracting a small helper that derives the final-answer markdown index from the full content and reuse it in both places.

Copilot uses AI. Check for mistakes.
Copy link
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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copy link
Collaborator

@justschen justschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking a look!

@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 15, 2026
@justschen justschen enabled auto-merge (squash) February 15, 2026 08:14
@justschen justschen merged commit 6b87182 into microsoft:main Feb 15, 2026
22 of 23 checks passed
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.

Chat final response collapses or is cutoff

4 participants