Skip to content

Studio: stabilize floating live monitor geometry - #7579

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
oobabooga:fix/studio-floating-monitor-drag
Jul 29, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
oobabooga:fix/studio-floating-monitor-drag

Conversation

@oobabooga

Copy link
Copy Markdown
Member

The floating Live Monitor had several related geometry bugs caused by combining transform-based dragging with the browser's native resize behavior.

Dragging against the window edges

Problem: Dragging the monitor fully left or right could place it against the window edge instead of keeping the intended 16px margin. Its final position could also depend on when the opening animation finished.

Fix: The monitor now uses a fixed 16px inset surface and explicit top/left coordinates. Dragging clamps its settled dimensions inside that surface instead of relying on a transform.

Resizing before and after moving

Problem: Resizing from the native lower-right grip could appear stuck, shift the card, or grow much more than the pointer moved. Chromium could also remember a resize that was blocked at the window edge, then reveal that hidden size as soon as the monitor was dragged elsewhere.

Fix: The native lower-right resize grip is preserved, but it now operates on stable top/left geometry. The monitor uses its initial rendered size as its minimum and the space from its current position as its maximum. A blocked inline resize is normalized to the size actually being rendered before dragging begins.

Content and window size changes

Problem: GPU rows that appeared after the first system response could be clipped by the initial height. Resizing the window could also leave stale limits or move the monitor outside its inset, especially if the window changed during an active drag.

Fix: The monitor observes both its own size and its inset surface. It reconciles its position and limits when content or viewport dimensions change, rebases any active drag session, and keeps the initial bottom-right anchor until the user moves the monitor. Narrow windows can reduce the preferred width without losing the inset.

Closing and reopening

Problem: Reopening the monitor before its exit animation completed could reuse the previous drag position or native resize dimensions.

Fix: Each reopened monitor gets a fresh geometry instance, while system polling still stops as soon as the overlay is closed.

Verification

  • Reproduced the edge overlap, amplified resize, and blocked-resize jump on main.
  • Confirmed dragging and native resizing remain inside the 16px inset.
  • Confirmed resizing follows the pointer without moving the top-left corner.
  • Confirmed delayed content can grow and shrink without clipping or losing the initial bottom anchor.
  • Confirmed bounds update while a drag is active and while the viewport changes.
  • Confirmed behavior at 1280x900, 500x400, and 260px wide.
  • npm run typecheck
  • npm test
  • npm run build

@oobabooga
oobabooga requested a review from danielhanchen as a code owner July 28, 2026 21:24
@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 4f6798584b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Delayed GPU rows arriving after the first /api/system response were
clipped or briefly pushed outside the inset, because min-height:
min-content and the computed max-height sat on the same element the
ResizeObserver watched. Chromium and WebKit let min-content win, so the
panel grew past the cap and was corrected a frame later (the CI failure:
content growth bottom inset expected 884, got 932). Firefox lets
max-height win, so the panel never resized, the observer never fired and
the cap was never lifted: the VRAM rows stayed hidden for good.

- Move the rows into a flex-1 min-h-0 overflow-y-auto region and observe
  the unclamped content wrapper, so growth is seen even while capped.
- Derive the wanted height from chrome + content instead of the rendered
  box, so top moves up in the same pass and nothing overshoots.
- Replace min-height: min-content with a resolved number clamped to
  maxHeight, keeping the initial size as the minimum.
- Re-measure the natural width when the surface resizes, deferred to
  rAF, so a monitor first opened in a narrow window widens again and
  Firefox does not report an observer loop.
- Point the growth probe at the content region, where a real row renders.

Verified on Chromium, Chrome, Firefox and WebKit across
[Windows, Linux, WSL, macOS] x [NVIDIA, AMD, CPU] payloads.
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for this, the drag, resize, edge clamping and reopen fixes are all solid and I could reproduce every one of the original bugs on main. I pushed one commit on top to fix the content growth path, which is what the red Chat UI jobs were catching.

What was wrong

min-height: min-content and the computed max-height were on the same element that the ResizeObserver watches, and the engines disagree on which one wins:

engine max-height: 50px + min-height: min-content over 200px of content result
Chromium / WebKit 200px, min-content wins panel grows past the cap, then gets corrected a frame later
Firefox 50px, max-height wins panel never resizes, so the observer never fires and the cap is never lifted

That gives two different symptoms on one code path. The monitor's open state is persisted, so on every reload with it open it mounts RAM only and then grows when the first /api/system response lands:

  • Chromium, Chrome and WebKit paint it about 32px below the bottom of the window for roughly two frames. That is exactly the CI failure, content growth bottom inset: expected 884, got 932.
  • Firefox never grows it at all, so 59 to 87px of the VRAM and GGUF inference rows stay hidden permanently, with no scrollbar to recover them.

The same thing happens when a GGUF model loads on a different backend and adds the inference row, and when the Appearance font scale changes while the monitor is open.

