Skip to content

The agent that grows with you

feat(delegation): surface config-level model_not_found notice in delegation batch reports

David Metcalfec05d04fffb69
diff --git a/tests/tools/test_process_registry.py b/tests/tools/test_process_registry.py
index 5fbde444dcf..8725a7f507b 100644
--- a/tests/tools/test_process_registry.py
+++ b/tests/tools/test_process_registry.py
@@ -2413,3 +2413,155 @@ class TestGetByPrefix:
result = registry.poll("4dae56ca")
assert result["session_id"] == "proc_4dae56ca81f6"
assert result["status"] == "running"
+
+
+# ---------------------------------------------------------------------------
+# Config-level model_not_found notice in delegation batch reports (#97654)
+# ---------------------------------------------------------------------------
+
+
+def _make_delegation_batch_evt(results):
+ """A batch async-delegation event carrying a per-task ``results`` list."""
+ return {
+ "type": "async_delegation",
+ "delegation_id": "deleg_97654",
+ "is_batch": True,
+ "results": results,
+ "goals": [r.get("goal") or "" for r in results],
+ "session_key": "agent:main:cli:dm:local",
+ "status": "completed",
+ "model": "upstage/solar-pro-4",
+ }
+
+
+def _patch_delegation_config(
+ monkeypatch, model="upstage/solar-pro-4", provider="openrouter", **over
+):
+ import tools.process_registry as _pr
+
+ cfg = {"model": model, "provider": provider}
+ cfg.update(over)
+ monkeypatch.setattr(_pr, "_delegation_config", lambda: cfg)
+ return cfg
+
+
+def _format_async(evt) -> str:
+ from tools.process_registry import format_process_notification
+
+ text = format_process_notification(evt)
+ assert text is not None, "format_process_notification returned None"
+ return text
+
+
+def test_model_not_found_notice_single_failure_once(monkeypatch):
+ evt = _make_delegation_batch_evt([
+ {
+ "task_index": 0,
+ "status": "failed",
+ "exit_reason": "error",
+ "goal": "Create bridge module",
+ "error": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ "summary": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ }
+ ])
+ _patch_delegation_config(monkeypatch)
+ text = _format_async(evt)
+ assert text is not None
+ assert text.count("SUBAGENT MODEL REJECTED") == 1
+ assert "upstage/solar-pro-4" in text
+ assert "openrouter" in text
+ assert "No fallback chain is configured" in text
+
+
+def test_model_not_found_notice_mixed_batch_named_model(monkeypatch):
+ evt = _make_delegation_batch_evt([
+ {
+ "task_index": 0,
+ "status": "failed",
+ "exit_reason": "error",
+ "goal": "A",
+ "error": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ "summary": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ },
+ {
+ "task_index": 1,
+ "status": "completed",
+ "goal": "B",
+ "summary": "ok",
+ "api_calls": 3,
+ },
+ ])
+ _patch_delegation_config(monkeypatch)
+ text = _format_async(evt)
+ assert text.count("SUBAGENT MODEL REJECTED") == 1
+ assert "upstage/solar-pro-4" in text
+
+
+def test_model_not_found_notice_absent_for_non_model_errors(monkeypatch):
+ evt = _make_delegation_batch_evt([
+ {
+ "task_index": 0,
+ "status": "failed",
+ "goal": "A",
+ "error": "HTTP 429: rate limit exceeded",
+ },
+ {
+ "task_index": 1,
+ "status": "failed",
+ "goal": "B",
+ "error": "Connection timed out",
+ },
+ ])
+ _patch_delegation_config(monkeypatch)
+ text = _format_async(evt)
+ assert "SUBAGENT MODEL REJECTED" not in text
+
+
+def test_model_not_found_notice_absent_when_configured_model_not_named(monkeypatch):
+ evt = _make_delegation_batch_evt([
+ {
+ "task_index": 0,
+ "status": "failed",
+ "goal": "A",
+ "error": "HTTP 400: gpt-99 is not a valid model ID",
+ }
+ ])
+ # Configured model is upstage/solar-pro-4; the rejection names gpt-99.
+ _patch_delegation_config(monkeypatch)
+ text = _format_async(evt)
+ assert "SUBAGENT MODEL REJECTED" not in text
+
+
+def test_model_not_found_notice_single_dispatch(monkeypatch):
+ evt = {
+ "type": "async_delegation",
+ "delegation_id": "deleg_single",
+ "session_key": "agent:main:cli:dm:local",
+ "goal": "task A",
+ "model": "upstage/solar-pro-4",
+ "status": "failed",
+ "error": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ "summary": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ }
+ _patch_delegation_config(monkeypatch)
+ text = _format_async(evt)
+ assert text.count("SUBAGENT MODEL REJECTED") == 1
+ assert "upstage/solar-pro-4" in text
+
+
+def test_model_not_found_notice_absent_when_fallback_chain_configured(monkeypatch):
+ evt = _make_delegation_batch_evt([
+ {
+ "task_index": 0,
+ "status": "failed",
+ "goal": "A",
+ "error": "HTTP 400: upstage/solar-pro-4 is not a valid model ID",
+ }
+ ])
+ _patch_delegation_config(
+ monkeypatch,
+ fallback_providers=[{"provider": "openrouter", "model": "upstage/solar-pro4"}],
+ )
+ text = _format_async(evt)
+ assert text.count("SUBAGENT MODEL REJECTED") == 1
+ assert "No fallback chain is configured" not in text
diff --git a/tools/process_registry.py b/tools/process_registry.py
index bca6f91a05d..5d25bf7384a 100644
--- a/tools/process_registry.py
+++ b/tools/process_registry.py
@@ -2960,6 +2960,93 @@ def _format_age(seconds: float) -> str:
return f"{h}h" if m == 0 else f"{h}h{m}m"
+# Model-not-found phrases lifted from agent/error_classifier.py so the
+# delegation batch renderer can spot a config-level rejection without pulling
+# the classifier's failover machinery. Kept in sync by hand.
+_MODEL_NOT_FOUND_PATTERNS = (
+ "is not a valid model",
+ "invalid model",
+ "model not found",
+ "model_not_found",
+ "does not exist",
+ "no such model",
+ "unknown model",
+ "unsupported model",
+)
+
+
+def _delegation_config() -> dict:
+ """Load the active delegation config (model/provider/fallbacks), fail-open.
+
+ Mirrors ``tools.delegate_tool._load_config`` so the renderer sees the same
+ ``model`` / ``provider`` the dispatcher used, without importing the heavy
+ delegation module at import time. Returns ``{}`` on any error so callers
+ fail open to "no notice" rather than dropping the per-task blocks.
+ """
+ try:
+ from tools.delegate_tool import _load_config as _cfg
+
+ return _cfg() or {}
+ except Exception:
+ return {}
+
+
+def _delegation_model_not_found(results, config) -> bool:
+ """True when a result entry reflects a config-level model_not_found rejection.
+
+ Matches when at least one entry's error/summary text contains both a
+ model-not-found phrase AND the name of the currently-configured delegation
+ model — so a stale task failing on a *different* (removed) model is not
+ mis-attributed to the config-level root cause.
+ """
+ model = (config or {}).get("model")
+ if not model:
+ return False
+ model = str(model).lower()
+ for r in results or []:
+ text = " ".join(
+ str(part) for part in (r.get("error"), r.get("summary")) if part
+ ).lower()
+ if not text or model not in text:
+ continue
+ if any(p in text for p in _MODEL_NOT_FOUND_PATTERNS):
+ return True
+ return False
+
+
+def _delegation_model_not_found_notice(results) -> "list[str] | None":
+ """Build the config-level model_not_found notice lines, or None.
+
+ Returns ``None`` unless at least one result entry shows the configured
+ delegation model being rejected by its provider, in which case a short
+ actionable block is returned. Every failure path fails open to ``None`` so
+ a config hiccup never hides the per-task blocks. Emit once per batch.
+ """
+ config = _delegation_config()
+ if not _delegation_model_not_found(results, config):
+ return None
+ model = config.get("model") or "?"
+ provider = config.get("provider") or "configured provider"
+ lines = [
+ "⚠ SUBAGENT MODEL REJECTED: the configured Subagent Model "
+ f'"{model}" was rejected by provider "{provider}" '
+ "(HTTP 400: not a valid model ID).",
+ "Every task in this batch failed for this reason before doing any work.",
+ "Check Settings → Advanced → Subagent Model (or: "
+ "hermes config get delegation.model).",
+ ]
+ try:
+ from hermes_cli.fallback_config import get_fallback_chain
+
+ if not get_fallback_chain(config):
+ lines.append(
+ "No fallback chain is configured, so no failover was attempted."
+ )
+ except Exception:
+ pass
+ return lines
+
+
def _format_async_delegation(evt: dict) -> str:
"""Format an async-delegation completion into a self-contained re-injection.
@@ -3018,6 +3105,10 @@ def _format_async_delegation(evt: dict) -> str:
lines.append("--- ERROR ---")
lines.append(f"The batch did not complete successfully: {error}")
return "\n".join(lines)
+ _notice = _delegation_model_not_found_notice(results)
+ if _notice:
+ lines.append("")
+ lines.extend(_notice)
for r in sorted(results, key=lambda x: x.get("task_index", 0)):
idx = r.get("task_index", 0)
r_status = r.get("status", "?")
@@ -3085,6 +3176,10 @@ def _format_async_delegation(evt: dict) -> str:
if toolsets:
lines.append(f"Toolsets: {', '.join(toolsets)}")
lines.append(f"Role: {role} Model: {model}")
+ _notice = _delegation_model_not_found_notice([evt])
+ if _notice:
+ lines.append("")
+ lines.extend(_notice)
_trunc = " [TRUNCATED: hit max_iterations — work may be incomplete]" if truncated else ""
lines.append(f"Status: {status} API calls: {api_calls} Duration: {duration}s{_trunc}")
lines.append("--- RESULT ---")