mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
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).
This commit is contained in:
parent
f3101be1a1
commit
b007da3dc9
1 changed files with 10 additions and 0 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue