Repository navigation
Studio: clear only the compiled cache unsloth_zoo writes to - #15628
Conversation
…d-only location [skip ci]
|
@codex review |
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: Didn't find any major issues. More of your lovely PRs please. 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: Didn't find any major issues. Hooray! 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". |
<tempdir>/<leaf> is a name every user and install on the machine shares, so a directory or symlink found there is not ours to clear or put on PYTHONPATH. Anchor a relative UNSLOTH_COMPILE_LOCATION at the CWD so the Settings purge gate sees an absolute path. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
`(Python 3.13, rest)` on #15810 failed `test_legacy_sandbox_is_migrated` with a log line that gives the cause away: ``` Moved 1 chat sandbox folder(s) from .../test_legacy_sandbox_is_migrate0/userprofile/studio_sandbox to .../test_sandbox_lives_under_the_s0/custom_studio_home/sandbox ``` The legacy folder of one test was moved into the sandbox root of the test that ran before it on the same xdist worker. ## Cause Since #15628, `get_sandbox_workdir` starts a background `sandbox-migrate` thread. That thread captures `sandbox_root()` when it starts, but reads the legacy root (`HOME/studio_sandbox`) only once it gets scheduled. `test_sandbox_lives_under_the_studio_home` never waits for its mover. On a busy worker the mover was still pending when `test_legacy_sandbox_is_migrated` switched `HOME` and reset `_legacy_sandbox_migrated`. It then moved the new test's folder into the old root. The new test's own `get_sandbox_workdir` found that mover still alive and reused it, so nothing ever moved the folder to where the test looks. The product is fine: in a real process `HOME` never changes under the mover. This is test isolation. There is a second hazard with the same root. The conftest does not isolate `HOME`, so a mover that outlives a test's `monkeypatch` reads the real `~/studio_sandbox`. ## Fix A conftest autouse fixture joins any live `sandbox-migrate` thread before and after every backend test. It raises if a mover does not finish in 30s instead of letting it leak. The fixture requests `monkeypatch`, so the drain runs before the test's `HOME` is restored and a late mover can never read the real home directory. ## Verification - Repro: a tiny plugin delays the mover by 1s, the way a loaded worker deschedules it. Running `test_sandbox_lives_under_the_studio_home` and then `test_legacy_sandbox_is_migrated`: - main `3db711acb5`: `1 failed, 1 passed`, with the same misplaced move as CI - this branch: `2 passed` - `test_sandbox_files_and_storage_roots.py` on its own: 321 passed. - The 10 backend test files that start a mover, under `-n 8`: 887 passed, 3 skipped. - Only `conftest.py` and `test_sandbox_files_and_storage_roots.py` drive the mover directly, and nothing holds one open across tests, so the drain cannot stall an unrelated test.
clear_unsloth_compiled_cacheand the Settings cache list decide which compiled-cache folders exist through_configured_cache_dirs()(studio/backend/utils/cache_cleanup.py). It always added<cwd>/unsloth_compiled_cachenext toUNSLOTH_COMPILE_LOCATION. Studio always sets that variable, andunsloth_zoothen never writes to the CWD, so a folder of that name in the launch directory is somebody else's or a stale leftover. Every clear and every Settings walk warned about it, and anyunsloth_compiled_module_*.pyfiles in it were deleted.What changes
_configured_cache_dirs()now returns only the folderunsloth_zoo.compilerwrites to (_get_compile_folder):UNSLOTH_COMPILE_LOCATIONwhen set (a relative value taken against the CWD, asos.makedirstakes it), otherwise<cwd>/unsloth_compiled_cache;<tempdir>/<same leaf>only when that location cannot be created, decided without creating anything.Ownership checks and
preserve_patternsare unchanged, and no caller changed.With the variable set, a leftover
<cwd>/unsloth_compiled_cachefrom an older install is no longer cleared or put onsys.path; it simply stays on disk, since the cleanup no longer deletes outside the folder the compiler uses. Studio still expands~in the variable whileunsloth_zoodoes not; that difference predates this change and is left alone.Tests
studio/backend/tests/test_compiled_cache_location.py(7, temporary directories only): with the variable set, a CWD folder of the same name is neither listed nor cleared and draws no warning; without it the CWD folder is the cache; a relative value is taken against the CWD; an uncreatable location falls back to the temp dir like the compiler, and a creatable one never does. 4 of them fail on main.test_sandbox_files_and_storage_roots.py:test_cache_cleanup_finds_the_configured_and_cwd_cachesasserted the old behaviour; it is nowtest_cache_cleanup_finds_the_configured_cache_and_not_the_cwd_one.Update after review
<tempdir>/<leaf>, the folder the compiler falls back to when the configured location cannot be used. That name is shared by every user and every install on the machine, so a folder or symlink found there is not provably ours: clearing it could follow a link into another marked cache, and registering it would put a foreign folder onPYTHONPATH. main never touched that folder either, so this is no change from main. The bullet about the temp fallback and the two fallback tests are replaced by tests that a marked temp folder, a symlink there, and a.leaf are all left alone and never registered.UNSLOTH_COMPILE_LOCATIONis now anchored at the working directory, so the Settings purge gate sees the absolute folder the compiler writes to.~is no longer expanded. The value is taken verbatim, asos.makedirsin the compiler takes it, so~/xmeans<cwd>/~/xin both places.