Skip to content

chat: compute tool-confirmation carousel max-height during layout - #327933

Closed
Bryan Chen (bryanchen-d) wants to merge 1 commit into
mainfrom
copilot/vscode/oneshot-carousel-max-height
Closed

Bryan Chen (bryanchen-d) wants to merge 1 commit into
mainfrom
copilot/vscode/oneshot-carousel-max-height

Conversation

@bryanchen-d

@bryanchen-d Bryan Chen (bryanchen-d) commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Relates to #316509 (ChatInputPart.containerHeight, bucket b47563cc-656f-baae-0d1c-0996d4838019).

What this is — and is not

updateToolConfirmationCarouselMaxHeight() measures this.container, then writes max-height onto the carousel — a descendant of that container:

const carouselHeight = this.chatToolConfirmationCarouselContainer.offsetHeight;
const otherInputHeight = Math.max(0, this.container.offsetHeight - carouselHeight);
carousel.setMaxHeight(this._maxHeight - otherInputHeight);

Calling that from the container's own ResizeObserver resizes the observed subtree during delivery, forcing another notification pass — the ResizeObserver loop completed with undelivered notifications warning.

4b0aa24 already addressed this by deferring the write to an animation frame, and it works. The probe added here confirms it directly:

Carousel write Warnings
Synchronous (pre-4b0aa247213) 4
Deferred to rAF (current main) 0
Computed in _layout() (this PR) 0

So this is not a behavioural bug fix, and reviewers should not expect it to change error rates. Please weigh it on the two things it actually offers.

1. Ownership

The carousel allocation is a layout decision that depends on a measurement _layout() already performs. Computing it there means the ResizeObserver callback no longer has to schedule layout work at all:

  • the AnimationFrameScheduler goes away;
  • the carousel no longer trails the input by a frame;
  • the callback is reduced to publishing this.height;
  • both consumers of _maxHeight (editor and carousel) are resolved from one measurement pass instead of two mechanisms.

The deferral fixed when the write happens. This fixes who owns it.

2. Regression coverage

The original fix was validated manually (open DevTools, type rapidly). There was no automated test, which is why its effect was never measurable. This adds one.

Why telemetry can't settle this

Worth recording, because it is easy to misread this bucket — I did at first.

The attribution is assigned in DisposableResizeObserver:

_lastInvokedDisposableResizeObserver = this;

That is whichever observer ran last in the observation phase, not the one that caused the loop. The bucket therefore aggregates every RO loop where this observer happened to run last. Consequences:

  • It could not have validated 4b0aa24, and it cannot validate this PR.
  • The bucket remaining active after 4b0aa24 is not evidence that fix failed.
  • Neither change should be expected to move it.

An earlier revision of this description argued from 7.2 → 6.7 hits/user across 1.120 → 1.121 that the deferral "barely helped." That inference was unsound and has been removed.

Separately: hits/user for this bucket jumps from ~4.4 (1.129.x) to ~57.8 (1.130.0 stable, 337,927 users) while ChatListItemRenderer.itemHeight moves the other way (13.6 → 10.5) over the same releases. Given attribution is non-causal I can no longer claim that is a carousel regression, but the asymmetry is real and probably deserves its own investigation.

Verification

  • New ResizeObserverLoopCarouselBudget probe sweeps budgets 560→280, asserting zero warnings and immediate settling.
  • It discriminates. Performing the allocation only from the observer (the pre-deferral shape) makes it fail. A test that cannot fail on the old code proves nothing, so this was checked explicitly.
  • It is not vacuous. The probe first requires the carousel element to exist — an earlier revision silently tested nothing because the fixture starved the list to 0px.
  • Behaviour is unchanged. The allocation series is byte-identical before and after:
    560:232|250 · 500:232|190 · 440:232|130 · 380:232|70 · 320:178|64 · 280:138|64
  • 5/5 playwright resize-observer tests pass; 5154 chat unit tests pass.

Note on #316509

The issue auto-closed as COMPLETED when 4b0aa24 merged. Given the attribution caveat above, closure was never verifiable either way — but the bucket is still among the largest chat error buckets, so it may be worth revisiting on its own terms rather than treating it as resolved.

Copilot AI review requested due to automatic review settings July 28, 2026 23:19

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

Moves carousel height allocation out of the primary container ResizeObserver to reduce loop warnings.

Changes:

  • Performs carousel allocation during input layout.
  • Adds a component-fixture regression probe.
  • Adds Playwright coverage for warnings and settling behavior.
Show a summary per file
File Description
chatInputPart.ts Relocates carousel height allocation.
chatWidget.fixture.ts Adds the carousel budget probe.
chatResizeObserver.spec.ts Tests the probe across height budgets.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 4
  • Review effort level: Medium

