Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Sep 6, 2025

Description

This PR addresses Issue #7744 where users experience API requests getting stuck indefinitely when using the Anthropic provider with large files (~2MB each).

Problem

The Anthropic provider was missing timeout configuration, unlike other providers (OpenAI, Ollama, LM Studio) which already had this implemented. This caused requests to hang indefinitely without providing any feedback to the user.

Solution

  • Added getApiRequestTimeout() to the Anthropic client initialization
  • This ensures API requests timeout properly instead of hanging indefinitely
  • Added comprehensive test coverage for the timeout configuration

Testing

  • Added 6 test cases covering various timeout scenarios
  • All existing tests pass
  • Follows the same pattern as other providers for consistency

Notes

While this PR adds the foundational timeout configuration, future improvements could include:

  • Enhanced error message display when timeouts occur
  • User-friendly timeout notifications in the UI
  • Adjustable timeout recommendations for large file processing

Fixes #7744


Important

Adds timeout configuration to AnthropicHandler to prevent hanging requests, with comprehensive test coverage for various timeout scenarios.

  • Behavior:
    • Adds getApiRequestTimeout() to AnthropicHandler in anthropic.ts to configure API request timeouts.
    • Prevents requests from hanging indefinitely by setting a default timeout of 600 seconds.
  • Testing:
    • Adds anthropic-timeout.spec.ts with 6 test cases for different timeout scenarios, including default, custom, and zero timeout.
    • Mocks getApiRequestTimeout and Anthropic SDK to test timeout behavior.
  • Misc:

This description was created by Ellipsis for d0f95a5. You can customize this summary. It will automatically update as commits are pushed.

- Added getApiRequestTimeout() to Anthropic client initialization
- This ensures API requests timeout properly instead of hanging indefinitely
- Particularly important when dealing with large files that may cause long processing times
- Added comprehensive tests for timeout configuration

Fixes #7744
@roomote roomote bot requested review from mrubens, cte and jr as code owners September 6, 2025 17:46
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 6, 2025
@roomote roomote bot mentioned this pull request Sep 6, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 6, 2025
Copy link
Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed my own code. Found it adequate. Would merge again.

this.client = new Anthropic({
baseURL: this.options.anthropicBaseUrl || undefined,
[apiKeyFieldName]: this.options.apiKey,
timeout: getApiRequestTimeout(),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment here explaining why timeout configuration is important for large file processing. Something like:

Suggested change
timeout: getApiRequestTimeout(),
// Configure timeout to prevent hanging on large files (see issue #7744)
// Uses the VSCode setting 'roo-cline.apiRequestTimeout' (default: 600 seconds)
timeout: getApiRequestTimeout(),

This would help future maintainers understand the context.

)
})

it("should use authToken when anthropicUseAuthToken is set with custom base URL", () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comprehensive test coverage! Consider grouping related tests together for better organization. For example, all auth-related tests (lines 112-150) could be grouped under a nested describe block:

describe('authentication handling', () => {
  it('should use authToken when anthropicUseAuthToken is set with custom base URL', ...)
  it('should use apiKey when anthropicUseAuthToken is set but no custom base URL', ...)
})


const mockAnthropicConstructor = Anthropic as any

describe("AnthropicHandler timeout configuration", () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the unit tests are thorough, have we considered adding an integration test that actually verifies timeout behavior with a real (or mocked) slow response? This could help catch regressions where the timeout isn't properly applied to the actual HTTP requests.

@daniel-lxs
Copy link
Collaborator

Closing in favor of #6319

@daniel-lxs daniel-lxs closed this Sep 9, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 9, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 9, 2025
@daniel-lxs daniel-lxs deleted the fix/anthropic-timeout-issue-7744 branch September 9, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Stuck at "API Request..."
3 participants