fix: enforce upper bound on history_length - #1177
Open
ez-lbz wants to merge 2 commits into
Open
Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/events/event_queue_v2.py | 91.79% | 91.28% | 🔴 -0.51% |
| src/a2a/utils/task.py | 95.16% | 95.59% | 🟢 +0.43% |
| src/a2a/utils/telemetry.py | 91.47% | 90.70% | 🔴 -0.78% |
| Total | 93.00% | 92.98% | 🔴 -0.02% |
Generated by coverage-comment.yml
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.
What changed
1. Enforce an upper bound on
historyLengthProblem:
validate_history_length()insrc/a2a/utils/task.pyonly rejected negative values. A client could sendhistoryLength=999999999and the server would materialize the full task history for every matching task (intasks/get,tasks/list, andmessage/send), allowing an unbounded-history read via an absurdly large parameter.Fix (src/a2a/utils/task.py):
MAX_HISTORY_LENGTH = 1000with a comment explaining the cap is a pragmatic bound aligned with the other A2A SDKs' "large value ≈ return everything available" semantics.validate_history_length()now raisesInvalidParamsErrorwhenhistory_length > MAX_HISTORY_LENGTH(in addition to the existing negative-value check). The validation already runs at the entry ofon_get_task,on_list_tasks, andon_message_send(V1) and their V2 counterparts, so the cap applies to all JSON-RPC / REST / gRPC paths without further changes.Testing
./.venv/Scripts/python -m pytest tests/utils/test_task.py tests/server/request_handlers/test_default_request_handler.py tests/server/request_handlers/test_default_request_handler_v2.py -q→ 150 passed (includes 8 new regression tests:validate_history_lengthunit tests plus handler-levelhistory_lengthover-limit rejection foron_get_taskandon_message_send)../.venv/Scripts/python -m ruff checkon modified files: clean.historyLengthabove 1000 now returnInvalidParamsErrorinstead of returning full history. Requests at or below the cap are unaffected (existing tests all use values ≤ 10).