fix(hermes): defer sanitizer patch out of plugin discovery lock - #60
Open
prismatic7 wants to merge 1 commit into
Open
fix(hermes): defer sanitizer patch out of plugin discovery lock#60prismatic7 wants to merge 1 commit into
prismatic7 wants to merge 1 commit into
Conversation
register() called _patch_hermes_sanitizer() eagerly, which imports run_agent while PluginManager holds _discovery_lock. The TUI gateway builds the agent in a parallel thread that imports run_agent and then calls model_tools.discover_plugins() under the same lock — an ABBA deadlock that stalls first TUI launch over SSH (renders, but nothing responds; ctrl+c and relaunch works). The patch is already applied safely in on_session_start(), which fires after the agent is built, so the eager call in register() is redundant.
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.
Problem
First launch of the Hermes TUI over an interactive SSH session stalls: the UI renders but nothing responds. Ctrl+C and relaunch works. This is an ABBA deadlock between two threads at TUI startup:
tui-mcp-discovery): holds_discovery_lock(in Hermes'hermes_cli/plugins.py) → loads plugins →contextpilot.register()→_patch_hermes_sanitizer()→import run_agent→ blocks on the Python import lock_build): holds the import lock (importingrun_agent) → module-levelmodel_tools.discover_plugins()→ blocks on_discovery_lockEach thread holds one lock and waits on the other → deadlock → the TUI's
run_after_agent_readywaits forever onready.wait().Fix
Remove the eager
_patch_hermes_sanitizer()call fromregister(). The patch is already applied safely inContextPilotEngine.on_session_start()(line 706), which Hermes invokes at agent init — after the agent is built, sorun_agentis already imported and there is no lock contention. The eager call inregister()is redundant and is the only path that importsrun_agentwhile the discovery lock is held.Verification
register()no longer importsrun_agent; the patch still installs on the first session start._patch_hermes_sanitizer()call sites remain.run_agentduring discovery.