fix: make concurrent tool batching path-aware for file mutations#1914
Merged
fix: make concurrent tool batching path-aware for file mutations#1914
Conversation
- Log malformed/non-dict tool arguments at debug level before falling back to sequential, instead of silently swallowing the error into an empty dict - Guard empty paths in _paths_overlap (unreachable in practice due to upstream filtering, but makes the invariant explicit) - Add tests: malformed JSON args, non-dict args, _paths_overlap unit tests including empty path edge cases - web_crawl is not a registered tool (only web_search/web_extract are); no addition needed to _PARALLEL_SAFE_TOOLS
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.
Salvage of PR #1873 by @kshitijk4poor (cherry-picked with authorship preserved, 2 commits). Fixes #1872.
Summary
The tool batching gate was too coarse — any multi-call batch without
clarifywent concurrent, which meant overlapping file mutations likewrite_file("src/a.py")+patch("src/a.py")could race each other with nondeterministic results.This makes the parallelization decision path-aware:
web_search,read_file,search_files, etc.) → always safe to parallelizeread_file,write_file,patch) → parallel only when targeting different pathsterminal, etc.) → forced sequentialDisjoint file operations keep their latency benefit while overlapping mutations stay ordered.
Changes
run_agent.py: New_should_parallelize_tool_batch()function with_PARALLEL_SAFE_TOOLS,_PATH_SCOPED_TOOLSallowlists, path overlap detectiontests/test_run_agent.py: 8 new test methods covering overlapping/disjoint writes, terminal batches, malformed args, plus unit tests for_paths_overlapTest plan
pytest tests/test_run_agent.py -n0 -q— 190 passed