OpenAI-compatible server reliability improvements via HTTP/1.1 keep-alive config and error handling#14
Open
BingqingLyu wants to merge 4 commits into
Open
Conversation
Previous behavior: Local OpenAI-compatible servers experienced intermittent connection failures and streaming issues due to missing HTTP/1.1 keep-alive configuration and inadequate timeout handling. What changed: - packages/core/src/core/openaiContentGenerator.ts: Add HTTP agent configuration with proper keep-alive settings, implement retry logic with exponential backoff, add constants for timeout and connection pooling - packages/cli/src/config/config.ts: Consolidate OpenAI configuration functions, add setupOpenAIFromCliArgs and getEffectiveAuthType for proper config hierarchy (CLI > env > settings) - packages/cli/src/validateNonInterActiveAuth.ts: Consolidate debug logging into multi-line statements, use getEffectiveAuthType for consistent auth resolution - packages/cli/src/gemini.tsx: Fix import order, add error logging in debug mode, update imports after config consolidation - packages/core/src/core/contentGenerator.ts: Add getBackendName function for human-readable API names in error messages - packages/core/src/core/geminiChat.ts: Add getConfig() method to expose configuration for error reporting - packages/core/src/core/turn.ts: Use getBackendName for better error messages - packages/cli/src/nonInteractiveCli.ts: Apply OpenAI CLI arguments before auth initialization - docs/cli/openai-auth.md: Document local server configuration options Why: Local OpenAI-compatible servers often have different connection characteristics than cloud services, requiring specific HTTP agent configuration to maintain stable connections. The changes ensure reliable streaming and prevent premature connection closures. Testable: Run with local OpenAI-compatible server using OPENAI_BASE_URL=http://localhost:1234/v1 and verify stable streaming without connection drops.
This was referenced Apr 28, 2026
5 tasks
Owner
Author
Conflict Group 1This PR shares modified functions with 20 other PR(s): #10, #112, #113, #114, #117, #17, #18, #20, #21, #22, #31, #36, #46, #6, #7, #71, #75, #86, #88, #94. These PRs should be reviewed as a batch — merging one may affect the others.
graph LR
PR14["PR #14"]
Fmain_4875["main<br>gemini.tsx"]
PR14 -->|modifies| Fmain_4875
PR17["PR #17"]
PR17 -->|modifies| Fmain_4875
PR20["PR #20"]
PR20 -->|modifies| Fmain_4875
PR94["PR #94"]
PR94 -->|modifies| Fmain_4875
FparseArguments_6977["parseArguments<br>config.ts"]
PR14 -->|modifies| FparseArguments_6977
PR10["PR #10"]
PR10 -->|modifies| FparseArguments_6977
PR112["PR #112"]
PR112 -->|modifies| FparseArguments_6977
PR113["PR #113"]
PR113 -->|modifies| FparseArguments_6977
PR114["PR #114"]
PR114 -->|modifies| FparseArguments_6977
PR117["PR #117"]
PR117 -->|modifies| FparseArguments_6977
PR17 -->|modifies| FparseArguments_6977
PR18["PR #18"]
PR18 -->|modifies| FparseArguments_6977
PR21["PR #21"]
PR21 -->|modifies| FparseArguments_6977
PR22["PR #22"]
PR22 -->|modifies| FparseArguments_6977
PR31["PR #31"]
PR31 -->|modifies| FparseArguments_6977
PR36["PR #36"]
PR36 -->|modifies| FparseArguments_6977
PR46["PR #46"]
PR46 -->|modifies| FparseArguments_6977
PR7["PR #7"]
PR7 -->|modifies| FparseArguments_6977
PR86["PR #86"]
PR86 -->|modifies| FparseArguments_6977
PR88["PR #88"]
PR88 -->|modifies| FparseArguments_6977
FresolveContentGeneratorConfigWithSources_5386["resolveContentGeneratorConfigWithSources<br>contentGenerator.ts"]
PR14 -->|modifies| FresolveContentGeneratorConfigWithSources_5386
PR17 -->|modifies| FresolveContentGeneratorConfigWithSources_5386
FrunNonInteractive_8467["runNonInteractive<br>nonInteractiveCli.ts"]
PR14 -->|modifies| FrunNonInteractive_8467
PR114 -->|modifies| FrunNonInteractive_8467
PR17 -->|modifies| FrunNonInteractive_8467
PR6["PR #6"]
PR6 -->|modifies| FrunNonInteractive_8467
PR71["PR #71"]
PR71 -->|modifies| FrunNonInteractive_8467
PR75["PR #75"]
PR75 -->|modifies| FrunNonInteractive_8467
FstartInteractiveUI_4875["startInteractiveUI<br>gemini.tsx"]
PR14 -->|modifies| FstartInteractiveUI_4875
PR114 -->|modifies| FstartInteractiveUI_4875
PR117 -->|modifies| FstartInteractiveUI_4875
PR17 -->|modifies| FstartInteractiveUI_4875
PR31 -->|modifies| FstartInteractiveUI_4875
PR6 -->|modifies| FstartInteractiveUI_4875
PR88 -->|modifies| FstartInteractiveUI_4875
PR94 -->|modifies| FstartInteractiveUI_4875
FvalidateNonInteractiveAuth_1241["validateNonInteractiveAuth<br>validateNonInterActiveAuth.ts"]
PR14 -->|modifies| FvalidateNonInteractiveAuth_1241
PR10 -->|modifies| FvalidateNonInteractiveAuth_1241
PR17 -->|modifies| FvalidateNonInteractiveAuth_1241
Posted by codegraph-ai conflict detection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the reliability of Qwen Code when using local OpenAI-compatible servers by implementing proper HTTP/1.1 keep-alive configuration and robust error handling.
Problem
Local OpenAI-compatible servers (running on localhost) were experiencing:
Solution
1. HTTP Agent Configuration
2. Retry Logic
undicimodule is not available3. Configuration Improvements
getBackendName()function to display actual backend name ("OpenAI API", "Qwen API", "Vertex AI", etc.) instead of undefined in error messagesChanges
config.ts, enforced CLI > env > settings.json precedenceopenai-auth.mdwith environment variable examplesTesting
To test with a local OpenAI-compatible server:
Compatibility
Fixes issues with local model inference reliability when using self-hosted models.