Repository navigation
Studio: account for resident memory during model reloads - #10627
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efa295a98d
ℹ️ 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".
| } | ||
| return { | ||
| cacheTypeKv: state.loadedKvCacheDtype, | ||
| nParallel: state.loadedNParallel, |
There was a problem hiding this comment.
Refresh the loaded slot baseline before pricing credit
When another client reloads the same GGUF with fewer parallel slots, loadedNParallel remains at the previous larger value because the status applier updates it only when the baseline is null or the model identity changes (apply-inference-status-to-store.ts:532-536). Unlike the KV/spec/tensor baselines updated in this patch, this newly consumed resident field can therefore overprice the resident KV and buffer allocations, overstate reclaimable memory, and suppress the free-memory warning. Advance this baseline on settled same-model status echoes while preserving a dirty nParallel control.
Useful? React with 👍 / 👎.
) * Refine Studio memory estimate layout and guidance * Handle RAM-only estimates and exhausted memory readings * Use the default cursor for memory estimates * Balance memory value padding and section spacing * Reduce the gap above memory figures * Tighten the memory figure's box and spacing The value pill was 92px to match the numeric inputs beside it, but those right-align their contents while this one centres, so the fixed width read as padding around the number rather than alignment. Narrow it to 80px and trim the surrounding gaps; the row is justify-between, so the right edges still line up with the Auto and dtype controls. * Say which memory is short in the pressure notes These verdicts are measured against what is FREE right now, not against capacity, but the copy said only "Memory is tight". On a 64 GB machine holding a 25 GB load that reads as false, and the note never said which memory it meant. Name the pool and the fact that it fits, so the reading is about the moment rather than the machine. Not "does not fit what is free": pressure starts at 85% of free, where the load does still fit, and the existing guard on that wording stays green. * Stop charging a reload for its own resident copy Studio unloads the resident model before the replacement allocates, so the memory it holds returns to the pool first. The free-memory verdicts charged it anyway, which counted a model against itself: opening Run settings for the model already loaded warned that its footprint would not fit the memory that same footprint was occupying. On a 64 GB Mac a 25.61 GiB load saw 25.53 GiB free and read as exceeding it. Price the resident copy at the settings it loaded with and credit it to the free-memory questions. Capacity is untouched, since unloading frees memory rather than adding any, and growth over what comes back still warns. Only settled estimates are credited, so a stale price cannot silence a real warning. Reloading the same model somewhere else is unaffected: switching to a DIFFERENT model still charges the outgoing one, which needs the resident footprint from the backend. * Close the gap above the memory figures The margin was already down to 2px; the rest of the space came from the heading row's own min-height rather than from spacing between the rows. Drop the margin and take the row to 28px. It stays full-width clickable, so the disclosure target is unaffected. * Fix resident memory credit and combined-capacity advice * Correct memory pressure thresholds and uncertain VRAM credit * Preserve reserves and shared RAM in reload estimates * Avoid moving host memory pressure onto a tight GPU * Avoid placement advice when both memory pools are pressured * [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>
|
You have reached your Codex usage limits for security reviews. Please try again later. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dcd418bd2c
ℹ️ 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 probe = await fetchSystemInfo({ refreshMemory: true }); | ||
| if (!probe?.memory_refreshed) throw new Error("Memory probe unavailable"); |
There was a problem hiding this comment.
Retry the resident probe after transient refresh failures
If the forced /api/system request transiently fails or returns an invalid response, this rejection is caught below and the resident estimate is discarded. Because the effect depends only on the unchanged estimate key and refreshMemory, later successful system-info polls do not rerun it, so reclaimable credit remains zero for the rest of the mounted page and an unchanged reload can continue showing a false free-memory warning. Preserve the estimate as stale and retry the refresh, or trigger a new attempt when system information recovers.
Useful? React with 👍 / 👎.
memory-unified-apu.test.ts pinned the panel's non-Apple unified-memory branch with two source anchors and a 160 character budget between them. #10627 (ab28823) rewrote that branch to return a record rather than a number, so the second anchor no longer exists anywhere in the file and the test has failed on main ever since. The rule it guards survived the rewrite and got stricter: the old Math.max fell back to the carved GPU window whenever the host RAM reading was missing, which is the substitution the assertion message forbids, and the new code reports known: false instead. Move the rule into gpu-vram.ts as resolveFreeGpuCapacityGb, beside the aggregates it is built from and reachable from the test runner, and have the panel call it. The test now runs the rule: a non-Apple unified pool answers from the host view rather than the window, an unread host figure is reported unread rather than replaced by the window, and Apple and discrete hosts still answer from their own free VRAM. One source assertion remains, for the one thing that is still not reachable from here, which flags the panel hands over, and it no longer depends on the distance between them.
…text (#10654) * Unbreak main: compare the autoload guard's conditions, not its exact text Two assertions in test_model_picker_contracts.py slice chat-adapter.ts on the exact one-line text of the autoload guards. #10508 added a validateFailures bound to both, which pushed each past the print width, so prettier wrapped them and both assertions stopped matching. Neither test was updated, so main fails them today. Comparing the SET of conditions instead survives a rewrap and survives a later PR adding another condition, while still failing when a condition is dropped. Checked both ways: removing the cancellation check from the if, and removing the attempts bound from the while, each fail the corresponding test. * Count the complete guards, and keep the operator Three problems with the first version, all reproduced before fixing: Splitting on both || and && discarded the operator, so flipping the if-guard from OR to AND still passed. Stopping at the first ) truncated the body when a condition held a call, and taking the first if in the slice parsed an unrelated earlier guard, both failing on a legitimate edit. Balanced parentheses and a required operator fix those, but scanning for the first guard that matches introduced a fourth: this slice carries the guard twice, so a condition dropped from one copy was masked by the other. Requiring every guard that mentions a condition to hold them all is wrong the other way, since a nearby guard legitimately tests a subset. Counting the complete ones catches a drop in either copy and leaves the neighbours alone. * Strip comments and respect string literals when reading a guard Scanning the raw source counted a commented-out copy of the old guard as live, so dropping a condition from the real one kept the count at two and the test passed. Reproduced before fixing. It now reads through _code_only, which this file already used for the same reason. The depth scan also treated a parenthesis inside a string as syntax, so a condition like reason.includes(")") truncated the body and failed the test on a legitimate edit. Both the balance scan and the operator split now track quote state, including escapes. * Blank comments and literal contents in one pass Two more holes, both reproduced first. A guard-shaped string, such as a diagnostic message quoting the guard, was counted as a live guard, so a real condition dropped from the actual guard kept the count at two and the test passed. And a live guard holding a URL string lost its tail, because the comment strip removed everything after the // inside the quotes. Handling comments and quotes separately cannot fix either: each pass needs the other's answer. One scan now blanks comment bodies and literal contents while preserving length, so delimiters and offsets still line up. Regex literals are left alone and the docstring says so; distinguishing them from division needs real parsing, and a guard holding one would be read with its slashes intact, which is visible rather than silent. * Pin the desktop startup gate to its condition, not its variable name test_desktop_startup_waits_for_auth_without_intermediate_handoff asserted the exact line 'const showApp = status === "running" && desktopAuthReady;'. That binding has since been renamed to canMountApp and showApp now also requires appShellReady, so the assertion fails on a clean checkout of main even though the contract it protects is intact. Match the condition and require the resulting binding to condition the mount in the markup. Removing desktopAuthReady, removing the status check, or taking the gate out of the mount all still fail; renaming the binding no longer does. * Measure the unified-memory pool rule instead of reading it back as text memory-unified-apu.test.ts pinned the panel's non-Apple unified-memory branch with two source anchors and a 160 character budget between them. #10627 (ab28823) rewrote that branch to return a record rather than a number, so the second anchor no longer exists anywhere in the file and the test has failed on main ever since. The rule it guards survived the rewrite and got stricter: the old Math.max fell back to the carved GPU window whenever the host RAM reading was missing, which is the substitution the assertion message forbids, and the new code reports known: false instead. Move the rule into gpu-vram.ts as resolveFreeGpuCapacityGb, beside the aggregates it is built from and reachable from the test runner, and have the panel call it. The test now runs the rule: a non-Apple unified pool answers from the host view rather than the window, an unread host figure is reported unread rather than replaced by the window, and Apple and discrete hosts still answer from their own free VRAM. One source assertion remains, for the one thing that is still not reachable from here, which flags the panel hands over, and it no longer depends on the distance between them. * Move the guard-reading helpers into tests/studio/_js_source.py and fix three holes Both contract files grew their own copy of the same scan, and the copies had drifted. One module now, beside the other _-prefixed helpers in this directory. Three defects went with the move, each reproduced first: - A ternary was accepted without looking at its arms, so {gate ? null : <Shell />} passed while mounting the shell exactly when the gate is false. The true arm is now checked. - The gate declaration was matched as exact text, so rewrapping it across lines turned a behaviour-preserving edit red. That is the failure this branch exists to fix, reintroduced two tests over. Operands are compared instead. - Splitting stopped at depth zero, so (a || b) || c reported no complete guard. Same-operator groups are flattened and redundant operand parens stripped. binding_joining locates declarations in the blanked source but reads operands from the original at the same offsets: blanking empties string literals, and status === "running" is a required operand. Matrix, both call sites: drop a condition FAIL, flip the operator FAIL, gate out of the mount FAIL, inverted ternary FAIL; rename, rewrap, redundant grouping and an added prerequisite all PASS. --------- Co-authored-by: danielhanchen <[email protected]>
…ll settings (unslothai#14210) Fixes unslothai#8039 ## Summary When another tab, or an API auto-switch, reloads the MLX model that is already resident with a different KV cache width or Int8 Prefill setting, this tab kept the old width, the old baseline and the old verdict. The status poll only seeded the MLX group on a model change, plus a recovery branch that needs every field still empty, so once the group held values a same-model reload was ignored. The editor then showed the old width, its verdict badge described a load that is no longer running, and the next Apply re-sent the old width, undoing the other client's change. The rest of the per-model load settings group already handles this on `main`: `kvCacheDtype`, `tensorParallel`, `specDraftNMax`, `speculativeType` and `chatTemplateOverride` advance their loaded baseline on every settled status and move the control only while it still sits on that baseline (unslothai#10627, `resolveChatTemplateSeed`). The shared Run settings draft (unslothai#10851), the matching editor keys in the sidebar and the model picker, and the `syncGeneration` fence on status reads cover the other parts the issue listed. This PR puts the MLX group on that same rule and drops the separate recovery branch it no longer needs: - `loadedMlxKvQuantRequested`, `loadedMlxInt8PrefillRequested` and the verdict fields (`mlxKvQuantReason`, `mlxKvQuantNote`, `chatTemplateOverrideReason`) follow every settled MLX status. - `mlxKvQuant` and `mlxInt8Prefill` follow while they equal their baseline, or on a model change. A value staged in this tab is kept, and its baseline still advances. - A non-MLX status still retires the verdict and leaves the width dormant. ## Test plan - [x] `node --experimental-strip-types --test tests/same-model-reload-load-settings.test.ts`: on the merge base the two MLX same-model reload cases fail (`'8' !== '4'`, `'8' !== null`); with this change all 5 pass. The GGUF case passes on both and pins the existing behaviour. - [x] Full frontend suite (`npm test`): 12681 tests, 0 failures. - [x] `tsc -p tsconfig.app.json --noEmit` clean. - [x] `pytest tests/studio/test_model_picker_contracts.py tests/studio/test_chat_autoload_failure_gate.py tests/studio/test_cli_attach_load_knobs.py`: 355 passed. ## Before / after Two isolated Studio installs, one at this PR's merge base `a33463f` and one at head `927c1a4`. This host has no MLX, so the page is given the status an MLX backend reports for a resident model loaded at 8-bit KV, on a Mac. The status then switches to the same model reloaded at 4-bit by another client, and the window regains focus, which is when Studio re-reads status. Before, Run settings still shows 8-bit and the 8-bit verdict over a model now running at 4-bit, so Reload would put it back to 8-bit. After, it shows 4-bit and the 4-bit verdict.  On real Apple Silicon (staging `macos-15`), a tiny MLX model was loaded twice through Studio's MLX backend at 8-bit and then 4-bit; feeding the two statuses it reported through the merge base leaves the control on 8, and through this PR moves control and baseline to 4.
Studio unloads the current model before allocating its replacement. The memory-fit verdict currently charges a reload against free memory while the resident copy is still occupying it, so an unchanged configuration can warn about its own footprint.
Credit the resident allocations that can be established before classifying the full requested footprint against post-unload availability. Physical-capacity verdicts and the 85% pressure threshold stay unchanged.
The layout, tooltips, value formatting, and guidance changes are separated into #10591.
Validation: 14 focused frontend regression tests pass. Application and test type checking pass. Backend cache bypass and endpoint forwarding were checked by executing the changed source with hardware stubs. Linting adds no diagnostics; the existing estimate-hook ref diagnostic remains. No CI or full suites were awaited.
Credit remains an estimate, not measured resident allocation. Uncertain placement and cached files can still produce conservative warnings. Switching to a different model remains outside this change because the panel only has a resident estimate for the model it is showing.
Each settled resident estimate adds one system-memory refresh. Regular monitoring retains its cache and polling frequency.