Skip to content

feat(buckets): open a bucket file as a streamed, seekable file - #2036

Open
alexandrujircan wants to merge 8 commits into
mainfrom
feat/buckets-open
Open

alexandrujircan wants to merge 8 commits into
mainfrom
feat/buckets-open

Conversation

@alexandrujircan

@alexandrujircan alexandrujircan commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds open() to BucketsService (sdk.buckets). It returns a read-only binary file over a file in a bucket, like a file opened with open(path, "rb"). The file is downloaded as it is read, so it can be passed to anything that takes a file without saving it to disk or holding it in memory first.

with sdk.buckets.open(name="Loans", blob_file_path="loan-123/application.pdf") as file:
    extraction = sdk.documents.start_ixp_extraction(
        project_name="LoanQAQC", tag="live", file=file
    )

The use case is a coded agent that sends large bucket files (50 MB and more) to Document Understanding. Today it has to download each file to disk, or into memory, before uploading it. With open the bytes go from the bucket to DU in 64 KiB chunks. No change to sdk.documents is needed: file= already accepts a binary file, and httpx sends this one like any other.

How it works

  • open: finds the bucket and returns an io.BufferedReader over a new private BucketFileReader (io.RawIOBase). The public return type is BinaryIO.
  • Read URL: each download looks up a fresh read URL, the first one included. On Orchestrator storage a URL is valid for about an hour, and a new URL also misses responses cached for an older one.
  • Read: a streamed GET, read one chunk at a time. The GET goes through the authenticated client, with the current token, when RequiresAuth is set, and through custom_client otherwise, as in download.
  • Size: from the download's Content-Length, or from Content-Range after a range request. If the storage reports neither, the size is known once a download reaches the end of the file. Asking for the size starts the download that the first read then continues, so seek(0, SEEK_END) followed by a full read is one GET.
  • Seek: moves the position only. The next read continues the open download when it is already at that position. Otherwise it starts a new download from there, with a Range header, and skips ahead when the storage ignores Range. Reading past the end returns end of file.
  • Rewind and retry: before each send, httpx rewinds a file passed to files=, so a retried upload sends the whole file again, from a new download.
  • Changed files: every download must return the same version of the file, by ETag and size. If the file was replaced in the bucket, the read raises the new BucketFileChangedError instead of cutting the file off or mixing bytes of two versions. Only an ETag tells two versions of the same size apart. Native Orchestrator storage can stream with no ETag or size, so there:
    • a new download from the start of the file, as a retried upload makes, is allowed: it has the whole file, so it can't mix versions. Its length must match the size already known, from its headers or, when it reports none, as it is read;
    • a new download from the middle of the file raises BucketFileChangedError.
  • Failures: the reader does not retry, and neither does its read-URL lookup. The code that reads the file retries, such as the sdk.documents upload's request retry, so a failure is retried at one layer.
    • An error status raises EnrichedException, as other SDK calls do.
    • A dropped connection, or a download that the storage ends before the end of the file, raises the new BucketFileReadError. The platform retry treats it as transient: the request sending the file was cut short, so it is sent again with the whole file. Read errors from the service itself keep the existing policy.
    • The next read starts a new download.
  • Signed URLs: the query string of a read URL is its signature.
    • A storage error carries the read URL without it. The status and headers stay, for the retry.
    • The download runs under suppress_http_instrumentation(), so HTTP client spans (httpx instrumentation, as in the agents runtime) don't record its URL. OTel redacts sig and Signature but not, for example, X-Amz-Signature.
  • Encoding: the GET asks for Accept-Encoding: identity, so the bytes read are the stored bytes and match the reported size.
  • download: download and download_async now use the shared read-URL lookup. Their behaviour is unchanged.

Async code

There is no open_async. Reading the file waits on the storage, as reading any file waits on the disk, and httpx reads files= uploads synchronously even in AsyncClient. So from async code, run open and the call that reads the file in a worker thread:

def extract(path):
    with sdk.buckets.open(name="Loans", blob_file_path=path) as file:
        return sdk.documents.start_ixp_extraction(project_name="LoanQAQC", tag="live", file=file)

extraction = await asyncio.to_thread(extract, "loan-123/application.pdf")

With a 100 MiB file from storage that pauses for 300 ms once, that kept the longest event-loop stall at 12 ms. Passing the file to start_ixp_extraction_async stalled it for 301 ms. Making the documents async upload read files off the event loop, local files included, is a follow-up in documents.

