Skip to content

The agent that grows with you

fix: WAF-block follow-ups β€” honest hint, cron action, anthropic debug dump (#24293)

teknium1cb062f7bd3d1
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index 6d0606bcc31..3df039c99dd 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -1337,11 +1337,17 @@ def dump_api_request_debug(
try:
body = {k: v for k, v in copy.deepcopy(api_kwargs).items() if v is not None and k != "timeout"}
api_key = None
+ # anthropic_messages keeps its SDK client on ``_anthropic_client`` (``client`` is None):
+ # read the key from there so the dump does not say "Bearer None" (#24293).
+ anthropic = agent.api_mode == "anthropic_messages"
try:
- api_key = getattr(agent.client, "api_key", None)
+ live = getattr(agent, "_anthropic_client", None) if anthropic else agent.client
+ api_key = getattr(live, "api_key", None) or getattr(live, "auth_token", None)
except Exception as e:
_ra().logger.debug("Could not extract API key for debug dump: %s", e)
- endpoint = "/responses" if agent.api_mode == "codex_responses" else "/chat/completions"
+ endpoint = {"codex_responses": "/responses", "anthropic_messages": "/messages"}.get(
+ agent.api_mode, "/chat/completions"
+ )
dump_payload: Dict[str, Any] = {
"timestamp": datetime.now().isoformat(), "session_id": agent.session_id, "reason": reason,
"request": {
diff --git a/agent/turn_recovery.py b/agent/turn_recovery.py
index 731e54bf4ec..7d7c955ca08 100644
--- a/agent/turn_recovery.py
+++ b/agent/turn_recovery.py
@@ -897,8 +897,8 @@ def nonretryable_client_error_result(
agent,
" πŸ’‘ The endpoint's firewall/CDN blocked the request before it reached the model β€” your key",
" and model access are probably fine. Relays often reject the SDK's default User-Agent:",
- " set `extra_headers: {User-Agent: HermesAgent/1.0}` on the custom_providers entry",
- " (or `model.default_headers`), or check the proxy/WAF rules and your network.",
+ " set `extra_headers: {User-Agent: HermesAgent/1.0}` on the custom_providers entry,",
+ " or check the proxy/WAF rules and your network.",
)
# Content-policy blocks: the provider refused this prompt, so recovery is a rephrase
# or another model, not key/retry advice.
diff --git a/cron/scheduler_failure_copy.py b/cron/scheduler_failure_copy.py
index d909b8b2b4a..eb5952b5a86 100644
--- a/cron/scheduler_failure_copy.py
+++ b/cron/scheduler_failure_copy.py
@@ -64,6 +64,11 @@ _PROVIDER_FAILURE_ACTION: dict[str, str] = {
"`hermes cron run {job_id}` to retry."
),
"model_not_found": "Pick another model with `hermes cron edit {job_id} --model <name>`.",
+ "upstream_blocked": (
+ "A firewall in front of the provider blocked the request (not your key): set a User-Agent "
+ "via `extra_headers` on the provider's custom_providers entry, or pin another provider with "
+ "`hermes cron edit {job_id} --provider <name>`."
+ ),
"context_overflow": "Shorten the job's prompt with `hermes cron edit {job_id} --prompt <text>`.",
}
_PROVIDER_FAILURE_ACTION["auth_permanent"] = _PROVIDER_FAILURE_ACTION["auth"]
diff --git a/tests/agent/test_run_agent_codex_responses.py b/tests/agent/test_run_agent_codex_responses.py
index c67b406261c..647a7b2c569 100644
--- a/tests/agent/test_run_agent_codex_responses.py
+++ b/tests/agent/test_run_agent_codex_responses.py
@@ -2226,6 +2226,26 @@ def test_dump_api_request_debug_uses_chat_completions_url(monkeypatch, tmp_path)
assert payload["request"]["url"] == "http://127.0.0.1:9208/v1/chat/completions"
+def test_dump_api_request_debug_reads_the_anthropic_client_and_messages_url(monkeypatch, tmp_path):
+ """anthropic_messages keeps its SDK client on ``_anthropic_client`` (``client`` is None):
+ the dump must show the masked key and /messages, not 'Bearer None' + /chat/completions (#24293)."""
+ import json
+ from types import SimpleNamespace
+ agent = _build_agent(monkeypatch)
+ agent.api_mode = "anthropic_messages"
+ agent.base_url = "https://relay.example.com/anthropic"
+ agent.client = None
+ agent._anthropic_client = SimpleNamespace(api_key="sk-ant-api03-abcdefghijklmnopqrstuvwxyz")
+ agent.logs_dir = tmp_path
+
+ dump_file = agent._dump_api_request_debug({"model": "claude", "messages": []}, reason="preflight")
+
+ payload = json.loads(dump_file.read_text(encoding="utf-8"))
+ assert payload["request"]["url"] == "https://relay.example.com/anthropic/messages"
+ assert "None" not in payload["request"]["headers"]["Authorization"]
+ assert "abcdefghijklmnopqrstuvwxyz" not in payload["request"]["headers"]["Authorization"]
+
+
# --- Reasoning-only response tests (fix for empty content retry loop) ---
diff --git a/tests/cron/test_cron_failure_notice_copy.py b/tests/cron/test_cron_failure_notice_copy.py
index 9d01cc96ee5..22b57fe0108 100644
--- a/tests/cron/test_cron_failure_notice_copy.py
+++ b/tests/cron/test_cron_failure_notice_copy.py
@@ -82,6 +82,16 @@ def test_cron_cause_gloss_is_the_shared_table():
assert provider_failure_notice("Morning brief", "ab12cd34", "unknown", backup_provider_phrase="x.") is None
+def test_waf_block_names_the_header_fix_not_a_bare_rerun(monkeypatch):
+ """A firewall refusing the SDK's User-Agent is healed by a header or another provider,
+ never by `hermes cron run` alone β€” the action must say so (#53099, #70566)."""
+ _no_chain(monkeypatch)
+ msg = _summarize_cron_failure_for_delivery(JOB, "Error code: 403 - Sorry, you have been blocked")
+ assert "extra_headers" in msg and "`hermes cron edit ab12cd34 --provider <name>`" in msg, msg
+ assert "Run it again with" not in msg, msg
+ assert "rejected" not in msg.lower(), msg # not read as a key rejection
+
+
def test_transient_provider_failures_never_lead_with_jargon(monkeypatch):
_no_chain(monkeypatch)
for err in ("Request timed out.", "HTTP 429: Too Many Requests"):