The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: canonical setup.runtime_check answers the legacy payload
Tekniumfc74d9249f03
diff --git a/hermes_cli/runtime_readiness.py b/hermes_cli/runtime_readiness.pyindex 715496c4521..9dfd87b8643 100644--- a/hermes_cli/runtime_readiness.py+++ b/hermes_cli/runtime_readiness.py@@ -1,39 +1,60 @@-"""Provider readiness probe shared by ``setup.runtime_check`` (TUI gateway) and the session authority."""+"""Provider readiness probe for the session authority's ``setup.runtime_check``.++Answers with the legacy ``tui_gateway/methods_config.py`` handler's payload so a client reads one+contract whichever backend it reached: ``ok``/``provider``/``model``/``source``, ``error`` on+failure (naming the configured pin, never the fallback chain's tail), ``free_tier_route`` on success.+"""def check_runtime_readiness(requested=None, *, strict_profile_scope=False, resolve=None):"""ok/error verdict for the runtime a session would be built with.- ``resolve`` is an optional ``() -> (model, runtime)`` pair supplied by the caller that owns the- session builder: without ``provider`` the TUI probe must run the SAME resolver as session creation- (startup model + provider pin, then the configured fallback chain) — a probe that ignores the chain- shows onboarding for a backend whose sessions build fine (#111775). An explicit ``requested``- provider stays a strict single-provider check so onboarding can verify the provider just connected+ Without ``requested`` the probe runs the SAME resolver as session creation (the configured+ model + provider pin, then the configured fallback chain) — a probe that ignores the chain+ shows onboarding for a backend whose sessions build fine (#111775). ``resolve`` replaces that+ resolver with the caller's own ``() -> (model, runtime)``. An explicit ``requested`` provider+ stays a strict single-provider check so onboarding can verify the provider just connectedwithout another provider's fallback masking a failed connection. Both branches report the model."""- from hermes_cli.runtime_provider import resolve_runtime_providerfrom hermes_cli.auth import has_usable_secret+ from hermes_cli.config import load_configfrom hermes_cli.main import _has_any_provider_configured+ from hermes_cli.runtime_provider import resolve_runtime_provider, resolve_runtime_with_fallback+ config = load_config()+ cfg_model = config.get('model')+ if isinstance(cfg_model, dict):+ configured_model = str(cfg_model.get('default') or cfg_model.get('model') or '') or None+ else:+ configured_model = cfg_model if isinstance(cfg_model, str) and cfg_model else Noneif resolve is not None:model, runtime = resolve()+ elif requested:+ model = configured_model+ runtime = resolve_runtime_provider(requested=requested, target_model=configured_model)else:- runtime = resolve_runtime_provider(requested=requested)- model = runtime.get('model')+ runtime, entry = resolve_runtime_with_fallback(config, target_model=configured_model)+ model = (entry or {}).get('model') or configured_model or runtime.get('model')configured = bool(_has_any_provider_configured(strict_profile_scope=strict_profile_scope))provider = runtime.get('provider') or 'provider'source = str(runtime.get('source') or '')- result = {'ok': True, 'provider': runtime.get('provider'),- 'model': model, 'source': runtime.get('source')}+ # When the chain only resolves at its tail the runtime stops there; a failure must name the+ # provider the user pinned, not a tail they never chose (#124939). Auto mode names the route.+ pinned = requested or (str(cfg_model.get('provider') or '').strip() if isinstance(cfg_model, dict) else '')+ blamed = pinned or provider++ def fail(error, src):+ return {'ok': False, 'provider': blamed, 'model': model, 'source': src, 'error': error}+if not configured and provider == 'bedrock' and source in {'iam-role', 'aws-sdk-default-chain'}:- return {**result, 'ok': False, 'error': 'No Hermes provider is configured.'}+ return fail('No Hermes provider is configured.', source)api_key = runtime.get('api_key')api_key_text = '' if callable(api_key) else str(api_key or '').strip()if not (callable(api_key) or api_key_text in {'aws-sdk', 'no-key-required'}or has_usable_secret(api_key_text) or bool(runtime.get('command'))):- return {**result, 'ok': False, 'error': f'No usable credentials found for {provider}.'}+ return fail(f'No usable credentials found for {blamed}.', runtime.get('source'))from hermes_cli.anon_auth import route_is_welcome_host- # free_tier is keyed on the SELECTED route (the welcome host serves only nous/welcome), not+ # free_tier_route is keyed on the SELECTED route (the welcome host serves only nous/welcome), not# on profile state: a paid Nous key beside a free-tier identity must not read as free.- result['free_tier'] = provider == 'nous' and route_is_welcome_host(runtime.get('base_url'))- return result+ return {'ok': True, 'provider': runtime.get('provider'), 'model': model, 'source': runtime.get('source'),+ 'free_tier_route': provider == 'nous' and route_is_welcome_host(runtime.get('base_url'))}diff --git a/tests/hermes_cli/test_main_merge_lifecycle.py b/tests/hermes_cli/test_main_merge_lifecycle.pyindex 1227a2fc3ae..d4fa88189dc 100644--- a/tests/hermes_cli/test_main_merge_lifecycle.py+++ b/tests/hermes_cli/test_main_merge_lifecycle.py@@ -16,7 +16,22 @@ def test_readiness_reports_selected_free_route(monkeypatch, provider, host, expemonkeypatch.setattr('hermes_cli.main._has_any_provider_configured', lambda **kw: True)monkeypatch.setattr('hermes_cli.runtime_provider.resolve_runtime_provider', lambda **kw: {'provider': provider, 'base_url': host, 'api_key': 'no-key-required', 'model': 'nous/welcome'})- assert check_runtime_readiness()['free_tier'] is expected+ # Same field the legacy setup.runtime_check answers and Desktop reads.+ assert check_runtime_readiness()['free_tier_route'] is expected+++def test_canonical_readiness_blames_the_pin_not_the_chain_tail(monkeypatch):+ """#124939 on the authority path: a chain that resolves only at its tail must not send+ onboarding after a provider the user never pinned."""+ from hermes_cli.runtime_readiness import check_runtime_readiness+ monkeypatch.setattr('hermes_cli.main._has_any_provider_configured', lambda **kw: True)+ monkeypatch.setattr('hermes_cli.config.load_config',+ lambda: {'model': {'provider': 'zai', 'default': 'glm-5.3'}})+ monkeypatch.setattr('hermes_cli.runtime_provider.resolve_runtime_provider', lambda **kw: {+ 'provider': 'openrouter', 'api_key': '', 'source': 'pool'})+ result = check_runtime_readiness()+ assert result == {'ok': False, 'provider': 'zai', 'model': 'glm-5.3', 'source': 'pool',+ 'error': 'No usable credentials found for zai.'}def test_local_launch_bootstraps_before_provider_guard(monkeypatch):