Skip to content

feat: Enhance streaming API timeout handling with mathematical modeling#22

Open
BingqingLyu wants to merge 28 commits into
mainfrom
fork-pr-485-ci-test-branch
Open

feat: Enhance streaming API timeout handling with mathematical modeling#22
BingqingLyu wants to merge 28 commits into
mainfrom
fork-pr-485-ci-test-branch

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

PR: feat: Enhance streaming API timeout handling with mathematical modeling

Overview

This PR addresses GitHub issue QwenLM#239 by implementing a comprehensive mathematical modeling approach to understand and solve the streaming API timeout issue that occurs after 64 seconds.

Problem

The streaming API setup was timing out after 64 seconds, causing user frustration and limiting the tool's effectiveness for large requests. The error message provided generic troubleshooting tips but didn't offer specific solutions based on the request characteristics.

Solution

We've implemented a comprehensive mathematical modeling approach to understand and solve this timeout issue:

1. Mathematical Modeling

We created a StreamingTimeoutModel that calculates expected streaming request times based on:

  • Data size and complexity
  • System load factors
  • Processing rates
  • Network latency

This allows us to predict when timeouts will occur and recommend appropriate solutions.

2. Adaptive Timeout Calculation

Instead of fixed timeouts, we now calculate adaptive timeouts based on request characteristics:

Adaptive Timeout = Base Timeout + 
                   (Data Size × 0.05) + 
                   (Complexity × 0.1) + 
                   (System Load × 20)

3. Enhanced Error Messaging

When timeouts occur, we now provide more specific troubleshooting guidance based on the request characteristics:

  • For large requests: Suggestions to break into smaller chunks
  • For complex requests: Recommendations for progressive summarization
  • Configuration suggestions: Current vs. recommended timeout values

4. CLI Configuration Options

New CLI options allow users to configure timeout behavior:

  • --openai-timeout: Set API timeout in milliseconds
  • --openai-max-retries: Set maximum retry attempts

5. Configuration Recommendations

The system now provides configuration recommendations based on analysis of current settings.

Technical Implementation

Core Changes

  1. Created StreamingTimeoutModel - A mathematical model for predicting and preventing timeouts
  2. Enhanced OpenAIContentGenerator - Added adaptive timeout handling and improved error messaging
  3. Added CLI options - New --openai-timeout and --openai-max-retries configuration options
  4. Added configuration recommendations - Based on analysis of current settings

Files Modified

  • packages/core/src/models/streamingTimeoutModel.ts - New mathematical model
  • packages/core/src/models/streamingTimeoutModel.test.ts - Tests for the model
  • packages/core/src/models/streamingTimeoutModel.verification.test.ts - Formal verification tests
  • packages/core/src/core/openaiContentGenerator.ts - Enhanced timeout handling
  • packages/cli/src/config/config.ts - Added CLI options

Usage Examples

CLI Usage

# Increase timeout for large requests
qwen --openai-timeout 300000 --prompt "Analyze this large codebase"

# Set retry policy
qwen --openai-max-retries 5 --prompt "Complex analysis task"

# Combine both for maximum reliability
qwen --openai-timeout 300000 --openai-max-retries 5 --prompt "Analyze large, complex codebase"

Configuration File

{
  "contentGenerator": {
    "timeout": 120000,
    "maxRetries": 3,
    "samplingParams": {
      "temperature": 0.7,
      "max_tokens": 2048
    }
  }
}

Testing

All tests pass, including new tests for the streaming timeout model:

  • Unit tests for mathematical calculations
  • Integration tests with the OpenAI content generator
  • CLI configuration tests
  • Formal verification tests proving deterministic behavior

Future Improvements

  1. Machine Learning Approach: Use historical data to predict optimal timeouts
  2. Dynamic Adjustment: Real-time adjustment of timeouts based on current performance
  3. Progressive Enhancement: Start with conservative timeouts and increase based on success patterns

This solution transforms a frustrating timeout issue into an opportunity for intelligent, adaptive system behavior that improves the user experience for large and complex requests.

Fixes QwenLM#239

qizwiz and others added 28 commits August 27, 2025 16:50
This commit addresses GitHub issue QwenLM#239 by implementing a comprehensive mathematical model for predicting and preventing streaming API timeouts. Key changes include:

- Created StreamingTimeoutModel with adaptive timeout calculations based on request characteristics

- Enhanced OpenAIContentGenerator with improved timeout handling and error messaging

- Added CLI options for configuring timeout and retry behavior

- Added configuration recommendations based on request analysis

- Included comprehensive tests for the new timeout model

- Added documentation explaining the modeling approach
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit adds a new Model-Context Protocol (MCP) server for timeout analysis that provides tools for analyzing and predicting streaming API timeouts based on mathematical modeling. Key changes include:

- Created timeout-analysis-server.ts with MCP tools for timeout analysis and configuration suggestions

- Added tests for the new MCP server

- Updated core index.ts to export the new server

- Updated CLI configuration to automatically include the timeout analysis MCP server

- Added documentation for the new MCP server

- Marked @modelcontextprotocol/sdk as external in esbuild config to avoid bundling issues
Fixed the path configuration for the timeout analysis MCP server to point to the correct location in the built distribution files.
Removing the MCP server changes as they are not part of the solution for the PR. The MCP server is a tool for self-improvement, not part of the timeout fix.
Removing all MCP server related changes as they are not part of the PR solution.
This PR fixes the streaming API timeout issue that occurs after 64 seconds by improving timeout handling and error messaging.

Changes include:

- Enhanced OpenAIContentGenerator timeout error handling

- Better error messages with specific troubleshooting guidance

- Improved timeout detection and reporting

- Added configuration recommendations

Fixes QwenLM#239
This PR fixes the streaming API timeout issue that occurs after 64 seconds by improving timeout handling and error messaging.

Changes include:

- Enhanced OpenAIContentGenerator timeout error handling

- Better error messages with specific troubleshooting guidance

- Improved timeout detection and reporting

- Added configuration recommendations

Fixes QwenLM#239
This PR addresses GitHub issue QwenLM#239 by implementing a comprehensive mathematical modeling approach to understand and solve the streaming API timeout issue that occurs after 64 seconds.

Key changes include:

- Created StreamingTimeoutModel with adaptive timeout calculations based on request characteristics

- Enhanced OpenAIContentGenerator with improved timeout handling and error messaging

- Added CLI options for configuring timeout and retry behavior (--openai-timeout, --openai-max-retries)

- Added configuration recommendations based on request analysis

- Included comprehensive tests for the new timeout model

- Added documentation explaining the modeling approach

The solution transforms a frustrating timeout issue into an opportunity for intelligent, adaptive system behavior that improves the user experience for large and complex requests.

Fixes QwenLM#239
@BingqingLyu

BingqingLyu commented May 7, 2026

Copy link
Copy Markdown
Owner Author

Conflict Group 1

This PR shares modified functions with 15 other PR(s): #10, #112, #113, #114, #117, #14, #17, #18, #21, #31, #36, #46, #7, #86, #88.

These PRs should be reviewed as a batch — merging one may affect the others.

Function File Also modified by
parseApprovalModeValue config.ts #10, #112, #113, #114, #117, #21, #36, #46, #86, #88
parseArguments config.ts #10, #112, #113, #114, #117, #14, #17, #18, #21, #31, #36, #46, #7, #86, #88
graph LR
    PR22["PR #22"]
    FparseApprovalModeValue_6977["parseApprovalModeValue<br>config.ts"]
    PR22 -->|modifies| FparseApprovalModeValue_6977
    PR10["PR #10"]
    PR10 -->|modifies| FparseApprovalModeValue_6977
    PR112["PR #112"]
    PR112 -->|modifies| FparseApprovalModeValue_6977
    PR113["PR #113"]
    PR113 -->|modifies| FparseApprovalModeValue_6977
    PR114["PR #114"]
    PR114 -->|modifies| FparseApprovalModeValue_6977
    PR117["PR #117"]
    PR117 -->|modifies| FparseApprovalModeValue_6977
    PR21["PR #21"]
    PR21 -->|modifies| FparseApprovalModeValue_6977
    PR36["PR #36"]
    PR36 -->|modifies| FparseApprovalModeValue_6977
    PR46["PR #46"]
    PR46 -->|modifies| FparseApprovalModeValue_6977
    PR86["PR #86"]
    PR86 -->|modifies| FparseApprovalModeValue_6977
    PR88["PR #88"]
    PR88 -->|modifies| FparseApprovalModeValue_6977
    FparseArguments_6977["parseArguments<br>config.ts"]
    PR22 -->|modifies| FparseArguments_6977
    PR10 -->|modifies| FparseArguments_6977
    PR112 -->|modifies| FparseArguments_6977
    PR113 -->|modifies| FparseArguments_6977
    PR114 -->|modifies| FparseArguments_6977
    PR117 -->|modifies| FparseArguments_6977
    PR14["PR #14"]
    PR14 -->|modifies| FparseArguments_6977
    PR17["PR #17"]
    PR17 -->|modifies| FparseArguments_6977
    PR18["PR #18"]
    PR18 -->|modifies| FparseArguments_6977
    PR21 -->|modifies| FparseArguments_6977
    PR31["PR #31"]
    PR31 -->|modifies| FparseArguments_6977
    PR36 -->|modifies| FparseArguments_6977
    PR46 -->|modifies| FparseArguments_6977
    PR7["PR #7"]
    PR7 -->|modifies| FparseArguments_6977
    PR86 -->|modifies| FparseArguments_6977
    PR88 -->|modifies| FparseArguments_6977
Loading

Posted by codegraph-ai conflict detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicting-group-1 Conflicting PR group 1 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✕ [API Error: Streaming setup timeout after 64s. Try reducing input length or increasing timeout in config.

2 participants