From c8928b40dad3284012e626d6952630908a45181b Mon Sep 17 00:00:00 2001 From: nthmost-orkes Date: Thu, 24 Sep 2026 14:27:32 -0700 Subject: [PATCH] Fix 39c serverless example: bind mock server inside __main__ The mock execution server was bound to port 9753 at module level. AgentRuntime re-imports the example in its worker process, so the worker hit the same bind and failed with "Address already in use", killing the worker. Move the bind inside the __main__ guard so the worker's re-import skips it. The Agent definition stays at module level (it only holds config and binds nothing), so the worker still gets what it needs. Fixes #512 --- examples/agents/39c_serverless_code_execution.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/agents/39c_serverless_code_execution.py b/examples/agents/39c_serverless_code_execution.py index 7794276e..46c95c9e 100644 --- a/examples/agents/39c_serverless_code_execution.py +++ b/examples/agents/39c_serverless_code_execution.py @@ -64,8 +64,6 @@ def _start_mock_server(port: int = 9753) -> HTTPServer: # ── Agent setup ─────────────────────────────────────────────────────── -mock_server = _start_mock_server(port=9753) - serverless_coder = Agent( name="serverless_coder", model=settings.llm_model, @@ -84,6 +82,11 @@ def _start_mock_server(port: int = 9753) -> HTTPServer: if __name__ == "__main__": + # Bind the mock server here, not at module level: AgentRuntime re-imports + # this file in its worker process, and a second bind on port 9753 would + # fail with "Address already in use" and kill the worker. + mock_server = _start_mock_server(port=9753) + with AgentRuntime() as runtime: print("--- Serverless Code Execution ---") result = runtime.run(