The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep the session-policy reason code in the pre-turn resolution reply
teknium1b8c6959614a5
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.pyindex 0233b700908..7f52d137cc6 100644--- a/gateway/run_turn_runner.py+++ b/gateway/run_turn_runner.py@@ -932,13 +932,19 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):# Model/credential resolution failed before the turn began; the raw text (URLs, status# codes) belongs in the log, and the chat gets the commands that fix it.logger.warning("Model resolution failed for session %s: %s", ctx.session_key or "", exc)- return {- "final_response": (- "⚠️ I couldn't connect to the AI model service, so this message wasn't processed. "- "Use /login to sign in again, or /model to pick a different model. If it keeps "- "failing, run `hermes doctor` on the host."),- "messages": [], "api_calls": 0, "tools": [],- }+ from hermes_state_runtime import RuntimeStoreError+ if isinstance(exc, RuntimeStoreError):+ # Session-policy refusals carry a stable reason code (e.g. a CLI launch key+ # revoked by daemon restart): keep it in the reply so clients can act on it, and+ # do not suggest /login — the profile's own credentials were never in play.+ text = (f"⚠️ This session's launch credentials are no longer available "+ f"({exc.reason}), so this message wasn't processed. Start a new "+ "session from the CLI to bind them again.")+ else:+ text = ("⚠️ I couldn't connect to the AI model service, so this message wasn't processed. "+ "Use /login to sign in again, or /model to pick a different model. If it keeps "+ "failing, run `hermes doctor` on the host.")+ return {"final_response": text, "messages": [], "api_calls": 0, "tools": []}pr = runner._provider_routingreasoning_config = (policy.reasoning_config if policy elserunner._resolve_session_reasoning_config(source=ctx.source, session_key=ctx.session_key, model=model))diff --git a/tests/gateway/fixtures/cli_launch_policy_probe.py b/tests/gateway/fixtures/cli_launch_policy_probe.pyindex 6271c48b8dd..fb19791e8d7 100644--- a/tests/gateway/fixtures/cli_launch_policy_probe.py+++ b/tests/gateway/fixtures/cli_launch_policy_probe.py@@ -32,7 +32,7 @@ class Model(BaseHTTPRequestHandler):self.server.barrier.wait(timeout=30)message = {'role': 'assistant', 'content': 'LAUNCH_POLICY_OK'}budget = any('BUDGET' in str(m.get('content', '')) for m in body['messages'] if m['role'] == 'user')- if budget and body.get('tools'):+ if budget and body.get('tools') and not _is_summary_round(body):message = {'role': 'assistant', 'content': None, 'tool_calls': [{'index': 0, 'id': 'budget-' + str(len(body['messages'])), 'type': 'function','function': {'name': 'terminal', 'arguments': json.dumps({'command': 'printf budget'})}}]}@@ -51,6 +51,13 @@ class Model(BaseHTTPRequestHandler):self.wfile.write(payload)+def _is_summary_round(body):+ """The iteration-limit summary request keeps ``tools`` for prompt-cache lineage (main's+ ``_chat_summary_attempt``); it is not a tool-calling round the max_turns budget paid for."""+ last = body['messages'][-1]+ return last['role'] == 'user' and 'maximum number of tool-calling iterations' in str(last.get('content', ''))++def probe(tmp_path):root = Path(__file__).resolve().parents[3]home, user = tmp_path / 'state', tmp_path / 'user'@@ -149,7 +156,9 @@ def probe(tmp_path):start = len(peer.requests)cli(side, sessions[side], budget=True)rounds = peer.requests[start:]- assert sum(bool(x['body'].get('tools')) for x in rounds) == expected, rounds+ budgeted = [x for x in rounds if x['body'].get('tools') and not _is_summary_round(x['body'])]+ assert len(budgeted) == expected, rounds+ assert all(x['body'].get('tools') for x in rounds), roundscount = len(peer.requests)with daemon(root, home, env, barrier=False) as (proc, desc):pids.append(proc.pid)