Skip to content

SSE endpoint: run_sse does not propagate exceptions or non-2xx status codes #4244

Closed

Description

@feng-95

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug

When calling the /run_sse endpoint, exceptions raised inside event_generator (for example from runner.run_async) are caught and converted into a synthetic Event with content "Error: {e}", and the server continues to return HTTP 200 for the SSE stream instead of surfacing a non-2xx status or propagating the original exception/stacktrace to the client. This makes it hard for clients to distinguish between successful and failed runs and to debug issues based on server responses.

To Reproduce

  1. Start the ADK web server with an app/agent that will raise an exception during runner.run_async (for example, a tool or agent implementation that raises a ValueError).
  2. Use the /run_sse endpoint with streaming=True for that app/user/session.
  3. Observe that the SSE stream includes an event whose content is "Error: ...", but the HTTP status code of the response remains 200 and no original exception type or stacktrace is propagated to the client (only logged on the server side)

Expected behavior

I would expect failures during runner.run_async in the /run_sse endpoint to be surfaced more explicitly to clients, for example by:

Returning a non-2xx HTTP status code (e.g. 500) and closing the SSE stream when an unhandled exception occurs, and/or
Emitting a structured error event that includes more detailed error information (error type, message, optional stacktrace) in a consistent schema, rather than swallowing the exception and only sending a generic "Error: {e}" message.
This would make it easier for clients consuming the SSE stream to correctly handle failures and for developers to debug issues.

Additional context

Relevant code in src/google/adk/cli/adk_web_server.py:

    @app.post("/run_sse")
    async def run_agent_sse(req: RunAgentRequest) -> StreamingResponse:
        ...
        async def event_generator():
            try:
                ...
                async with Aclosing(
                    runner.run_async(...)
                ) as agen:
                    async for event in agen:
                        ...
                        yield f"data: {sse_event}\n\n"
            except Exception as e:
                logger.exception("Error in event_generator: %s", e)
                error_event = Event(
                    author="system",
                    content=types.Content(
                        role="model", parts=[types.Part(text=f"Error: {e}")]
                    ),
                )
                yield (
                    "data:"
                    f" {error_event.model_dump_json(by_alias=True, exclude_none=True)}\n\n"
                )

In this code path the original exception is logged but not propagated to the client, and the HTTP response status for the SSE stream remains 200 even when an internal error occurs.

Activity

  1. added
    web[Component] This issue will be transferred to adk-web
    on Jan 23, 2026
  2. added theissue type on Jan 23, 2026
  3. svelezdevilla commented on Jan 23, 2026

    @svelezdevilla

    The Event object (being a child from LlmResponse) has two components that I think could be used here: error_code and error_message precisely for this, no? Instead of wrapping everything into the Content object.

  4. ViktorVeselov commented on Jan 26, 2026

    @ViktorVeselov

    Hold on for a second. There is another issue that is potentially related to LlmResponse. I pointed out that the current LlmResponse design is flawed, and potentially it needs re-design from Google Staff/Distinguished Eng. or a collective consensus on this problem/approach. We need to find a long-term solution, or we will end up patching those issues non-stop.

    Currently, LlmResponse supports multiple versions of multiple outputs, and it does cause some issues. Something related was mentioned there: https://github.com/google/adk-python/issues/4260. It is a different problem, but it looks like the root cause is still the same.

  5. llalitkumarrr commented on Feb 20, 2026

    @llalitkumarrr
    Collaborator

    Hello @feng-95 ,

    This can be a little confusing but if we go through the logs carefully, we can see the error message details, even the UI also shows a pop-up communicating the error.

    I believe reading the logs should provide the user with enough information about the error. Or do we expect the stream to disconnect in case of any agent error?

  6. adk-bot commented on Feb 28, 2026

    @adk-bot
    Collaborator

    This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.

  7. added
    stale[Status] Issues which have been marked inactive since there is no user response
    request clarification[Status] The maintainer need clarification or more information from the author
    on Feb 28, 2026
  8. adk-bot commented on Mar 7, 2026

    @adk-bot
    Collaborator

    This has been automatically closed because it has been marked as stale for over 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

request clarification[Status] The maintainer need clarification or more information from the authorstale[Status] Issues which have been marked inactive since there is no user responseweb[Component] This issue will be transferred to adk-web

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions