Skip to content

Prevent Studio reloads from flashing blank - #9251

Merged
danielhanchen merged 49 commits into
unslothai:mainfrom
oobabooga:fix/studio-reload-content-flash
Aug 23, 2026
Merged

danielhanchen merged 49 commits into
unslothai:mainfrom
oobabooga:fix/studio-reload-content-flash

Conversation

@oobabooga

@oobabooga oobabooga commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Reloading an already-rendered Studio tab visibly tears down the Chat UI before the replacement document is ready:

rendered Chat -> blank document -> Loading... -> replacement Chat

This is not a second Studio navigation. The browser makes one document request, retains the old document until the replacement's first paint, then paints Studio's initially empty client root while the bundle and credential gate start. The existing route fallback arrives later, followed by the real shell.

Before

before-timeline

Fix

Carry the rendered shell across reloads instead of asking the replacement document to reconstruct a lookalike.

The outgoing page listens for pageswap and records a snapshot only when the activation type is reload. The copy is limited to elements that are laid out inside the viewport, stripped of active or embeddable content, capped at 3 MiB, and expires after ten seconds. It lives in tab-scoped session storage, together with the stylesheet URLs and the appearance hooks the outgoing page was styled by, only long enough for the replacement document to consume it.

A parser-blocking head script restores that shell before the replacement document's first paint. It is built inside a closed shadow tree that loads the document's own stylesheets, so it renders identically while staying out of the page tree: the markup duplicates the live shell, and anything that queries the document, the app itself included, would otherwise be unable to tell the copy from the real thing. Because selectors do not cross that boundary, the copy is rooted in an html element carrying the classes and appearance attributes it was styled by, and the design tokens declared through :root are frozen onto it. The host is aria-hidden, inert and pointer-events: none, so the live document underneath keeps taking clicks for as long as the copy is up.

React signals readiness from inside the route's own Suspense boundary, so a lazily loaded page keeps the copy up instead of uncovering Loading..., and the copy is removed two animation frames after that. A five-second fail-open timeout exposes the real document if startup never completes.

Fresh launches, client-side route changes, and non-reload navigations do not create or restore a snapshot. The existing Loading... fallback is unchanged; it is simply covered during a reload by the UI the user was already looking at.

After

after-timeline

Paired evidence

This branch and its merge base were built separately and each driven through five authenticated /chat reloads in Playwright Chromium at 1440x900 with 4x CPU throttling. Every animation frame of the replacement document was classified by what the viewport showed.

build reloads showing an empty viewport empty frames frames showing an uncovered Loading... first painted content
merge base 5 / 5 35 / 501 12 463 to 685 ms
this branch 0 / 5 0 / 554 0 153 to 181 ms

The same run on /images, /video, /audio, /hub and /settings, warm and cold cache, found no frame where the fallback was uncovered and no route where a document query matched the copy as well as the live shell. Comparing every element of the copy against its live counterpart, on color, background, border, font, size, opacity and shadow, leaves 0 differences on /hub and 1 on /chat, a composer box-shadow whose live value is entirely transparent.

Tests

  • Frontend suite: 3,815 passed, 0 failed
  • npm run typecheck
  • npm run build
  • tests/reload-snapshot.test.ts covers reload-only capture, the parser-blocking head placement, removal once the replacement shell is paint-ready, the closed shadow tree and the stylesheets it loads, the html root and frozen tokens the copy is styled through, keeping what a display: contents wrapper renders while still dropping what is offscreen, the appearance carry-over, live field state (and the password value that stays behind), click-through, and dropping the copy's animations rather than pausing them.

@pre-commit-ci
pre-commit-ci Bot requested a review from danielhanchen as a code owner August 19, 2026 04:45
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

The direction is right, but this also reformats an unrelated assert in tests/studio/test_inference_smoke_http_diagnostics.py and leaves a full-viewport overlay with pointer-events auto that can swallow clicks for up to five seconds, and the Chat UI and loaded-models CI jobs are red. Could you narrow it to the reload snapshot alone and make the retained shell fully click-through?

@oobabooga

Copy link
Copy Markdown
Member Author

All three addressed in 2e4481e.

The reformat of tests/studio/test_inference_smoke_http_diagnostics.py came from the pre-commit-ci autofix commit on this branch. That file is back to its main content, so the diff is the reload snapshot and its test again.

The shell is click-through: .reload-snapshot is now pointer-events: none, and a click during the retained window lands on the live document rather than on the copy.

The red Chat UI job was this branch's fault. playwright_extra_ui.py reloads and then waits on textarea[aria-label="Message input"]; the retained copy carries that markup, so the wait returned before the app had rendered anything, and the next step's role query (which skips the aria-hidden copy) found nothing, producing "Compare nav not found" 10 ms into the step. Eleven other page.reload() sites across the studio suites had the same ambiguity, and some of them would have passed against the copy instead of failing. The shell is now built inside a closed shadow tree that loads the document's own stylesheets, so it is invisible to every document query: measured 0 duplicate matches on /chat, /images, /video, /audio, /hub and /settings, warm and cold cache, at 4x and 6x CPU throttling.

