The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): write memory-provider refusals to gateway.log and name a log every host has
unsupportedpastels93a267dcf202
diff --git a/agent/memory_caller_scope.py b/agent/memory_caller_scope.pyindex 0a9eaaca13a..cda9e41ba8f 100644--- a/agent/memory_caller_scope.py+++ b/agent/memory_caller_scope.py@@ -11,7 +11,8 @@ the rule is the multiplexing contract in ``agent/memory_provider.py``. The manag- one provider instance serves one profile: a plugin that hands several agents the same instance isrefused for every profile after the first, instead of being rebound to it.-Refusals log the check's code and both homes; the model/chat only ever sees a generic refusal.+Refusals log the check's code and both homes (errors.log on every host, gateway.log on a gateway); the+model/chat only ever sees a generic refusal."""from __future__ import annotations@@ -34,7 +35,7 @@ _claims_lock = threading.RLock() # reentrant: a weakref callback can fire fromdef refused_tool_message(tool_name: str) -> str:"""What the model/chat sees for a refused memory tool call: no check name, no home paths."""- return f"Memory tool '{tool_name}' refused. Ask the operator to check gateway.log."+ return f"Memory tool '{tool_name}' refused. Ask the operator to check `hermes logs errors`."def _home_key(home: Any) -> Optional[str]:diff --git a/agent/memory_manager.py b/agent/memory_manager.pyindex 71af356bb5c..f27fe5ec9e2 100644--- a/agent/memory_manager.py+++ b/agent/memory_manager.py@@ -670,7 +670,7 @@ class MemoryManager:"""if not self._owner_allows("on_pre_compress"):if require_checkpoint: # the caller keeps the uncompressed transcript- raise RuntimeError("Memory pre-compress checkpoint refused; see gateway.log")+ raise RuntimeError("Memory pre-compress checkpoint refused; see `hermes logs errors`")return ""parts = []checkpoint_succeeded = Falsediff --git a/hermes_logging.py b/hermes_logging.pyindex 8066e82d435..047eabd6e64 100644--- a/hermes_logging.py+++ b/hermes_logging.py@@ -306,8 +306,9 @@ class _ComponentFilter(logging.Filter):COMPONENT_PREFIXES = {# ``plugins.platforms``: messaging adapters that migrated out of# ``gateway/platforms/`` into bundled plugins (#41112) are still gateway- # components and belong in gateway.log.- "gateway": ("gateway", "hermes_plugins", "plugins.platforms"),+ # components and belong in gateway.log. ``agent.memory_caller_scope``: a multiplexed gateway's+ # memory-provider profile refusals (#140058), which the operator reads in gateway.log.+ "gateway": ("gateway", "hermes_plugins", "plugins.platforms", "agent.memory_caller_scope"),"agent": ("agent", "run_agent", "model_tools", "batch_runner"),"tools": ("tools",),"cli": ("hermes_cli", "cli"),diff --git a/tests/agent/test_memory_provider_caller_profile.py b/tests/agent/test_memory_provider_caller_profile.pyindex 52d33157166..439d72467b5 100644--- a/tests/agent/test_memory_provider_caller_profile.py+++ b/tests/agent/test_memory_provider_caller_profile.py@@ -143,9 +143,10 @@ _REFUSAL_CODE = "memory_caller_profile_unresolved"def _assert_generic_refusal(result, caplog, *homes):- """The model/chat sees a generic refusal; gateway.log keeps the check's code and the homes."""+ """The model/chat sees a generic refusal pointing at a log every host writes (errors.log; gateway.log+ too on a gateway); the log keeps the check's code and the homes."""error = result.get("error", "")- assert "refused" in error and "gateway.log" in error, result+ assert "refused" in error and "hermes logs errors" in error, resultassert _REFUSAL_CODE not in error and not any(str(home) in error for home in homes), resultlogged = "\n".join(r.getMessage() for r in caplog.records if r.name == "agent.memory_caller_scope")assert _REFUSAL_CODE in logged, logged@@ -335,10 +336,20 @@ def test_multiplexed_lifecycle_hook_without_a_caller_scope_is_refused(homes, hoodef test_refused_checkpoint_compression_fails_closed(homes):alpha_home, beta_home = homesalpha = _manager(alpha_home)- with _Scope(beta_home), pytest.raises(RuntimeError):+ with _Scope(beta_home), pytest.raises(RuntimeError, match="hermes logs errors"):alpha.on_pre_compress([{"role": "user", "content": "x"}], require_checkpoint=True)+def test_refusals_are_written_to_gateway_log():+ # gateway.log keeps only the gateway component's loggers; the refusals must be among them.+ import logging++ from agent import memory_caller_scope+ from hermes_logging import COMPONENT_PREFIXES, _ComponentFilter+ record = logging.LogRecord(memory_caller_scope.logger.name, logging.WARNING, __file__, 1, "refused", (), None)+ assert _ComponentFilter(COMPONENT_PREFIXES["gateway"]).filter(record)++def test_background_hook_runs_under_the_owning_profile_explicitly(homes, multiplexed):# The turn proves its profile through the secret scope alone (no HERMES_HOME override): the# background worker must still run the provider under the owner's home, not the process's.diff --git a/website/docs/developer-guide/memory-provider-plugin.md b/website/docs/developer-guide/memory-provider-plugin.mdindex 8cc94659144..9ea6b0bd880 100644--- a/website/docs/developer-guide/memory-provider-plugin.md+++ b/website/docs/developer-guide/memory-provider-plugin.md@@ -444,7 +444,7 @@ One gateway process can serve several profiles at once, and their turns run conc- **Bind from `initialize()`.** Derive every store, path, client, bank and tenant from the `hermes_home` keyword (and secrets read through `get_secret()` during `initialize`), and keep that binding on `self`.- **Keep nothing profile-specific at module or class level.** No global "current store", and no rebinding a shared binding on each call. Two profiles' calls interleave, so a per-call rebind races.-The manager enforces the other half. It runs tool calls and every lifecycle hook (`prefetch`, `queue_prefetch`, `sync_turn`, `on_memory_write`, `on_session_end`, …) only from the profile the instance was initialized for. On a multiplexed gateway a caller that names no profile is refused, and the refusal is logged in `gateway.log` as `memory_caller_profile_unresolved`. Background hooks run under the owning profile's `HERMES_HOME`. `handle_tool_call(..., **kwargs)` also receives `hermes_home`, `agent_identity` and `caller_gsk`. They name the profile your instance is already bound to, so you can assert on them, but don't rebind from them.+The manager enforces the other half. It runs tool calls and every lifecycle hook (`prefetch`, `queue_prefetch`, `sync_turn`, `on_memory_write`, `on_session_end`, …) only from the profile the instance was initialized for. On a multiplexed gateway a caller that names no profile is refused, and the refusal is logged as `memory_caller_profile_unresolved` in the profile's `errors.log` (`hermes logs errors`) and in `gateway.log`. Background hooks run under the owning profile's `HERMES_HOME`. `handle_tool_call(..., **kwargs)` also receives `hermes_home`, `agent_identity` and `caller_gsk`. They name the profile your instance is already bound to, so you can assert on them, but don't rebind from them.Hermes can't verify a provider's internals. A provider that keeps a process-wide binding still mixes profiles' memories, even with these checks in place.