fix(client): FileSet upload retries and timeout propagation #1125
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 542 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1125"
general
weight: 0.35
matthewgrossman
Summary
It was observed that a FileSet upload that hit a transient failure failed with
h11._util.LocalProtocolError: Too little data for declared Content-Lengtherror. However, this is a bit of a red herring, because it hides the underlying issue, which is a bit gnarly, so let's dig a bit deeper.Root cause
The core crux of the issue is in
filesystem.py'sFilesetFileSystem._put_file, which implementsfsspec.The
stream_file()is a generator object that gets called and stored once inPreparedRequest.contentand reused by every pass ofNemoClient's retry loop. If any transient failures occur, then the sameContent-Lengthfollowed by zero bytes (the generator is already exhausted) is sent, which breaks the HTTP/1.1 protocol, and we get ahttpx.LocalProtocolError, which subclassesTransportError, which gets retried until attempts ran out. This is bad because we actually lose the information for the original error.So what could've caused the original failure?
Let's start with entrypoint from Customizer's
file_iotaks:The expected behaviour is that
UPLOAD_TIMEOUTwould propagate down tofiles.upload, which should extend the write timeout to a generous 600s. However, this is not the case. What actually happened was:with_options(...)created a newNeMoPlatformclient with the new timeout based onUPLOAD_TIMEOUT, but keeps the _original_httpx.Client, which has its own timeout (60s). So now there are two timeouts:-
NeMoPlatform.timeout = Timeout(30, write=600, read=300)-
NeMoPlatform._client.timeout = Timeout(60, ...)client_from_platformshares theNeMoPlatform._client. The sharing is not wrong by itself, it's the fact that we didn't propagate theNeMoPlatform.timeoutin the first place.FilesetFileSystem._ensure_asyncbuilt a brand newhttps.AsyncClientwith no timeout at all, which defaults to5s.Essentially,
FilesetFileSystem._put_file's httpx client had a timeout of 5s (on both writes and reads). This could error for both scenarios:1. Streaming all the chunks of a large file took longer than 5s, times out on the write phase
2. Even if we streamed all the chunks, the Files service might not respond within 5s because it needs to commit all the chunks to storage, triggering a timeout
The fix involved changes in multiple layers of the code:
client/client.py-- don't retry requests with generator bodies, at least not at this layer of the codetasks/file_io/run.py-- retry here instead, since it can rebuild the generatorclient/adapter.py+filesystem/filesystem.py-- propagate the timeout properly- Adapter applies
client.with_options(timeout=platform.timeout)-
ensure_asyncpropagates the timeout onto both the newhttps.AsyncClientas well as theAsyncFilesClient<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Bug Fixes
Bug Fixes
Client timeout settings are now preserved across synchronous, asynchronous, and filesystem operations, including unlimited-timeout configurations.
Retry behavior now avoids replaying partially consumed streaming uploads.
File operations retry more reliably for temporary connection, rate-limit, and server errors.
Upload failures now surface consistently after retry attempts are exhausted.
Fileset metadata is validated consistently during creation and updates.
File listings now provide consistent file details.
Documentation
* Clarified retry behavior for one-time request bodies and streaming uploads.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->