The other three red checks were infrastructure rather than code: "Chat UI Tests (banner)" and "Loaded-models indicator" both failed in "Install Playwright browsers", "Chat UI Tests (chat)" was cancelled at "Linux deps", and "Frontend build + bundle sanity" was cancelled at "Install Chromium" after build, typecheck and unit tests had already passed.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Aug 19, 2026
* Give apt one bounded, retrying entry point, and fix the retry that never ran

Two problems, one of them mine.

The retry I added to the Playwright install last round was dead on arrival.
GitHub runs `run:` blocks as `bash -e`, and I wrote the loop as

    timeout --signal=TERM --kill-after=30 480 python -m playwright "$@"
    rc=$?

A bare failing command under -e aborts the step then and there, so the second
attempt never ran. The step exited 124 having printed none of its own warnings --
indistinguishable from the unbounded stall it was meant to replace, which is
exactly how it read on #9251's indicator and banner shards, both dying at 8m05s.
The previous version used `if timeout ...; then` and was exempt from -e; changing
it to read the exit code is what broke it. Reproduced both forms under `bash -e`.

The second is broader. `Linux deps` is a bare `apt-get update && apt-get install`
with no bound at all, and on #9251 it sat on the Azure mirror for 28 minutes. Of
24 apt-invoking steps across 13 workflows, 2 were bounded. An unbounded apt step
is not slow, it is silent: it spends the job's whole budget, GitHub scores the
result as "cancelled" rather than a failure, prints no reason, and skips every
step after it.

.github/scripts/retry-with-apt-lock.sh is now the single definition: per-attempt
timeout, retry, dpkg-lock wait between attempts, and exit codes reported honestly
(124/137 as a stall, anything else as the status it actually returned). It carries
no `set -e` and uses `|| rc=$?`, so it works whatever the caller set. Six paths
exercised locally, including the regression above: called from a `bash -e` step,
both attempts still run.

Sizing respects what this file already learned. The note on ui-smoke's
timeout-minutes records that cutting the JOB budget to 20 turned this same stall
from a slow pass into a red build, because one attempt had nowhere to go. The
retry is what changes that, not a shorter wait: 180s is ~14x the 13 seconds
`Linux deps` takes healthy, so only a mirror that is genuinely gone burns all
three attempts. Every step's worst case fits inside its own bound and every step
bound sits under the job's 30, which stays the final backstop and is deliberately
not tightened.

Listed in the workflow's paths filter, since both apt steps now execute it.

The other 20 unbounded apt steps are left alone: every stall observed so far has
been in this workflow, and converting release workflows unreviewed is a worse
trade than leaving them until one of them actually stalls.

* Bound every apt step in CI, not just the two that were noticed

Three jobs were lost to an unbounded apt step in one day, each in a
different workflow and each reported as "cancelled" with no reason:
Chat UI Tests (chat) at 30m18s, Frontend build at 16m38s inside
playwright install --with-deps, and Source lint at 5m02s on a job whose
whole budget was 5 minutes. None of the three said anything about its
actual subject, and the last was noticed only because someone happened
to open a job that said "cancelled".

Routes the remaining twelve on-runner apt steps through the shared
retry helper, gives each an explicit step timeout, and adds a guard so
the next one cannot be added without one. update and install now go as
a single unit: retrying the install after a stalled update just re-reads
the same broken package list.

playwright install --with-deps counts as an apt step, because that is
what it is. Leaving it out by name is what cost the Frontend build job.

Job budgets were raised where the step's bounded worst case no longer
fit: source-lint 5 to 20, api-smoke 12 to 20, frontend build 20 to 40.
A job timeout is a backstop for the unforeseen; using it as the bound
on a known-flaky step is what turns a diagnosable failure into a silent
one.

Not converted, with reasons recorded in the guard: clean-machine-install-ci
runs apt inside bare containers and WSL with no checkout and deliberately
no sudo, and the two steps where apt is the assertion rather than the
setup.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Aug 19, 2026
#9251's Windows Chat UI run failed with

  [ui-extra] FAIL: Compare nav not found

six milliseconds after the step began. Locator.count() does not wait.
Playwright's auto-waiting covers actions and expectations, not counting,
so the gate was a sample of one instant presented as a question about the
app, and it sampled the instant a reload snapshot overlay was still up.
#9251 paints a cloned overlay over the app and removes it on hydration
(or after 5000ms), which opens a window where the composer is on screen
but not yet in the accessibility tree.

The report was true about that instant and false about the app, and in CI
it is indistinguishable from the menu item having been deleted, which is
the expensive part: it sends the next reader looking for a removed control
that was never removed.

wait_for_first() waits and returns None on timeout, so the callers keep
their present-or-not branch, including the fallback that legitimately
expects a miss and looks under the More submenu. Only a timeout is
swallowed: a closed page still raises rather than being reported as a
missing feature. The failure message now names which of the two controls
never appeared.

This is the first step after load, so it is the one that pays for anything
slowing first paint. It will not be the last change to do that.

