From f2d8d78027bdc856a7da47910462233aedeab709 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Thu, 7 May 2026 13:28:23 -0700 Subject: [PATCH] fix(v2 managed agents): apply default_user fallback in events SSE stream --- litellm/proxy/managed_agents_endpoints/events.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/managed_agents_endpoints/events.py b/litellm/proxy/managed_agents_endpoints/events.py index 59af407a4b9..1028805490b 100644 --- a/litellm/proxy/managed_agents_endpoints/events.py +++ b/litellm/proxy/managed_agents_endpoints/events.py @@ -41,6 +41,12 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth router = APIRouter() +# Mirrors `agents.py` โ€” fallback owner when no user_id is attached to the +# verification token (master-key call, etc.). Without this, master-key +# callers cannot read back sessions they created (the row stores +# "default_user" but the lookup would pass None). +_DEFAULT_CREATED_BY = "default_user" + # SSE response headers per contract ยง6.6. SSE_HEADERS = { "Cache-Control": "no-cache", @@ -52,7 +58,7 @@ SSE_HEADERS = { # --------------------------------------------------------------------------- # Pre-forward helper # --------------------------------------------------------------------------- -# TODO: extract to shared helper โ€” `litellm/managed_agents/endpoints/_helpers.py` +# TODO: extract to shared helper โ€” `litellm/proxy/managed_agents_endpoints/_helpers.py` # once the messages endpoint lands. Both endpoints need the same logic. @@ -79,7 +85,7 @@ async def _load_ready_session( session_row = await get_session( prisma_client, session_id=session_id, - created_by=user_api_key_dict.user_id, + created_by=user_api_key_dict.user_id or _DEFAULT_CREATED_BY, ) if not session_row: raise HTTPException(status_code=404, detail=f"Session {session_id} not found")