Repository navigation
Studio: optimize model picker scans with shared inventory caching - #8381
danielhanchen merged 5 commits into
Conversation
|
Reviewed and measured this one. It does what it says, and by a wider margin than the description claims. VerificationFrontend gate at The red checks on this PR are all pre-existing on
MeasurementTwo isolated Studio installs from Scenario: load
Worth calling out the The one thing I went looking for, and did not find
Live it does not happen. An open picker on an empty Studio, left alone:
Same numbers at both windows, so the renders that would re-arm it are not occurring. Not a blocker, just the fragile part of the change: it now depends on render cadence rather than on a latch. One behaviour noteChat's local model list moves from No screenshots: the picker renders identically on both sides, as it should for a change about when a scan runs. Posting a pair here would prove nothing. Also note #8043 attacks the same problem from the backend with no file overlap, so the two are complementary rather than competing. |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
Date.now() follows the system clock, so an NTP correction, a VM resume or a user editing the clock can leave a refresh stamp in the future. now - stamp is then negative, which read as younger than the freshness window: every picker open reused, and the local model list stayed frozen for the length of the skew. refreshIfOlderThan(0), which means refresh unconditionally, became a no-op the same way. Share one isInventoryStampFresh helper between the reuse decision and the empty-inventory revalidation check so the guard cannot be missed in one of them.
|
Pushed one fix to this branch (8162d7f) after simulating the change rather than only reading it. Details below, including what I could not break. The bug: a backwards clock step freezes the inventory
When the clock steps backwards, The fix is one shared helper so the guard cannot be present in one place and missing in the other: export function isInventoryStampFresh(stamp: number | null, now: number, maxAgeMs: number) {
if (stamp === null) return false;
const age = now - stamp;
return age >= 0 && age < Math.max(0, maxAgeMs);
}Three regression tests added to How it was found and what else was checkedI wrote the failure modes down first and then built simulations to decide each one.
Re-measured the original scenario at the fixed head to confirm the fix did not cost anything: still 13 inventory requests -> 3, the three picker opens alone still 12 -> 2, 0.88s -> 0.13s of request time. Idle on an empty inventory is unchanged at 7 -> 5 over both 90s and 300s. On breaking existing installsDeliberately checked, all negative:
Two things left alone, on purpose
|
The compat /api/models/local endpoint and the shared /api/hub/local inventory do not agree on three points, and moving Chat across lost models on each. Ollama: the compat scanner labelled pulled models "custom", the shared one reports source "ollama", so the source filter dropped every Ollama model. Multi-format directories: the shared inventory keys a row on (format, path), so a directory holding GGUF and safetensors weights arrives as two rows with one load id. The selector keys on that id, so both collided on a React key and rendered as selected together. Collapse to one option per load id, as the compat endpoint returned. Empty revalidation: any forced scan stamped revalidatedAt, so a manual refresh of a populated inventory that came back empty recorded itself as its own confirmation and settled the picker on "no models" after one scan. Stamp only when the scan confirms an inventory that was already observed empty. Chat's mapping moves to local-model-options.ts so it can be tested directly.
The revalidation stamp means an empty inventory has been seen twice, so a scan that returns rows has to clear it. It did not: the stamp was decided from the previous state alone, so a forced scan that found rows kept refreshing it, and a later first empty scan inside the 30s window read as already confirmed. The picker then settled on no models after one look. Fold both ends into nextRevalidationStamp: rows found clears, a forced scan over an inventory already observed empty stamps, everything else carries for the same key.
Reverts the Ollama source I added two commits ago. /api/hub/local scans read-only and returns an opaque ollama-manifest: reference as the row id, which only materialize_ollama_model_ref can turn into a .gguf path, and nothing calls that function. Selecting one of those rows fails instead of loading, so the list entry was worse than its absence. The picker withholds the same rows through PICKER_LOCAL_SOURCES for this exact reason, so Chat now matches it. Restoring Ollama models to both belongs in the load path, not in a wider source filter.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
Review converged. Codex approved the head and the cross-platform runs are green, so this is the wrap-up. What landed on top of the original change
The Ollama one is worth calling out because I got it wrong first. Chat losing Ollama models on the endpoint switch is real, but the fix is not to widen the filter: Verification
Two gaps left for the backend, deliberatelyBoth are pre-existing divergences between
Happy to open separate PRs for either. |
unslothai#8381 added refreshInventoryIfOlderThan to the chat picker inventory hook at the same call site this branch passes allowedHiddenModelIds through, so both are kept.
Opening Studio's model picker repeatedly scans the same model folders, even when Chat completed the same scan only seconds earlier. Each unnecessary scan took 0.6 to 2.8 seconds on the test machine and repeated the same disk and CPU work.
This change makes Chat and the model picker use the same inventory result. A completed scan can be reused for 30 seconds, and a picker opened while a scan is running joins that scan instead of scheduling another one.
What changed
Results
Scenario: load
/chat, wait 8 seconds, then open and close the model picker three times.Testing
node --experimental-strip-types --test tests/inventory-freshness.test.ts tests/inventory-settlement.test.ts(9 passed)npm run typechecknpm run build