feat: callback-based progress tracking for uploads and downloads#19
Open
assafvayner wants to merge 11 commits intomainfrom
Open
feat: callback-based progress tracking for uploads and downloads#19assafvayner wants to merge 11 commits intomainfrom
assafvayner wants to merge 11 commits intomainfrom
Conversation
Callback-based progress system for upload/download with ProgressHandler trait, ProgressEvent enum, xet polling bridge, and indicatif CLI bars matching the Python hf CLI style.
Design for adding TransferTask<T> with ProgressHandle to download/upload APIs, using IntoFuture for backward-compatible .await and lazy polling of hf-xet progress objects.
assafvayner
commented
Apr 6, 2026
assafvayner
commented
Apr 6, 2026
Account for blocking API macro refactor (sync_api!/sync_api_stream!/ sync_api_async_stream! in macros.rs), new download methods (download_file_stream, download_file_to_bytes), and lib.rs glob re-export pattern. The polling design gains a sync_api_transfer! macro variant and updated blocking API section. The callback design notes that macros forward progress transparently via params structs.
Add a ProgressHandler trait and structured ProgressEvent types that allow callers to receive real-time progress updates during file transfers. The library emits events for upload phases (preparing, checking upload mode, uploading, committing) and per-file download byte progress. The hfrs CLI wires up an indicatif-based handler that renders progress bars matching the Python hf CLI style.
- Move inline `use` statements to top of file (xet.rs, download_test.rs) - Update Project Layout in CLAUDE.md with new progress.rs module - Add examples/progress.rs demonstrating ProgressHandler usage - Replace unwrap() with expect()/unwrap_or_else() in CLI progress.rs - Remove trivial doc comments that restate type names - Wire progress through snapshot_download (was being ignored)
Doc comments (///) on public types generate cargo doc output and should not be stripped as trivial comments. Updated CLAUDE.md to distinguish inline comments (no restating code) from doc comments (required on all public API surface).
Add doc comments to ProgressHandler::on_progress(), FileStatus variants, CliProgressHandler, and progress_disabled().
- Fix nested lifecycle: snapshot_download no longer emits duplicate
Start/Complete through child download_file calls. Introduced
download_file_inner() without lifecycle events; download_concurrently
uses it while the public download_file() wraps with Start/Complete.
- Add xet download progress: all three xet download methods now accept
a Progress handle and spawn a polling task that emits AggregateProgress
every 100ms during group.finish(). Cache path also emits per-file
Complete (was missing entirely).
- Add xet upload progress: replace single-shot before/after emit with
a polling task that reports UploadEvent::Progress{Uploading} every
100ms during commit().await.
- Emit per-file Complete events for xet batch downloads in
snapshot_download so the CLI files_bar increments correctly.
Resolve conflicts in repo_params (params moved to types/repo_params.rs on main), add progress fields to the new param location. Update download_test.rs: - Read-only tests use prod_api() (HF_PROD_TOKEN in CI) - Upload progress tests use hub_ci_api() (HF_CI_TOKEN in CI) - New tests: upload_file_with_progress, create_commit_with_progress (multiple files), upload_with_no_progress_handler - All write tests create temporary repos on hub-ci and clean up
Collaborator
Author
Code reviewFound 2 issues:
huggingface_hub_rust/huggingface_hub/src/api/files.rs Lines 111 to 120 in b340113
huggingface_hub_rust/huggingface_hub/src/bin/hfrs/progress.rs Lines 212 to 218 in b340113 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ProgressHandlertrait and structuredProgressEventtypes (UploadEvent,DownloadEvent) that allow callers to receive real-time progress callbacks during file transfersPreparing→CheckingUploadMode→Uploading→Committing) plus aggregate byte progressStarted→InProgress→Complete) and aggregate xet progressprogress: Progressfield (Option<Arc<dyn ProgressHandler>>) that defaults toNone— existing callers are unaffectedindicatif-based handler (CliProgressHandler) that renders multi-progress bars, respects--quietandHF_HUB_DISABLE_PROGRESS_BARSGroupProgressReportNew files
huggingface_hub/src/types/progress.rsProgressHandler,ProgressEvent,UploadEvent,DownloadEvent,FileProgress,FileStatus,UploadPhase,Progress,emit()huggingface_hub/src/bin/hfrs/progress.rsCliProgressHandlerwith indicatifMultiProgressKey design decisions
ProgressEvent::Upload(UploadEvent)) separates upload/download concerns at the type levelProgresstype alias (Option<Arc<dyn ProgressHandler>>) keeps params structs cleanprogresspasses through as part of the params struct via existingsync_api!macrosTest plan
types/progress.rs— event recording, phase progression, batched file complete, None handler is no-op, Send+Sync compile check (6 tests)tests/download_test.rs— download with progress to local dir, download with progress to cache, download without progress handler (3 tests)cargo +nightly fmt --checkpassescargo clippy --all-features -D warningspassescargo test -p huggingface-hub --lib— 67 tests passcargo build --releasesucceedscargo test -p huggingface-hub --all-featureswhich picks up all new unit and integration tests automatically