fix: reject terminal tasks before persisting push config (V2) - #1178
Open
ez-lbz wants to merge 2 commits into
Open
fix: reject terminal tasks before persisting push config (V2)#1178ez-lbz wants to merge 2 commits into
ez-lbz wants to merge 2 commits into
Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/request_handlers/default_request_handler_v2.py | 94.17% | 94.27% | 🟢 +0.10% |
| Total | 93.00% | 93.00% | ⚪️ 0.00% |
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. Check terminal task state before persisting the push config (V2 handler)
Problem: In
DefaultRequestHandlerV2._setup_active_task()(src/a2a/server/request_handlers/default_request_handler_v2.py), the push-notification config was written to the store viaset_info()before the terminal-state check ran insideActiveTask.start(). As a result, sending a message to an already-completed/canceled/failed/rejected task with atask_push_notification_configin the request still persisted the config for that terminal task. V1's handler checks terminal state before any persistence.Fix (src/a2a/server/request_handlers/default_request_handler_v2.py):
message.task_idis provided and the task exists, the terminal-state check now runs immediately after loading the task and before the request-context build /set_info()call, matching V1's ordering (default_request_handler.py_setup_message_execution).InvalidParamsError("Task {id} is in terminal state: {state}")thatActiveTask.start()raised before, so the error contract is unchanged; thestart()check remains as a second line of defense.Testing
./.venv/Scripts/python -m pytest tests/server/request_handlers/test_default_request_handler_v2.py -q→ 63 passed../.venv/Scripts/python -m pytest tests/server/request_handlers/test_default_request_handler.py tests/utils/test_task.py -q→ 82 passed (V1 unaffected).on_message_send/on_message_send_streamterminal-state tests to seed the terminal task through the task store (the check now runs earlier than the patchedTaskManager.get_task), and added a new parametrized regression testtest_on_message_send_terminal_task_skips_push_config_persistenceassertingset_infois never awaited for terminal tasks../.venv/Scripts/python -m ruff checkon modified files: clean (the pre-existingtoo-many-positional-argumentsfinding on the handler__init__exists onmain).