mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
fix: make display_hermes_home imports lazy to prevent ImportError during hermes update (#3776)
When a user runs 'hermes update', the Python process caches old modules in sys.modules. After git pull updates files on disk, lazy imports of newly-updated modules fail because they try to import display_hermes_home from the cached (old) hermes_constants which doesn't have the function. This specifically broke the gateway auto-restart in cmd_update — importing hermes_cli/gateway.py triggered the top-level 'from hermes_constants import display_hermes_home' against the cached old module. The ImportError was silently caught, so the gateway was never restarted after update. Users with a running gateway then hit the ImportError on their next Telegram/Discord message when the stale gateway process lazily loaded run_agent.py (new version) which also had the top-level import. Fixes: - hermes_cli/gateway.py: lazy import at call site (line 940) - run_agent.py: lazy import at call site (line 6927) - tools/terminal_tool.py: lazy imports at 3 call sites - tools/tts_tool.py: static schema string (no module-level call) - hermes_cli/auth.py: lazy import at call site (line 2024) - hermes_cli/main.py: reload hermes_constants after git pull in cmd_update Also fixes 4 pre-existing test failures in test_parse_env_var caused by NameError on display_hermes_home in terminal_tool.py.
This commit is contained in:
parent
442888a05b
commit
c62cadb73a
7 changed files with 36 additions and 16 deletions
|
|
@ -48,7 +48,7 @@ logger = logging.getLogger(__name__)
|
|||
# long-running subprocesses immediately instead of blocking until timeout.
|
||||
# ---------------------------------------------------------------------------
|
||||
from tools.interrupt import is_interrupted, _interrupt_event # noqa: F401 — re-exported
|
||||
from hermes_constants import display_hermes_home
|
||||
# display_hermes_home imported lazily at call site (stale-module safety during hermes update)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
|
@ -158,7 +158,8 @@ def _handle_sudo_failure(output: str, env_type: str) -> str:
|
|||
|
||||
for failure in sudo_failures:
|
||||
if failure in output:
|
||||
return output + f"\n\n💡 Tip: To enable sudo over messaging, add SUDO_PASSWORD to {display_hermes_home()}/.env on the agent machine."
|
||||
from hermes_constants import display_hermes_home as _dhh
|
||||
return output + f"\n\n💡 Tip: To enable sudo over messaging, add SUDO_PASSWORD to {_dhh()}/.env on the agent machine."
|
||||
|
||||
return output
|
||||
|
||||
|
|
@ -444,7 +445,7 @@ def _parse_env_var(name: str, default: str, converter=int, type_label: str = "in
|
|||
except (ValueError, json.JSONDecodeError):
|
||||
raise ValueError(
|
||||
f"Invalid value for {name}: {raw!r} (expected {type_label}). "
|
||||
f"Check {display_hermes_home()}/.env or environment variables."
|
||||
f"Check ~/.hermes/.env or environment variables."
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1284,7 +1285,8 @@ if __name__ == "__main__":
|
|||
print(f" TERMINAL_MODAL_IMAGE: {os.getenv('TERMINAL_MODAL_IMAGE', default_img)}")
|
||||
print(f" TERMINAL_DAYTONA_IMAGE: {os.getenv('TERMINAL_DAYTONA_IMAGE', default_img)}")
|
||||
print(f" TERMINAL_CWD: {os.getenv('TERMINAL_CWD', os.getcwd())}")
|
||||
print(f" TERMINAL_SANDBOX_DIR: {os.getenv('TERMINAL_SANDBOX_DIR', f'{display_hermes_home()}/sandboxes')}")
|
||||
from hermes_constants import display_hermes_home as _dhh
|
||||
print(f" TERMINAL_SANDBOX_DIR: {os.getenv('TERMINAL_SANDBOX_DIR', f'{_dhh()}/sandboxes')}")
|
||||
print(f" TERMINAL_TIMEOUT: {os.getenv('TERMINAL_TIMEOUT', '60')}")
|
||||
print(f" TERMINAL_LIFETIME_SECONDS: {os.getenv('TERMINAL_LIFETIME_SECONDS', '300')}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue