Skip to content

The agent that grows with you

refactor(gateway): legacy migration drops ROUTE_BOUND_KEYS off another route

Tekniumfdfcb4880dc6
diff --git a/gateway/session_local_migration.py b/gateway/session_local_migration.py
index 9cd82e3c6c6..35832eaf383 100644
--- a/gateway/session_local_migration.py
+++ b/gateway/session_local_migration.py
@@ -147,7 +147,7 @@ def adopt_legacy_session(authority, actor, row):
config = _load_gateway_config()
model_cfg = config.get('model')
if isinstance(model_cfg, dict) and ('provider' in params or 'base_url' in params):
- from gateway.session_route_identity import resolved_route, same_route
+ from gateway.session_route_identity import ROUTE_BOUND_KEYS, resolved_route, same_route
saved = {'provider': params.get('provider', model_cfg.get('provider')), 'base_url': params.get('base_url')}
# ``auto`` matches every route, so an ``auto`` side proves nothing about the saved endpoint.
if ('auto' not in (resolved_route(model_cfg, config)[0], resolved_route(saved, config)[0])
@@ -158,9 +158,11 @@ def adopt_legacy_session(authority, actor, row):
params.pop('base_url', None)
else:
# Another route than the profile's: its endpoint, wire mode, context pin and credential
- # (inline key, key_env pointer) stay with the profile, never paired with the legacy route.
- config['model'] = {k: v for k, v in model_cfg.items() if k not in (
- 'base_url', 'api_mode', 'context_length', 'api_key', 'api', 'key_env', 'api_key_env')}
+ # (inline key, key_env pointer, api_key_from) stay with the profile, never paired with the
+ # legacy route. ``provider`` stays: the saved route's own provider is in params, or it is
+ # the profile's when the saved row carried only a base_url (resolved by _endpoint_owner).
+ dropped = tuple(k for k in ROUTE_BOUND_KEYS if k != 'provider')
+ config['model'] = {k: v for k, v in model_cfg.items() if k not in dropped}
if saved['base_url']:
params['provider'] = _endpoint_owner(saved, config)
policy = build_policy(params, config, private_secrets=private)