Repository navigation
studio: close the delete-vs-load races around the H3 companion repos - #8657
Conversation
asset_repos is what stops the delete-cached guard admitting a delete of the H3 companion repos while a load is pulling from them. #8560 moved the sd-cli preflight ahead of the four-file download, which is right, but the claim stayed below it, so the window the guard is blind to is now the whole prebuilt install: minutes, not microseconds. A delete admitted inside that window is not revoked by claiming the repos afterwards, and it can then remove cached files underneath the load that follows. The base_repo and asset_repos claim moves above the preflight. expected_bytes stays where it is, since the sizes are not known any earlier.
|
Codex Review: Didn't find any major issues. Another round soon, 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff1c46bb80
ℹ️ 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".
| # registry claim, so nothing marks them active. Without this the claim is checked and then | ||
| # deleted around, which is the check-then-act the reservation exists to close. | ||
| try: | ||
| blocks_detail = await asyncio.to_thread(_load_state_blocks_delete) |
There was a problem hiding this comment.
Make load admission share the delete reservation
When an Images or Video load starts after this second read returns but before or during _delete_cached_model_blocking, the new load publishes its claim too late and deletion can still unlink files it is downloading or assembling. Fresh evidence in this revision is that the new check at line 830 is followed by the destructive dispatch at line 842 without any lock or reservation that VideoBackend.begin_load() must acquire; begin_delete() only excludes registry-backed downloads, while these loads bypass that registry. The added test covers a load appearing between the first and second reads, but not this remaining post-check interval, so admission needs a shared reservation rather than another point-in-time read.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one here. The remaining window is real but it is the point-in-time guard design that every backend already shares, and it is not what this PR set out to change: the guard was minutes wide when a load could start during the sd-cli preflight, is now the recheck-to-unlink interval, and each narrowing has been inside the scope the previous one opened. The shared reservation you are describing does already exist, claim_repository_owner, and begin_delete refuses against it, so the correct closure is for load admission to take it rather than for the guard to be read a third time. That changes download admission for the whole repo for the duration of a load, applies to chat and Images equally rather than to the H3 path this PR touches, and needs its own tests, so it belongs in its own change rather than tacked onto this one.
|
Codex Review: Didn't find any major issues. Another round soon, 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. Keep it up! 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". |
Summary
_loading.asset_reposis what stops the delete-cached guard admitting a delete of the H3 companion repos while a load is pulling from them. Its own comment says so.#8560 moved the sd-cli preflight ahead of the four-file download, which is right. But the claim stayed below it, so the window the guard is blind to became the whole prebuilt install rather than the microseconds it used to be:
A delete admitted inside that window is not revoked by claiming the repos afterwards, so it can then remove cached files underneath the load that follows. Review found two narrower versions of the same check-then-act above and below that one, and this PR closes all three.
Changes
1. The claim moves above the preflight (
video.py).expected_bytesstays where it is, since the sizes are not known any earlier.2.
begin_loadpublishes the claim with the loading state. Moving it to the top of the worker still left a gap:begin_loadreturns as soon as the thread is scheduled, so a delete arriving before that thread runs readsloading_repo_ids()with onlyrepo_idandbase_repo. The companion tuple now goes into the_VideoLoadingStateconstructor, inside the same locked section that publishes_loading. The worker-side claim stays as a no-op repeat forload_pipeline, which never goes throughbegin_load.3. The delete guard is re-read after the scope is reserved (
deletion.py). The guard ran beforebegin_delete, with the cache-key case resolution between them, andbegin_deletecould not see these loads either: video and image loads download directly rather than through a registry claim, so nothing marks them active. The guard is now re-derived once the reservation succeeds, which is the same reserve-then-re-derive theonly_if_orphanbranch below it already does for its own question.Validation
test_h3_native_load_claims_the_companion_repos_before_the_preflightasserts the claim is visible from inside the preflight. Fails on main withassert [()] == [('unsloth/MiniMax-H3-GGUF', 'Comfy-Org/MiniMax-H3')].test_begin_load_publishes_the_h3_companion_claim_with_the_loading_statestubs the load thread so it never starts and asserts both companions are already claimed;test_begin_load_claims_no_companion_repos_for_a_non_h3_familypins the other side. The first fails without change 2.test_delete_cached_rechecks_the_load_guard_after_reserving_the_scopereports idle on the first guard read and loading on the second, and expects the delete refused. Fails without change 3.test_video_backend.py,test_sd_cpp_backend.py,test_sd_cpp_engine.py,test_diffusion_engine_router.py,test_cached_gguf_routes.py,test_video_routes.py: all pass. Ruff clean.Not in this PR
The remaining interval between the second guard read and the unlink needs load admission to take the
claim_repository_ownerreservation thatbegin_deletealready refuses against. That changes download admission for the whole repo for the duration of a load and applies to chat and Images equally, so it belongs in its own change rather than here.Supersedes #8570, which I closed: #8560 landed the preflight hoist, the cancel check and the unmanaged re-vet, and did the last of those better than my version (dropping the ownership test outright, and using a verdict form for the accelerator probe that does not fold "could not tell" into True). This ordering fix is the one thing that was left.