The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-relay): classify a target-scope spawn refusal as its own reason
nicolajbjerregaard1996-pixelbc0520a04a06
diff --git a/tests/tools/test_bot_failure_reasons.py b/tests/tools/test_bot_failure_reasons.pyindex a36c1349379..2d626ee1406 100644--- a/tests/tools/test_bot_failure_reasons.py+++ b/tests/tools/test_bot_failure_reasons.py@@ -19,6 +19,18 @@ FIXTURE_NO_PROVIDER = ("a provider, or run `hermes setup` for first-time configuration.")FIXTURE_NO_TOKEN = "agent init failed: No access token found for Nous Portal login."+# The two spellings of a target-scope spawn refusal, captured verbatim from the relay ledger after a+# relayed DM into a PEER's default profile (the raising process is the TARGET's, not the sender's).+FIXTURE_TARGET_SCOPE = (+ "Hermes could not read this profile's API key (an internal profile-scoping bug on the "+ "multiplexed gateway, not your configuration). Run `hermes gateway restart`; if it keeps "+ "happening, report it with `hermes debug share`."+)+FIXTURE_TARGET_SCOPE_DETAILED = (+ "served_profile_child_env(inherit_credentials=True) called with no target home and no profile "+ "secret scope bound while multiplexing is on; the child would inherit the launch profile's "+ "credentials. Bind the profile scope (or pass target_home) at the spawn site."+)@@ -43,6 +55,8 @@ FIXTURE_NO_TOKEN = "agent init failed: No access token found for Nous Portal log("model_not_found", fr.MODEL_UNAVAILABLE),("status: 401 unauthorized", fr.PROVIDER_AUTH_OR_ACCESS),("upstream server error", fr.PROVIDER_SERVER_ERROR),+ (FIXTURE_TARGET_SCOPE, fr.TARGET_SCOPE_UNRESOLVED),+ (FIXTURE_TARGET_SCOPE_DETAILED, fr.TARGET_SCOPE_UNRESOLVED),# bare numbers WITHOUT a status-code context must not classify —# they feed AUTO_RETRYABLE and a misfire could auto-retry a# permanent local failure (review finding on #93101).@@ -78,6 +92,20 @@ def test_fixture_no_access_token_is_missing_config():assert fr.classify_agent_error(FIXTURE_NO_TOKEN) == fr.MISSING_CONFIG+def test_target_scope_refusal_wins_over_the_api_key_wording_and_never_auto_retries():+ """The copy says "API key" and names a gateway restart, but nothing was ever sent to a provider:+ the delivery turn was never created because a spawn site could not resolve the target profile's+ secret scope. Reading it as auth would put it on the wrong ladder and send the reader to a+ restart on the wrong machine; it must classify as its own class and never auto-retry."""+ assert "api key" in FIXTURE_TARGET_SCOPE.lower() # the word that must not win+ for text in (FIXTURE_TARGET_SCOPE, FIXTURE_TARGET_SCOPE_DETAILED):+ code = fr.classify_agent_error(text)+ assert code == fr.TARGET_SCOPE_UNRESOLVED+ assert code in fr.ALL_REASONS+ assert not fr.is_auto_retryable(code)+ assert fr.retry_action(code) == fr.RETRY_NONE++def test_auto_retryable_set_and_predicate():for code in fr.AUTO_RETRYABLE:assert fr.is_auto_retryable(code)diff --git a/tools/bot_failure_reasons.py b/tools/bot_failure_reasons.pyindex 5e30b368291..c9c0b030f71 100644--- a/tools/bot_failure_reasons.py+++ b/tools/bot_failure_reasons.py@@ -28,12 +28,17 @@ PROVIDER_SERVER_ERROR = "provider_server_error"CONTEXT_OVERFLOW = "context_overflow"MISSING_CONFIG = "missing_config"MODEL_UNAVAILABLE = "model_unavailable"+# A relay delivery (or a local Bot Chat spawn) could not resolve the target PROFILE's secret scope,+# so the delivery turn was never created. Distinct from a provider failure: nothing was ever sent to+# a model, and the remedy is at the spawn site, not on the sender's gateway.+TARGET_SCOPE_UNRESOLVED = "target_scope_unresolved"UNKNOWN = "unknown"ALL_REASONS = frozenset({RUNTIME_OFFLINE, QUEUED_EXPIRED, DELIVERY_TIMEOUT, AGENT_BLOCKED, CANCELLED,PROVIDER_AUTH_OR_ACCESS, PROVIDER_QUOTA_LIMIT, PROVIDER_RATE_LIMIT,- PROVIDER_SERVER_ERROR, CONTEXT_OVERFLOW, MISSING_CONFIG, MODEL_UNAVAILABLE, UNKNOWN,+ PROVIDER_SERVER_ERROR, CONTEXT_OVERFLOW, MISSING_CONFIG, MODEL_UNAVAILABLE,+ TARGET_SCOPE_UNRESOLVED, UNKNOWN,})#: Reasons a supervisor may retry automatically without human intervention.@@ -70,6 +75,12 @@ _STATUS = r"(?:error code:?\s*|status(?:\s*code)?:?\s*|http\s*)"_RULES: tuple[tuple[re.Pattern[str], str], ...] = tuple((re.compile(pat, re.IGNORECASE), code)for pat, code in (+ # FIRST: the message text itself mentions an "API key" and a restart, so it must be claimed+ # before the auth/status rules can read it as a provider verdict. Two spellings reach here —+ # the generic ``UnscopedSecretError`` copy (secret name empty, so the lede is a stand-in) and+ # ``served_profile_child_env``'s detailed one.+ (r"could not read this profile's api key|served_profile_child_env\(inherit_credentials=true\)",+ TARGET_SCOPE_UNRESOLVED),(rf"authentication_error|invalid api key|{_STATUS}(?:401|403)\b", PROVIDER_AUTH_OR_ACCESS),(rf"{_STATUS}402\b|out of funds|quota|balance", PROVIDER_QUOTA_LIMIT),(rf"{_STATUS}429\b|rate.?limit", PROVIDER_RATE_LIMIT),