Skip to content

Studio Hub download: keep refs/main on the last complete snapshot under failed updates and concurrent workers - #16422

Merged
danielhanchen merged 11 commits into
mainfrom
dh/hub-download-ref-rollback
Nov 3, 2026
Merged

danielhanchen merged 11 commits into
mainfrom
dh/hub-download-ref-rollback

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Failed or overlapping Studio model updates can leave refs/main on an incomplete or older snapshot, breaking later offline loads by repository ID even when complete files remain in the cache. Downloads now resolve an immutable revision, verify its expected files, and publish only the most recently started successful attempt.

A process-shared ledger coordinates publication and cancellation. Native owner locks let a later worker prune an abandoned attempt without guessing from PIDs, and GGUF reclamation protects the published revision and active peers. Saved manifests retain the revision needed for offline resumes.

The Windows run also exposed a cache identity mismatch: a symlink target can use an extended Windows path while the cache root uses an ordinary drive path. Blob classification now uses directory identity when resolved spellings differ, so obsolete blobs can be reclaimed without classifying outside-directory hard links as cache blobs.

Validation

  • Merge-base versus head tests reproduce failed updates, ordering races, cancellation, offline resumes and copied-file progress through a loopback HTTP Hub and the real offline Hugging Face resolver. No model weights were downloaded.
  • Linux: 70 download tests and 345 existing inventory, path-boundary, copy-layout, sibling-deletion and update-robustness tests passed. The identity fix's 12 reclaim/cancellation checks passed.
  • The protocol tests enumerate 13,440 two-worker and 8,870,400 three-worker schedules across three initial references and success, failure, cancellation and killed-owner outcomes.
  • Final-head differential: 29 behavioral fixes, no head failures or skips; 36 tests pass on head versus 32 failures and four passes on the merge base. New-helper and passing-on-base cases are excluded from the behavioral-fix count.
  • Scoped platform staging is green on Linux, Apple Silicon macOS and Windows. Windows: 65 passed, one POSIX-only SIGKILL test skipped, including the extended-path regression and the previously failing reclaim cases.
  • Current-head review is approved with no open findings. Local switchboard: NO_REGRESSION, current under its format-only rule for the empty CI-trigger commit. Staged browser comparisons: NO_REGRESSION on Linux, macOS and Windows; all nine jobs passed.
  • A focused before/after Model Hub parity capture from two isolated installs has identical heading, tabs and pixels. The broad crawler retains interaction-timing differences; the Ubuntu staging difference is confined to 364 pixels at the bottom edge of a model-list row. No UI control or layout change is introduced.

The publication protocol coordinates participating Studio workers. It does not claim a power-loss transaction across journal/reference writes, and external or older workers that ignore the ledger remain outside its ordering guarantee.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T05:20:17.890069Z 324b3d6 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…der snapshot, a rolled-back restart does not block a peer's publication

[skip ci]
…ed ledger, checked over every 2 and 3 worker interleaving

[skip ci]
…the ledger lock; manifests attest the resolved commit

[skip ci]
@Imagineer99 Imagineer99 self-assigned this Nov 2, 2026
@danielhanchen danielhanchen self-assigned this Nov 3, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 77398a74c2

ℹ️ 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".

danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 3, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: e2dbbd5284

ℹ️ 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".

danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 3, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 3, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 324b3d683d

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 1a951a9 into main Nov 3, 2026
@danielhanchen
danielhanchen deleted the dh/hub-download-ref-rollback branch November 3, 2026 05:35
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…as benign timing (#16526)

## Summary

`workflow-trigger lint` is red on main since #16422 (`1a951a93d6`). Its
"Workflow guard suites" step fails on unrelated PRs. In the last hour
that was the staging runs for #16423, #16182 and #16523:

```
tests/studio/test_backend_ci_parallel_isolation.py::test_every_tight_elapsed_bound_is_isolated
AssertionError: these backend tests compare clock-derived values and still run under -n 4 ...:
{'test_hf_download_fallback_and_kill.py': ['...:32 one duration against another'],
 'test_hf_download_reclaim_race.py': ['...:113 one duration against another'],
 'test_hf_download_ref_concurrency.py': ['...:72 one duration against another']}
```

All three sites are the same poll loop, which waits for a child process
to touch a `ready` file:

```python
deadline = time.monotonic() + 20   # 10 in test_hf_download_ref_concurrency.py
while not (tmp_path / "ready").exists():
    assert child.poll() is None, child.communicate()
    assert time.monotonic() < deadline, "worker did not reach the transfer barrier"
    time.sleep(0.01)
```

Being descheduled under `-n 4` only delays a poll; it cannot make the
condition false. The guard casts a deliberately wide net, and its
message names this exact case: a poll deadline goes in `BENIGN_TIMING`
as `(file, enclosing function)` with a reason. The tests and #16422's
download logic are fine; those entries were just never added.

## Change

`tests/studio/test_backend_ci_parallel_isolation.py`: three
`BENIGN_TIMING` entries under one reason comment. Each names the
function that holds the loop:
- `_wait_for_transfer`
- `test_gguf_reclaim_preserves_publication_and_active_peer`
- `test_peer_completion_survives_an_older_process`

I checked each of those functions: its only uses of `time.` are this
deadline, the comparison and the `sleep`, so the entries hide no other
timing check.

## Testing

- `tests/studio/test_backend_ci_parallel_isolation.py`:
- main: `test_every_tight_elapsed_bound_is_isolated` fails with the
error above;
  - this branch: 43 passed.
- No product or workflow file changes.
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…16530)

## Summary

Since #16422 (`1a951a93d6`), `(Python 3.13, rest)` fails on unrelated
PRs. On staging CI it hit #16423, #16182 and #16523 in the last hour,
and it reproduces on current main:

```
studio/backend/tests/test_scoped_download_worker.py::test_offline_scoped_download_fails_when_the_files_are_not_on_disk
studio/backend/tests/test_scoped_download_worker.py::test_offline_scoped_download_passes_when_every_file_is_present
studio/backend/tests/test_scoped_download_worker.py::test_a_dangling_symlink_does_not_count_as_present
hub/workers/hf_download.py:476: in _pinned_snapshot_download
E   OSError: Cannot resolve an immutable revision for black-forest-labs/FLUX.1-dev; retry when metadata is available
```

#16422 made every download pin an immutable commit. When metadata is
unreachable, `_pinned_snapshot_download` takes the commit from the Hub
cache's `refs/main` and refuses when there is none, rather than letting
`snapshot_download` hand back whatever folder is there. That is the
point of #16422, and I left it alone.

These tests' `offline` fixture predates it. It returns a bare tmp
`snapshot` dir and never puts a `refs/main` in the Hub cache, so every
case now stops at "no revision to pin" before reaching what it checks:
an incomplete copy, a complete copy, a dangling blob symlink. A real
offline user with a previously downloaded model has `refs/main` and its
`snapshots/<commit>`, so nothing changes for them.

## Change

`studio/backend/tests/test_scoped_download_worker.py` only:
- The fixture points `huggingface_hub.constants.HF_HUB_CACHE` at a tmp
dir. It writes `refs/main` and returns `snapshots/<commit>` there, the
layout an earlier download leaves behind.
- The three existing tests and their assertions are unchanged.
- New `test_offline_with_no_cached_revision_refuses_before_downloading`:
with no metadata and no `refs/main`, the worker raises the "immutable
revision" `OSError` and never calls `snapshot_download`. This pins
#16422's refusal, so the fixture change cannot hide a regression there.

## Testing

- `tests/test_scoped_download_worker.py`:
  - main: 3 failed, 1 passed (the error above);
  - this branch: 5 passed.
- Sabotage: with the offline missing-file refusal in
`_download_scoped_snapshot` disabled, the incomplete-copy and
dangling-symlink tests fail, so they still guard what they were written
for.
- `tests/test_hf_download*.py` plus this file: 102 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants