Repository navigation
feat(studio): rework train page setup flow - #7633
Conversation
Unify model and dataset picker behavior, training start guards, and token handling. Validate cache provenance for local models, downloaded resources, and processed datasets. Prevent stale preview and history state while keeping the train page modular.
…ork-main-adapt # Conflicts: # studio/frontend/src/features/settings/index.ts # studio/frontend/src/i18n/locales/ja.ts # studio/frontend/src/i18n/locales/pt-br.ts # studio/frontend/src/i18n/locales/zh-CN.ts # tests/studio/test_model_picker_contracts.py
Preserve freeform local model paths, reject remote GGUF-only repositories, and correct the training start snapshot contract.
Preserve local dataset path intent, localize setup-change errors, and remove unused picker tour hooks. Refresh model picker and PDF recipe contracts for the refactored training flow.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
On the third item in that review, the cached-preview one at
So I have not changed it here. The asymmetry it points at is worth fixing on its own: |
Deleting a run with its artifacts stages the output directory with a same-parent rename and
purges it once the database row is gone. The purge swallowed OSError while the response still
said artifacts_deleted=true, so a failed rmtree stranded every byte under the hidden randomized
.{name}.deleting-<hex> name: the row is gone by then, so nothing points at it and no retry can
rediscover it.
The purge now reports whether the bytes are actually gone, and puts the directory back under its
own name when they are not. The response says the artifacts were kept, with a purge_failed
reason, and the history grid's existing artifacts_deleted check surfaces it.
Same window, other half: when the row delete and the restoring rename both fail, the response now
names the staged path instead of raising a bare 500 that leaves the artifacts unreachable.
Aligning the picker's grammar with TrainingStartRequest went one step too far: _valid_option started refusing ".." anywhere, for both fields. _check_split_name does reject ".." outright, so that is right for splits, but _check_subset only constrains the charset, which means a config directory named v1..v2 is perfectly startable and the picker was hiding it. That is the same bug as offering an option the start request rejects, just pointing the other way. The ".." refusal is now scoped to split names. Neither charset admits a separator, so the bare "." and ".." names remain the only traversal shapes left to refuse for either field. test_processed_cache_options_are_local_deduplicated_and_non_train_capable pinned the pre-change behaviour for both names in its fixture. Its "config with spaces" entries stay dropped, since _check_subset rejects the space and offering it turns a click into a 422, and "v1..v2" comes back.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
|
Closing the loop on finding 1 from my earlier testing, now that The case is a normal 16-bit repo with the 4-bit toggle on — Phase 1 — train 8 steps, Phase 2 — a second run with The step counter picking up at 9 is the part worth noting: the optimizer state and loss history came back, so this is a real resume rather than a fresh run pointed at an old directory. So the MLX resume work in this PR does what it says — the gate was the only thing standing in the way, and with attestation fixed the machinery underneath was already correct. Worth recording because the original report made resume look broken on Apple Silicon when in fact only the provenance check was. Two things still open from that testing, neither a regression here:
Environment: M2 MacBook Air (16GB), mlx 0.31.2, mlx-lm 0.31.2, |
) * lower the train configure two-column threshold to 56rem The Run preview card and its Start training button only split into a second column when the train-configure container query matches. That container is the page wrapper, so its width is min(1180, window - sidebar) - 72, and the sidebar is 280px by default. The 64rem tier from #7633 needed a 1376px window, and below that the card stacked under the wizard as a full-width row. 56rem is the narrowest tier that still leaves the wizard column past its own 28rem @md/train-section threshold once the 320px preview track, the 32px gap and the card's 40px padding come out, so the model/method/token row stays two across. The second column now appears from a 1248px window with the sidebar expanded, and from 1016px with it collapsed to the rail. * add a regression test for the train preview column budget The threshold is a class name on the design scale, so nothing in the source says it is really a window-width requirement. The test reads the tier, the preview track, the gaps, the page padding, the training card's inset and SIDEBAR_WIDTH_DEFAULT out of the source and out of Tailwind's own scales, then holds both ends: two columns must be reachable in a 1280px window, and the wizard column must still clear @md/train-section, the narrowest tier the wizard's own sections use. It also pins the sticky offset to the same tier as the column split, so the preview cannot scroll away inside its own track, and checks that both named containers are still declared, since every tier it reads is inert without them. A tier it cannot resolve throws rather than dropping out of the budget. * clarify train preview breakpoint test --------- Co-authored-by: Leo Borcherding <[email protected]>
… since a clean pass (unslothai#16270) ## Studio: skip the startup manifest downgrade scan when nothing changed since the last clean pass ### What changes Every backend start runs `migrate_ordinary_v2_manifests_for_downgrade()` inside the lifespan, before the server answers anything. It globs every Hub download manifest, stats each one and reads a 256 byte prefix to find ordinary v2 records to rewrite as v1. On a home with thousands of manifests that is the largest single lifespan step, and it competes for the GIL with the hardware detection thread, so it costs far more in the server than in isolation (about 65 us per file in the server vs 12 us standalone). The scan now records a clean pass and skips itself on the next start when nothing it depends on has changed: - After a complete pass that found no ordinary v2 record, it writes `hub-state/manifest_migration.json` with the mtime of `manifests/` and of each `cache-*` scope dir, the active hub cache (canonical and raw), the manifest versions and a migration id. - On the next start, if the marker matches the current mtimes and settings, the scan is skipped. That costs one stat per scope dir. - Every manifest write goes through `tmp + os.replace`, so any added or replaced manifest moves the mtime of the dir holding it. A new scope dir moves the parent's. So any download, any manifest written by another Studio version, a cache setting change or a bump of `_MANIFEST_MIGRATION_ID` / `_MANIFEST_VERSION` re-runs the full scan. - No marker is written when the pass migrated something, hit a write or read failure (an unreadable manifest or a `cache-*` scope that cannot be listed), stopped at the 10,000 file cap, or saw an ordinary v2 record it left alone. It is also skipped when the dirs changed in the last 2 s, so a write landing in the same mtime tick as the scan cannot be missed. In that case the next start scans as before. - The marker lives beside `manifests/`, not inside it, so writing it does not move the mtimes it records. The migration still runs synchronously in the same place in the lifespan, before any download can start, so no write moves into a window where it could race a download. ### Results, base vs head `run.py --api-only` on a scratch Studio home with 5000 manifests (10% v2 on first start), 1000 chat threads, 4000 messages and 200 research runs, CPU only, empty scratch HF cache. Interleaved base/head, separate home copy per arm. Medians [range], ms. | 5000 manifests | base | head | |---|---|---| | migration step, warm (5 runs) | 339 [316-481] | 3 [2-3] | | lifespan, warm | 506 [473-652] | 147 [143-150] | | spawn to ready, warm | 2334 [2213-2558] | 1973 [1891-2037] | | spawn to first /api/health done, warm | 3727 [3562-3789] | 3197 [3110-3245] | | login, warm | 52 [42-83] | 45 [41-66] | | spawn to ready, first start on a fresh copy (3 runs) | 2975 [2765-4981] | 2806 [2768-2960] | Every warm head run is faster than the fastest warm base run. The first start does the full scan on both sides, as expected. | 500 manifests | base | head | |---|---|---| | migration step, warm (4 runs) | 50 [35-57] | 3 [1-44] | | lifespan, warm | 193 [174-216] | 155 [144-175] | | spawn to ready, warm | 2040 [1981-2246] | 1930 [1905-2192] | The 44 ms head run at 500 is the first start after a start that migrated 50 manifests. That pass is not recorded, so the next one scans again and then writes the marker. Other startup maintenance measured on the same home and left alone: studio.db schema check plus research claim backfill (`open_wal_keeper`) 11-14 ms warm, orphan reconciliation under 7 ms. ### Tests - New `tests/test_manifest_migration_marker.py`, 18 tests (one POSIX-only, skipped on Windows). Head passes 18/18 on Linux and macOS, 17 + 1 skipped on Windows. - Manifest bytes after startup match the unmarked scan on a home with v1, ordinary v2 (scoped and unscoped), dataset v2 and a dataset completion record. A fresh home with no manifests dir also works. - The second start reads no manifest. This fails on main, where 10 manifests are read again. - The scan re-runs for each of these: a new v2 manifest, an overwritten manifest name, a new cache scope, a migration id change, a manifest version change, an active cache change and a corrupt marker. - No marker is written after a pass that migrated something, after recent dir changes, after a write failure, or at the file cap. - Neighbour suites (35 files touching manifests or hub state), base vs head: 2354 passed on both sides, with the same 13 failing IDs on both. Those are in `test_cached_gguf_routes`, `test_export_offline_window`, `test_hub_download_http_size_ceiling` and `test_mtp_drafter_companion`, and they predate this change. #- A marker that cannot be read (including deeply nested JSON that raises `RecursionError`) or any unexpected error in the marker check falls back to the full scan and writes no marker, so a bad marker can never block the migration. - What a skipped migration would cost: no code on main writes an ordinary v2 manifest, so only pre-unslothai#7633 builds or another Studio version sharing the home can leave one. The migration only matters for a later downgrade to a v1-only version, which would then miss one partial download; the current version reads both. Every Studio writer goes through `tmp` + `os.replace`, which moves the folder mtime. ## Not covered - Windows and macOS were not run. The skip relies on a directory's mtime moving when an entry is renamed into it. That holds on ext4, APFS and NTFS. On a filesystem that does not maintain directory mtimes (FAT/exFAT under Windows), a v2 manifest written by another Studio version could go unmigrated until the next download changes the dir. - No GPU host. The cost under contention depends on what the hardware detection thread is doing at that moment. - The one-time cost of actually migrating many v2 manifests (about 3 ms each, from the fsync per rewrite) is unchanged. ### Follow-ups in this PR - A manifest that cannot be read during the pass (for example a Windows sharing violation) now keeps the pass unclean instead of being treated as not v2. - Migration candidates are listed with `os.scandir` per directory instead of `Path.glob`, which silently returns nothing for a directory it cannot read. A `cache-*` scope that cannot be listed blocks the marker while the other scopes still migrate. Matching stays case-insensitive on Windows, as glob was.
Reworks the train page setup flow: a new wizard for model, dataset, and parameters, shared resource pickers, cache-aware model/dataset resolution for training starts, and artifact-aware training history with deletion support.