fix: bound AI request and stream payloads - #2539
Merged
lizhimins merged 1 commit intoAug 25, 2026
Merged
Conversation
RockteMQ-AI
approved these changes
Aug 22, 2026
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR adds defense-in-depth payload size validation for the RocketMQ Studio AI subsystem. A new AiPayloadGuard class validates UTF-8 byte budgets for user-controlled AI payloads (chat messages, context, tool inputs, outbound prompts) before they reach the LLM gateway, CLI execution, or tool registry. The implementation is thorough, well-tested, and follows existing error handling patterns.
Review Highlights
- Correctness: UTF-8 byte counting handles surrogate pairs correctly, with proper early exit when limits are exceeded.
LimitedInputStreamcorrectly detects limit crossing by reading one extra byte. - Security: Validates at all entry points (chat, command, tool, outbound) with clear error codes (
llm.request.payload_too_large,llm.provider.response_too_large). - Tests: Excellent coverage including boundary conditions, multi-byte character handling, and verification that oversized payloads are rejected before calling upstream.
- Design: Package-private
AiPayloadGuardwith static methods is appropriate for a utility class. The inconsistency betweenchat()(throws) andexecute()(returns result) is intentional and documented by the different return types.
Minor Observations
CliAgentProvider.complete()validates before checkingavailable()— this is fine since the 400 error is more specific than a 503.- The
exceedsUtf8Limit()comment about unpaired surrogates being replaced with '?' by the JDK encoder is accurate.
Overall, this is a solid security improvement that prevents potential resource exhaustion from oversized AI payloads.
Automated review by github-manager-bot
lizhimins
force-pushed
the
codex/bound-ai-payloads
branch
from
August 25, 2026 09:27
f7ed315 to
8a99278
Compare
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
Why
Successful OpenAI-compatible SSE responses currently use an unbounded input stream, while every other provider/CLI response path is capped. AI request DTOs and structured tool inputs also have no centralized size checks before serialization or process/provider execution. This makes the streaming path inconsistent and lets a single request or provider response retain unnecessarily large payloads.
Implementation notes
llm.provider.response_too_largeTests
git diff --check: passedProduction changes: 237 additions / 5 deletions. The size comes from the central guard and bounded SSE implementation, not test padding.
Closes #2538