From fe9f9b2a905757089412434d2e95392a0a3b62cc Mon Sep 17 00:00:00 2001 From: Iko Date: Fri, 23 Oct 2026 19:21:50 -0400 Subject: [PATCH] fix: resolve tool serializers per call, not at import Importing this module called `_tool_result_helpers()` at module level, which imported `tools.registry` at import time. pytest imports the repo's conftest.py as `builder.conftest` (the repo root is a package), so `builder/__init__.py` executes before conftest can put Hermes core on sys.path -- and `tools` bound to whichever hermes-agent was pip-installed rather than the pinned checkout the tests are meant to exercise. `model_tools` then came from the pinned core while `tools.registry` came from the installed copy, so the chat-dispatch integration tests failed to import and skipped themselves instead of running. Resolving per call removes the import-time dependency on core and restores the pinned checkout as the source of `tools`. No test referenced the removed `_TOOL_RESULT` / `_TOOL_ERROR` module constants. Verified: `.venv/bin/python -m pytest -q` -> 264 passed, 1 skipped (was 263 passed / 1 failed / 1 skipped with the integration tests skipping); verify.py green. Without a pinned checkout at HERMES_HOME the provider test fails again, so this does not mask a real requirement. --- __init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index d19726f..e0fb6fb 100644 --- a/__init__.py +++ b/__init__.py @@ -179,18 +179,24 @@ def _error(message: str, code: str = "error", *, success: bool = False): return _result, _error -_TOOL_RESULT, _TOOL_ERROR = _tool_result_helpers() _registered = False _provider_worker: threading.Thread | None = None _provider_worker_lock = threading.Lock() def _success(data: dict[str, Any]) -> str: - return _TOOL_RESULT(success=True, **data) + # Resolved per call, not at import: importing this module must not bind + # `tools.registry` before the host has had a chance to put its Hermes core + # on sys.path (conftest does this). Binding at import time pinned `tools` to + # whichever hermes-agent happened to be installed, so a pinned core checkout + # was ignored and the integration tests resolved a mismatched registry. + tool_result, _ = _tool_result_helpers() + return tool_result(success=True, **data) def _error(message: str, code: str = "error") -> str: - return _TOOL_ERROR(message, code=code, success=False) + _, tool_error = _tool_result_helpers() + return tool_error(message, code=code, success=False) def _check_available() -> bool: