Skip to content

dom: attribute ResizeObserver loop telemetry to DisposableResizeObserver name - #314411

Merged
Bryan Chen (bryanchen-d) merged 10 commits into
mainfrom
brchen/resize-observer-loop-batch
May 6, 2026
Merged

Bryan Chen (bryanchen-d) merged 10 commits into
mainfrom
brchen/resize-observer-loop-batch

Conversation

@bryanchen-d

@bryanchen-d Bryan Chen (bryanchen-d) commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Attribute ResizeObserver loop completed with undelivered notifications. telemetry to the specific DisposableResizeObserver that most recently ran. Every DisposableResizeObserver now requires a stable name ("<ClassName>.<purpose>"); on the telemetry side, when the loop warning surfaces we prefix both msg and callstack with that name so the bucket splits by offender instead of pooling everything into one opaque bucket.

Motivation

ResizeObserver loop completed with undelivered notifications. has been the #1 error bucket since v1.106 (#293359). Chromium fires it on window.onerror whenever any ResizeObserver callback writes to layout in a way the browser couldn't fully drain in the same frame.

Because the warning carries no useful stack (<no error message> from a synthetic ErrorEvent), every offender — chat row height, KaTeX, find-widget, terminal tool progress, plan review, etc. — collapses into one bucket. We can't tell which observer is the dominant source, so we can't fix it.

What changed

