The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
chore: merge origin/main (resolve tests/agent/test_output_cap_parsing.py, tests/hermes_cli/test_runtime_provider_resolution.py)
teknium17aff381943d6
diff --cc agent/model_metadata.pyindex eeeca1812d6,34e6e8309a7..e937d558c97--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@@ -1345,9 -1385,9 +1388,10 @@@ _PARSEABLE_OUTPUT_CAP_SIGNALS =("max_tokens", "available_tokens"), ("max_tokens", "available tokens"),("in the output", "maximum context length"),("maximum context length", "requested", "output tokens"),+ ("maximum context length", "in the completion"), ("maximum context length", "for the completion"),("range of max_tokens should be",), ("exceeds model", "maximum output tokens"),("output limit",), ("max_tokens", "maximum allowed number of output tokens"),+ ("limited to",),)diff --cc tests/agent/test_output_cap_parsing.pyindex f21fac74151,3d10c23b3e2..efe786cc7cd--- a/tests/agent/test_output_cap_parsing.py+++ b/tests/agent/test_output_cap_parsing.py@@@ -210,9 -210,24 +210,32 @@@ class TestParseVllmTokenBasedOutputCap+def test_limited_to_phrasing_is_an_output_cap():+ """#67453: Scaleway rejects an oversized budget with "max_completion_tokens is limited to N for+ <model>" — an output cap (step the budget down), not a context overflow (do not compress)."""+ assert is_output_cap_error("max_completion_tokens is limited to 16384 for glm-5.2")+ assert parse_available_output_tokens_from_error("max_completion_tokens is limited to 16384 for glm-5.2") == 16384+ assert not is_output_cap_error("prompt is too long: max_tokens limited to 100 given the input")+++++ class TestParseOpenAiCompletionSplit:+ """OpenAI's original overflow wording, copied by vLLM / llama-cpp-python, splits the request+ as "(A in the messages, B in the completion)" and never names max_tokens (#90607)."""++ @pytest.mark.parametrize("msg, budget", [+ ("This model's maximum context length is 102400 tokens. However, you requested 102401 tokens "+ "(36865 in the messages, 65536 in the completion). Please reduce the length of the messages or completion.",+ 102400 - 36865),+ ("This model's maximum context length is 4097 tokens, however you requested 4771 tokens "+ "(771 in your prompt; 4000 for the completion). Please reduce your prompt; or completion length.",+ 4097 - 771),+ ])+ def test_split_is_output_cap_with_window_minus_measured_prompt(self, msg, budget):+ assert parse_available_output_tokens_from_error(msg) == budget+ assert is_output_cap_error(msg)++ def test_split_with_prompt_filling_window_stays_on_compression(self):+ msg = ("This model's maximum context length is 4097 tokens. However, you requested 6000 tokens "+ "(5000 in the messages, 1000 in the completion). Please reduce the length of the messages or completion.")+ assert parse_available_output_tokens_from_error(msg) is None+ assert not is_output_cap_error(msg)diff --cc tests/hermes_cli/test_runtime_provider_resolution.pyindex 3d2815d2ace,cc5bd78e38f..d34cd41a7e8--- a/tests/hermes_cli/test_runtime_provider_resolution.py+++ b/tests/hermes_cli/test_runtime_provider_resolution.py@@@ -1973,44 -2022,46 +2022,89 @@@ def test_removed_keyless_free_provider_assert "opencode-zen" in message and "opencode-go" in message+def test_bare_custom_resolves_model_key_env_for_configured_base_url(monkeypatch):+ """#67453: ``model.provider: custom`` + ``model.base_url`` + ``model.key_env`` (the setup wizard's+ bare-custom shape) must send the named variable's value, not the ``no-key-required`` placeholder.+ A CUSTOM_BASE_URL pointing elsewhere is a different endpoint: the declared key stays home."""+ monkeypatch.setattr(rp, "resolve_provider", lambda *a, **k: "custom")+ monkeypatch.setattr(rp, "load_config", lambda: {"custom_providers": []})+ monkeypatch.setattr(rp, "_get_model_config", lambda: {+ "provider": "custom", "base_url": "https://api.example.test/v1", "key_env": "MY_LLM_API_KEY",+ "default": "glm-5.2", "api_mode": "chat_completions"})+ for var in ("CUSTOM_BASE_URL", "OPENROUTER_BASE_URL", "OPENAI_API_KEY", "OPENROUTER_API_KEY"):+ monkeypatch.delenv(var, raising=False)+ monkeypatch.setenv("MY_LLM_API_KEY", "scw-real-key-0123456789abcdef")++ resolved = rp.resolve_runtime_provider(requested="custom")+ assert (resolved["base_url"], resolved["api_key"]) == ("https://api.example.test/v1", "scw-real-key-0123456789abcdef")++ monkeypatch.setenv("CUSTOM_BASE_URL", "https://other.example.test/v1")+ assert rp.resolve_runtime_provider(requested="custom")["api_key"] == "no-key-required"++ # Direct-alias rung (`hermes --resume` provider change, `/model` direct aliases pass explicit_base_url):+ # the declared key follows the configured endpoint and stays home for any other endpoint.+ monkeypatch.delenv("CUSTOM_BASE_URL", raising=False)+ direct = rp.resolve_runtime_provider(requested="custom", explicit_base_url="https://api.example.test/v1")+ assert (direct["source"], direct["api_key"]) == ("direct-alias", "scw-real-key-0123456789abcdef")+ other = rp.resolve_runtime_provider(requested="custom", explicit_base_url="https://other.example.test/v1")+ assert other["api_key"] == "no-key-required"+++def test_configured_key_env_resolving_empty_is_logged(monkeypatch, caplog):+ """#67453: a declared ``key_env`` whose variable is unset used to be laundered silently into+ ``no-key-required`` and surface only as the provider's 403; a keyless block stays silent."""+ monkeypatch.setattr(rp, "resolve_provider", lambda *a, **k: "custom")+ monkeypatch.setattr(rp, "load_config", lambda: {"custom_providers": [+ {"name": "scw", "base_url": "https://api.example.test/v1", "key_env": "UNSET_LLM_KEY", "model": "m"},+ {"name": "local", "base_url": "http://127.0.0.1:8080/v1", "model": "m"}]})+ monkeypatch.delenv("UNSET_LLM_KEY", raising=False)+ with caplog.at_level("WARNING", logger="hermes_cli.runtime_provider"):+ assert rp.resolve_runtime_provider(requested="custom:scw")["api_key"] == "no-key-required"+ assert rp.resolve_runtime_provider(requested="custom:local")["api_key"] == "no-key-required"+ hits = [r for r in caplog.records if "UNSET_LLM_KEY" in r.getMessage()]+ assert len(hits) == 1 and "scw" in hits[0].getMessage()+++++ # ── model.openai_runtime: codex_app_server on every ladder rung (#115169) ─────────────────++ _CODEX_STORE_CREDS = {"base_url": "https://chatgpt.com/backend-api/codex", "api_key": "tok",+ "source": "hermes-auth-store", "last_refresh": 1}+++ def _codex_rung(monkeypatch, rung: str) -> dict:+ """Isolate one openai-codex ladder rung; returns the kwargs for resolve_runtime_provider."""+ monkeypatch.setattr(rp, "resolve_codex_runtime_credentials", lambda: dict(_CODEX_STORE_CREDS))+ if rung == "pool":+ entry = SimpleNamespace(api_key="tok", runtime_api_key="tok", base_url="", source="pool")+ monkeypatch.setattr(rp, "load_pool", lambda _p: SimpleNamespace(+ has_credentials=lambda: True, select=lambda model=None: entry))+ monkeypatch.setattr(rp, "credential_pool_matches_provider", lambda *a, **k: True)+ return {}+ monkeypatch.setattr(rp, "load_pool", lambda _p: SimpleNamespace(has_credentials=lambda: False))+ return {"explicit_api_key": "sk-explicit"} if rung == "explicit" else {}+++ @pytest.mark.parametrize("rung", ["pool", "oauth", "explicit"])+ def test_openai_runtime_codex_app_server_applies_on_every_rung(monkeypatch, rung):+ """#115169: the opt-in was applied only inside the credential-pool rung, so the OAuth-store+ and explicit --api-key/--base-url rungs silently resolved codex_responses."""+ kwargs = _codex_rung(monkeypatch, rung)+ monkeypatch.setattr(rp, "_get_model_config", lambda: {+ "provider": "openai-codex", "default": "gpt-5.5", "openai_runtime": "codex_app_server"})++ resolved = rp.resolve_runtime_provider(requested="openai-codex", **kwargs)++ assert resolved["provider"] == "openai-codex"+ assert resolved["api_mode"] == "codex_app_server"+++ @pytest.mark.parametrize("rung", ["pool", "oauth", "explicit"])+ @pytest.mark.parametrize("openai_runtime", [None, "auto"])+ def test_openai_runtime_unset_keeps_wire_api_mode(monkeypatch, rung, openai_runtime):+ kwargs = _codex_rung(monkeypatch, rung)+ model_cfg = {"provider": "openai-codex", "default": "gpt-5.5"}+ if openai_runtime is not None:+ model_cfg["openai_runtime"] = openai_runtime+ monkeypatch.setattr(rp, "_get_model_config", lambda: model_cfg)++ assert rp.resolve_runtime_provider(requested="openai-codex", **kwargs)["api_mode"] == "codex_responses"