From 4c35cb03adebcf2b523911af3d459c6dd161d556 Mon Sep 17 00:00:00 2001 From: Hanush H Nair Date: Fri, 27 Feb 2026 23:19:40 +0530 Subject: [PATCH] fix(backend): Return None instead of 401 when agent not found in get_agent_auth_context_optional --- backend/app/core/agent_auth.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/app/core/agent_auth.py b/backend/app/core/agent_auth.py index a5f322dc..97d92ad6 100644 --- a/backend/app/core/agent_auth.py +++ b/backend/app/core/agent_auth.py @@ -168,11 +168,12 @@ async def get_agent_auth_context_optional( return None agent = await _find_agent_for_token(session, resolved) if agent is None: - logger.warning( - "agent auth optional invalid token path=%s token_prefix=%s", - request.url.path, - resolved[:6], - ) - raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) + if agent_token: + logger.warning( + "agent auth optional invalid token path=%s token_prefix=%s", + request.url.path, + resolved[:6], + ) + return None await _touch_agent_presence(request, session, agent) return AgentAuthContext(actor_type="agent", agent=agent)