Comment on lines +3549 to 3553
// warning (see #316509). It is computed in `_layout()` instead, from
// the same measurement pass that sizes the editor.
const inputResizeObserver = this._register(new dom.DisposableResizeObserver('ChatInputPart.containerHeight', () => {
updateCarouselMaxHeightScheduler.schedule();
const newHeight = this.container.offsetHeight;
this.height.set(newHeight, undefined);
Comment on lines +4577 to +4581
// Allocate the carousel from this same pass, once the editor has been
// sized. Doing it here rather than from the container's ResizeObserver
// keeps the write outside resize delivery, so it cannot force another
// notification pass (see #316509).
this.updateToolConfirmationCarouselMaxHeight();
expect(Number(warningText?.replace('Warnings: ', ''))).toBe(0);
// A one-shot allocation reaches its final value immediately, rather than
// converging over successive frames.
expect(settled).toBe('true');
Comment on lines +769 to +782
/**
* Reproduces the `ChatInputPart.containerHeight` feedback edge.
*
* The input editor and the tool-confirmation carousel share one `_maxHeight`
* budget, and each derives its own allowance by measuring the container and
* subtracting itself — that is, by measuring "everything else", which includes
* the other one. Under a tight budget where both want more than their share,
* each hands back exactly the space the other just released, so the pair never
* settles.
*
* The probe squeezes the budget, then samples the carousel's resolved
* `max-height` and the editor's rendered height once per frame. If allocation
* converges, the tail of that sample series is constant.
*/
@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Base: 54917b34 Current: 4bc0af4d

No screenshot changes.

@bryanchen-d Bryan Chen (bryanchen-d) changed the title fix(chat): allocate the tool-confirmation carousel outside resize delivery chat: compute tool-confirmation carousel max-height during layout Jul 29, 2026
`updateToolConfirmationCarouselMaxHeight()` measures `this.container` and
then writes `max-height` onto the carousel, a descendant of that container.
Calling it from the container's own ResizeObserver resizes the observed
subtree during delivery, which forces another notification pass - the
"ResizeObserver loop completed with undelivered notifications" warning
tracked in #316509.

4b0aa24 already addressed that by deferring the write to an animation
frame, and it works: in the probe added here, restoring the synchronous
write produces warnings and the deferral produces none. This change is
therefore not a behavioural bug fix and is not expected to change error
rates.

What it changes is ownership. The carousel allocation is a layout decision
that depends on a measurement `_layout()` already takes, so computing it
there removes the need for the ResizeObserver callback to schedule layout
work at all: the scheduler goes away, the carousel no longer trails the
input by a frame, and the callback is reduced to publishing `this.height`.
Both consumers of `_maxHeight` are then resolved from one measurement pass
rather than two mechanisms.

The `ChatInputPart.containerHeight` bucket cannot validate either approach.
`DisposableResizeObserver` records attribution as
`_lastInvokedDisposableResizeObserver = this`, i.e. whichever observer ran
last in the observation phase rather than the one that caused the loop, so
the bucket aggregates every loop where this observer happened to run last.

Verification:
- New `ResizeObserverLoopCarouselBudget` probe sweeps budgets 560..280 and
  asserts zero warnings plus immediate settling. It guards against a vacuous
  pass by first requiring the carousel element to exist; an earlier revision
  silently tested nothing because the fixture starved the list to 0px.
- The probe discriminates: performing the allocation only from the observer
  makes it fail.
- The allocation series is byte-identical before and after
  (560:232|250, 500:232|190, 440:232|130, 380:232|70, 320:178|64, 280:138|64),
  so this changes when the value is computed, not what it is.
- 5/5 playwright resize-observer tests pass; 5154 chat unit tests pass.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: aacd276e-cf84-48bd-a2ab-6f6a4d4c3431
@bryanchen-d

Copy link
Copy Markdown
Collaborator Author

Follow-up on the telemetry interpretation in this PR:

The existing DisposableResizeObserver prefix is not causal attribution. It records whichever wrapped observer callback ran last before Chromium dispatched the stackless loop warning. The browser's ErrorEvent exposes only the generic message; the skipped target and causative callback remain internal.

Consequently, the ChatInputPart.containerHeight bucket staying active—or its 1.130 spike—cannot validate or invalidate either the existing rAF deferral or this layout-ownership change. The original deferral does prevent the carousel write from occurring during ResizeObserver delivery, and this PR should be reviewed on the narrower claims now stated in its description:

  1. _layout() should own the carousel allocation instead of a ResizeObserver callback scheduling layout work.
  2. The new browser regression test covers the synchronous pre-deferral failure shape and proves allocation output is unchanged.

I opened #328065 separately to correct the bucket mechanism. It replaces the misleading last-callback prefix with a bounded, deterministic, per-window set explicitly labeled recentWrappedObservers—honest delivery context rather than an "offending component."

I am keeping that telemetry correction separate so this PR does not mix a global bucket-shape change into the chat layout refactor.

@bryanchen-d

Copy link
Copy Markdown
Collaborator Author

Closing after reconsidering the existing deferral and the CCR findings.

The current AnimationFrameScheduler is not merely hiding the warning. It provides the needed invariant: whenever any input chrome change resizes this.container, recalculate the carousel allowance after ResizeObserver delivery has finished. It also coalesces a burst of resize notifications into one calculation.

Moving the calculation solely into _layout() is not equivalent:

  • attachments, working-set expansion/list changes, followups, and other intrinsic chrome mutations can change the container height without calling _layout(), leaving the carousel allowance stale;
  • compact mode calls layout() synchronously from ChatInputPart.compactToolbars, which is itself a ResizeObserver callback, so _layout() is not guaranteed to be outside resize delivery;
  • the regression probe proves that a synchronous descendant write warns and the deferred write does not, but it does not prove every height mutation can be represented as one explicit layout transaction.

So the existing deferral is the safer and more complete fix for #316509. The broader error bucket cannot validate either approach because its current prefix is last-callback delivery order rather than causality; #328065 addresses that separately.

CCR also correctly found two test/documentation gaps, and CI currently fails because the fixture passes an unsupported renderStyle option. Since the product premise is no longer sound, fixing those would not justify keeping this PR open.

Thanks Harald Kirschner (@digitarald) and Copilot Code Review for catching the missing mutation paths and compact-mode re-entry.

@bryanchen-d
Bryan Chen (bryanchen-d) deleted the copilot/vscode/oneshot-carousel-max-height branch August 12, 2026 23:37
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 12, 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.

3 participants