The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): honour the TUI's /verbose on canonical sessions
teknium103e33529352b
diff --git a/gateway/run_turn_progress.py b/gateway/run_turn_progress.pyindex df31f31634f..a4ef6682ae2 100644--- a/gateway/run_turn_progress.py+++ b/gateway/run_turn_progress.py@@ -787,9 +787,15 @@ class GatewayTurnProgressMixin:def combined_tool_complete_callback(self, call_id, tool_name, args, result):from agent.display import _detect_tool_failureis_error, _ = _detect_tool_failure(tool_name, result)- self._publish_execution("tool.complete", {- **_tool_lifecycle_payload(call_id, tool_name, args), "is_error": bool(is_error),- "result": result if isinstance(result, str) else str(result)})+ payload = {**_tool_lifecycle_payload(call_id, tool_name, args), "is_error": bool(is_error),+ "result": result if isinstance(result, str) else str(result)}+ owner = self._approval_owner+ live = owner[0].sessions.get(owner[1]) if owner is not None else None+ # A session's /verbose (gateway/session_busy_controls.py) ships the Result block text.+ if live is not None and (getattr(live, "tool_progress_mode", None) or self._ctx.progress_mode) == "verbose":+ from tui_gateway.tool_progress import _tool_result_text+ payload["result_text"] = _tool_result_text(result)+ self._publish_execution("tool.complete", payload)self._publish_api_tool("tool.complete", call_id, tool_name, args, result)if self._ctx._native_slack_task_cards:self.native_tool_complete_callback(call_id, tool_name, args, result)diff --git a/gateway/session_busy_controls.py b/gateway/session_busy_controls.pyindex 4e57b480879..f649433c752 100644--- a/gateway/session_busy_controls.py+++ b/gateway/session_busy_controls.py@@ -27,6 +27,8 @@ def authorize(connection, ref, params, capability):async def busy_config(connection, ref, params, *, write=False):allowed = {'session_id', 'profile', 'key'} | ({'value'} if write else set())+ if params.get('key') == 'verbose' and not set(params) - allowed and ref.session_id:+ return verbose_config(connection, ref, params, write)if (set(params) - allowed or not ref.session_id or params.get('key') != 'busy'or (write and params.get('value') not in ('interrupt', 'steer', 'queue'))):raise RuntimeStoreError('invalid_params')@@ -48,6 +50,24 @@ async def busy_config(connection, ref, params, *, write=False):return {'key': 'busy', 'value': value, 'scope': 'session'}+_VERBOSE_CYCLE = ('off', 'new', 'all', 'verbose')+++def verbose_config(connection, ref, params, write):+ """Session-scoped /verbose: the tool-progress mode the next tool events of+ this session render with (read by TurnRunner), like busy never a settings write."""+ value = params.get('value')+ if write and value not in (*_VERBOSE_CYCLE, 'cycle'):+ raise RuntimeStoreError('invalid_params')+ authorize(connection, ref, params, 'session:control' if write else 'session:read')+ live = connection.authority.sessions[ref.session_id]+ current = getattr(live, 'tool_progress_mode', None) or 'all'+ if write:+ live.tool_progress_mode = current = (+ _VERBOSE_CYCLE[(_VERBOSE_CYCLE.index(current) + 1) % 4] if value == 'cycle' else value)+ return {'key': 'verbose', 'value': current, 'scope': 'session'}++async def correct(connection, ref, params, *, verb):if (set(params) - {'session_id', 'profile', 'text', 'execution_generation'}or not isinstance(params.get('text'), str) or not params['text'].strip()diff --git a/gateway/session_config.py b/gateway/session_config.pyindex 3471d546ce3..ae95f8ef957 100644--- a/gateway/session_config.py+++ b/gateway/session_config.py@@ -53,7 +53,7 @@ async def config_get(connection, ref, params):key = params.get('key')if not isinstance(key, str):raise RuntimeStoreError('invalid_params')- if key == 'busy':+ if key in ('busy', 'verbose'):from gateway.session_busy_controls import busy_configreturn await busy_config(connection, ref, params)policy = _authorize(connection, ref, params)diff --git a/tests/acp_adapter/test_gateway_tool_projection.py b/tests/acp_adapter/test_gateway_tool_projection.pyindex 0cca23fef33..8828b64411c 100644--- a/tests/acp_adapter/test_gateway_tool_projection.py+++ b/tests/acp_adapter/test_gateway_tool_projection.py@@ -53,6 +53,8 @@ def test_gateway_publishes_tool_arguments_and_result_for_live_viewers():published = []class Authority:+ sessions = {} # no live session: the viewer stream carries no verbose result_text+def publish_execution(self, session_id, generation, event_type, payload):published.append((event_type, payload))return Truediff --git a/tests/gateway/test_session_busy_controls.py b/tests/gateway/test_session_busy_controls.pyindex dd50d59dd65..0503c396c87 100644--- a/tests/gateway/test_session_busy_controls.py+++ b/tests/gateway/test_session_busy_controls.py@@ -129,6 +129,12 @@ def test_busy_policy_is_authorized_session_scoped_and_not_inference(tmp_path):'key': 'busy', 'value': 'queue', 'scope': 'session'}, resultassert (await rpc(ws, 'config.get', session_id=ids[0], key='busy'))['result']['value'] == 'queue'assert (await rpc(ws, 'config.get', session_id=ids[1], key='busy'))['result']['value'] == 'steer'+ # /verbose is the same kind of session-scoped display negotiation.+ result = await rpc(ws, 'config.set', session_id=ids[0], key='verbose', value='cycle')+ assert result.get('result') == {'key': 'verbose', 'value': 'verbose', 'scope': 'session'}, result+ assert (await rpc(ws, 'config.get', session_id=ids[1], key='verbose'))['result']['value'] == 'all'+ assert (await rpc(ws, 'config.set', session_id=ids[0], key='verbose', value='loud')+ )['error']['message'] == 'invalid_params'assert (home / 'config.yaml').read_bytes() == config_beforeassert not admissions(home) and not peer.requestsasyncio.run(probe())