Skip to content

Increase the bounded SSE event limit for larger responses - #1333

Open
AdityaSreevatsaK wants to merge 2 commits into
pydantic:mainfrom
AdityaSreevatsaK:fix/sse-event-size-1259-upstream
Open

AdityaSreevatsaK wants to merge 2 commits into
pydantic:mainfrom
AdityaSreevatsaK:fix/sse-event-size-1259-upstream

Conversation

@AdityaSreevatsaK

@AdityaSreevatsaK AdityaSreevatsaK commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1259.

SSE events can legitimately exceed the 1 MiB limit introduced in v2.10.0, including MCP tools/list responses. Applications using the default SSE configuration currently fail on those events.

  • Increase the default max_event_size from 1 MiB to 8 MiB, while retaining an explicit per-event buffer limit. A caller can still set a smaller limit, a larger limit, or None to disable it.
  • Add SSEEventTooLarge(SSEError) for size-limit failures, allowing downstream consumers to distinguish deterministic oversize errors from transient transport errors. Existing except SSEError handlers remain compatible.
  • Add sync/async regression tests for legitimate large events, default-limit rejection, and the new exception; document the trade-off and configuration.

Design consideration: 8 MiB is a proposed bounded default, not a fixed requirement. It permits the reported 1.4 MiB response, at the cost of an increased maximum per-event buffer allocation. I am open to adjusting the default or exception design based on maintainer feedback. The approach is also outlined on issue #1259.

Validation

  • Fork test-suite CI: passed on Python 3.11–3.15, including lint, typing, package and documentation builds, tests, and the coverage gate.
  • Fork CodSpeed: all 17 performance and the memory benchmark tests passed, but uploading their results was rejected with 401 Unauthorized because the fork is not authorised for CodSpeed. Upstream PR checks should validate the integration.
  • The current PR branch contains one clean commit with the exact code tested above.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Prepared with AI assistance. The changes and linked validation results were reviewed before submission.

View guided diff

@veria-ai

veria-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@codspeed

codspeed Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing AdityaSreevatsaK:fix/sse-event-size-1259-upstream (1490e80) with main (f4f65c1)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread docs/sse.md Resolved
Comment thread src/httpx2/httpx2/_sse.py Resolved
Comment thread docs/sse.md Resolved

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 MiB default max_event_size (2.10.0) silently breaks SSE streams with large single events (MCP tools/list, ~1.4 MiB)

1 participant