From b007da3dc90f3665fcf8a14be06206f37de60534 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 6 May 2026 15:51:30 -0700 Subject: [PATCH] fix(run_endpoints): drive session busy<->ready oscillation on run create/cancel Two call sites added: * After POST /v2/sessions/{sid}/runs creates a queued run, call refresh_session_status_from_runs so the parent session moves 'ready' -> 'busy'. * After POST /v2/sessions/{sid}/runs/{rid}/cancel marks a run cancelled, call the same helper so the session moves 'busy' -> 'ready' if no other active runs exist. Greptile P1 (review #PRR_kwDOKALCgc78u9En). --- litellm/proxy/agent_session_endpoints/run_endpoints.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/litellm/proxy/agent_session_endpoints/run_endpoints.py b/litellm/proxy/agent_session_endpoints/run_endpoints.py index 78223654840..76d5ccb8bc9 100644 --- a/litellm/proxy/agent_session_endpoints/run_endpoints.py +++ b/litellm/proxy/agent_session_endpoints/run_endpoints.py @@ -36,6 +36,9 @@ from litellm.proxy.agent_session_endpoints.ownership import ( ) from litellm.proxy.agent_session_endpoints.schemas import RunCreate, RunResponse from litellm.proxy.agent_session_endpoints.serialization import run_row_to_response +from litellm.proxy.agent_session_endpoints.session_status import ( + refresh_session_status_from_runs, +) from litellm.proxy.auth.user_api_key_auth import user_api_key_auth router = APIRouter() @@ -177,6 +180,10 @@ async def create_run( raise verbose_proxy_logger.info("run.create id=%s session_id=%s", row.id, session_id) + # Run was just created in ``queued``. Drive the session + # ``ready`` -> ``busy`` flip so SDK consumers polling + # GET /v2/sessions/{id} see the right status. + await refresh_session_status_from_runs(prisma_client, session_id) return run_row_to_response(row) @@ -282,6 +289,9 @@ async def cancel_run( next_seq, exc, ) + # Run just transitioned to ``cancelled`` (terminal). If it was the + # only active run, flip the session ``busy`` -> ``ready``. + await refresh_session_status_from_runs(prisma_client, session_id) return run_row_to_response(updated)