Testing

  • Unit tests: TestOpen in tests/services/test_buckets_service.py:
    • reading, getting the size without a second download, and rewinding to a new download from a new URL;
    • range requests, including when the storage ignores them, and reading past the end;
    • the URL looked up when the download starts;
    • the platform credentials and current token for storage that requires auth;
    • failures: no retry in the reader or its URL lookup, the next read starting again, and error responses closed;
    • a platform upload that retries a dropped download with the whole file, and a URL lookup failure retried five times in all, not five per attempt;
    • a download that ends before the end of the file;
    • the read URL's signature kept out of the error, with the status and Retry-After kept, and out of httpx instrumentation spans, on success and on an error status (opentelemetry-instrumentation-httpx is a new dev dependency for this test);
    • storage without an ETag or size: a rewind downloads the whole file again, a replacement of another length fails, a download from the middle is refused, and a platform upload retries a dropped download, chunked;
    • an httpx files= upload with an exact Content-Length that resends the whole file on a retry;
    • a file replaced in the bucket, by ETag and by size;
    • the size from a later 206 when the first download had none.
  • Full suite: the uipath-platform suite passes. ruff and mypy are clean on the changed files.
  • Live test on alpha (Orchestrator bucket storage, served through Cloudflare, RequiresAuth: false):
    • a 20 MiB file read whole and from the middle (206);
    • a file replaced in the bucket and read again, which raised BucketFileChangedError;
    • sdk.documents.start_ixp_extraction(file=<opened bucket file>), with the IXP extraction finishing with the expected values;
    • the same with storage without an ETag or size (headers removed from the real responses) and the first download dropped halfway: the upload was retried, chunked, from a new download, and the extraction finished.
  • Storage behaviour seen on alpha: ETag, Content-Length and Accept-Ranges: bytes are sent. If-Match is ignored. Read URLs expire after about an hour. Responses are cached per URL for 4 hours (cache-control: public, max-age=14400).

Notes

  • Resume triggers: with DocumentExtraction(file=...), the extraction starts after the step pauses, and by then a with block has closed the file. That case should keep the file open, or use file_path.
  • Follow-ups:
    • documents' async upload reading files off the event loop;
    • download streaming to disk with the same reader;
    • download and upload to external storage not checking the response status;
    • httpx logs every request URL at INFO level, so signed read URLs reach logs wherever INFO is on, for download too;
    • download and upload sending signed URLs with HTTP instrumentation on, as open did before this change.

🤖 Generated with Claude Code

`sdk.buckets.open()` and `open_async()` return a read-only binary file over
a file in a bucket. The file is downloaded as it is read, so it can be
handed to anything that takes a file, such as `file=` of
`sdk.documents.start_ixp_extraction`, without saving it to disk or holding
it in memory first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Dec 2, 2026
@alexandrujircan
alexandrujircan marked this pull request as ready for review December 2, 2026 10:39
Copilot AI balanced review requested due to automatic review settings December 2, 2026 10:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Authenticated downloads can send stale tokens, while stream error and EOF handling can prevent retries or produce unexpected 416 errors.

4 open issues
What changed in this PR

Adds streamed, seekable bucket files to the UiPath SDK, allowing direct uploads to Document Understanding without first downloading files to disk.

Changes:

  • Adds open() and open_async() with buffered reads, seeking, and refreshed download URLs.
  • Shares read-URL lookup logic and adds usage documentation and tests.
  • Bumps uipath-platform to 0.3.23 and updates lockfiles.
File Description
packages/​uipath/​uv.lock Updates the platform package version.
packages/​uipath/​docs/​core/​functions.md Documents direct bucket-to-document uploads.
packages/​uipath-platform/​uv.lock Updates the platform package version.
packages/​uipath-platform/​tests/​services/​test_buckets_service.py Tests streaming, seeking, authentication, and upload retries.
packages/​uipath-platform/​src/​uipath/​platform/​orchestrator/​_buckets_service.py Adds file-opening APIs and shared download helpers.
packages/​uipath-platform/​src/​uipath/​platform/​orchestrator/​_bucket_file_reader.py Implements the streamed, seekable reader.
packages/​uipath-platform/​pyproject.toml Bumps the package version to 0.3.23.

Review effort: Balanced

From review of the bucket file reader:
- A download that fails is dropped, so the next read starts a new one.
  Before, a rewind after a failure before the first chunk read as the end
  of the file, so a retried upload sent no file bytes.
- When the storage reports no size, the size is known once a download
  reaches the end of the file, so reading again at the end returns b"".
- A seek past the end before any read returns end of file: a 416 response
  gives the size instead of raising.
- A download that needs platform credentials sends the current token,
  which may have been renewed since the client was created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The reader ignores size information in later responses after an initial unknown size, and failed error-body reads can leave response streams open during retries.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Discover size from later responses when initially unknown

packages/​uipath-platform/​src/​uipath/​platform/​orchestrator/​_bucket_file_reader.py:121

