Repository navigation
Studio: answer slow cache sizes at once and walk cache trees faster - #15627
Conversation
…s or deletes [skip ci]
[skip ci]
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 |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e68d517db2
ℹ️ 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 patterns is None: | ||
| # Sanity on the oracle itself: the outside-linked and unreadable bytes are not counted. | ||
| nested = sum(100 + a * 10 + d for a in range(4) for d in range(3)) | ||
| assert expected == (11 + nested + 5000, 7) |
There was a problem hiding this comment.
Make the unreadable-directory assertion work under root
When this test runs as root, as in a root-based development or CI container, chmod(0) does not prevent the walker from reading these directories. Both implementations correctly return 8803 bytes, but this assertion requires 6403 bytes, so the new test fails despite identical walk behavior. Simulate permission failures deterministically or condition the unreadable-byte assertion on whether access is actually denied.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ba66b1e: root bypasses permission checks (capabilities(7) CAP_DAC_OVERRIDE), so the oracle sanity check now expects the locked directories' bytes when geteuid() == 0; the new-vs-reference equality is unchanged.
…an build [skip ci]
|
@codex review |
1 similar comment
|
@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". |
# Conflicts: # studio/backend/hub/utils/inventory_scan.py
…wing the old number (unslothai#15718) Follow-up to unslothai#15627. Before unslothai#15627, Settings measured a cache again in the request whenever its last measurement was more than 60 seconds old, so the size shown was always current. unslothai#15627 answers a slow cache from its last walk and walks it again in the background. That keeps the page fast, but the page never fetched the new number. A size changed by an install, a training run or a tool outside Studio stayed old on screen until the next visit. This PR closes that gap and a few related ones. ### Changes - The inventory response has a `refreshing` flag. It is set when any size came from an expired walk that is being redone. - Settings asks again every 2 seconds, at most 60 times, until every size is current. These follow-up reads only swap in the newer sizes: there is no measuring state, and a failed one keeps the rows. They stop when you leave the page, start a newer request or clear a cache. - A background refresh queued behind another cache's walk no longer holds its own cache's lock while it waits. A clear, download or Recheck of that cache walks right away. - The queued refresh skips itself if a newer size was stored in the meantime. - If the background thread cannot start, the read walks in the request instead of serving the old size. - Clearing one Hugging Face cache no longer forgets the sizes of the other three. A download or delete still forgets all four. - Recheck accepts any walk that began after the click, instead of only one that began after that cache's turn in the request. - The memo test fixture waits for background walk threads before restoring the patched state. ### Tests - Five new cases in `test_cache_inventory_walk.py` fail on main and pass here: - a queued walk does not hold a read - a refresh that cannot start walks in the request - Recheck accepts a walk begun after the request - the `refreshing` flag - clearing one Hugging Face cache keeps the other sizes - The new case in `cache-rows-model-folder.test.ts` fails on main and passes here. - Frontend: 13 of 13 tests pass across `cache-rows-model-folder.test.ts` and `settings-cache-purge.test.ts`. The typecheck passes. - Ten neighbouring cache, hub cache and route test files: main 934 passed, this branch 939 passed. - Both show the same single failure, `test_cached_gguf_routes.py::test_pipeline_class_guard_passes_every_shipped_family`. It is unrelated and already fails on main. - `py_compile` is clean on Python 3.9 and 3.10. ### Before and after Settings > System > Cache files, with a Triton cache whose walk takes a few seconds. The page read the cache once, the cache then grew by 5 GB after the 60 second memo expired, and Settings was opened again. Both shots are taken 25 seconds after opening. Both servers already held the new 5 GB size by then. Before this PR the row kept showing 0 B; with it the follow-up read swaps in 5.00 GB. 
The Settings page's cache list (
/api/settings/caches,studio/backend/utils/cache_inventory.py) sizes every cache bylstating every file under it: sizes and hard-link accounting needst_size,st_nlinkandst_inoper file. A machine with a large uv or Triton cache (here 3.9M and 2.17M files) pays 30 to 40 s per full inventory warm, and over 200 s with a cold inode cache, so the request times out. The answer is kept for 60 s, so every visit after the first minute paid the whole walk again on the request thread.What changes
studio/backend/utils/cache_inventory.py, response shape unchanged, frontend unchanged:Results
Per-root walk, warm, median of 3 (range), same roots on both sides:
Kernel time is unchanged: one
lstatper file is the floor, which is why the slow caches are refreshed off the request instead.Full
cache_inventory()request, wall time:The remaining 0.6 to 1.8 s is the torch inductor cache (about 1 s, under the threshold) and the small caches; the background refresh of uv and Triton then finishes in 26 to 42 s off the request thread.
Tests
studio/backend/tests/test_cache_inventory_walk.py(11): the new walk against the previous walk, kept as an oracle, on a tree with symlinks, hard links, unreadable and nested directories, a junction below the top level is still not walked, and the background refresh (a slow expired cache answers at once, a quick one is still walked in the request, Recheck waits for a fresh walk, a purge during a walk is not overwritten, background walks run one at a time and start after the request's own). 4 of them fail on main.test_artifact_mirrors,test_cached_gguf_routesx2,test_mlx_bnb_substitutionx3).Not covered
os.scandir/DirEntrycalls and the same junction handling as before.