1818use std:: fmt:: Debug ;
1919use std:: sync:: Arc ;
2020
21- use backon:: ExponentialBuilder ;
22- use backon:: Retryable ;
2321use bytes:: Buf ;
2422use bytes:: Bytes ;
2523use http:: Request ;
@@ -219,7 +217,6 @@ pub struct HfCore {
219217 pub root : String ,
220218 pub token : Option < String > ,
221219 pub endpoint : String ,
222- pub max_retries : usize ,
223220
224221 /// HTTP client with redirects disabled, used by XET probes to
225222 /// inspect headers on 302 responses.
@@ -243,7 +240,6 @@ impl HfCore {
243240 root : String ,
244241 token : Option < String > ,
245242 endpoint : String ,
246- max_retries : usize ,
247243 no_redirect_client : HttpClient ,
248244 ) -> Self {
249245 Self {
@@ -252,7 +248,6 @@ impl HfCore {
252248 root,
253249 token,
254250 endpoint,
255- max_retries,
256251 no_redirect_client,
257252 }
258253 }
@@ -267,21 +262,12 @@ impl HfCore {
267262 root : String ,
268263 token : Option < String > ,
269264 endpoint : String ,
270- max_retries : usize ,
271265 ) -> Result < Self > {
272266 let standard = HttpClient :: with ( build_reqwest ( reqwest:: redirect:: Policy :: default ( ) ) ?) ;
273267 let no_redirect = HttpClient :: with ( build_reqwest ( reqwest:: redirect:: Policy :: none ( ) ) ?) ;
274268 info. update_http_client ( |_| standard) ;
275269
276- Ok ( Self :: new (
277- info,
278- repo,
279- root,
280- token,
281- endpoint,
282- max_retries,
283- no_redirect,
284- ) )
270+ Ok ( Self :: new ( info, repo, root, token, endpoint, no_redirect) )
285271 }
286272
287273 /// Build an authenticated HTTP request.
@@ -304,30 +290,14 @@ impl HfCore {
304290 self . repo . uri ( & self . root , path)
305291 }
306292
307- /// Send a request with retries, returning the successful response.
308- ///
309- /// Retries on commit conflicts (HTTP 412) and transient server errors
310- /// (HTTP 5xx) up to `self.max_retries` attempts with exponential backoff.
293+ /// Send a request and return the successful response or a parsed error.
311294 pub ( super ) async fn send ( & self , req : Request < Buffer > ) -> Result < Response < Buffer > > {
312- let backoff = ExponentialBuilder :: default ( )
313- . with_min_delay ( std:: time:: Duration :: from_millis ( 200 ) )
314- . with_max_delay ( std:: time:: Duration :: from_millis ( 6400 ) )
315- . with_max_times ( self . max_retries . saturating_sub ( 1 ) ) ;
316- let client = self . info . http_client ( ) ;
317-
318- let send_once = || async {
319- let resp = client. send ( req. clone ( ) ) . await ?;
320- if resp. status ( ) . is_success ( ) {
321- Ok ( resp)
322- } else {
323- Err ( parse_error ( resp) )
324- }
325- } ;
326-
327- send_once
328- . retry ( backoff)
329- . when ( |e : & Error | e. kind ( ) == ErrorKind :: ConditionNotMatch || e. is_temporary ( ) )
330- . await
295+ let resp = self . info . http_client ( ) . send ( req) . await ?;
296+ if resp. status ( ) . is_success ( ) {
297+ Ok ( resp)
298+ } else {
299+ Err ( parse_error ( resp) )
300+ }
331301 }
332302
333303 /// Send a request, check for success, and deserialize the JSON response.
@@ -402,16 +372,11 @@ impl HfCore {
402372 . body ( Buffer :: new ( ) )
403373 . map_err ( new_request_build_error) ?;
404374
405- let mut attempt = 0 ;
406- let resp = loop {
407- let resp = self . no_redirect_client . send ( req. clone ( ) ) . await ?;
375+ let resp = self . no_redirect_client . send ( req) . await ?;
408376
409- attempt += 1 ;
410- let retryable = resp. status ( ) . is_server_error ( ) ;
411- if attempt >= self . max_retries || !retryable {
412- break resp;
413- }
414- } ;
377+ if resp. status ( ) . is_client_error ( ) || resp. status ( ) . is_server_error ( ) {
378+ return Err ( parse_error ( resp) ) ;
379+ }
415380
416381 let hash = resp
417382 . headers ( )
@@ -434,11 +399,6 @@ impl HfCore {
434399 Ok ( Some ( XetFileInfo :: new ( hash. to_string ( ) , size) ) )
435400 }
436401
437- /// Commit file changes (uploads and/or deletions) to the repository.
438- ///
439- /// Retries on commit conflicts (HTTP 412) and transient server errors
440- /// (HTTP 5xx), matching the behavior of the official HuggingFace Hub
441- /// client.
442402 /// Determine upload mode by calling the preupload API.
443403 ///
444404 /// Returns the upload mode string from the API (e.g., "regular" or "lfs").
@@ -626,7 +586,6 @@ pub(crate) mod test_utils {
626586 "/" . to_string ( ) ,
627587 None ,
628588 endpoint. to_string ( ) ,
629- 3 ,
630589 HttpClient :: with ( mock_client. clone ( ) ) ,
631590 ) ;
632591
0 commit comments