If the initial download omits Content-Length, _size_checked becomes true while _size remains unknown. A later seek can receive a valid 206 with Content-Range, but this guard ignores its total, so seek(0, SEEK_END) still raises UnsupportedOperation even though storage has now reported the size. Please keep checking new responses until _size is known.

Medium severity Close error responses when reading their bodies fails

packages/​uipath-platform/​src/​uipath/​platform/​orchestrator/​_buckets_service.py:1831

If reading an error response body raises (for example, a timeout while receiving a 503 body), response.close() is skipped. The reader has not received this response yet, so it cannot clean it up either, leaving an open stream behind on each retry. Close the response in a finally block so failed error-body reads also release the connection.

4 resolved since last review

Review effort: Balanced

- Remove open_async. Reading the file waits on the storage, like reading
  any file waits on the disk, so an async method would suggest otherwise.
  From async code, read the file in a worker thread.
- Do not retry downloads in the reader. The code that reads the file
  retries, such as the sdk.documents upload, so a storage failure is
  retried once instead of up to 25 times.
- Raise BucketFileChangedError when a later download returns another
  version of the file, by ETag or size, instead of cutting it off or
  mixing two versions. Take the size from the first response reporting it.
- Look up a new read URL before every download, the first one included:
  the URL expires, and a new one misses responses cached for an older one.
- Close an error response even when reading its body fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unresolved issues allow replaced files to be silently truncated or accepted at the wrong length and cause storage connection resets to abort uploads instead of triggering retries.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

High severity Validate replacement download length against cached size

packages/​uipath-platform/​src/​uipath/​platform/​orchestrator/​_bucket_file_reader.py:84

When storage omits ETag and size headers, rewinding after a replacement does not validate its actual length against the cached size. A larger replacement can be silently cut off at the old size, while a shorter replacement reaches EOF at lines 92–94 without raising BucketFileChangedError. Validate the observed download length against the cached size, rejecting both premature EOF and extra bytes rather than treating the cached size alone as proof of EOF.

Medium severity Make storage read errors eligible for upload retries

packages/​uipath-platform/​src/​uipath/​platform/​orchestrator/​_bucket_file_reader.py:167

A storage connection reset raises httpx.ReadError, which is re-raised unchanged here, but the documents upload's retry predicate in common/retry.py:74–81 does not accept it. Consequently, start_ixp_extraction(file=...) aborts instead of rewinding and retrying the download. Make storage-body failures recognizable to the upload retry policy while keeping retries out of the reader itself.

Review effort: Balanced

file off at the old size, or mix bytes of the two versions.
"""
etag = response.headers.get("ETag")
if (etag and self._etag and etag != self._etag) or (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

native Orchestrator can stream without ETag or Content-Length. after a rewind, the cached size can truncate a larger replacement or accept a shorter one, and matching sizes can still mix versions. let's require a reliable storage version or fail a reopen we can't validate. earlier version-check thread

alexandrujircan and others added 2 commits December 3, 2026 12:37
… errors

- A download that fails, or that the storage ends before the end of the
  file, raises BucketFileReadError. The platform retry treats it as
  transient: the request sending the file was cut short, so a documents
  upload sends the whole file again from a new download. Errors from the
  service itself keep the existing retry policy.
- The read-URL lookup of an opened file makes a single attempt, like the
  download: whoever reads the file retries, at one layer.
- A storage error carries the read URL without its query string, which is
  its signature; the status and headers stay for the retry.
- A download after the first needs the first one's ETag. A storage that
  reports none can't show a replacement of the same size, so such a file
  isn't downloaded a second time (BucketFileChangedError, verified=False).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Native Orchestrator storage can stream a file with no ETag or size. The
previous rule refused any second download there, so a retried upload
failed instead of sending the file again.

A download from the start of the file has the whole file, so it can't
mix two versions: without an ETag it is now allowed, and checked by its
length against the size already known, from its headers or, when it
reports none, as it is read (no extra bytes, no early end). A download
from the middle still needs the ETag. Reads also stop at the known size.

Checked live on alpha with the ETag and size headers removed and the
first download dropped halfway: the documents upload retried, chunked,
and the extraction finished.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The read URL's query string is its signature, and httpx instrumentation,
as the agents runtime sets it up, records each request's URL. It redacts
`sig` and `Signature`, not every storage's signature, such as
`X-Amz-Signature`. The download now runs under
`suppress_http_instrumentation()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexandrujircan and others added 2 commits December 3, 2026 13:54
0.3.23 was released from main. The uipath lock also records
uipath-platform's new dev dependency.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-integrations cross-tests are FAILING 🚨

Your changes may break one or more integrations in uipath-integrations-python:

  • uipath-openai-agents
  • uipath-google-adk
  • uipath-agent-framework
  • uipath-llamaindex
  • uipath-pydantic-ai

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants