Skip to content

fix(egress): unblock SSE/chunked streaming through mitmproxy#898

Merged
hittyt merged 2 commits into
alibaba:mainfrom
Pangjiping:fix/egress-mitmproxy-sse-streaming
May 18, 2026
Merged

fix(egress): unblock SSE/chunked streaming through mitmproxy#898
hittyt merged 2 commits into
alibaba:mainfrom
Pangjiping:fix/egress-mitmproxy-sse-streaming

Conversation

@Pangjiping
Copy link
Copy Markdown
Collaborator

Summary

The mitmdump --set stream_large_bodies=1m option (added to prevent OOM on large downloads) buffers any response under 1 MiB before forwarding, which stalls LLM SSE / chunked streams of small chunks until the stream ends or the threshold is hit, producing perceptible stutter downstream.

Introduce a bundled system addon that is always loaded by the egress launcher and forces flow.response.stream = True for responses with content-type: text/event-stream or transfer-encoding: chunked. Large- body OOM protection from stream_large_bodies stays intact for everything else.

The previous example script add_header.py is renamed to system.py and repurposed as the always-on system addon (wire-transparent: no headers added or altered). User-supplied addons via OPENSANDBOX_EGRESS_MITMPROXY_SCRIPT are still loaded after the system addon and may observe or override its hooks.

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

The mitmdump --set stream_large_bodies=1m option (added to prevent OOM
on large downloads) buffers any response under 1 MiB before forwarding,
which stalls LLM SSE / chunked streams of small chunks until the stream
ends or the threshold is hit, producing perceptible stutter downstream.

Introduce a bundled system addon that is always loaded by the egress
launcher and forces flow.response.stream = True for responses with
content-type: text/event-stream or transfer-encoding: chunked. Large-
body OOM protection from stream_large_bodies stays intact for everything
else.

The previous example script add_header.py is renamed to system.py and
repurposed as the always-on system addon (wire-transparent: no headers
added or altered). User-supplied addons via OPENSANDBOX_EGRESS_MITMPROXY_SCRIPT
are still loaded after the system addon and may observe or override its
hooks.

Refs: https://project.aone.alibaba-inc.com/v2/project/2135082/req/82131871

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Pangjiping Pangjiping requested review from hittyt and jwx0925 as code owners May 15, 2026 15:43
@Pangjiping Pangjiping added bug Something isn't working component/egress labels May 15, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83dad20c3f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread components/egress/mitmscripts/system.py
Comment thread components/egress/docs/mitmproxy-transparent.md Outdated
Normalize content-type and transfer-encoding to lowercase before substring
matching in the system addon, so legal mixed-case values like
Transfer-Encoding: Chunked or Content-Type: Text/Event-Stream still trigger
streaming instead of getting buffered by stream_large_bodies=1m.

Also fix the transparent-mode doc, which referenced a non-existent
OPENSANDBOX_EGRESS_MITMPROXY_SYSTEM_SCRIPT env var as a way to disable or
swap the system addon. The launcher always appends the bundled system addon
unconditionally; document that users override behavior via
OPENSANDBOX_EGRESS_MITMPROXY_SCRIPT (loaded after the system addon).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@hittyt hittyt left a comment

Choose a reason for hiding this comment

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

LGTM

@hittyt hittyt merged commit 73973af into alibaba:main May 18, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working component/egress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants