Skip to content

Conversation

@stdrc
Copy link
Collaborator

@stdrc stdrc commented Dec 9, 2025

…ice fails

Related Issue

Resolve #(issue_number)

Description

Copilot AI review requested due to automatic review settings December 9, 2025 05:56
@stdrc stdrc changed the title fix(fetch): fix fetchurl tool incorrect output when fetching via serv… fix(fetch): fix fetchurl tool incorrect output when fetching via service fails Dec 9, 2025
Copy link
Contributor

Copilot AI left a 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-except block to catch aiohttp.ClientError exceptions when calling the fetch service, providing better error messages
  • Refactored ToolResultBuilder initialization 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_get for 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.


@staticmethod
async def fetch_with_http_get(params: Params) -> ToolReturnValue:
builder = ToolResultBuilder()
Copy link

Copilot AI Dec 9, 2025

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:

  1. Web content (HTML/markdown) often has long lines
  2. The SearchWeb tool in the same module uses max_line_length=None for similar reasons
  3. Extracted text from trafilatura can contain long lines
Suggested change
builder = ToolResultBuilder()
builder = ToolResultBuilder(max_line_length=None)

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +150
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",
)
Copy link

Copilot AI Dec 9, 2025

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:

  1. The service is unreachable (network error)
  2. 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)

Copilot uses AI. Check for mistakes.
Signed-off-by: Richard Chien <[email protected]>
@stdrc stdrc merged commit 1744acc into main Dec 9, 2025
5 checks passed
@stdrc stdrc deleted the rc/fix-fetch-url-fallback branch December 9, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants