Skip to content

fix(python-sdk): download files over HTTP/1.1 to avoid h2 too_many_data_frames - #2088

Merged
mishushakov merged 7 commits into
mainfrom
devin/1793731677-python-downloads-http1
Nov 3, 2026
Merged

mishushakov merged 7 commits into
mainfrom
devin/1793731677-python-downloads-http1

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2027. Same change as the closed #2039, rebased on main. It replaces the Accept-Encoding: identity approach from #2087, which broke /proc and /sys reads on envd 0.10.0.

Root cause: httpx asks for gzip by default, so envd gzips file downloads and sends no Content-Length. Through the sandbox proxy chain, that body reaches HTTP/2 clients with an empty non-final DATA frame after about every 32 KiB. The h2 bundled in pyqwest counts empty DATA frames over the whole life of a connection and closes it after 100 with ENHANCE_YOUR_CALM / too_many_data_frames. So a single read of about 3.2 MB or more always fails, and smaller reads fail once a reused connection has built up enough empty frames. The JS SDK isn't affected: its HTTP/2 client doesn't enforce that limit.

Fix: files.read, sync and async, in every format, now goes over dedicated HTTP/1.1 clients, whatever http_version is set to. Everything else, including uploads, keeps the configured version.

ENVD_API_FILE_DOWNLOAD_HTTP_VERSION: HttpVersion = "1.1"
get_envd_api(config, url, http_version=ENVD_API_FILE_DOWNLOAD_HTTP_VERSION)                      # buffered reads
get_envd_api(config, url, for_streaming=True, http_version=ENVD_API_FILE_DOWNLOAD_HTTP_VERSION)  # format="stream"

This works on every envd version, including gzip reads of /proc files.

Trade-off: on HTTP/1.1, each in-flight download holds a whole connection. The pool's E2B_MAX_CONNECTIONS cap (default 200) applies per resolved address, and every sandbox shares envd's edge address. So a process can run at most that many downloads at once; any more wait for a connection. The README now says this.

E2B_MAX_CONNECTIONS=400 python eval.py

Verification

  • I ran the issue's live script on this branch: 0/10 failures at 0.5, 2, 4.5 and 8 MB.
  • New offline test tests/test_envd_file_download_empty_data_frames.py: a local server sends empty DATA frames over h2. It fails with too_many_data_frames without the fix.
  • The existing live read, content-encoding and filesystem-only snapshot tests pass, and format, lint and typecheck pass.

Link to Devin session: https://app.devin.ai/sessions/550e475556994f51b1ba7970bc4590f5
Open in Devin Desktop: https://app.devin.ai/desktop/session/550e475556994f51b1ba7970bc4590f5?variant=devin


Devin Review

…ta_frames

The sandbox proxy pads file responses with an empty non-final DATA frame
every ~32 KiB. h2 (bundled by pyqwest) counts those over a connection's
lifetime and closes it with ENHANCE_YOUR_CALM after 100, failing reads of
a few MB every time and smaller ones once a pooled connection accumulates
the count. Route files.read over the HTTP/1.1 envd transport.

Fixes #2027

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…indows

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T18:51:21.875773Z c341367 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from a376b57. Download artifacts from this workflow run.

JS SDK (e2b@2.62.2-devin-1793731677-python-downloads-http1.0, with @e2b/dockerfile-utils@0.1.2-devin-1793731677-python-downloads-http1.0):

npm install ./e2b-dockerfile-utils-0.1.2-devin-1793731677-python-downloads-http1.0.tgz ./e2b-2.62.2-devin-1793731677-python-downloads-http1.0.tgz

CLI (@e2b/cli@2.23.1-devin-1793731677-python-downloads-http1.0):

npm install ./e2b-cli-2.23.1-devin-1793731677-python-downloads-http1.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.9.2-devin-1793731677-python-downloads-http1.0):

npm install ./e2b-code-interpreter-2.9.2-devin-1793731677-python-downloads-http1.0.tgz

Desktop JS SDK (@e2b/desktop@2.5.1-devin-1793731677-python-downloads-http1.0):

npm install ./e2b-desktop-2.5.1-devin-1793731677-python-downloads-http1.0.tgz

Python SDK (e2b==2.62.0+devin.1793731677.python.downloads.http1, with e2b-dockerfile-utils==0.1.1+devin.1793731677.python.downloads.http1):

pip install ./e2b_dockerfile_utils-0.1.1+devin.1793731677.python.downloads.http1-py3-none-any.whl ./e2b-2.62.0+devin.1793731677.python.downloads.http1-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.11.7+devin.1793731677.python.downloads.http1):

pip install ./e2b_code_interpreter-2.11.7+devin.1793731677.python.downloads.http1-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.7.2+devin.1793731677.python.downloads.http1):

pip install ./e2b_desktop-2.7.2+devin.1793731677.python.downloads.http1-py3-none-any.whl

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TASTE.md review: complies, 0 violations. Checked T-1/T-2 (JS/sync/async parity; the download-only HTTP/1.1 override is a Python-only workaround for a pyqwest h2 limit, applied to both sync and async, and documented on ApiParams.http_version), T-3a (new http_version is keyword-only), T-11 (uses HttpVersion), T-47 (ENVD_API_FILE_DOWNLOAD_HTTP_VERSION is a named constant), T-49 (config precedence unchanged), and T-24/T-48 (files.read formats and stream_idle_timeout unchanged).

Written by Devin

@mishushakov
mishushakov enabled auto-merge (squash) November 3, 2026 18:51
@mishushakov
mishushakov disabled auto-merge November 3, 2026 18:53
claude[bot]

This comment was marked as resolved.

…ONS cap

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f8b6b23

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@e2b/python-sdk Patch
@e2b/code-interpreter-python Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mishushakov

Copy link
Copy Markdown
Member

actually I think global connection limit was okay

…MAX_CONNECTIONS

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Done. I reverted the separate E2B_MAX_HTTP1_CONNECTIONS cap in b3954ec, so downloads are capped by E2B_MAX_CONNECTIONS again. In 5ca8dc1 I added a short README note: downloads use an HTTP/1.1 pool under that limit, so a process can run at most that many downloads at once.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mishushakov
mishushakov merged commit 48d24ac into main Nov 3, 2026
34 checks passed
@mishushakov
mishushakov deleted the devin/1793731677-python-downloads-http1 branch November 3, 2026 19:29
mishushakov added a commit that referenced this pull request Nov 30, 2026
…/2 again (#2197)

## Summary
Bumps `pyqwest` `>=0.12.0,<0.13` → `>=0.15.0,<0.16`
([v0.15.0](https://github.com/curioswitch/pyqwest/discussions/308)) and
drops the workarounds it makes unnecessary. Lockfiles of `acp-python`,
`code-interpreter-python` and `desktop-python` are relocked.

- **HTTP/2 downloads (#2027):** pyqwest 0.15 ships h2 with the
empty-DATA-frame fix (anuraaga/h2#1, cherry-pick of hyperium/h2#972):
empty frames now cost from a budget that payload frames refill, instead
of a 100-per-connection lifetime cap. So the #2088 workaround is
narrowed: `files.read` in `text`/`bytes` format uses `self._envd_api` on
the configured `http_version` (the dedicated `_envd_api_download` client
is gone).
- **Streamed reads stay on HTTP/1.1:**
`ENVD_API_FILE_DOWNLOAD_HTTP_VERSION` becomes
`ENVD_API_FILE_STREAM_HTTP_VERSION = "1.1"`, used by
`_envd_api_streaming` (sync + async) and, for an explicit async
`stream_idle_timeout`, a new `_envd_api_stream` client (previously that
branch used `_envd_api`). Over HTTP/2, data a caller hasn't read holds
the connection's flow-control window, so a few partly read or abandoned
`format="stream"` readers stall every other request on that connection,
including envd RPC.
- **Upload chunk errors (0.14, curioswitch/pyqwest#287):** an exception
raised by the request-body iterator is now re-raised as-is instead of
becoming `WriteError`, so `ChunkCheck` (which recorded the
`InvalidArgumentException` to re-raise it) is removed.
- **Timeouts (0.15, curioswitch/pyqwest#305):** the httpx adapter uses
`max(read, write)` instead of `read + write`, so Python SDK timeouts are
no longer doubled (SDK-451). This supersedes #2175.
- **gevent (0.15, curioswitch/pyqwest#306):** sync calls yield
cooperatively under gevent monkey-patching.

## Verification
- `test_envd_file_download_empty_data_frames.py` asserts `bytes`/`text`
reads use the configured version and streamed reads use HTTP/1.1; the
fake server sends 600-byte frames each followed by an empty one (the
real proxy sends ~32 KiB per empty frame). It fails on pyqwest 0.12 with
`too_many_data_frames` and passes on 0.15.
- Real sandbox, buffered reads over HTTP/2 (envd negotiates HTTP/2 via
ALPN, checked with a raw pyqwest request): sync and async, 40 sequential
text reads and 32 concurrent 4 MiB reads pass; the same script fails
with `too_many_data_frames` on pyqwest 0.12.
- Real sandbox, streams: with streamed reads on HTTP/2, 3 partly read 8
MiB async streams (`stream_idle_timeout=15`) made the 4th `files.read`
and `commands.run` time out. With this PR, 10 such open streams don't
block a new read, `commands.run` or `files.list`.
- Real sandbox uploads over HTTP/2 (32 concurrent 4 MiB writes,
iterator, file object, gzip, `write_files`) pass sync and async,
checksums match.
- Unit tests: 1047 passed. `files` integration tests: 133 passed, 2
failed (`test_file_symlink`, a backend failure already on `main`, see
#2194).

Link to Devin session:
https://app.devin.ai/sessions/d734c4752b1a4f7b90b09bfd3379c6f4
Open in Devin Desktop:
https://app.devin.ai/desktop/session/d734c4752b1a4f7b90b09bfd3379c6f4?variant=devin
Requested by: @mishushakov
<!-- devin-review-badge-begin -->

---

🟢 Devin Review found nothing to fix · [View
findings](https://app.devin.ai/review/e2b-dev/e2b/pull/2197)

<a href="https://app.devin.ai/review/e2b-dev/e2b/pull/2197"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a><!-- devin-review-badge-end -->

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: mish@e2b.dev <mish@e2b.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python SDK files.read of files over ~500 KB fails at random with too_many_data_frames (pyqwest h2)

1 participant