Skip to content

fix(discord): bound standalone REST response reads - #60122

Merged
teknium1 merged 2 commits into
mainfrom
salvage/55209-standalone-read-caps
Jul 7, 2026
Merged

fix(discord): bound standalone REST response reads#60122
teknium1 merged 2 commits into
mainfrom
salvage/55209-standalone-read-caps

Conversation

@teknium1

@teknium1 teknium1 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

The Discord standalone REST send path (used by cron delivery and send_message when 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 unbounded resp.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_limited helpers routed through all 9 previously-unbounded read sites (channel probe, forum/thread creation, message send, media upload, error paths)
  • Follow-up commit (ours): streaming-body detection is structural — an inspect.iscoroutinefunction probe on content.read — replacing the contributor's unittest.mock module-name sniffing, and the duplicate read/iter_chunked reader paths are collapsed into one. Non-streaming objects fall back to the response's native json()/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 responses

Validation

Before After
2 MiB JSON body fully buffered by resp.json() ValueError: exceeds 1048576 bytes, connection closed early
Oversized error text fully buffered capped at 8 KiB
Normal send / probe works unchanged
Test doubles (MagicMock) n/a fall back to native json() — verified

E2E-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

Bounded Standalone Discord Sends

ooiuuii and others added 2 commits July 7, 2026 02:19
…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.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/discord Discord bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 7, 2026
@teknium1
teknium1 merged commit f341cad into main Jul 7, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/55209-standalone-read-caps branch July 7, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/discord Discord bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discord standalone send reads unbounded API response bodies

3 participants