From 4470d1f971c151729ea73fd4b9396acf72628546 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Sun, 5 Jul 2026 17:25:08 -0700 Subject: [PATCH] [eric] agents: drop spurious @staticmethod on invoke_agent (every InvokeAgent call 500'd) --- backend/apps/agents/manager/AgentLaunch.py | 3 +-- backend/tests/test_invoke_agent.py | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 backend/tests/test_invoke_agent.py diff --git a/backend/apps/agents/manager/AgentLaunch.py b/backend/apps/agents/manager/AgentLaunch.py index c8d2a54a..83c5057d 100644 --- a/backend/apps/agents/manager/AgentLaunch.py +++ b/backend/apps/agents/manager/AgentLaunch.py @@ -1,4 +1,4 @@ -"""Agent run entry points for AgentManager: launch a new top-level run and the staticmethod +"""Agent run entry points for AgentManager: launch a new top-level run and the invoke_agent helper (fork-and-send a sub-agent). The no-SDK mock fallback lives in MockAgent. Split into a mixin to keep the manager file under the size ceiling; self.run_agent_loop / self.sessions resolve across the MRO exactly as before.""" @@ -137,7 +137,6 @@ class AgentLaunch(AgentManagerProtocol): return session - @staticmethod @typechecked async def invoke_agent( self, diff --git a/backend/tests/test_invoke_agent.py b/backend/tests/test_invoke_agent.py new file mode 100644 index 00000000..ea4c88a0 --- /dev/null +++ b/backend/tests/test_invoke_agent.py @@ -0,0 +1,31 @@ +"""InvokeAgent (agent-to-agent) binding invariant. + +The bug: invoke_agent carried a spurious @staticmethod on a def whose first +parameter is self, so the instance never bound and EVERY call raised +TypeError("missing 1 required positional argument: 'self'"), which +/api/invoke-agent/run surfaced as a 500 to the calling agent. + +The seal: call it exactly the way the route does (instance, all-keyword args) +and pin that it reaches the method body: an unknown session must raise the +body's ValueError, never a binding TypeError. +""" + +import asyncio + +import pytest + +import backend.apps.agents.manager.AgentLaunch as agent_launch_module +from backend.apps.agents.agent_manager import agent_manager + + +def test_invoke_agent_binds_as_instance_method(monkeypatch) -> None: + monkeypatch.setattr(agent_launch_module, "load_session_data", lambda sid: None) + + async def run() -> None: + with pytest.raises(ValueError, match="not found"): + await agent_manager.invoke_agent( + source_session_id="no-such-session", + message="what did you do?", + ) + + asyncio.run(run())