The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): /status keeps the default runtime endpoint and context pin when no /model switch owns the route
teknium19660195388aa
diff --git a/gateway/run.py b/gateway/run.pyindex 7b936a91126..bf1d09f82ca 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -2317,10 +2317,12 @@ def _resolve_gateway_model_context(def _read_runtime() -> None:nonlocal provider, base_url, api_key- if route is not None:- # The winning session route only — never the default route's endpoint under its model.+ if route and route.get("base_url"):+ # A session route with its own endpoint (a /model switch) replaces the default runtime+ # read; a route without one (persisted / SessionDB / plain config) still resolves the+ # default runtime credentials so a custom endpoint and its context_length pin survive.provider = route.get("provider") or provider- base_url = route.get("base_url") or None+ base_url = route["base_url"]api_key = route.get("api_key")returnruntime = _resolve_runtime_agent_kwargs()diff --git a/gateway/slash_commands_status.py b/gateway/slash_commands_status.pyindex b88a909d160..cc94a1807ad 100644--- a/gateway/slash_commands_status.py+++ b/gateway/slash_commands_status.py@@ -89,7 +89,8 @@ def _status_model_route(Order: live/cached agent route -> active session override -> persisted recent route ->SessionDB row -> gateway config (only loaded when something is still missing). ``route`` carriesthe ``provider`` / ``base_url`` / ``api_key`` of the winning source only, so a later context-window- lookup queries the endpoint that serves the displayed model (never a losing route's endpoint).+ lookup queries the endpoint that serves the displayed model (never a losing route's endpoint);+ a winner without a ``base_url`` leaves the lookup on the default runtime route."""from gateway.run import _AGENT_PENDING_SENTINEL, _load_gateway_config, _resolve_gateway_modelcontext_used = context_total = 0diff --git a/tests/gateway/test_status_command.py b/tests/gateway/test_status_command.pyindex bf40007071a..d22916b037f 100644--- a/tests/gateway/test_status_command.py+++ b/tests/gateway/test_status_command.py@@ -314,6 +314,47 @@ async def test_status_command_keeps_occupancy_only_for_unknown_model_window():assert f"**Context:** 4,321 / {DEFAULT_FALLBACK_CONTEXT:,} (2%)" in result+async def test_status_command_default_route_keeps_runtime_endpoint_and_context_pin():+ """No /model switch and no resident agent (first /status after a restart): the winner is the+ persisted route or the SessionDB row, which carry no endpoint of their own. The window must then+ be resolved against the default runtime route (custom base_url + key, ``model.context_length``+ pin intact) exactly as /context does, not against an empty endpoint that drops the pin."""+ config = {"model": {"default": "my-local-model", "provider": "custom",+ "base_url": "http://127.0.0.1:1/v1", "context_length": 32_768}}+ runtime = {"model": "my-local-model", "provider": "custom",+ "base_url": "http://127.0.0.1:1/v1", "api_key": "local-key"}+ route = {"model": "my-local-model", "billing_provider": "custom"}+ for persisted_route, session_row in ((route, None), ({}, dict(route))):+ session_entry = SessionEntry(+ session_key=build_session_key(_make_source()),+ session_id="sess-1",+ created_at=datetime.now(),+ updated_at=datetime.now(),+ platform=Platform.TELEGRAM,+ chat_type="dm",+ )+ session_entry.last_prompt_tokens = 9_000+ runner = _make_runner(session_entry)+ runner._session_db._db.get_session.return_value = session_row+ runner._session_db._db.get_recent_session_model_route.return_value = persisted_route++ with patch("gateway.run._load_gateway_config", return_value=config), patch(+ "gateway.run._resolve_runtime_agent_kwargs", return_value=runtime+ ) as default_runtime, patch(+ "agent.model_metadata.get_model_context_length",+ side_effect=lambda _model, **kw: kw["config_context_length"] or 8_192,+ ) as lookup:+ result = await runner._handle_message(_make_event("/status"))++ assert "**Model:** `my-local-model` (custom)" in result+ assert "**Context:** 9,000 / 32,768 (27%)" in result+ default_runtime.assert_called_once()+ kwargs = lookup.call_args.kwargs+ assert (kwargs["base_url"], kwargs["api_key"], kwargs["config_context_length"]) == (+ runtime["base_url"], runtime["api_key"], 32_768)++@pytest.mark.asyncioasync def test_agents_command_reports_active_agents_and_processes(monkeypatch):session_key = build_session_key(_make_source())