Skip to content

Studio: trim idle polling of training downloads and engine status - #18871

Merged
danielhanchen merged 5 commits into
mainfrom
perf/r37-idle-poll-trims
Nov 23, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
perf/r37-idle-poll-trims

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Two polls run in every Studio tab on every route, because DownloadManagerPanel is mounted by the app shell, and both keep going while the tab is hidden.

  • useTrainingDownloads re-arms GET /api/hub/active-downloads every 1.5 s forever, with no visibility check. That is about 39 requests per minute per tab, visible or hidden, even when nothing is training.
  • The panel's background useEngines(enabled, true) calls GET /api/engines every 30 s, hidden or not. On the backend, every call prices an install of each engine that is not installed and current: it parses the ~380 KB lock, hashes it with SHA-256, walks torch's dependency metadata and parses about 100 package specs. On an idle chat with a model loaded, the run-settings engine picker also polls this route every 3 s while the tab is visible, so the pricing runs about 22 times a minute.

Change

  • features/hub/download-manager/visibility-poll.ts (new): one self-rearming poll chain. A delay(hidden) callback spaces the runs, null parks a hidden tab, and showing the tab refreshes right away. restart() replaces a run that is still in flight, so an auth reset never leaves two timers armed. refresh() joins a run that is already in flight.
  • use-training-downloads.tsx: polls every 1.5 s while visible and every HIDDEN_POLL_INTERVAL_MS (10 s, the regular download manager's hidden interval) while hidden, and polls as soon as the tab is shown. Auth reset, the storage listener and dispose behave as before.
  • use-engines.ts and engine-poll-delay.ts: the background caller parks while the tab is hidden and refreshes when it is shown. Foreground callers (pickers, Settings, the offer dialog) keep their 3 s / 1 s / hidden 30 s timer and get no extra refresh on show.
  • core/inference/engine_install.py: download_bytes reuses the priced plan (lock sizes plus the names Studio provides). The cache key is the lock path and its stat identity (mtime, ctime, size, inode), the compat file's identity, the same site-packages mtime key _studio_packages uses, Studio's package versions (including torch), the engine profile and the interpreter version. Any engine job state change, remove and rollback clear it. The install itself still calls install_plan fresh.

Nothing changes in the UI while the tab is visible. A training download that is still running at the next hidden poll gets adopted while hidden, as before, and shows the same panel row and toast when the tab comes back. One case narrows: /api/hub/active-downloads only lists running jobs, so a training download that starts and fails within one hidden interval (10 s, was 1.5 s) is never seen by a hidden tab, and its error row does not appear in the panel on return. The training page still reports the failure itself.

Results

Production build, headless Chromium, /api stubbed, idle on a chat for 5 minutes visible and then 5 minutes hidden. Three runs per arm, requests per minute:

endpoint base visible head visible base hidden head hidden
/api/hub/active-downloads 39.4 / 39.6 / 39.4 39.4 / 39.2 / 39.4 39.2 / 39.2 / 38.8 5.8 / 6.0 / 6.0
/api/engines 21.8 / 22.0 / 22.0 22.0 / 22.0 / 22.0 4.0 / 4.0 / 4.0 2.0 / 2.2 / 2.2
all /api 80.0 / 80.4 / 80.4 80.2 / 80.0 / 80.4 43.4 / 43.4 / 43.0 8.0 / 8.4 / 8.4

A hidden tab drops from about 43 to about 8 requests per minute. Visible traffic is unchanged. The spread between the three base runs is at most 0.4 per minute.

Backend cost of one warm GET /api/engines (engine_install.status for both engines, the same calls the route makes), on Linux with CUDA, neither engine installed, median of 30 calls, two process runs per arm:

state base CPU head CPU base wall head wall
hardware detection complete (a running backend) 64.8 / 71.4 ms 8.1 / 9.9 ms 107 / 113 ms 8.7 / 10.7 ms
before hardware detection 128.2 / 118.6 ms 46.3 / 42.4 ms 146 / 150 ms 73 / 45 ms

download_bytes returns the same values on both arms (vLLM 4,858,571,804, SGLang 4,027,350,437).

Training download adopted while hidden: a training job appears 5 s after the tab is hidden, runs for 25 s, ends as released (idle) or error, and the tab is shown 20 s later. The panel and toast sequence is the same on both arms: the row and the "Preparing ..." toast appear while hidden, and when the tab is shown the row either clears (released) or shows the error for 12 s, with the toast dismissed.

Tests

  • studio/frontend/tests/idle-visibility-poll.test.ts (new, 8 tests, fails on main, which has no hidden interval or visibility refresh): hidden interval and catch-up on show, a single armed timer when the tab is shown during an in-flight poll, an auth reset replacing an in-flight poll, a stale-session poll ending the chain until the next reset, dispose during an in-flight poll, the background engines poll parking while hidden, and the foreground cadence staying the same.
  • studio/backend/tests/test_engine_status_price_memo.py (new, 5 tests, fails on main): repeated status polls price the plan once, a change in Studio's packages reprices, job state changes and remove clear the cache while progress updates keep it, a rewritten lock reprices, and the install path never reads the cache.
  • Frontend: the 83 existing test files that touch the download manager or engines give 1024 passed on base and 1024 passed plus the 8 new ones on head. npm run typecheck is clean.
  • Backend: test_managed_engines.py, test_managed_engines_rocm.py, test_engine_status_stays_cold.py, test_engine_install_uv_lookup.py, test_engine_atomic_json.py, test_wsl_host.py and test_managed_engine_offer.py. The same three ROCm tests fail on both arms (test_amd_refuses_4_bit_before_unloading, test_amd_refuses_a_gpu_device_ordinal_mask, test_a_rollback_never_crosses_gpu_platforms), so they were already failing. test_installer_publishes_bounded_output_before_exit is timing sensitive on a loaded host: across reruns it passed 4 of 4 on head and failed 1 of 4 on base.

Follow-up commits

  • _pins now parses each lock once per file identity (mtime, ctime, size, inode). download_bytes still re-parsed the ~380 KB lock on every status poll through flashinfer_kernel_wheel, outside the priced-plan memo. Cached vLLM download_bytes, median of 30 calls, ABAB on a loaded host (ratios only): base 58 / 57 ms, head 11 / 14 ms (was about 21 ms before this commit); SGLang base 52 / 47 ms, head 11 / 10 ms. Byte values unchanged on both arms. New test test_lock_pins_parse_once_per_file_identity.
  • Dropped a redundant price reset at the start of remove and trimmed comments that restated the code.

Re-measured on real Studio installs

Base and head Studio installs, idle chat tab, 2 minutes visible then 2 minutes hidden, ABAB, requests per minute:

arm visible active-downloads visible all /api hidden active-downloads hidden engines hidden all /api
base 1 / 2 40.0 / 39.5 80.5 / 80.5 39.5 / 39.5 2.0 / 2.0 41.5 / 41.5
head 1 / 2 39.5 / 39.5 81.0 / 76.0 6.0 / 6.0 0.5 / 0.5 6.5 / 6.5

Studio regression switchboard (auth, settings, model picker, inference settings, crawl, upstream CI, diffusion imports): no regression, no UI change. Cross-platform staging (Linux, macOS, Windows): green.

The global training download discovery re-armed a 1.5 s GET /api/hub/active-downloads
forever, visible or hidden, in every tab. A hidden tab now waits HIDDEN_POLL_INTERVAL_MS
(10 s, the regular download manager's hidden pace) and polls at once when shown.

The download panel's background GET /api/engines poll parks while the tab is hidden and
refreshes when it is shown. Foreground engine pickers keep their cadence.

GET /api/engines priced an install of every engine on each call (lock parse, SHA-256,
torch metadata walk, spec parsing). The priced plan is now reused until the lock file,
Studio's site-packages, Studio's package versions or the engine profile change, and is
dropped on any engine job state change, removal or rollback. The install path still
plans fresh.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 9d5f6d4c18

ℹ️ 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 commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-23T05:06:10.114528Z
We couldn’t complete this review. Comment @codex review to try again.
40a1ee3 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

danielhanchen added a commit that referenced this pull request Nov 23, 2026
…Run settings close (#18984)

## Summary

`Chat UI Tests (extra)` fails intermittently on unrelated PRs at the
same step of `tests/studio/playwright_model_config.py`:

```
[ui-modelcfg] STEP Hub Run opens run settings on a page loaded at /hub
[ui-modelcfg] OK Hub Run kept run settings open on a page loaded at /hub
[ui-modelcfg] FAIL: composer could not be focused after the Hub Run settings closed
```

Seen on #18871 (09:37) and #18738 (20:00) today. Neither touches the
chat composer or the model picker, and the same suite passes on other
runs.

The step presses Escape, waits for the run settings to hide, then calls
`focus()` on the composer in one `evaluate` and reads
`document.activeElement` in a second. The run settings live in the model
picker, a Radix `Popover`, which returns focus to its trigger as it
closes. A focus move like that, landing between the two calls, makes
this single attempt fail even though the composer is focusable.

The product behaviour this guards is unchanged:
`ChatComposerFocusableContext` lifts the `focus()` gate in the same
commit that closes the picker, and a real click focuses the composer
regardless.

## Fix

The check now retries `focus()` plus the `activeElement` read for up to
5 s (every 250 ms) through the suite's existing `wait_until`, and fails
with the same message if the composer never takes focus. A composer that
stays gated after the settings close still fails the gate.

Only the test changes.

## Testing

- `python -m py_compile` and `ruff check --select F` on the driver:
clean.
- The suites that read this driver (CI wiring and Playwright selftests):
213 passed.
- I could not reproduce the intermittent failure locally, so the timing
explanation above is inferred from the two CI logs and the picker's
focus handling, not observed directly.
@danielhanchen danielhanchen self-assigned this Nov 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: b61cb47cbd

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

download_bytes still re-parsed the ~380 KB lock on every status poll via
flashinfer_kernel_wheel, outside the priced-plan memo.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f52ed72956

ℹ️ 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
danielhanchen marked this pull request as ready for review November 23, 2026 05:06
@danielhanchen
danielhanchen merged commit 21cab81 into main Nov 23, 2026
@danielhanchen
danielhanchen deleted the perf/r37-idle-poll-trims branch November 23, 2026 05:06
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.

1 participant