Skip to content

The agent that grows with you

fix: the late launch-key refusal and a reopened chat keep the /new remedy

Tekniuma6d3d40bd5b0
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.py
index 5457f2adfdc..255d7534d67 100644
--- a/gateway/run_turn_runner.py
+++ b/gateway/run_turn_runner.py
@@ -141,6 +141,11 @@ def _resolution_failure_reply(exc: Exception, platform: Platform) -> tuple[str,
from hermes_cli.auth import AuthError, is_rate_limited_auth_error
from hermes_state_runtime import RuntimeStoreError
auth_permanent = FailoverReason.auth_permanent.value
+ if isinstance(exc, RuntimeStoreError) and exc.reason == 'launch_credentials_unavailable':
+ # The session's launch key is gone (a restart revoked a CLI --api-key, a route key changed):
+ # the shared refusal copy names /new, never a resend.
+ from agent.turn_failure_copy import launch_credentials_copy
+ return launch_credentials_copy(exc), 'launch_credentials_unavailable', False
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
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index f5f301ece33..434fc3a65be 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -1065,15 +1065,21 @@ def workspace_unavailable_result(policy) -> dict:
def refused_turn_result(policy, exc) -> dict | None:
"""A failed, never-run turn for an owner refusal at scope entry that an unchanged resend repeats
(gone working folder, changed launch key); None for any other refusal."""
+ from agent.error_surface import build_error_surface_from_result
+ from agent.turn_failure_copy import launch_credentials_copy, stamp_failure
if exc.reason == 'workspace_unavailable':
- return workspace_unavailable_result(policy)
- if exc.reason != 'launch_credentials_unavailable':
+ result = workspace_unavailable_result(policy)
+ elif exc.reason == 'launch_credentials_unavailable':
+ text = launch_credentials_copy(exc)
+ result = stamp_failure({"final_response": text, "messages": [], "api_calls": 0, "tools": [],
+ "failed": True, "completed": False, "error": text},
+ "launch_credentials_unavailable", False)
+ else:
return None
- from agent.turn_failure_copy import launch_credentials_copy, stamp_failure
- text = launch_credentials_copy(exc)
- return stamp_failure({"final_response": text, "messages": [], "api_calls": 0, "tools": [],
- "failed": True, "completed": False, "error": text},
- "launch_credentials_unavailable", False)
+ # The descriptor makes settlement commit the explanation and its card as the transcript's
+ # failed-turn boundary (gateway_refusal_boundary), so a reopened chat still shows the way out.
+ result["error_surface"] = build_error_surface_from_result(result)
+ return result
@contextmanager
diff --git a/gateway/session_settlement_recovery.py b/gateway/session_settlement_recovery.py
index dc12fb99c3a..f5f125c8999 100644
--- a/gateway/session_settlement_recovery.py
+++ b/gateway/session_settlement_recovery.py
@@ -146,7 +146,7 @@ def owner_stop_notice(captured, outcome, row=None):
def gateway_refusal_boundary(captured, outcome):
"""``(notice, display_metadata)`` for a failed turn the gateway itself refused with a renderable
- descriptor (``session_cron.execute``: the only producer of ``result.error_surface``), else None."""
+ descriptor (``result.error_surface``: ``session_cron.execute``, ``session_policy.refused_turn_result``), else None."""
value = (captured or {}).get('result') or {}
surface, error = value.get('error_surface'), value.get('error')
if outcome != 'failed' or not isinstance(surface, dict) or not isinstance(error, str) or not error:
diff --git a/tests/gateway/test_launch_credentials_refusal_copy.py b/tests/gateway/test_launch_credentials_refusal_copy.py
index aa7497578b4..046f4fcc057 100644
--- a/tests/gateway/test_launch_credentials_refusal_copy.py
+++ b/tests/gateway/test_launch_credentials_refusal_copy.py
@@ -36,6 +36,7 @@ def test_turn_on_a_chat_whose_route_key_changed_names_new_chat_not_retry(tmp_pat
assert 'route-token' not in text and 'rotated-token' not in text
assert captured['result'] == result # what the classic CLI viewer reads off the receipt
surface = build_error_surface_from_result(result)
+ assert result['error_surface'] == surface # committed as the transcript's refusal card on settlement
assert (surface['layer'], surface['code'], surface['retryable']) == ('gateway', 'launch_credentials_unavailable', False)