The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): a gateway-hosted CLI session prints its startup warnings on the first turn
Teknium7298f46b7d85
diff --git a/agent/status_output.py b/agent/status_output.pyindex c56678d5c84..7ed88543d92 100644--- a/agent/status_output.py+++ b/agent/status_output.py@@ -107,12 +107,16 @@ class StatusOutputMixin:def _emit_startup_warning(self, message: str) -> None:"""A warning raised during ``__init__`` that the user must see (e.g. a memory provider that- could not be recovered). The CLI prints it. Other drivers get a sticky warn ``AgentNotice``:- Desktop renders notices but no warn-kind ``status.update``, and the messaging gateway wires- its callbacks per turn, after init, so a notice raised before then waits for- :meth:`_replay_startup_warnings` on the first turn."""+ could not be recovered). The CLI prints it; a CLI session the gateway hosts (``hermes chat``) has+ no viewer sink until its first turn wires one, so the line waits for that turn. Other drivers get+ a sticky warn ``AgentNotice``: Desktop renders notices but no warn-kind ``status.update``, and the+ messaging gateway wires its callbacks per turn, after init, so a notice raised before then waits+ for :meth:`_replay_startup_warnings` on the first turn."""message = message.strip()if (getattr(self, "platform", None) or "cli") == "cli":+ if getattr(self, "_gateway_session_key", None):+ self._pending_startup_prints = [*getattr(self, "_pending_startup_prints", ()), message]+ returnself._emit_warning(message)returnimport zlib@@ -128,6 +132,11 @@ class StatusOutputMixin:self._pending_startup_notices = [*getattr(self, "_pending_startup_notices", ()), notice]def _replay_startup_warnings(self) -> None:+ prints = getattr(self, "_pending_startup_prints", None)+ if prints:+ self._pending_startup_prints = []+ for message in prints:+ self._emit_warning(message)pending = getattr(self, "_pending_startup_notices", None)if pending and getattr(self, "notice_callback", None):self._pending_startup_notices = []diff --git a/agent/turn_context.py b/agent/turn_context.pyindex b49d32d28fc..10952e4678b 100644--- a/agent/turn_context.py+++ b/agent/turn_context.py@@ -651,7 +651,8 @@ def _reset_per_turn_agent_state(agent: Any) -> None:if agent._compression_warning:agent._replay_compression_warning()agent._compression_warning = None # send once- if getattr(agent, "_pending_startup_notices", None): # gateway: init ran before its callbacks+ if getattr(agent, "_pending_startup_notices", None) or getattr(agent, "_pending_startup_prints", None):+ # gateway: init ran before this turn's callbacks / viewer print sinkagent._replay_startup_warnings()agent.iteration_budget = IterationBudget(agent.max_iterations)diff --git a/tests/agent/test_memory_migration_notifications.py b/tests/agent/test_memory_migration_notifications.pyindex 67564af9479..c95c6fc7531 100644--- a/tests/agent/test_memory_migration_notifications.py+++ b/tests/agent/test_memory_migration_notifications.py@@ -45,3 +45,16 @@ def test_gateway_start_replays_the_refusal_once_on_first_turn(tmp_path, monkeypaagent._replay_startup_warnings()assert len(notices) == 1 and notices[0].level == "warn"assert "hermes plugins install scout_missing_provider" in notices[0].text+++def test_a_gateway_hosted_cli_session_prints_the_startup_warning_on_its_first_turn():+ """``hermes chat`` runs its agent in the gateway: built before the viewer's print sink is wired, a+ startup line printed during init reached only the gateway's stdout log. It prints on the first turn, once."""+ agent = StartupAgent("cli")+ agent._gateway_session_key = "agent:main:cli:dm:local"+ agent._warning_presentation_enabled = lambda: True+ agent._emit_startup_warning("✓ Something moved out of core — installed its plugin.")+ assert agent.printed == []+ agent._replay_startup_warnings() # first turn: the viewer's sink is wired now+ agent._replay_startup_warnings()+ assert agent.printed == ["✓ Something moved out of core — installed its plugin."]