fix(anthropic_stream_events): bound streaming tool-call state (max_tool_blocks) - #862
Open
leseb wants to merge 1 commit into
Open
fix(anthropic_stream_events): bound streaming tool-call state (max_tool_blocks)#862leseb wants to merge 1 commit into
leseb wants to merge 1 commit into
Conversation
…x_tool_blocks The filter stored two ctx.filter_metadata entries per unique streaming tool-call index and never released them, so a backend that streams an unbounded number of distinct tool-call indices could grow per-response memory without limit (DoS). Add a max_tool_blocks cap (default 10,000; zero is rejected at config build). The filter counts tool-call content blocks as they open and fails the stream closed before opening a block beyond the cap, so per-response memory stays bounded. Scope is the Anthropic filter only. Adds unit tests, a self-validating integration test pair (within-cap completes with message_stop; over-cap aborts before message_stop), the example-config knob, and regenerated filter docs. Signed-off-by: Sébastien Han <seb@redhat.com>
leseb
enabled auto-merge
September 2, 2026 06:57
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
anthropic_stream_eventsfilter stored twoctx.filter_metadataentries per unique streaming tool-call index and never released them, so a backend that streams an unbounded number of distinct tool-call indices could grow per-response memory without limit (DoS). This adds amax_tool_blockscap (default 10,000; zero rejected at config build) that counts tool-call content blocks as they open and fails the stream closed before opening a block beyond the cap, keeping per-response memory bounded. Scope is the Anthropic filter only.Related issue
Closes #412
Validation
cargo test -p praxis-ai-apis -- max_tool_blocks(parse custom cap, reject zero, fail closed past cap)cargo test -p praxis-tests-integration -- streaming_tool_calls(self-validating pair: within-cap completes withmessage_stop; over-cap aborts beforemessage_stop)make lint(also ranmake build, clean)Checklist
Signed-off-bytrailer.Breaking changes
None.
max_tool_blocksdefaults to 10,000, so existing configs are unaffected; operators may lower it to tighten the bound or raise it for workloads with many concurrent tool calls.