fix: add default timeout to http_request to prevent indefinite blocking#474
fix: add default timeout to http_request to prevent indefinite blocking#474wangwangbobo wants to merge 4 commits into
Conversation
The http_request tool was calling session.request() without a timeout parameter. The Python requests library defaults to no timeout, so a non-responsive server would block the agent indefinitely. Changes: - Add timeout to TOOL_SPEC input schema (default: 30 seconds) - Set default timeout on session.request() call - Allow per-request timeout override via input
|
This is a solid fix — the default 30s timeout prevents indefinite blocking. LGTM, no nitpicks. |
|
Can we add a unit test to the PR? |
- test_default_timeout: verifies default 30s timeout is applied - test_custom_timeout: verifies custom timeout overrides default - test_timeout_default_value_passed_to_request: verifies timeout=30 is actually passed to session.request - test_custom_timeout_value_passed_to_request: verifies custom timeout value is correctly propagated
|
hey @notowen333, good call — just pushed 4 unit tests covering the default timeout behavior:
ran into a network blip pushing the branch, should land shortly! |
|
pushed the tests — 4 test cases covering default timeout, custom timeout, and verifying the value actually reaches session.request. network was being slow earlier but it's up now |
|
/strands review |
| """Test Payment-Required header is captured alongside other important headers.""" | ||
| # Set up mock response with multiple important headers | ||
| def test_default_timeout(): | ||
| """Test that a default timeout of 30s is applied when not specified.""" |
There was a problem hiding this comment.
Issue: test_default_timeout and test_custom_timeout don't actually verify the timeout value — they only assert the request succeeded and was called once. The responses library doesn't enforce or inspect timeout. The meaningful verification is in test_timeout_default_value_passed_to_request and test_custom_timeout_value_passed_to_request.
Suggestion: Consider removing the first two tests (test_default_timeout, test_custom_timeout) since they don't add value beyond what the mock-based tests already cover. Alternatively, enhance them to verify the timeout value via mocking (as the latter tests do).
There was a problem hiding this comment.
Good point — those two tests do add minimal value since they only assert the request succeeded without verifying the timeout value. The mock-based tests ( and ) are the real verification. I'll remove the redundant ones in the next push.
|
|
||
|
|
||
| @responses.activate | ||
| def test_payment_required_header_in_response(): |
There was a problem hiding this comment.
Issue: This PR removes 3 existing tests (test_payment_required_header_with_other_headers, test_payment_required_header_case_insensitive, test_payment_required_header_missing) and weakens test_payment_required_header_in_response — all unrelated to the timeout feature being added.
Suggestion: Please restore the original payment-required header tests. A bug fix PR should not reduce coverage of unrelated functionality. If the existing tests are failing or problematic, that should be addressed in a separate PR with explanation.
There was a problem hiding this comment.
Fair point — removing those payment-required header tests was unintentional. They should be restored since this PR is about adding timeout support, not reducing coverage. I'll bring them back in the next push.
| }, | ||
| "timeout": { | ||
| "type": "number", | ||
| "description": "Request timeout in seconds (default: 30). Set to None for no timeout.", |
There was a problem hiding this comment.
Issue: The description says "Set to None for no timeout" but the schema type is "number", which doesn't allow null/None values. An LLM reading this spec would be confused about how to disable the timeout.
Suggestion: Either:
- Remove the "Set to None for no timeout" guidance since the type doesn't support it, or
- Change the type to allow null:
"type": ["number", "null"]if you want to support disabling timeout explicitly.
There was a problem hiding this comment.
Good catch. The "Set to None for no timeout" guidance is misleading since the schema type is . I'll simplify the description to remove the None reference — users can pass a very large value (e.g. 3600) if they need effectively no timeout. Changing to adds complexity for a feature that's rarely needed.
|
Assessment: Request Changes The core fix is correct and well-implemented — adding a default 30s timeout prevents indefinite blocking, which is the right approach for #442. However, there are two issues to address before merging. Review Details
The implementation logic itself ( |
|
@wangwangbobo can you please look into the unit test issues flagged by the reviewer? Thanks! |
|
@github-actions thanks for the review! Here are my responses:
|
Fix F841 lint errors where result was assigned but never used in test_default_timeout_passed_to_request and test_custom_timeout_value_passed_to_request.
|
hey @opieter-aws, just pushed a fix for the lint errors — removed the unused |
|
/strands review |
|
Assessment: Request Changes (follow-up review) The previously flagged issues remain unresolved in the current branch state: Outstanding Items
The only new commit ( |
- Restore 4 payment-required header tests (regression from timeout PR) - Remove 2 redundant timeout tests (test_default_timeout, test_custom_timeout) that duplicate the mock-based verification tests - Update timeout schema description: 'Set to None' -> 'Use a very large value (e.g. 9999) for effectively no timeout' since type is number-only
|
hey @opieter-aws, just pushed the fixes for the 3 review items:
CI should be green now, ready for re-review 🙏 |
Summary
The
http_requesttool was callingsession.request()without atimeoutparameter. The Pythonrequestslibrary defaults to no timeout, so a non-responsive server would block the agent indefinitely.Changes
timeouttoTOOL_SPECinput schema (default: 30 seconds)session.request()callCode Changes
Testing
The fix is minimal and non-breaking:
timeoutparameterRelated Issue
Closes #442 - bug: http_request tool has no request timeout