fix: prevent DO RPC size limit crash on large chat sessions#918
Merged
simple-agent-manager[bot] merged 1 commit intomainfrom May 6, 2026
Merged
fix: prevent DO RPC size limit crash on large chat sessions#918simple-agent-manager[bot] merged 1 commit intomainfrom
simple-agent-manager[bot] merged 1 commit intomainfrom
Conversation
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>
|
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
DEFAULT_CHAT_SESSION_MESSAGE_LIMITfrom 3000 to 500 — the frontend already paginates viabefore/hasMoregetMessages()that estimates cumulative response size and truncates early (settinghasMore=true) before hitting the 32MiB Cloudflare DO RPC serialization ceilingRoot 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: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=3000or 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 sethasMore: trueso the frontend knows to paginate.Test plan
🤖 Generated with Claude Code