Skip to content

fix: prevent DO RPC size limit crash on large chat sessions#918

Merged
simple-agent-manager[bot] merged 1 commit intomainfrom
sam/fix-rpc-size-limit
May 6, 2026
Merged

fix: prevent DO RPC size limit crash on large chat sessions#918
simple-agent-manager[bot] merged 1 commit intomainfrom
sam/fix-rpc-size-limit

Conversation

@simple-agent-manager
Copy link
Copy Markdown
Contributor

Summary

  • Lower DEFAULT_CHAT_SESSION_MESSAGE_LIMIT from 3000 to 500 — the frontend already paginates via before/hasMore
  • Add RPC size guard in getMessages() that estimates cumulative response size and truncates early (setting hasMore=true) before hitting the 32MiB Cloudflare DO RPC serialization ceiling

Root Cause

Session 046208eb (investigating task with 5,672 messages) accumulated ~45MB of message data. When loading the session, getMessages() returned 3000 rows via DO RPC, exceeding Cloudflare's hard 32MiB serialization limit:

Error: Serialized RPC arguments or return values are limited to 32MiB,
but the size of this value was: 45221234 bytes.

This caused "internal server error" for any user trying to view that session (or any session with enough large messages).

Fix Details

Layer 1 — Lower default limit (3000 → 500)
The previous limit of 3000 was set when messages were expected to be small streaming tokens. With tool call output and full file contents in messages, 3000 rows can easily exceed 32MB. 500 is still plenty for the initial chat view, and the frontend already handles pagination.

Layer 2 — RPC size guard in the DO
Even with a lower limit, a caller could pass ?limit=3000 or individual messages could be huge. The size guard walks the result set, estimates cumulative serialized size, and truncates before exceeding 30MiB (leaving 2MiB margin for envelope overhead). Truncated responses set hasMore: true so the frontend knows to paginate.

Test plan

  • Typecheck passes
  • 4,427 unit tests pass (full API test suite)
  • CI green
  • Deploy to production — verify the previously-crashing session loads

🤖 Generated with Claude Code

The ProjectData DO's getMessages() could return >32MiB of serialized
data for sessions with many streaming tokens, hitting Cloudflare's
hard RPC serialization ceiling and causing "internal server error".

Two fixes:
1. Lower DEFAULT_CHAT_SESSION_MESSAGE_LIMIT from 3000 to 500 —
   the frontend already paginates via before/hasMore.
2. Add an RPC size guard in getMessages() that estimates cumulative
   response size and truncates early (setting hasMore=true) if
   approaching the 30MiB budget. This prevents the crash even if
   a caller passes a high limit.

Root cause: session 046208eb had 5,672 messages (~45MB serialized).
The 3000-row default caused a 45MB RPC return, exceeding the 32MB limit.

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

sonarqubecloud Bot commented May 6, 2026

@simple-agent-manager simple-agent-manager Bot merged commit ba22f2a into main May 6, 2026
18 of 19 checks passed
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 participant