← Back to Pull requests

fix(client): FileSet upload retries and timeout propagation #1125

Closed
unknown closed this pull request without merging on Aug 07, 2026 15:57 UTC
View on GitHub
unknown unknown commented on Aug 06, 2026 04:06 UTC
Author

Summary

It was observed that a FileSet upload that hit a transient failure failed with h11._util.LocalProtocolError: Too little data for declared Content-Length error. 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's FilesetFileSystem._put_file, which implements fsspec.

file_size =  (await anyio.Path(lpath).stat()).st_size

async def stream_file() -> AsyncIterator[bytes]:
    async with await anyio.open_file(lpath, "rb") as f:
        while chunk := await f.read(self.blocksize):
            callback.relative_update(len(chunk))
            yield chunk

await self._client.with_headers({"Content-Length": str(file_size)}).upload_file(
    ...
    content=stream_file(),
)

The stream_file() is a generator object that gets called and stored once in PreparedRequest.content and reused by every pass of NemoClient's retry loop. If any transient failures occur, then the same Content-Length followed by zero bytes (the generator is already exhausted) is sent, which breaks the HTTP/1.1 protocol, and we get a httpx.LocalProtocolError, which subclasses TransportError, 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_io taks:

UPLOAD_TIMEOUT = httpx.Timeout(30.0, write=10 * 60, read=5 * 60)
self.sdk.with_options(timeout=UPLOAD_TIMEOUT).files.upload(...)

The expected behaviour is that UPLOAD_TIMEOUT would propagate down to files.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 new NeMoPlatform client with the new timeout based on UPLOAD_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, ...)
  • then client_from_platform shares the NeMoPlatform._client. The sharing is not wrong by itself, it's the fact that we didn't propagate the NeMoPlatform.timeout in the first place.

  • the issue is made worse by the fact that downstream,FilesetFileSystem._ensure_async built a brand new https.AsyncClient with no timeout at all, which defaults to 5s.
  • 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 code

  • tasks/file_io/run.py -- retry here instead, since it can rebuild the generator

  • client/adapter.py + filesystem/filesystem.py -- propagate the timeout properly

  • - Adapter applies client.with_options(timeout=platform.timeout)
    - ensure_async propagates the timeout onto both the new https.AsyncClient as well as the AsyncFilesClient

    <!-- 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 -->

    Diff: 542 lines (+406 / -136) across 6 files Reviewer: matthewgrossman Review duration: 2151m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.0% (MEDIUM) · Higher = larger blast radius
    48.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.8% · Safe to merge
    20.8%