feat(cli): add startup optimization with API preconnect and early input capture - #3085
feat(cli): add startup optimization with API preconnect and early input capture#3085doudouOUC wants to merge 4 commits into
Conversation
…ut capture Implements #3011 startup optimization with two key features: 1. API Preconnect - Warms TCP+TLS connection before first API call - Fire-and-forget HEAD request to reduce first API call latency - Smart skip conditions: proxy, custom CA, sandbox mode, custom baseUrl - Environment variable toggle: QWEN_CODE_DISABLE_PRECONNECT=1 2. Early Input Capture - Captures user input during REPL initialization - Filters terminal responses (DA, DA2, OSC, DCS) while preserving user input - Preserves arrow keys (ESC [ A/B/C/D) and function keys (F1-F4) - 64KB buffer limit for safety - Environment variable toggle: QWEN_CODE_DISABLE_EARLY_CAPTURE=1 Benchmark results: - TCP+TLS handshake time: 181ms → 56ms (69% improvement) - First API call latency: estimated 100-200ms reduction
📋 Review SummaryThis PR implements startup optimization with two key features: API preconnect (warming TCP+TLS connections before the first API call) and early input capture (preventing keystroke loss during REPL initialization). The implementation is well-structured with comprehensive test coverage (34 tests total), thoughtful skip conditions, and environment variable toggles for both features. The code demonstrates good engineering practices with proper error handling and debug logging. 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
1. Move preconnect after loadCliConfig to avoid unnecessary HEAD requests for --help/--version flows 2. Lookup env baseUrl based on authType instead of fixed order 3. Translate Chinese comments to English for consistency 4. Add try-catch for preconnect call to handle missing getModelsConfig Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
回复 @wenshao 的评论评论 1: preconnect 时机问题 ✅ 已修复
修复方案: 将 preconnect 移到 评论 2: 环境变量查找顺序问题 ✅ 已修复
修复方案: 根据 authType 查找对应的环境变量:
评论 3: ESC 序列过滤问题 ❌ 不采纳
说明: 这些是标准控制序列起始符(OSC/DCS/PM/APC),在终端协议中永远不会是用户输入。用户 Meta/Alt 组合键是 Commit: 00749d4 |
- Update copyright from 'Google LLC' to 'Qwen Team' - Translate all Chinese comments to English for consistency
- Fix double-counting in benchmark-api-latency.sh (time_appconnect already includes time_connect) - Fix hardcoded worktree paths in benchmark scripts, use relative paths - Simplify preconnect abort logic with AbortSignal.timeout(5s) instead of manual AbortController+setTimeout(10s) - Fix startup benchmark scripts: remove misleading preconnect comparison since --version exits before preconnect runs - Translate remaining Chinese comments to English in KeypressContext.tsx - Use temp directory instead of repo-local ./benchmark-results Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Closes #3223, Closes #3224
Summary
Implements two sub-issues from #3011 (Startup Optimization):
1. API Preconnect (#3223)
QWEN_CODE_DISABLE_PRECONNECT=12. Early Input Capture (#3224)
QWEN_CODE_DISABLE_EARLY_CAPTURE=1Benchmark Results
Test Plan
🤖 Generated with Claude Code