PIGS-1096 - Presigned URLs, streaming upload/download, and progress bars - #15
Merged
brianom merged 3 commits intoSep 10, 2026
Merged
Conversation
…gress bars - Add BaseOAuthClient.build() as a context-managed factory, backed by two httpx2 clients: one authenticated against the platform, one plain for presigned/arbitrary URLs so the platform bearer token never leaks onto them - Switch every file upload to the platform's presigned-URL flow (mint a fresh pair, stream the file to it, submit an application/vnd.gonitro.url+json file reference) instead of inlining raw bytes into the multipart request - Stream both the upload and the async job's result download in chunks with a live rich progress bar, instead of buffering whole files in memory - Rewrite PlatformAPIClient's SSE job-status handling on httpx2's native SSE support with a discriminated pydantic union (ProgressUpdate/StatusUpdate/ Redirect) validated via TypeAdapter, replacing the hand-rolled line parser - Fix _request_async_bytes fetching the job's JSON representation instead of the actual result file (it relied on an Accept header the API doesn't honor) - Split benchmark.OperationResult into OperationSuccess/OperationFailure so a run's fields are only ever the ones that outcome can actually produce - Add FatalError (a SystemExit subclass) for clean, traceback-free CLI errors on user-facing validation failures, replacing scattered print+exit pairs - Add services.OptimizerService as a small facade over PlatformAPIClient for the optimize workflow, and wire optimize_benchmark.py through it - Assorted cleanup: MIME type lookup by extension instead of the stdlib mimetypes module, httpx2 status codes instead of hardcoded ints, and other small consistency fixes across the API clients Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…L job flow Every PlatformAPIClient operation now goes through the async job flow (submit with Prefer: respond-async, follow the SSE status stream, fetch the result) with the file uploaded via a presigned URL, matching the pattern optimize() already used — factored the shared submit/poll/fetch logic into _submit_async_job. extract_text is the deliberate exception: it stays on a synchronous, non-presigned request, for operations known to always run against small, bounded documents where the extra round trip isn't worth it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
brianom
approved these changes
Sep 10, 2026
brianom
left a comment
Contributor
There was a problem hiding this comment.
Focused on optimize benchmark tool, looks good
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
application/vnd.gonitro.url+jsonfile reference) instead of inlining raw bytes into the multipart requestrichprogress bar, instead of buffering whole files in memoryBaseOAuthClient.build()is now a context-managed factory backed by twohttpx2clients — one authenticated against the platform, one plain for presigned/arbitrary URLs, so the platform bearer token never leaks onto themhttpx2's native SSE support with a discriminated pydantic union (ProgressUpdate/StatusUpdate/Redirect), replacing the hand-rolled line parser_request_async_bytesfetching the job's JSON representation instead of the actual result file (it relied on anAcceptheader the API doesn't honor)benchmark.OperationResultintoOperationSuccess/OperationFailureso a run's fields are only ever the ones that outcome can actually produceFatalError(aSystemExitsubclass) for clean, traceback-free CLI errors on user-facing validation failuresservices.OptimizerServiceas a small facade overPlatformAPIClientfor the optimize workflow, and wiredoptimize_benchmark.pythrough itmimetypesmodule,httpx2status codes instead of hardcoded ints, and other small consistency fixes across the API clientsTest plan
ruff check .andpyrightclean across the wholesamples/pythonprojectmerge(multi-file), the full async optimize job flow (submit → SSE progress → result download), and the streaming upload/download progress bars (verified byte-for-byte content integrity via SHA-256 on a multi-MB file)pyte(real terminal emulation) to confirm the progress bars don't corrupt surrounding CLI outputtask optimize-benchmark INPUT_DIR=... OUTPUT_DIR=...)