-
Notifications
You must be signed in to change notification settings - Fork 337
fix(fetch): fix fetchurl tool incorrect output when fetching via service fails #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ice fails Signed-off-by: Richard Chien <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an issue where the FetchURL tool would return incorrect output when fetching via the Moonshot fetch service fails. The fix improves error handling and implements a proper fallback mechanism to the local HTTP GET method.
Key Changes
- Added
try-exceptblock to catchaiohttp.ClientErrorexceptions when calling the fetch service, providing better error messages - Refactored
ToolResultBuilderinitialization to be created within each fetch method rather than in the main__call__method - Extracted HTTP GET fetching logic into a separate static method
fetch_with_http_getfor better code organization
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/kimi_cli/tools/web/fetch.py | Improved error handling for fetch service failures with network error catching, and refactored builder initialization |
| CHANGELOG.md | Added entry documenting the fix for FetchURL tool output issue |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/kimi_cli/tools/web/fetch.py
Outdated
|
|
||
| @staticmethod | ||
| async def fetch_with_http_get(params: Params) -> ToolReturnValue: | ||
| builder = ToolResultBuilder() |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ToolResultBuilder() is now created with default parameters, which includes max_line_length=2000. Previously, the builder was created with max_line_length=None to avoid truncating long lines in web content. This change might cause long lines in fetched content to be truncated.
Consider using ToolResultBuilder(max_line_length=None) here to maintain the previous behavior, especially since:
- Web content (HTML/markdown) often has long lines
- The
SearchWebtool in the same module usesmax_line_length=Nonefor similar reasons - Extracted text from trafilatura can contain long lines
| builder = ToolResultBuilder() | |
| builder = ToolResultBuilder(max_line_length=None) |
| except aiohttp.ClientError as e: | ||
| return builder.error( | ||
| ( | ||
| f"Failed to fetch URL via service due to network error: {str(e)}. " | ||
| "This may indicate the service is unreachable." | ||
| ), | ||
| brief="Network error when calling fetch service", | ||
| ) |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new error handling for network errors when calling the fetch service lacks test coverage. While there's a test for successful service calls (test_fetch_url_with_service in tests/test_fetch_url.py), there's no test for when:
- The service is unreachable (network error)
- The service returns a non-200 status code with the new error path
Consider adding tests to verify:
- The fallback to HTTP GET works when the service encounters a network error
- The error message format is correct for network errors
- The logging behavior (warning message at line 36)
Signed-off-by: Richard Chien <[email protected]>
…ice fails
Related Issue
Resolve #(issue_number)
Description