Skip to content

fix: defer terminal tool confirmation editor layout to next animation frame (fixes #333221) - #333227

Open
VS Code PR Bot (vscodebot-pr) wants to merge 2 commits into
microsoft:mainfrom
vscodebot-pr:fix/resize-observer-terminal-confirmation-333221-aw-33200593327
Open

VS Code PR Bot (vscodebot-pr) wants to merge 2 commits into
microsoft:mainfrom
vscodebot-pr:fix/resize-observer-terminal-confirmation-333221-aw-33200593327

Conversation

@vscodebot-pr

Copy link
Copy Markdown
Contributor

Summary

ResizeObserver loop completed with undelivered notifications is firing across the chat confirmation surface. The synthetic browser warning carries only non-causal delivery context (ResizeObserverLoopContext(...)) listing the wrapped observers that ran in the same rendering frame — the browser does not expose the actual observer that skipped a delivery. Among the listed observers, the one that synchronously writes layout back into its own observed element is ChatTerminalToolConfirmationSubPart.editor, which calls editor.object.layout(width) inside the resize callback; that write flexes the embedded editor's height back into the observed elements.editor, re-entering the same observation phase and tripping the loop warning under bursty resizes. Impact: noisy unhandled-error telemetry (spike on 1.136.0-insider), no functional break.

Fixes #333221
Recommended reviewer: @bryanchen-d

Culprit Commit

No single culprit commit introduced this regression. The observers named in the bucket context (BaseChatConfirmationWidget.message, BaseChatConfirmationWidget.messageContent, ChatInputPart.containerHeight, ChatTerminalToolConfirmationSubPart.editor, ChatThinkingContentPart.wrapper, ChatToolConfirmationCarouselPart.contentExpansion) all pre-date the 08d4889f...3fcbd108 regression window — a -S search for each name inside the range returns nothing. The [ResizeObserverLoopContext(...)] bucketing format itself was introduced in #328065 (Jul 29), also before the window.

This is the same self-feeding pattern previously fixed for ChatInputPart.containerHeight in #316524 (fixes #316509), recurring in a sibling widget. The spike is best explained by increased exercise of the terminal tool confirmation surface rather than a new triggering commit, so the bug is treated as pre-existing and the fix is applied at the self-feeding write site.

Code Flow

sequenceDiagram
    participant Browser as Browser layout
    participant Observer as ChatTerminalToolConfirmationSubPart.editor observer
    participant Editor as editor.object
    participant Site as elements.editor (observed)

    Browser->>Observer: deliver resize entry (width)
    Note over Observer: ⚠️ Root cause:<br/>synchronous editor.object.layout(width)
    Observer->>Editor: layout(width)
    Editor->>Site: height flexes back into observed element
    Site->>Browser: resize re-entered in same phase
    Note over Browser: 💥 ResizeObserver loop completed<br/>with undelivered notifications
Loading

Affected Files

File Role Evidence
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolConfirmationSubPart.ts root cause / fix L194-L200 (pre-fix): new DisposableResizeObserver('ChatTerminalToolConfirmationSubPart.editor', entries => { ... editor.object.layout(width); }) — synchronous layout write into the observed element
src/vs/base/browser/dom.ts context provider L2169-L2184: getRecentDisposableResizeObserverContextForLoopError — names are delivery context only, "not causal attribution"
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts precedent fix L4022-L4036: prior rAF-deferral fix for the identical pattern (#316524)

Repro Steps

  1. Start a chat session and trigger a terminal tool confirmation so the ChatTerminalToolConfirmationSubPart embedded editor renders.
  2. Rapidly resize the chat panel / window (or stream content that repeatedly changes the editor width) so the editor width observer fires in bursts.
  3. Observe the ResizeObserver loop completed with undelivered notifications warning surface in error telemetry. It is timing-dependent; bursty width changes within a single rendering frame increase the likelihood of the browser skipping a delivery.

How the Fix Works

Chosen approach — In chatTerminalToolConfirmationSubPart.ts, the resize callback no longer calls editor.object.layout(width) synchronously. It records the last observed width and schedules the layout on the next animation frame via an AnimationFrameScheduler (disposed with the part). Deferring the layout write out of the resize-observation phase breaks the self-feeding loop while preserving the resize behavior — the editor still lays out to the observed width, just one frame later. This fixes the problem at the site that produces the feedback write (the self-resizing layout call), not at a crash site or by suppressing the warning, and it reuses the exact pattern already proven for ChatInputPart.containerHeight in #316524.

Alternatives considered — Wrapping the layout call in try/catch was rejected because the warning is delivered as a stackless ErrorEvent on window, not thrown at the call site, so a local catch would not suppress it and would hide nothing useful. Widening or muting the telemetry context in dom.ts was rejected because that helper is intentionally non-causal delivery context and other observers legitimately rely on it.

Recommended Owner

@bryanchen-d — authored the precedent fix #316524 and the ResizeObserver delivery-context telemetry (#328065, #2613d4a naming), owns the chat confirmation widget area, and is the current issue assignee.

Generated by errors-fix · opus48 · 418.4 AIC · ⌖ 12.3 AIC · ⊞ 18.6K · ◷

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Defers terminal confirmation editor layout to prevent self-feeding ResizeObserver warnings.

Changes:

  • Coalesces width updates with AnimationFrameScheduler.
  • Disposes the scheduler with the confirmation subpart.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ondense resize comment to a single line

Co-authored-by: Copilot <[email protected]>
@vs-code-engineering

Copy link
Copy Markdown
Contributor
Driver cycle recordederrors-fix-driver:cycle head:5da7bc8f59e58a77618d8900e124681a7afdbb9d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@vs-code-engineering

Copy link
Copy Markdown
Contributor

Merge conflicts with main block this PR and need a maintainer branch update: this workflow's append-only publishing path cannot publish rebased history, and its push tool prohibits merge commits. The review thread is already resolved and Copilot reviewed the current head, but VS Code PR Check remains in progress.

@vs-code-engineering

Copy link
Copy Markdown
Contributor

Follow-up paused after 40 completed driver attempts; human intervention is required.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants