Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 31, 2025

Fixes #6521

Summary

This PR adds configurable timeout support for the LM Studio provider to address timeout issues when using large local models that require more processing time, especially when split between GPU and CPU.

Changes

Core Implementation

  • Provider Settings Schema: Added lmStudioTimeoutSeconds setting (30-3600 seconds range)
  • LM Studio Handler: Implemented AbortController with configurable timeout for both streaming and non-streaming requests
  • Default Timeout: Set to 600 seconds (10 minutes) - suitable for local model scenarios
  • Error Handling: Enhanced timeout error messages with troubleshooting guidance

Testing

  • Added comprehensive timeout functionality tests
  • Tests cover default timeout behavior, custom timeout configuration, and AbortError handling
  • Updated existing tests to accommodate new AbortSignal parameter
  • All existing functionality preserved and tested

Technical Details

The implementation follows the same pattern used in the Bedrock provider:

  • Uses AbortController to manage request timeouts
  • Properly cleans up timeouts on completion or error
  • Provides user-friendly error messages when timeouts occur
  • Maintains backward compatibility with existing configurations

User Impact

Users experiencing timeout issues with LM Studio (especially with large models like Deepseek R1 14b/32b, Qwen2.5 Coder Instruct 32b) can now:

  1. Configure longer timeouts in LM Studio settings
  2. Receive clear error messages when timeouts occur
  3. Get troubleshooting guidance in timeout error messages

Testing

cd src && npx vitest run api/providers/__tests__/lmstudio.spec.ts

All tests pass, including new timeout-specific test cases.


Important

Adds configurable timeout for LM Studio provider with AbortController, defaulting to 600 seconds, and enhances error handling and testing.

  • Core Implementation:
    • Added lmStudioTimeoutSeconds to lmStudioSchema in provider-settings.ts (30-3600 seconds range).
    • Implemented AbortController in LmStudioHandler in lm-studio.ts for request timeouts.
    • Default timeout set to 600 seconds.
    • Enhanced timeout error messages with guidance.
  • Testing:
    • Added tests in lmstudio.spec.ts for default and custom timeout behavior.
    • Tests for AbortError handling and AbortSignal usage in requests.
  • User Impact:
    • Users can configure timeouts for large models in LM Studio settings.
    • Clear error messages and troubleshooting guidance for timeouts.

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

- Add lmStudioTimeoutSeconds setting to provider schema (30-3600 seconds)
- Implement AbortController with configurable timeout in LM Studio handler
- Default timeout set to 600 seconds (10 minutes) for local model scenarios
- Add comprehensive timeout tests including AbortError handling
- Provide user-friendly timeout error messages with troubleshooting tips

Fixes #6521
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 31, 2025 22:27
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 31, 2025
Copy link
Contributor 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.

Reviewing my own code is like debugging in production - technically possible but morally questionable. I've reviewed the changes and left some suggestions inline to improve the implementation.

let timeoutId: NodeJS.Timeout | undefined

// Get timeout from settings or use default (10 minutes)
const timeoutSeconds = this.options.lmStudioTimeoutSeconds ?? LMSTUDIO_DEFAULT_TIMEOUT_SECONDS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this intentional that LM Studio has a configurable timeout while Bedrock has a hardcoded 10-minute timeout? This inconsistency might confuse users who work with both providers. Consider either making Bedrock's timeout configurable too, or documenting why they differ.

const timeoutMs = timeoutSeconds * 1000

try {
timeoutId = setTimeout(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The timeout setup logic is duplicated between createMessage and completePrompt. Could we extract this into a helper method like createAbortControllerWithTimeout(timeoutSeconds: number)?

Suggested change
timeoutId = setTimeout(() => {
private createAbortControllerWithTimeout(timeoutSeconds: number): { controller: AbortController; timeoutId: NodeJS.Timeout } {
const controller = new AbortController()
const timeoutId = setTimeout(() => {
controller.abort()
}, timeoutSeconds * 1000)
return { controller, timeoutId }
}

// Check if this is an abort error (timeout)
if (error instanceof Error && error.name === "AbortError") {
throw new Error(
`LM Studio request timed out after ${timeoutSeconds} seconds. This can happen with large models that need more processing time. Try increasing the timeout in LM Studio settings or use a smaller model.`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When logging timeout errors, could we include the actual timeout value used? This would help with debugging:

Suggested change
`LM Studio request timed out after ${timeoutSeconds} seconds. This can happen with large models that need more processing time. Try increasing the timeout in LM Studio settings or use a smaller model.`,
throw new Error(
`LM Studio request timed out after ${timeoutSeconds} seconds (configured: ${this.options.lmStudioTimeoutSeconds || 'default'}). This can happen with large models that need more processing time. Try increasing the timeout in LM Studio settings or use a smaller model.`,
)

lmStudioBaseUrl: z.string().optional(),
lmStudioDraftModelId: z.string().optional(),
lmStudioSpeculativeDecodingEnabled: z.boolean().optional(),
lmStudioTimeoutSeconds: z.number().min(30).max(3600).optional(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is 30 seconds a reasonable minimum for very large models? Some models might need more time just to start processing. Consider if 60 seconds would be a safer minimum to prevent user frustration.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 31, 2025
@daniel-lxs
Copy link
Member

daniel-lxs commented Aug 1, 2025

This should be a general setting for all providers, closing for now

@daniel-lxs daniel-lxs closed this Aug 1, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 1, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request 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.

Roo Code disconnects before LM Studio can finish its response

4 participants