feat(core): intelligent tool parallelism with Kind-based batching and shell read-only detection#2864
feat(core): intelligent tool parallelism with Kind-based batching and shell read-only detection#2864wenshao wants to merge 8 commits intoQwenLM:mainfrom
Conversation
…ching Replace the hard-coded Agent-vs-others split with consecutive batching based on tool Kind. Read-only tools (Read, Search, Fetch, Think) now execute in parallel; mutating tools (Edit, Execute) run sequentially. - Add CONCURRENCY_SAFE_KINDS set to tools.ts - Add partitionToolCalls() for consecutive batch grouping - Add isConcurrencySafe() helper (Agent name + Kind check) - Add runConcurrently() with configurable concurrency cap (QWEN_CODE_MAX_TOOL_CONCURRENCY env var, default 10) - Update MockTool to support custom Kind for testing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📋 Review SummaryThis PR implements intelligent tool parallelism based on tool 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Shell commands detected as read-only (e.g., git log, cat, ls) now run concurrently with other safe tools instead of breaking parallel batches. Uses the existing isShellCommandReadOnly() checker (synchronous, fail-closed). Commands that can't be verified as read-only remain sequential. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the core tool scheduling logic to reduce end-to-end latency by executing consecutive “concurrency-safe” tool calls in parallel (batched by tool Kind), instead of only running Agent tools concurrently.
Changes:
- Introduces a
CONCURRENCY_SAFE_KINDSallowlist to classify tool kinds as parallel-safe. - Adds batching + capped parallel execution to
CoreToolSchedulerviapartitionToolCalls()andrunConcurrently(). - Updates test utilities and scheduler tests to support/verify kind-driven parallelism.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/core/src/tools/tools.ts | Adds a concurrency-safe Kind set used to determine which tool calls may run in parallel. |
| packages/core/src/core/coreToolScheduler.ts | Implements Kind-based batching, safety checks, and concurrency-capped parallel execution. |
| packages/core/src/test-utils/mock-tool.ts | Allows tests to assign a custom kind to mock tools. |
| packages/core/src/core/coreToolScheduler.test.ts | Updates the concurrency test to assert parallel execution for concurrency-safe tools. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove Kind.Think from CONCURRENCY_SAFE_KINDS (save_memory and todo_write write to disk) - Use .finally() instead of .then() in runConcurrently for cleanup - Validate maxConcurrency (clamp to >= 1, default 10) - Add comment explaining why sync checker is used over async AST - Add test for mixed safe/unsafe tool batch partitioning Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… calls Let all calls go through executeSingleToolCall which handles abort internally, ensuring every tool reaches a terminal state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Update batching comment to clarify Execute conditional safety - Rename describe block to "Concurrent tool execution" - Add test for shell read-only concurrency (git log + ls parallel, npm install sequential) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prevents false-positive test passes when expected log entries are missing (indexOf returns -1 which is always < any positive index). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Major additions to qwen-code-improvement-report.md: 1. New P0 item: Mid-Turn Queue Drain (PR QwenLM/qwen-code#2854 open) 2. Upgraded P2→P1: Tool parallelism with Kind-based batching (PR QwenLM/qwen-code#2864 open) 3. New P1 items: startup optimization, CLAUDE.md conditional rules 4. New P2 items: shell security, MDM enterprise, API token counting 5. Added Fork Subagent deep-dive cross-reference link 6. Expanded summary table from 10→16 dimensions with "进展" column tracking Qwen Code PR status 7. Fixed forkSubagent.ts line count 211→210 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rt (#34) * docs: add English terms to technical concepts, fix leaked source reference and relative paths - Remove 'leaked' reference in qwen-code-improvement-report.md - Fix 14 relative paths from '../claude-code-leaked/' to 'claude-code/' - Add English annotations to technical terms across 10 comparison docs (Speculation, Context Compression, Subagent, Telemetry, etc.) Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * docs: convert source code references to clickable local links in qwen-code-improvement-report.md - Add local source paths section (claude-code-leaked + qwen-code) - Convert 14 Claude Code source refs to clickable links - Convert 7 Qwen Code source refs to clickable links Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * docs: fix qwen-code-improvement-report.md local links - Replace external source code links with internal article links - Convert 21 external file links to internal documentation links - Add related article references for all 5 Top 5 improvement sections - Use '源码:' format for source code references instead of clickable links Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * fix: correct improvement report accuracy issues 1. reactiveCompact.ts does NOT exist — changed to apiMicrocompact.ts 2. Qwen Code speculation is complete in v0.15.0 (563 lines + overlayFs + speculationToolGate), only default-disabled — updated description, matrix row, summary table, and suggestions 3. Claude Code speculation.ts: 992 → 991 lines Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: replace 'leaked 源码' with '源码分析' in startup-optimization disclaimer Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Copilot review — rename claude-code-leaked path reference Changed `../claude-code-leaked/` → `../claude-code/`(源码快照)in the source path hint to avoid inconsistency with "源码分析" description. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: enhance improvement report with deep-dive findings and PR status Major additions to qwen-code-improvement-report.md: 1. New P0 item: Mid-Turn Queue Drain (PR QwenLM/qwen-code#2854 open) 2. Upgraded P2→P1: Tool parallelism with Kind-based batching (PR QwenLM/qwen-code#2864 open) 3. New P1 items: startup optimization, CLAUDE.md conditional rules 4. New P2 items: shell security, MDM enterprise, API token counting 5. Added Fork Subagent deep-dive cross-reference link 6. Expanded summary table from 10→16 dimensions with "进展" column tracking Qwen Code PR status 7. Fixed forkSubagent.ts line count 211→210 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: simplify improvement matrix table to 5 columns, add deep-dive links - Reduced matrix from 7 columns to 5 (优先级/改进点/现状/难度/进展) to eliminate GitHub horizontal scrollbar - Added section 五 with 12 deep-dive cross-reference links - Tracked Qwen Code PR status: #2854 (mid-turn drain), #2864 (parallelism), #2525 (speculation, merged) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: correct line counts and anchor link in improvement report - compact.ts: 1706→1705 - AgentTool.tsx: 1398→1397 - runAgent.ts: 974→973 - autoDream.ts: 325→324 - Fix anchor: #相关-deep-dive-文章 → #五相关-deep-dive-文章 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
What this PR does
When the model returns multiple tool calls in one response, they used to execute one by one — even if they're all read-only. This PR makes read-only tools run in parallel.
Before vs After
With mixed safe/unsafe tools, ordering is preserved via consecutive batching — consecutive safe tools are grouped into one parallel batch, but an unsafe tool breaks the batch:
What's safe to parallelize
git log,git status,cat,ls,wc,diff, ...)isShellCommandReadOnly()— a whitelist of ~30 commands with git subcommand validation. Unknown commands → sequential (fail-closed)npm install,rm,mkdir, ...)Kind.Thinkbut write to diskBehavior change: Agent tools
Previously, Agent tools were unconditionally pulled into a separate concurrent group (ran in parallel regardless of position). Now they follow the same consecutive batching rules as other safe tools.
[Edit, Agent]previously ran concurrently; now Agent waits for Edit to finish. This is safer — it preserves the model's intended ordering.Comparison with Claude Code
Core parallel execution capability is now on par with Claude Code.
Note: Qwen Code also has a tree-sitter-bash AST parser (
isShellCommandReadOnlyAST) used for permission decisions. The concurrency check uses the synchronous regex-based checker for performance (partitioning must be synchronous). Both checkers share the same command whitelist.Changes
tools.tsCONCURRENCY_SAFE_KINDSset (Read, Search, Fetch)coreToolScheduler.tsisConcurrencySafe(),partitionToolCalls(),runConcurrently()with shell read-only detection and configurable concurrency cap (QWEN_CODE_MAX_TOOL_CONCURRENCY, default 10)mock-tool.tskindoption for testingcoreToolScheduler.test.tsTest plan
npx vitest run packages/core/src/core/coreToolScheduler.test.ts— 55 tests passnpx tsc --noEmit -p packages/core/tsconfig.json— type check passes🤖 Generated with Claude Code