fix(discord): bound standalone REST response reads - #60122
Merged
Conversation
…module sniffing Replace the unittest.mock module-name check with an inspect.iscoroutinefunction probe on content.read, and collapse the duplicate read/iter_chunked reader paths into one. Non-streaming objects (test doubles, proxy wrappers) fall back to the response's native json()/text() as before.
This was referenced Jul 7, 2026
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
The Discord standalone REST send path (used by cron delivery and
send_messagewhen no live gateway adapter is up) now reads API response bodies through bounded chunked readers — 1 MiB for JSON success bodies, 8 KiB for error diagnostics — instead of unboundedresp.json()/resp.text(), and closes the connection early when a body exceeds its cap.Salvage of #55209 by @ooiuuii, cherry-picked onto current main with authorship preserved. Fixes #55208.
Changes
plugins/platforms/discord/adapter.py: bounded_standalone_read_json_limited/_standalone_read_text_limitedhelpers routed through all 9 previously-unbounded read sites (channel probe, forum/thread creation, message send, media upload, error paths)inspect.iscoroutinefunctionprobe oncontent.read— replacing the contributor'sunittest.mockmodule-name sniffing, and the duplicateread/iter_chunkedreader paths are collapsed into one. Non-streaming objects fall back to the response's nativejson()/text().tests/tools/test_send_message_tool.py: streaming-response regression coverage that fails if the code falls back to unbounded reads on real streamed responsesValidation
resp.json()ValueError: exceeds 1048576 bytes, connection closed earlyjson()— verifiedE2E-verified against a real aiohttp session hitting a local HTTP server. Targeted suites (
test_send_message_tool.py,test_discord_adapter.py) green — 152 passed.Infographic