From 94f77dfa0d2ca7462d57f10d0f9d74a5872ef13e Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 10 Sep 2026 10:11:06 -0700 Subject: [PATCH] fix(agent): thread turn_author through conversation_loop.run_conversation The facade forwarded turn_author= to the loop's public entry point, which did not declare it: every real AIAgent.run_conversation() turn raised TypeError (16 CI failures across provider, sidecar, cron and finite-chat suites). The PR's tests only exercised build_turn_context directly, so the missing hop was invisible. Adds one facade-through-loop test that goes red when the kwarg is dropped. --- agent/conversation_loop.py | 2 ++ tests/agent/test_turn_context.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py index 480a592b25..f27245eba4 100644 --- a/agent/conversation_loop.py +++ b/agent/conversation_loop.py @@ -1581,6 +1581,7 @@ def run_conversation( persist_user_display_metadata: Optional[Dict[str, Any]] = None, persist_user_platform_id: Optional[str] = None, moa_config: Optional[dict[str, Any]] = None, + turn_author: Optional[Dict[str, Any]] = None, ) -> Dict[str, Any]: """Run one turn (see ``_run_conversation_turn``) and export the current-turn boundary. @@ -1604,6 +1605,7 @@ def run_conversation( persist_user_display_metadata=persist_user_display_metadata, persist_user_platform_id=persist_user_platform_id, moa_config=moa_config, + turn_author=turn_author, ) return export_current_turn_boundary(agent, result, user_message) diff --git a/tests/agent/test_turn_context.py b/tests/agent/test_turn_context.py index 622d2fed20..a08d6665e2 100644 --- a/tests/agent/test_turn_context.py +++ b/tests/agent/test_turn_context.py @@ -320,6 +320,31 @@ def test_turn_without_author_clears_previous_bot_author(): assert kwargs["author_is_bot"] is False +def test_turn_author_reaches_the_agent_through_the_real_facade(monkeypatch): + """``AIAgent.run_conversation(turn_author=...)`` crosses the facade and the loop entry point, not only + ``build_turn_context``; a kwarg dropped at either hop raised TypeError on every real turn.""" + from types import SimpleNamespace + from run_agent import AIAgent + + class _Completions: + def create(self, **_kw): + return SimpleNamespace(choices=[SimpleNamespace( + message=SimpleNamespace(content="ok", tool_calls=None, reasoning=None, reasoning_content=None), + finish_reason="stop")], usage=None, model="test-model") + + monkeypatch.setattr("agent.process_bootstrap.OpenAI", + lambda **_kw: SimpleNamespace(chat=SimpleNamespace(completions=_Completions()))) + monkeypatch.setattr("model_tools.get_tool_definitions", lambda *a, **k: []) + agent = AIAgent(model="test-model", api_key="k", base_url="http://localhost:1/v1", platform="cli", + max_iterations=2, quiet_mode=True, skip_memory=True) + agent._disable_streaming = True + + agent.run_conversation("hi", turn_author={"id": "bot:alpha", "name": "Alpha", "is_bot": True}) + assert agent._turn_author == {"id": "bot:alpha", "name": "Alpha", "is_bot": True} + agent.run_conversation("hi again") + assert agent._turn_author is None + + def test_turn_start_replaces_stale_parent_history_with_compression_child(): agent = _FakeAgent() stale_history = [{"role": "user", "content": "stale parent"}]