Six tests, no browser needed, since a locator is a small protocol. All
four mutants (shortened default, blanket except, raising, waiting on
visible) were reintroduced and confirmed red.
@Imagineer99 Imagineer99 self-assigned this Aug 19, 2026
danielhanchen added a commit that referenced this pull request Aug 19, 2026
* Wait for the Compare nav instead of sampling for it

#9251's Windows Chat UI run failed with

  [ui-extra] FAIL: Compare nav not found

six milliseconds after the step began. Locator.count() does not wait.
Playwright's auto-waiting covers actions and expectations, not counting,
so the gate was a sample of one instant presented as a question about the
app, and it sampled the instant a reload snapshot overlay was still up.
#9251 paints a cloned overlay over the app and removes it on hydration
(or after 5000ms), which opens a window where the composer is on screen
but not yet in the accessibility tree.

The report was true about that instant and false about the app, and in CI
it is indistinguishable from the menu item having been deleted, which is
the expensive part: it sends the next reader looking for a removed control
that was never removed.

wait_for_first() waits and returns None on timeout, so the callers keep
their present-or-not branch, including the fallback that legitimately
expects a miss and looks under the More submenu. Only a timeout is
swallowed: a closed page still raises rather than being reported as a
missing feature. The failure message now names which of the two controls
never appeared.

This is the first step after load, so it is the one that pays for anything
slowing first paint. It will not be the last change to do that.

Six tests, no browser needed, since a locator is a small protocol. All
four mutants (shortened default, blanket except, raising, waiting on
visible) were reintroduced and confirmed red.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from Imagineer99 Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@unslothai unslothai deleted a comment from Imagineer99 Aug 23, 2026
@unslothai unslothai deleted a comment from Imagineer99 Aug 23, 2026
@unslothai unslothai deleted a comment from Imagineer99 Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…hai#9251

capturePixels rasterizes at devicePixelRatio, so an identical page costs
4x on a 2x display and 9x on a 3x one. Measured at 1440x900: a viewport of
full-width media stores 929KB at dpr 1 but passes the 3 MiB cap outright at
dpr 2, and a dense thumbnail grid passes it at dpr 3. The cap then threw the
whole snapshot away and put back the blank flash this exists to remove.

On overflow, drop the materialized pixels and re-serialize before giving up.
The layout survives, which is the point of the copy. Under the cap nothing
changes: dpr 1 still stores all 16 frames.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: db2b940485

ℹ️ 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".

Post-convergence pass. Six of the wordiest blocks lose a line or two each
without losing a why; the rest stay, since they document cross-engine
behavior that is not derivable from the code. Comments only, no code.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The projects import dialog renders importFile.name in a span and the recipe
upload list renders entry.name; neither has a file input in the rendered
tree, and the dialog portals out of any marked ancestor, so both names were
serialized. Reproduced on Chromium, Firefox and WebKit, redacted on all
three after the markers, with the surrounding markup still carried.

The test now asserts per site rather than on the picker alone.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

Captured before/after evidence for this from two isolated installs, one built at the merge base 27e0ff1ab and one at head 4869bb041. Not one Studio with a checkout in between, since install.sh --local builds the frontend from the checked-out tree and swapping branches under a running server just serves the old bundle.

900 ms into a reload of /chat

first paint after reload

Left is the merge base, right is this branch, same instant on both. Facts read off the page at that moment: overlay_present false -> true, overlay_covers_viewport_pct 0 -> 100.

Two controls, so the pair above is not read as more than it is.

Just before the reload, both sides are the same page:

before the reload

And once settled, both sides are the same page again, with overlay_retired true on both, so the copy is taken down rather than left sitting over the app:

settled

Three things a reader should know before quoting these:

  • The app's /assets/*.js are delayed 2500 ms on both sides. On warm loopback the boot window is a few tens of milliseconds, so an undelayed shot is a coin flip, not a photograph. The delay does not cover /reload-snapshot.js, which is parser blocking and only exists on one side, so that side is not being handed a head start.
  • The shot is taken on a timer after commit, not at domcontentloaded. index.html loads the app as <script type="module">, which is deferred and therefore runs before DOMContentLoaded fires, so domcontentloaded already photographs a booted app on both sides.
  • The greeting line rotates per load, so "Ready when you are" against "How can I help?" across a pair is that rotation, not this change.

One thing I expected to move and did not: the client root is empty at that instant on both sides. #root is genuinely blank either way, because the restored shell is a separate div.reload-snapshot painted over it rather than content written into the root.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: b3322c9259

ℹ️ 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

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a370eb67b0

ℹ️ 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".

@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: a370eb67b0

ℹ️ 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".

// <html> element carrying the classes and gate attributes it was styled by,
// plus the marker index.css hangs the shell's own rules off.
var shellRoot = document.createElement("html");
if (fontLoads.length) shellRoot.style.visibility = "hidden";

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 Keep the retained shell visible while fonts load

When a selected imported font is registered, this hides the entire snapshot shell until the font finishes loading or the 250 ms timeout expires. Because the fixed overlay still paints its opaque background, every reload using a custom font shows exactly the blank frame this feature is intended to prevent; render the shell with a fallback font while the imported face loads instead of hiding the whole root.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants