Repository navigation
Make the legacy-migration picker step deterministic, and unit-test the migration - #9603
Conversation
…e migration `legacy unsloth_load_settings migrates once and stays idempotent` in tests/studio/playwright_model_config.py flips between pass and fail on identical input. It has gone red on main itself three times (runs 32671622061 @0fea40d75, 32677249361 @0df6fde86, 32680622174 @3c998cc8f, all push events on main) and on two unrelated branches, and a re-run of a failed job passes with no code change. There is no regression behind it. The assertion's message was also misleading. It reported "legacy context 4096 not migrated", which reads as the migration running and dropping a field. It was not: the record left behind carries kvCacheDtype null although the seed carried q8_0, so nothing from the seed had been imported at all. What actually happens. The step clears localStorage in the live document and then reloads. Opening the run-settings panel starts a GET of the model overrides and writes the resolved row back into `unsloth_model_configs` when it answers, so a response still in flight from the previous step lands in the ~20ms between `removeItem` and the navigation and re-creates the key. The reloaded page then finds that key occupied, `mergeLegacyEntries` skips the entry it was seeded to import, and `migrateLegacyLoadSettingsOnce` latches the flag anyway. A second route to the same red: the step clears local storage but never the server-side override rows that steps 2 to 4 leave behind, and a row carrying a context of its own outranks the migrated value. Both are reproducible on demand against an unmodified driver, and both reproduce a CI failure byte for byte: driver injection result HEAD none PASS HEAD late write-back before reload FAIL customContextLength null, kvCacheDtype null HEAD server row carrying ctx 2048 FAIL customContextLength 2048, kvCacheDtype q8_0 fixed late write-back before reload PASS fixed server row carrying ctx 2048 PASS fixed none PASS The first failing shape is the one seen on main; the second is the one seen on branch restore-resumable-http-partials. The fix is to the test, not to the product. Seeding now happens in an init script that runs at document start on the page under test, after every write from the discarded document has gone with it, so the store the import reads is the one the step asked for. The step also drops the server override rows for its model first, which is what makes it a test of the legacy import rather than of server precedence. The fixed sleep after the panel opens is replaced by a wait on the condition the assertions need, the migration flag appearing, which is the last thing the import does on every path it takes. The assertion now separates "the import ran and lost the context" from "the import never ran", using a Disable Vision fingerprint that only this seed can supply: no other step sets it, and the API only sends it when true, so a row mirrored back down cannot forge it. That distinction is what was missing, and chasing the old message cost an investigation of normalizeV1, which was innocent. The migration had no unit test anywhere; its only coverage was this browser step. studio/frontend/tests/legacy-load-settings-migration.test.ts pins the contract in milliseconds and through the module's public read path, so re-keying or re-versioning the records stays free. Checked for reachability rather than argued: with a real upgrade shape at document start (legacy blob, no versioned map, no flag) and the write-back armed by an existing server row, the remembered context survives. `storedAtStart` is itself a store read, so it always reflects the completed import, and an absent server field falls back to it. The harness ingredient that makes the failure possible, deleting the map after the flag has latched, is not something the app can do to itself. Anti-vacuity. With `legacyEntryToConfig` altered to drop `contextLength` and the frontend rebuilt, the repaired Playwright step fails, and fails through the new branch: "was DROPPED by the migration ... disableVision true, customContextLength null". Against the unit tests, four separate mutations were tried: dropping the context, never latching the flag, letting a legacy blob overwrite a config saved by this build, and importing an all-defaults blob. The first three are caught; the third initially was not, because the case saved its record after seeding and the save itself triggers the import, so the precedence branch never ran. Reordering it to save first makes the mutation red, and the comment there records why.
|
@codex review |
|
Correction to the description, which originally answered "no" to whether this is data loss for a user. That answer was right about the migration and wrong to generalise. The probe behind it covered a single-tab upgrade, which is a sound test of the migration-clobber hypothesis and not a test of concurrent writers. With a second tab in the picture there is a real lost update in the hydration write-back added by #9492: it snapshots the stored config at panel mount and writes the merge after an awaited GET, so a save made in another tab inside that window is overwritten by a value read before it existed. Reproduced with real gestures in both tabs and the mirror PUT failing: a remembered context of 4096 goes back to null with no user action. With a healthy mirror there is no loss, so it needs two surfaces on the same origin, a slow hydration, and an unreachable or failing mirror. That is a product bug and not what makes this job red, so it is filed separately as #9604 rather than bundled here. This PR remains test-only and changes no production source. The description has been updated. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 867070e6fd
ℹ️ 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 [] | ||
| return [ | ||
| k for k in body["overrides"] | ||
| if _normalize_model_identity(str(k)) in want |
There was a problem hiding this comment.
Normalize POSIX-path variants separately
When GGUF_REPO is a case-sensitive POSIX path, _normalize_model_identity deliberately preserves the entire string, so an override key such as /models/Foo.gguf:UD-Q4_K_XL does not match the lowercased qualified value placed in want. The stale server row therefore survives cleanup and can again override the migrated context in local-path runs. Parse the model and quant portions and normalize the quant independently, as entries_for_model already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c7a19ce, and the remedy is the one you name: model and quant are now normalised separately, which is what entries_for_model already does with these same two values.
Confirmed against the shipped normaliser before and after, with GGUF_REPO=/models/Foo.gguf:
key OLD NEW want
/models/Foo.gguf:UD-Q4_K_XL False True True <- the row that survived
unsloth/gemma-3-270m-it-GGUF:UD-Q4_K_XL True True True
/models/Foo.gguf True True True
/models/other.gguf:UD-Q4_K_XL False False False
/models/foo.gguf:UD-Q4_K_XL False False False
The last row is the case-sensitivity that normalizeModelIdentity keeps on purpose, since those are two different files, and it stays unmatched.
| if migrated_ctx: | ||
| info(f"OK migration: legacy context {DISTINCT_CTX} preserved after migrating") |
There was a problem hiding this comment.
Require the migration fingerprint for success
When a server override survives cleanup and carries DISTINCT_CTX—for example, the row written by the earlier persistence step—hydration can put that context into model_entries even if the legacy import never applied the seed. The success branch checks only migrated_ctx, so it reports the migration as working without requiring the new disableVision fingerprint that was added specifically to prove provenance. Require both values on the migrated entry before declaring success.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and this one was self-inflicted: disableVision was added precisely because the context cannot say where it came from, and then the branch deciding whether the step passed read the context alone. A surviving server override row carries DISTINCT_CTX too, since step 3b writes it, so hydration could produce a green step with the legacy import never having applied the seed.
Fixed in c7a19ce. The pass now requires both, and context-without-fingerprint is its own distinct failure naming the surviving override row as the thing that produces it, rather than being folded into either of the existing two.
| body = resp.get("body") | ||
| if not isinstance(body, dict) or not isinstance(body.get("overrides"), dict): | ||
| return [] |
There was a problem hiding this comment.
Fail when the override inventory request fails
When the override GET times out or returns an HTTP error such as 401/500, evaluate_fetch returns a result with status == 0/error or an error body rather than throwing. This branch interprets every such response as an empty override map, so cleanup and its post-delete verification are silently skipped and stale rows can contaminate the migration check. Validate status and error before accepting the response as an empty inventory.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c7a19ce, and evaluate_fetch's own docstring says exactly this: treat status == 0 or a non-None error as a transport failure. rows_for_model checked neither, so a request that never landed came back as "there are no override rows" -- the cleanup did nothing, and its own post-delete verification then passed on the same silence, with no line of output saying so.
It now returns None for could-not-read, which is deliberately not the empty list, and warns on both the initial read and the re-read after clearing.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e77eee9dfb
ℹ️ 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".
| "Authorization": f"Bearer {token}", | ||
| "Content-Type": "application/json", | ||
| }, | ||
| body = {"model_id": key, "remove": True}, |
There was a problem hiding this comment.
Preserve existing launch flags during cleanup
In the documented STUDIO_LOGIN_PW attach mode, the matching override row may predate this test and contain llama_extra_args or other settings that the preceding picker steps deliberately preserve. Sending remove: true deletes the entire persistent server row, so running this test against an existing Studio silently destroys those settings. Preserve fields outside this test's scope or snapshot and restore the row after the migration check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one, though the concern is fair in isolation.
The step cannot leave the row in place. What contaminates the migration is the row EXISTING: the server override outranks the local record, so opening the panel writes it back down over the migrated map, which is the whole failure this step was rewritten to stop measuring. Preserving fields inside a row that stays present does not help.
Snapshot-and-restore-after would work in the happy path only. If the run aborts between the removal and the restore, which is exactly when a test is most likely to stop, the settings are gone anyway and now without the record of it that a plain removal at least makes obvious.
The deciding point is that this test is already destructive to this model's override row: steps 2 to 4 mirror saves into it, so an attached Studio's llama_extra_args for the model under test do not survive the run whatever step 5 does. Preserving them at step 5 alone would not make the test non-destructive, only inconsistently so, and that is a worse thing to document.
The other four in this round are fixed in c7a19ce.
| return flag | ||
|
|
||
| try: | ||
| clear_server_overrides_for_model() |
There was a problem hiding this comment.
Drain pending mirror writes before clearing overrides
When a mirror PUT from steps 2–4 takes longer than the fixed UI waits, this cleanup can finish while that write is still queued by the frontend's fire-and-forget syncModelOverride. The delayed PUT can then recreate the row after rows_for_model() verifies it absent, allowing hydration to contaminate the newly seeded migration and reintroducing the flake this change is intended to remove. Ensure the old document's pending writes are terminated or settled before clearing, then verify the inventory.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and this is the same race the PR is about, one layer down. Fixed in c7a19ce.
A single post-delete read can only say the row was gone at one instant, and a fire-and-forget syncModelOverride PUT still in flight from steps 2 to 4 can recreate it immediately afterwards. Absence is now confirmed over a short window instead, and a row that comes back inside that window is removed again rather than being reported as having survived removal.
I did not go as far as terminating the old document's pending writes: the PUT may already have reached the backend, so stopping the client side would not be the guarantee it looks like. Re-checking the server's own inventory until it stays empty is the thing that actually answers the question.
Three ways the step 5 cleanup could leave the migration check measuring server precedence while reporting nothing. A failed inventory read as an empty one. evaluate_fetch reports a timeout or an HTTP error by returning status 0 or a non-None error rather than raising, which is what its own contract says to check. rows_for_model checked neither, so a request that never landed came back as there are no override rows: the cleanup did nothing and its own post-delete verification passed on the same silence. It now returns None for could not read, which is not the empty list, and says so. Local-path rows never matched. The whole model:quant string was folded as one identity, which only works while the model half folds too. normalizeModelIdentity deliberately keeps a plain POSIX path's case, so with a local-path GGUF_REPO the row /models/Foo.gguf:UD-Q4_K_XL normalised to itself and never matched the lowercased ...:ud-q4_k_xl being compared against. Model and quant are now normalised separately, which is what entries_for_model already does with these same two values. A row that came back after being removed. syncModelOverride is fire-and-forget, so a mirror PUT from steps 2 to 4 can still be in flight and recreate the row moments after a single post-delete read found it gone. Absence is now confirmed over a short window instead of at one instant, and a row that reappears is removed again. And the pass now requires the fingerprint. disableVision is the field only this seed sets, and the success branch was reading the context alone -- which a surviving server override row also carries, since step 3b wrote it. So the step could report OK migration on a context that the legacy import never applied. That is the exact confusion the fingerprint was added to end, missing from the branch that decides whether the step passed; it is now its own distinct failure.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7a19ce717
ℹ️ 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".
| if not left: | ||
| break |
There was a problem hiding this comment.
Keep checking after the first empty inventory read
When a queued syncModelOverride PUT arrives more than 250 ms after the cleanup, the first inventory read is empty and this break exits the loop, so the delayed write can recreate the row before migration hydration and reintroduce the original flake. The fresh evidence is that the new settling loop stops after one empty sample rather than confirming absence across the stated window; continue sampling for all four intervals, removing any row that reappears.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and my own comment claimed the window while the code broke out of it after the first empty sample. Fixed in 1fb71cf: it now samples all four intervals and removes any row that reappears, so the window in the sentence is the window enforced. A read that fails mid-window still ends it as unknown rather than as absent.
The loop broke on the first empty inventory read, which confirms absence at one instant plus 250 ms. That is the single-read weakness it was written to replace, moved one step along: a queued syncModelOverride PUT arriving in a later interval still recreates the row before hydration reads it, which is the flake this step is about. It now samples every interval and removes any row that comes back, so the window in the comment is the window the code actually enforces. A read that fails mid-window still ends it as unknown rather than as absent.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fb71cf66b
ℹ️ 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".
| def _is_row_for_model(key: str) -> bool: | ||
| if _normalize_model_identity(key) == want_model: | ||
| return True | ||
| model, sep, quant = key.rpartition(":") | ||
| return bool(sep) and ( | ||
| _normalize_model_identity(model) == want_model | ||
| and quant.strip().lower() == want_quant |
There was a problem hiding this comment.
Clear cached-path aliases before migration
When attach mode targets a Hugging Face repo whose existing override was stored by an older Studio under its models--…/snapshots/…:QUANT load path, this predicate does not recognize that row because it compares only the literal GGUF_REPO spelling. The backend explicitly treats such snapshot keys as aliases via cached_repo_alias_keys, and the picker asks fetchLoadModelOverride using both the load path and repo alias, so the surviving path row can still hydrate over the newly migrated record and make this supposedly isolated migration check fail. Resolve and remove all backend-equivalent keys, not only literal model/quant matches.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The aliasing is real, but it removes the row rather than leaving it. The PUT route retires the other spelling after a non-fill save (studio/backend/routes/settings.py:1683-1685) and clears it on remove (1632-1633), and the steps before this check (the context save and the advanced save) are both non-fill saves, as is the cleanup's own remove PUT. So a snapshot-path row from an older install is gone before the migration step runs; test_model_override_schema_compatibility.py:238-240 states the same thing.
The frontend never writes the snapshot spelling either: every mirror goes through syncModelOverride(configId, ...) and configId for a cached repo is the repo id (model-selector/types.ts:92-97, hub-page.tsx:1471).
And in the case where a row did survive, the step does not pass: the pass requires the disableVision fingerprint alongside the context (line 1201), and the context-only branch soft-fails naming a surviving override row hydrating over the map as the cause. No false pass to fix here, so leaving the predicate as is.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
What is wrong
legacy unsloth_load_settings migrates once and stays idempotent, in theChat UI Tests (picker)job, flips between pass and fail on identical input. It is a flaky test, not a regression.Evidence that there is nothing to bisect:
32671622061(0fea40d75),32677249361(0df6fde86),32680622174(3c998cc8f), allpushevents onmain.restore-resumable-http-partials.The failure message also pointed the wrong way. It said
legacy context 4096 not migrated, which reads as the import running and dropping a field. It was not running at all: the record left behind carrieskvCacheDtype: nullalthough the seed carriedq8_0, so nothing from the seed had been imported.Why it flips
Two routes to the same red, and neither is a product defect.
1. The seed races the document it is written into. The step clears
unsloth_model_configsin the live page and then reloads. Opening the run-settings panel starts a GET of the model overrides and writes the resolved row back into that key when it answers, so a response still in flight from the previous step lands in the ~20 ms betweenremoveItemand the navigation and re-creates the key. The reloaded page finds it occupied,mergeLegacyEntriesskips the entry it was seeded to import, andmigrateLegacyLoadSettingsOncelatches the flag anyway.2. The step is not isolated from its predecessors. It clears local storage but never the server-side override rows that steps 2 to 4 leave behind, and a row carrying a context of its own outranks the migrated value.
Both reproduce on demand against an unmodified driver, and both match a real CI failure byte for byte:
customContextLength: null, kvCacheDtype: nullcustomContextLength: 2048, kvCacheDtype: "q8_0"The first failing shape is the one seen on main. The second is the one seen on
restore-resumable-http-partials.Is this data loss for a user?
Not through the legacy migration, but there is a separate real one nearby, and this
section originally said otherwise. Correcting that.
The migration is safe. Driving a real upgrade shape at document start (legacy blob, no
versioned map, no flag) with the write-back armed by an existing server row, the
remembered context survives.
storedAtStartis a store read, so it reflects thecompleted import, and an absent server field falls back to it. Deleting the map after
the flag has latched is something only a harness does.
What that probe did not cover, and what I wrongly generalised from it, is a second
writer. The hydration write-back is a read-modify-write across an awaited request:
model-config-page.tsxsnapshotsstoredAtStartat panel mount and writesfromApiOverride(serverRow, storedAtStart)after the GET resolves.localStorageisshared across tabs, so a save made in another tab inside that window is written into a
map the first tab has already snapshotted. Reproduced with only real gestures in both
tabs, the sole intervention being latency on one request:
Remember, presses Reload model. Tab A's response is then released.
model-overrides.tsdocuments itself): tab A's late write erases tab B's save,customContextLengthback tonull. No user action, no message.re-derives it.
gpuLayersandnCpuMoealso survived here.So the conditions are: two surfaces on the same origin, a hydration slower than the other
surface's save, and the server mirror failing or unreachable. Narrower than "any two
tabs", but latency and a down server are not faults.
That is a product bug in the write-back added by #9492, not in the migration, and not
what makes this job red. It is filed separately rather than bundled into a
main-unblocking test fix, and this PR still changes no production source.
The fix
Test-only. No production source is touched.
The migration had no unit test anywhere; its only coverage was this browser step.
legacy-load-settings-migration.test.tspins the contract in milliseconds, through the module's public read path, so re-keying or re-versioning records stays free.Anti-vacuity
The repaired test can still fail.
With
legacyEntryToConfigaltered to dropcontextLengthand the frontend rebuilt, the repaired Playwright step fails, and fails through the new branch:Against the unit tests, four mutations were tried: drop the context, never latch the flag, let a legacy blob overwrite a config saved by this build, and import an all-defaults blob. Three were caught immediately. The precedence one was not, because the case saved its record after seeding and the save itself triggers the import, so the branch never ran. Reordering it to save first makes the mutation red; the comment there records why.
Local runs
Full driver, corrected model hint, against a Studio built from this branch:
That
cleared 1 server override row(s)line is the cross-step contamination, observed and removed.Frontend unit suite: 4820 pass, 0 fail.
tsc -p tsconfig.test.json: clean.