fix(tools): serialize concurrent hermes_tools RPC calls from execute_code#17872
Closed
vominh1919 wants to merge 1 commit into
Closed
fix(tools): serialize concurrent hermes_tools RPC calls from execute_code#17872vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
…code When execute_code scripts call hermes_tools functions from multiple threads (ThreadPoolExecutor), the RPC responses get mismatched — each thread receives another thread's response. UDS transport: All threads share a single socket (_sock). Concurrent send+recv interleaves, so thread A reads thread B's response. Fix: wrap send+recv in a threading.Lock(). File transport: The global _seq counter has a race condition — two threads can increment simultaneously and get the same seq number, causing response file collisions. Fix: wrap _seq increment and seq_str assignment in a threading.Lock(). Fixes NousResearch#17770
Collaborator
Collaborator
|
Likely duplicate of #17771 |
This was referenced Apr 30, 2026
Contributor
|
Thanks for tackling this! Closing in favor of #17902 which went with @Heltman's #17771 (he filed the original issue #17770 a few hours earlier). Two things your version would have hit in production that the merged one avoids:
The merged fix snapshots |
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
When a script run via
execute_codecalls hermes_tools functions (terminal,read_file, etc.) from multiple threads (e.g.ThreadPoolExecutor), each thread frequently receives another thread's response.Root Cause
UDS transport (local backend): All threads share a single socket (
_sock). Concurrent send+recv interleaves.File transport (remote backends): The global
_seqcounter has a race condition — two threads can get the same seq number.Fix
threading.Lock()around send+recv_seqrace conditionthreading.Lock()around_seqincrementFixes #17770