Commit 6e29505
feat(core): intelligent tool parallelism with Kind-based batching and shell read-only detection (#2864)
* feat(core): implement intelligent tool parallelism via Kind-based batching
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>
* feat(core): add conditional concurrency for shell read-only commands
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>
* fix: address Copilot review on tool parallelism
- 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>
* fix: update comment to match CONCURRENCY_SAFE_KINDS (remove Think)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: remove abort break in runConcurrently to prevent stuck scheduled 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>
* test: isolate concurrency tests from QWEN_CODE_MAX_TOOL_CONCURRENCY env
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address Copilot review - comment, test label, shell test
- 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>
* fix: add indexOf !== -1 guards to concurrency test assertions
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>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent dddb56d commit 6e29505
File tree
4 files changed
+344
-36
lines changed- packages/core/src
- core
- test-utils
- tools
4 files changed
+344
-36
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
3004 | 3004 | | |
3005 | 3005 | | |
3006 | 3006 | | |
3007 | | - | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
3008 | 3021 | | |
3009 | 3022 | | |
3010 | 3023 | | |
| |||
3132 | 3145 | | |
3133 | 3146 | | |
3134 | 3147 | | |
3135 | | - | |
| 3148 | + | |
3136 | 3149 | | |
3137 | 3150 | | |
3138 | 3151 | | |
| |||
3151 | 3164 | | |
3152 | 3165 | | |
3153 | 3166 | | |
| 3167 | + | |
3154 | 3168 | | |
3155 | 3169 | | |
3156 | 3170 | | |
3157 | | - | |
| 3171 | + | |
3158 | 3172 | | |
3159 | 3173 | | |
3160 | 3174 | | |
| |||
3176 | 3190 | | |
3177 | 3191 | | |
3178 | 3192 | | |
| 3193 | + | |
| 3194 | + | |
3179 | 3195 | | |
3180 | 3196 | | |
3181 | 3197 | | |
| |||
3215 | 3231 | | |
3216 | 3232 | | |
3217 | 3233 | | |
3218 | | - | |
3219 | | - | |
3220 | | - | |
3221 | | - | |
3222 | | - | |
3223 | | - | |
3224 | | - | |
3225 | | - | |
3226 | | - | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
3227 | 3244 | | |
| 3245 | + | |
3228 | 3246 | | |
3229 | 3247 | | |
3230 | | - | |
3231 | | - | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
| 3262 | + | |
| 3263 | + | |
| 3264 | + | |
| 3265 | + | |
| 3266 | + | |
| 3267 | + | |
| 3268 | + | |
| 3269 | + | |
| 3270 | + | |
| 3271 | + | |
| 3272 | + | |
| 3273 | + | |
| 3274 | + | |
| 3275 | + | |
| 3276 | + | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
| 3284 | + | |
| 3285 | + | |
| 3286 | + | |
| 3287 | + | |
| 3288 | + | |
| 3289 | + | |
| 3290 | + | |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
| 3301 | + | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
| 3322 | + | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
| 3332 | + | |
| 3333 | + | |
| 3334 | + | |
| 3335 | + | |
| 3336 | + | |
| 3337 | + | |
| 3338 | + | |
| 3339 | + | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
| 3368 | + | |
| 3369 | + | |
| 3370 | + | |
| 3371 | + | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
| 3396 | + | |
| 3397 | + | |
| 3398 | + | |
| 3399 | + | |
| 3400 | + | |
| 3401 | + | |
| 3402 | + | |
| 3403 | + | |
| 3404 | + | |
| 3405 | + | |
| 3406 | + | |
| 3407 | + | |
| 3408 | + | |
| 3409 | + | |
| 3410 | + | |
| 3411 | + | |
| 3412 | + | |
| 3413 | + | |
| 3414 | + | |
| 3415 | + | |
| 3416 | + | |
| 3417 | + | |
| 3418 | + | |
| 3419 | + | |
| 3420 | + | |
| 3421 | + | |
| 3422 | + | |
| 3423 | + | |
| 3424 | + | |
| 3425 | + | |
| 3426 | + | |
| 3427 | + | |
| 3428 | + | |
| 3429 | + | |
| 3430 | + | |
| 3431 | + | |
| 3432 | + | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
| 3439 | + | |
| 3440 | + | |
| 3441 | + | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
| 3445 | + | |
| 3446 | + | |
| 3447 | + | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
3232 | 3454 | | |
3233 | 3455 | | |
3234 | 3456 | | |
| |||
0 commit comments