DisposableResizeObserver (src/vs/base/browser/dom.ts)

  • New required name: string first constructor parameter. Convention: "<ClassName>.<purpose>". Stable across releases (does not embed line numbers or call-site stacks).
  • Wrapper records _lastInvokedDisposableResizeObserver = this immediately before invoking the user callback, inside a try/catch that routes thrown errors to onUnexpectedError (so one bad consumer can't break delivery for every other observer in the realm).
  • New exported helper getRecentDisposableResizeObserverAttributionForLoopError(message) returns [DisposableResizeObserver(<name>)] <message> when the message matches the loop warning, otherwise undefined.
  • Optional targetWindow + { resizeObserverCtor } constructor options preserved (the latter exists for tests).

BrowserErrorTelemetry (src/vs/platform/telemetry/browser/errorTelemetry.ts)

In _onUncaughtError, after the existing err.stack handling, call the helper above. If it returns a string we overwrite both data.msg and data.callstack with the prefixed value so the telemetry bucket key carries the offending observer's name.

Convert remaining raw new ResizeObserver(...) sites

So every observer gets a stable name and the same attribution path:

  • chatMarkdownContentPart (KaTeX layout participants) → ChatMarkdownContentPart.mathLayout
  • chatTerminalToolProgressPart → ChatTerminalToolProgressPart.handleResize
  • browserEditorFindFeature → BrowserEditorFindFeature.heightChange (passes getWindow(container) to preserve aux-window realm)

Name every existing call site

All 17 production DisposableResizeObserver constructions now pass a stable name:

File Name
chatCompositeBar.ts ChatCompositeBar.activeTabReveal
browserEditorFindFeature.ts BrowserEditorFindFeature.heightChange
aiCustomizationWelcomePagePromptLaunchers.ts AICustomizationWelcomePagePromptLaunchers.scrollable
chatListRenderer.ts ChatListItemRenderer.itemHeight
chatInputPart.ts ChatInputPart.containerHeight, ChatInputPart.compactToolbars
chatConfirmationWidget.ts BaseSimpleChatConfirmationWidget.message (+3 siblings)
chatMarkdownContentPart.ts ChatMarkdownContentPart.mathLayout
chatPlanReviewPart.ts ChatPlanReviewPart.messageScrollable
chatQuestionCarouselPart.ts ChatQuestionCarouselPart.inputScrollable
chatSubagentContentPart.ts ChatSubagentContentPart.layout
chatThinkingContentPart.ts ChatThinkingContentPart.child, ChatThinkingContentPart.wrapper
chatToolConfirmationCarouselPart.ts ChatToolConfirmationCarouselPart.contentExpansion
chatTerminalToolProgressPart.ts ChatTerminalToolProgressPart.handleResize

Why this approach

Earlier iterations explored capturing a creation stack and matching it to the loop warning. Two problems:

  1. Stacks are large and change across releases — they're useless as a bucket key.
  2. The actual offender at fire time is the observer whose callback most recently wrote to layout, not necessarily the one that constructed last.

A stable, hand-assigned name is small, version-stable, and grouped by intent. Recording _lastInvokedDisposableResizeObserver right before invoking the callback gives us a precise "who fired most recently" pointer that survives into the synchronous window.onerror handler.

This is a diagnostic change, not a behavioural fix — it does not by itself reduce the loop-warning rate. It unblocks the next step: with attribution per observer we can see which one dominates the bucket and target that fix specifically (the chat-row height feedback loop is the prime suspect).

Refs

#293359 (top error bucket since v1.106)

Test plan

  • New unit tests in src/vs/base/test/browser/dom.test.ts cover constructor, dispose, throwing-callback routing, name exposure, and the attribution helper for both matching and non-matching messages.
  • Manual: provoke a ResizeObserver loop in chat; telemetry payload now contains [DisposableResizeObserver(<name>)] ResizeObserver loop completed with undelivered notifications. in both msg and callstack.

Wrap the user callback of DisposableResizeObserver with
scheduleAtNextAnimationFrame so layout writes done by the callback
(scanDomNode, KaTeX layout, height assignments, ...) land in the next
layout pass instead of re-entering the current one. Also coalesce
multiple deliveries within a frame into a single callback invocation.

This fixes the root cause of the "ResizeObserver loop completed with
undelivered notifications" warning that has been the top error bucket
since v1.106 (#293359 - 54M hits / 2.5M users). The warning is benign
on its own (Chromium just defers the leftover entries to the next
frame), but every occurrence costs an extra layout pass per frame on
the affected element. With chat streaming UI (thinking, tool
confirmations, plan review, KaTeX) all observing simultaneously, this
adds up to several extra layout passes per streamed token on slow
machines.

Also accept an optional targetWindow so observers created for elements
in an auxiliary window use that window's ResizeObserver constructor and
animation-frame timer.

Convert the three remaining raw `new ResizeObserver(...)` sites to use
the wrapper so they inherit the batching + disposable lifetime:
- chatMarkdownContentPart (KaTeX layout participants)
- chatTerminalToolProgressPart (terminal output resize)
- browserEditorFindFeature (find widget height tracking - now passes
  getWindow(container) to preserve aux-window correctness)

Refs #293359
Copilot AI review requested due to automatic review settings May 5, 2026 16:19
@github-actions

github-actions Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Base: c17280fc Current: 1c644ff5

No screenshot changes.

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

This PR updates the shared browser DOM resize-observer wrapper to defer callbacks to the next animation frame, then migrates a few chat/browser-view call sites to that wrapper so resize-driven layout work no longer runs inside the native ResizeObserver delivery phase.

Changes:

  • Reworks DisposableResizeObserver in src/vs/base/browser/dom.ts to batch deliveries per frame, defer callbacks with scheduleAtNextAnimationFrame, and support an explicit target window.
  • Converts chat markdown, chat terminal tool progress, and browser find-widget resize handling to use the shared disposable wrapper.
  • Aligns the browser find widget with auxiliary-window handling by passing the container window into the wrapper.
Show a summary per file
File Description
src/vs/base/browser/dom.ts Adds deferred/batched DisposableResizeObserver behavior and target-window support.
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownContentPart.ts Switches KaTeX/layout participant resize handling to the shared wrapper.
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.ts Switches terminal output section resize handling to the shared wrapper.
src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorFindFeature.ts Replaces the raw observer with the shared wrapper and preserves the container window realm.

Copilot's findings

Comments suppressed due to low confidence (1)

src/vs/base/browser/dom.ts:2084

  • Concatenating every native delivery into one batch changes the callback contract in a breaking way: existing DisposableResizeObserver consumers still assume entries[0] is the current size for the target (for example chatListRenderer.ts:639-642 and chatThinkingContentPart.ts:566-571). If the same element resizes twice before the rAF runs, entries[0] stays the oldest record, so we can cache/fire a stale height and never observe the final one. The coalescing here needs to keep the latest entry per target instead of appending historical entries.
			if (this.pendingEntries) {
				this.pendingEntries.push(...entries);
				return;
			}
			this.pendingEntries = entries.slice();
  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread src/vs/base/browser/dom.ts Resolved
Addresses Copilot review feedback on #314411 — covers rAF deferral, per-frame coalescing, cancel-on-dispose, and reschedule-after-frame.
@vs-code-engineering

vs-code-engineering Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Kyle Cutler (@kycutler)

Matched files:

  • src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorFindFeature.ts

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorFindFeature.ts

@jruales

Copy link
Copy Markdown
Contributor

The change in Integrated Browser related file browserEditorFindFeature.ts looks good to me

@mjbvz Matt Bierner (mjbvz) 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.

Change looks ok but the tests shouldn't be adding more any casts or needing to modify global objects

Comment thread src/vs/base/test/browser/dom.test.ts Resolved
Addresses @mjbvz review on #314411 — drops the global mutation and any-casts in the DisposableResizeObserver test suite by adding an optional resizeObserverCtor parameter (DI). Also addresses Copilot's coalescing finding: per-target latest-wins so consumers reading entries[0] always see the freshest size.
…tions

Records the rule that arose from review on #314411: don't mutate globals or use any-casts to install fakes in tests; inject the dependency via an optional constructor parameter.
…ution

Reverts the rAF deferral and per-frame coalescing introduced earlier in this PR. Behavior is now identical to the pre-PR sync wrapper, plus:

- targetWindow parameter (preserved) for aux-window correctness.

- try/catch around the user callback so a single bad consumer cannot kill delivery for every other observer in the realm.

- name + creationStack capture, plus a one-shot window 'error' listener that prints which DisposableResizeObservers' callbacks ran in the same task whenever the 'ResizeObserver loop completed with undelivered notifications' warning fires. The browser dispatches that warning as an ErrorEvent (not a thrown exception, error is null), so a try/catch around the callback cannot capture it; we use addEventListener('error', ...).

- resizeObserverCtor option for tests (DI seam, replaces global mutation in the test suite).
…r name

Replace the previous suspect-set + window error listener attribution with
a simpler design:

- DisposableResizeObserver now takes a required `name: string` as its first
  constructor parameter. Drop the per-instance creation stack capture
  (callstacks change across releases and bloat telemetry).
- Track the most recently invoked observer in a module-level slot and
  expose `getRecentDisposableResizeObserverAttributionForLoopError(msg)`
  which, for the stackless `ResizeObserver loop completed with undelivered
  notifications` warning, returns
  `[DisposableResizeObserver(<name>)] <msg>`.
- Browser ErrorTelemetry uses the helper to prefix both `msg` and
  `callstack` so the telemetry bucket carries the offending observer's
  name instead of just the generic warning.
- Name all 17 production sites with `<ClassName>.<purpose>` (e.g.
  ChatListItemRenderer.itemHeight, ChatInputPart.containerHeight).

Refs #293359.
@bryanchen-d Bryan Chen (bryanchen-d) changed the title dom: batch DisposableResizeObserver via rAF + convert raw call sites dom: attribute ResizeObserver loop telemetry to DisposableResizeObserver name May 6, 2026
@bryanchen-d
Bryan Chen (bryanchen-d) marked this pull request as draft May 6, 2026 16:29
@bryanchen-d
Bryan Chen (bryanchen-d) force-pushed the brchen/resize-observer-loop-batch branch from 634b089 to 0c4d442 Compare May 6, 2026 16:38
…microtask

The slot is set just before the user callback runs and cleared by a microtask in the same step, so the attribution helper only returns a name when the loop warning fires in the same task as the offending observer's callback. Unrelated errors fired later in the renderer no longer inherit a stale observer name.
…setTimeout(0)

queueMicrotask clears the slot too eagerly: Chromium runs a microtask checkpoint after each ResizeObserver callback returns, which is *before* the synthetic 'ResizeObserver loop completed with undelivered notifications' error fires at the end of the observation phase. A 0-ms timer runs after the entire current task (callbacks + loop-error dispatch) completes, so the slot is still set when window.onerror picks it up, while still being cleared before any unrelated error in the next task can inherit a stale name. Verified by hand in Code-OSS DevTools.
@bryanchen-d
Bryan Chen (bryanchen-d) marked this pull request as ready for review May 6, 2026 18:52

@roblourens roblourens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good idea, seems fine. I just wonder whether there's a chance that multiple observers would run within that window though. Seems like it would be usually correct though.

@bryanchen-d
Bryan Chen (bryanchen-d) merged commit 3d58420 into main May 6, 2026
40 of 41 checks passed
@bryanchen-d
Bryan Chen (bryanchen-d) deleted the brchen/resize-observer-loop-batch branch May 6, 2026 19:55
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone May 6, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jun 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants