Skip to content

The agent that grows with you

fix(gateway): adopted v0.21 CLI session keeps its custom provider with its endpoint

Teknium8d83a202620a
diff --git a/gateway/session_local_migration.py b/gateway/session_local_migration.py
index 03d24dff525..7fc12125339 100644
--- a/gateway/session_local_migration.py
+++ b/gateway/session_local_migration.py
@@ -80,6 +80,9 @@ def legacy_launch_params(row):
billing_base_url = row.get('billing_base_url')
if 'base_url' not in route and isinstance(billing_base_url, str) and billing_base_url.strip():
route['base_url'] = billing_base_url.strip()
+ # The reader drops a bare ``custom``/``auto`` billing provider: that endpoint is a custom
+ # route, never one to pair with the profile's provider.
+ route.setdefault('provider', 'custom')
if row['source'] == 'acp' and 'cwd' not in params and Path(str(saved.get('cwd') or '')).is_absolute():
params['cwd'] = saved['cwd']
params.update({key: route[key] for key in ('provider', 'base_url') if key in route})
diff --git a/tests/gateway/test_legacy_session_route_turn.py b/tests/gateway/test_legacy_session_route_turn.py
index 448e5af5738..62db8ca143b 100644
--- a/tests/gateway/test_legacy_session_route_turn.py
+++ b/tests/gateway/test_legacy_session_route_turn.py
@@ -93,6 +93,31 @@ def test_adopted_legacy_session_turn_goes_to_its_route_with_its_own_key(monkeypa
assert {r['auth'] for r in legacy.requests} == {'Bearer sk-legacy-own'}
+def test_adopted_cli_custom_session_keeps_custom_route_when_profile_moved_to_another_provider(monkeypatch):
+ """A v0.21 CLI row's route is ``billing_provider='custom'`` + ``billing_base_url``. With the profile now
+ on Anthropic, adoption must not pair ``anthropic`` (its wire mode and key) with the legacy endpoint."""
+ from run_agent import AIAgent
+ with FakeLLMServer([Text('legacy ok')]) as legacy:
+ home = Path(os.environ['HERMES_HOME'])
+ monkeypatch.setattr('gateway.run._hermes_home', home)
+ monkeypatch.setenv('ANTHROPIC_API_KEY', 'sk-ant-profile-only')
+ home.mkdir(parents=True, exist_ok=True)
+ (home / 'config.yaml').write_text(
+ 'model:\n default: claude-profile\n provider: anthropic\n'
+ 'agent:\n api_max_retries: 1\nplatform_toolsets:\n tui: []\n'
+ f'custom_providers:\n - name: legacy-box\n base_url: {legacy.base_url}\n api_key: sk-legacy-own\n')
+ policy, (model, runtime) = _adopt_and_resolve(home, {}, source='cli', billing={
+ 'billing_provider': 'custom', 'billing_base_url': legacy.base_url})
+ agent = AIAgent(model=model, **{k: runtime[k] for k in ('api_key', 'base_url', 'provider', 'api_mode')},
+ reasoning_config=policy.reasoning_config, quiet_mode=True, skip_context_files=True,
+ skip_memory=True, enabled_toolsets=['memory'])
+ agent.run_conversation('hello again')
+
+ assert [r['model'] for r in legacy.main_requests()] == ['legacy-model']
+ assert legacy.requests and all('sk-ant-profile-only' not in str(r['headers']) for r in legacy.requests)
+ assert {r['auth'] for r in legacy.requests} == {'Bearer sk-legacy-own'}
+
+
def test_adopted_legacy_session_whose_provider_lost_credentials_is_refused_by_name(monkeypatch):
with FakeLLMServer([Text('profile')]) as profile:
home = Path(os.environ['HERMES_HOME'])