The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): `hermes chat -q` codex exec/apply_patch approvals fail closed at once
kshitijk4poorc61242020b91
diff --git a/agent/codex_runtime.py b/agent/codex_runtime.pyindex 4c3a20d403a..eb55492ab77 100644--- a/agent/codex_runtime.py+++ b/agent/codex_runtime.py@@ -615,11 +615,14 @@ def _ensure_codex_session(agent, messages: List[Dict[str, Any]] | None = None) -from agent.transports.codex_app_server_session import CodexAppServerSession, _ServerRequestRoutingfrom hermes_cli.codex_runtime_switch import get_configured_codex_binaryfrom hermes_cli.config import load_config- # Approval callback: Hermes' standard prompt flow when a CLI thread installed one.+ # Approval callback: Hermes' standard prompt flow when a CLI thread installed one. `hermes chat -q`, cron and+ # unattended platforms can have one registered with nobody to answer it, so they get none and fail closed at once.approval_callback = Nonewith suppress(Exception):+ from tools.approval_context import _no_user_can_answerfrom tools.terminal_tool import _get_approval_callback- approval_callback = _get_approval_callback()+ if not _no_user_can_answer():+ approval_callback = _get_approval_callback()# Gateway/cron have no UI for codex approval requests, so exec/apply_patch fail closed by default. Only an# explicit approval bypass (approvals.mode: off, /yolo, --yolo, HERMES_YOLO_MODE) hands policy to codex's sandbox.auto_approve_requests = Falsediff --git a/tests/agent/test_codex_runtime_prompt_handoff.py b/tests/agent/test_codex_runtime_prompt_handoff.pyindex 33aa4d53294..473de4fd737 100644--- a/tests/agent/test_codex_runtime_prompt_handoff.py+++ b/tests/agent/test_codex_runtime_prompt_handoff.py@@ -119,3 +119,23 @@ def test_runtime_retires_thread_when_an_in_place_switch_changes_the_codex_providstarts = [p.get("modelProvider") for (m, p) in client.requests if m == "thread/start"]assert starts == [None, "my-gateway"]assert client.closed == 1+++def test_runtime_gives_no_approval_callback_when_nobody_can_answer(monkeypatch):+ """`hermes chat -q` registers the CLI panel callback but nobody answers it: the codex session gets no+ callback, so exec/apply_patch requests fail closed at once instead of waiting the approval timeout."""+ from tools.terminal_tool import set_approval_callback++ monkeypatch.setattr(sess_mod, "CodexAppServerClient", lambda **kw: _FakeClient())+ panel = lambda *args, **kwargs: "once" # noqa: E731+ set_approval_callback(panel)+ try:+ interactive = _agent()+ codex_runtime._ensure_codex_session(interactive)+ monkeypatch.setenv("HERMES_SINGLE_QUERY_SESSION", "1")+ single_query = _agent()+ codex_runtime._ensure_codex_session(single_query)+ finally:+ set_approval_callback(None)+ assert interactive._codex_session._approval_callback is panel+ assert single_query._codex_session._approval_callback is None