Skip to content

The agent that grows with you

fix(kanban): worker exits EX_CONFIG on a terminal provider error

teknium1c20432fffa51
diff --git a/cli.py b/cli.py
index ffc124df4bc..3af89c3d034 100644
--- a/cli.py
+++ b/cli.py
@@ -4119,6 +4119,15 @@ _TRANSIENT_PROVIDER_REASONS = frozenset({
"rate_limit", "upstream_rate_limit", "billing", "overloaded", "server_error", "timeout",
})
+# ``failure_reason`` values a retry can never heal: the credential was rejected, the model does
+# not exist for this account, or the TLS chain is broken. A Kanban worker exits
+# ``KANBAN_TERMINAL_PROVIDER_EXIT_CODE`` so the dispatcher parks the card after ONE spawn with
+# the provider's words as the reason, instead of re-spawning into the same wall until
+# ``kanban.failure_limit`` is spent. ``billing`` stays transient: credit comes back.
+_TERMINAL_PROVIDER_REASONS = frozenset({
+ "auth", "auth_permanent", "model_not_found", "ssl_cert_verification",
+})
+
def _single_query_exit_code(result) -> int:
"""Map a one-shot turn result onto a process exit code, for both `-q` and `-Q`.
@@ -4129,6 +4138,8 @@ def _single_query_exit_code(result) -> int:
failed purely on a provider rate-limit / billing wall exits ``KANBAN_RATE_LIMIT_EXIT_CODE``
(EX_TEMPFAIL): the dispatcher books that run ``rate_limited`` and requeues the task
WITHOUT counting a failure, so a quota window or a provider outage cannot trip the breaker.
+ One that failed on a terminal provider error (credential revoked, model gone) exits
+ ``KANBAN_TERMINAL_PROVIDER_EXIT_CODE`` (EX_CONFIG): the dispatcher blocks the card at once.
"""
if not isinstance(result, dict):
return 1
@@ -4136,9 +4147,14 @@ def _single_query_exit_code(result) -> int:
return 130
if not (result.get("failed") or result.get("partial") or result.get("completed") is False):
return 0
- if os.environ.get("HERMES_KANBAN_TASK") and result.get("failure_reason") in _TRANSIENT_PROVIDER_REASONS:
- from hermes_cli.kanban_db import KANBAN_RATE_LIMIT_EXIT_CODE
- return KANBAN_RATE_LIMIT_EXIT_CODE
+ if os.environ.get("HERMES_KANBAN_TASK"):
+ reason = result.get("failure_reason")
+ if reason in _TRANSIENT_PROVIDER_REASONS:
+ from hermes_cli.kanban_db import KANBAN_RATE_LIMIT_EXIT_CODE
+ return KANBAN_RATE_LIMIT_EXIT_CODE
+ if reason in _TERMINAL_PROVIDER_REASONS:
+ from hermes_cli.kanban_db import KANBAN_TERMINAL_PROVIDER_EXIT_CODE
+ return KANBAN_TERMINAL_PROVIDER_EXIT_CODE
return 1
diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.py
index 38396ade79c..248bd25e2fa 100644
--- a/hermes_cli/kanban_db.py
+++ b/hermes_cli/kanban_db.py
@@ -305,6 +305,11 @@ DEFAULT_CRASH_GRACE_SECONDS = 30
# breaker must never trip on a throttle). 75 == BSD EX_TEMPFAIL.
KANBAN_RATE_LIMIT_EXIT_CODE = 75
+# Worker exit "provider rejected the configuration": credential revoked (401/403), model gone
+# (404), TLS chain broken — a retry cannot fix it, so the dispatcher parks the card blocked on
+# the FIRST occurrence instead of spending ``failure_limit`` identical spawns. 78 == BSD EX_CONFIG.
+KANBAN_TERMINAL_PROVIDER_EXIT_CODE = 78
+
def _resolve_crash_grace_seconds() -> int:
"""``HERMES_KANBAN_CRASH_GRACE_SECONDS`` (0 = immediate, for tests) else default."""
diff --git a/tests/hermes_cli/test_single_query_exit_contract.py b/tests/hermes_cli/test_single_query_exit_contract.py
index cef28eea59d..79ac9748d5f 100644
--- a/tests/hermes_cli/test_single_query_exit_contract.py
+++ b/tests/hermes_cli/test_single_query_exit_contract.py
@@ -13,7 +13,7 @@ from types import SimpleNamespace
import pytest
import cli
-from hermes_cli.kanban_db import KANBAN_RATE_LIMIT_EXIT_CODE
+from hermes_cli.kanban_db import KANBAN_RATE_LIMIT_EXIT_CODE, KANBAN_TERMINAL_PROVIDER_EXIT_CODE
@pytest.fixture(autouse=True)
@@ -53,6 +53,16 @@ def test_dispatcher_spawned_worker_signals_a_provider_outage_not_a_protocol_viol
assert code == KANBAN_RATE_LIMIT_EXIT_CODE
[email protected]("reason", ["auth", "auth_permanent", "model_not_found", "ssl_cert_verification"])
+def test_dispatcher_spawned_worker_signals_a_terminal_provider_error(monkeypatch, reason):
+ """A revoked credential / missing model cannot be retried into working: the worker says so
+ with EX_CONFIG so the dispatcher parks the card after one spawn. A person's run keeps 1."""
+ monkeypatch.setenv("HERMES_KANBAN_TASK", "t_abc123")
+ assert _run_non_quiet(monkeypatch, {"failed": True, "failure_reason": reason}) == KANBAN_TERMINAL_PROVIDER_EXIT_CODE
+ monkeypatch.delenv("HERMES_KANBAN_TASK")
+ assert _run_non_quiet(monkeypatch, {"failed": True, "failure_reason": reason}) == 1
+
+
@pytest.mark.parametrize(
("turn_result", "expected"),
[