What the commit changes

  • Rows move into a flex-1 min-h-0 overflow-y-auto region, and the observer watches the unclamped content wrapper, so growth is visible even while the panel is capped.
  • The wanted height is derived from chrome plus content instead of the rendered box, so top moves up in the same reconcile pass and there is no overshoot frame.
  • min-height: min-content becomes a resolved number clamped to maxHeight. Your "initial rendered size is the minimum" behaviour is kept, without an intrinsic minimum that outranks max-height.
  • The natural width is re-measured when the surface resizes, deferred to requestAnimationFrame. maxWidth is derived from the panel's own position, so while anchored it equals the current width and acts as a floor as well as a ceiling, which meant a monitor first opened in a narrow window could never widen again. Doing that measurement inline made Firefox log ResizeObserver loop completed with undelivered notifications, hence the rAF.
  • One line in the test: the growth probe now goes into the content region via floating-monitor-content, where a real row is actually rendered, rather than being appended to the panel root.

Verification

Chromium, Chrome 147, Firefox and WebKit, against [Windows, Linux, WSL, macOS] x [NVIDIA, AMD, CPU] system payloads including 8 GPUs, Windows ROCm with null VRAM usage, Apple unified memory, a separate Vulkan inference GPU, and MLX. Scenarios covered cold mount then first response, warm mount, late inference row, drag then grow, resize then grow, font scale, long labels, RTL, short viewports down to 120px plus 390x844 and 260x400, viewport round trip, first open in a narrow window, rapid reopen, StrictMode, a 30 mutation observer storm, and device scale factors 1 through 2.

main this PR before after this commit
total 146/172 108/172 172/172
cold mount then first response 60/60 16/60 60/60
warm mount 60/60 60/60 60/60

Your own exercise_floating_monitor_geometry assertions now pass on Chromium, Chrome and Firefox. npm run typecheck, npm test and npm run build are clean, and biome check on the file reports only the complexity warning that was already there before.

Two things worth knowing that are not regressions from this PR:

  • The native lower-right resize grip never engages under WebKit, on main and on this branch alike, so resize behaviour is effectively unverified on Safari. Worth a follow up.
  • Geometry is only exercised in Chromium in CI, since the Firefox and WebKit UI jobs run with STUDIO_UI_PERMISSION_ONLY=1 and exit before this block. That is why the Firefox case was invisible.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 852ace5622

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

const width = Math.min(desiredWidth, constraintsBox.width);
const height = Math.min(desiredHeight, constraintsBox.height);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor the resized height when clamping vertical position

When a user moves the monitor, gives it an explicit native-resize height, and later GPU/inference rows make the natural content taller than that height, this uses desiredHeight rather than the rendered monitorBox.height to calculate maxTop. The content remains scrollable within the user's explicit height, but reconcileGeometry nevertheless moves the panel upward as though it had expanded, leaving an unnecessary gap below it. For panels with monitor.style.height, base this bound on the rendered height so delayed content does not reposition a hand-resized monitor.

Useful? React with 👍 / 👎.

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.

Confirmed and fixed in 6cd4a35. Reproduced it by parking the monitor against the bottom inset, growing it with the native grip to a height between the old and new natural content height, then delivering GPU rows: the panel jumped up 58.5px and left a 19px gap below the inset in Chromium, 58.5px in Firefox. desiredPanelHeight now reports the rendered height when monitor.style.height is set, so a hand-resized panel scrolls and stays put. Gap is 0px in Chromium, Firefox and WebKit after the change.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Jul 29, 2026
@danielhanchen

Copy link
Copy Markdown
Member

The org Chat UI jobs are still sitting in the queue, so I ran the same script end to end on a staging runner against a live Studio. It gets past the assertion that was failing and finishes the whole flow:

[ui] STEP persisted monitor stays dormant on /login and resumes after auth
[ui] OK persisted monitor stayed dormant on /login and resumed after authentication
[ui] OK floating monitor preserves native resize and stays stable across content, drag, and viewport changes
[ui] STEP Shutdown via account menu
[ui] OK 'Unsloth Studio has stopped' placeholder rendered
[ui] OK port closed -- server process is gone
[ui] console.error events: 0 total (0 non-benign)
[ui] PASS comprehensive UI flow

Worth noting the shutdown step and the console error assertion at the end had not been running at all since the geometry failure aborted the script before reaching them. Both pass now.

A panel with an explicit native-resize height scrolls its content rather
than growing, but reconcileGeometry still clamped its position against
the taller natural height, pulling it up and leaving a gap below the
inset. Report the rendered height for such panels, and pull the layout
equality check and the anchor/clamp choice into helpers.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Jul 29, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 6cd4a351f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Jul 29, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Jul 29, 2026
@danielhanchen

Copy link
Copy Markdown
Member

One note so the wall of red does not mislead: every one of the 15 workflow runs on 6cd4a35 came back cancelled, not failed, all at about 7m30s. That was the org-wide queue cull, not this branch. I have re-queued the three Chat UI runs and Frontend CI.

In the meantime the full playwright_chat_ui.py run on a staging runner is green end to end against a live Studio, this time including the first-run "Setup your account" rotation and the post-rotation auth checks:

[ui] OK after CLI rotation: NEW=401, NEW2=200 -- old studio creds dead
[ui] OK persisted monitor stayed dormant on /login and resumed after authentication
[ui] OK floating monitor preserves native resize and stays stable across content, drag, and viewport changes
[ui] OK 'Unsloth Studio has stopped' placeholder rendered
[ui] console.error events: 0 total (0 non-benign)
[ui] PASS comprehensive UI flow

Linux, macOS and Windows all pass on the same tree. Nothing outstanding from my side.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Jul 29, 2026
@danielhanchen
danielhanchen merged commit b144d54 into unslothai:main Jul 29, 2026
2 of 51 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.

2 participants