The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: Bot Chat tool refresh re-pins the frozen session policy's toolsets
Tekniumd6b44a83c4ec
diff --git a/agent/conversation_loop.py b/agent/conversation_loop.pyindex d88600832e5..d491dcdba94 100644--- a/agent/conversation_loop.py+++ b/agent/conversation_loop.py@@ -728,11 +728,19 @@ def _refresh_bot_chat_tools(agent) -> None:gateway keeps agents alive across turns; every other surface builds a fresh agent whosetools[] already reflects config. No prefix preservation: a disabled toolset must drop,and the prompt rebuild this rides on already breaks the cache."""+ from gateway.session_policy import active_policy+ policy = active_policy()platform = getattr(agent, "platform", None)- if platform not in ("desktop", "tui"):+ if policy is None and platform not in ("desktop", "tui"):returntry:from tools.mcp_tool_agent import refresh_agent_mcp_tools+ if policy is not None:+ # Gateway-owned session (managed worker / owner turn): toolsets are frozen in its+ # launch policy, so live config edits never widen or narrow a running session.+ refresh_agent_mcp_tools(agent, enabled_override=list(policy.toolsets),+ quiet_mode=True, content_aware=True)+ returnfrom tui_gateway.server import _load_disabled_toolsets, _load_enabled_toolsetsrefresh_agent_mcp_tools(agent, enabled_override=_load_enabled_toolsets(platform),diff --git a/gateway/session_policy.py b/gateway/session_policy.pyindex 5aa15e8e8fc..46dec3aea9d 100644--- a/gateway/session_policy.py+++ b/gateway/session_policy.py@@ -1,5 +1,6 @@"""Frozen, explicit local-client launch policy for the existing TurnRunner."""from contextlib import contextmanager+from contextvars import ContextVarfrom dataclasses import dataclassimport jsonfrom pathlib import Path@@ -10,6 +11,7 @@ CREATE_FIELDS = frozenset({'request_id', 'source', 'cwd', 'model', 'toolsets','provider', 'base_url', 'reasoning', 'max_turns', 'ignore_rules', 'api_key', 'editor','yolo', 'safe_mode', 'ignore_user_config'})BYPASS_FIELDS = ('safe_mode', 'ignore_user_config')+_ACTIVE_POLICY: ContextVar = ContextVar('local_session_policy', default=None)SURFACES = {'cli': 'cli', 'tui': 'tui', 'gui': 'desktop', 'acp': 'acp'}@@ -303,11 +305,19 @@ def policy_scope(policy, *, authority=None):terminal[path[1]] = valuecwd_token = set_session_cwd(policy.cwd)terminal_token = set_terminal_scope(terminal)+ policy_token = _ACTIVE_POLICY.set(policy)from gateway.session_local_editor import editor_scopetry:from gateway.session_local_mcp import editor_mcp_scopewith editor_scope(policy), editor_mcp_scope(authority, policy):yieldfinally:+ _ACTIVE_POLICY.reset(policy_token)reset_terminal_scope(terminal_token)cwd_token.var.reset(cwd_token)+++def active_policy():+ """The frozen launch policy of the turn executing in this context, or ``None`` (standalone+ serve / messaging turns). Consumers read it instead of re-deriving from live config."""+ return _ACTIVE_POLICY.get()diff --git a/tests/agent/test_bot_chat_toolset_refresh.py b/tests/agent/test_bot_chat_toolset_refresh.pyindex e899386f45b..1e92cff4949 100644--- a/tests/agent/test_bot_chat_toolset_refresh.py+++ b/tests/agent/test_bot_chat_toolset_refresh.py@@ -74,3 +74,19 @@ def test_stale_epoch_leaves_a_per_process_surface_alone():builder.assert_not_called()refresh.assert_not_called()+++def test_frozen_session_policy_wins_over_live_surface_config():+ """A gateway-owned session runs under its frozen launch policy: the refresh re-pins the+ policy's toolsets and never consults the live-config surface builder."""+ from gateway.session_policy import _ACTIVE_POLICY+ agent, _db = _stale_bot_chat_agent("desktop")+ token = _ACTIVE_POLICY.set(MagicMock(toolsets=("file", "web")))+ try:+ builder, refresh = _run_stale_refresh(agent)+ finally:+ _ACTIVE_POLICY.reset(token)++ builder.assert_not_called()+ assert refresh.call_args.kwargs["enabled_override"] == ["file", "web"]+ assert refresh.call_args.kwargs.get("disabled_override") is None