Skip to content

Fix/sse request alias#116

Merged
krisztianfekete merged 3 commits intoagentevals-dev:mainfrom
Navteca:fix/sse-request-alias
Apr 13, 2026
Merged

Fix/sse request alias#116
krisztianfekete merged 3 commits intoagentevals-dev:mainfrom
Navteca:fix/sse-request-alias

Conversation

@frivas-at-navteca
Copy link
Copy Markdown
Contributor

@frivas-at-navteca frivas-at-navteca commented Apr 11, 2026

I recently upgraded from 0.6.3 to 0.6.4 in my k8s cluster and realized I was seeing the "Disconnected". When checked the Developer Tools - Network I realized I was getting a 422 from the /stream/ui-updates endpoint.

As far as I understand FastAPI reads a function's type hints to figure out what each parameter is. If it sees Request, it knows and will expect an HTTP object. If it sees something it doesn't recognize, it assumes that it might be a query parameter which is what is happening with _Request, FastAPI as that alias only exist in a local function not module level so that is why FastAPI is expecting request to be a query parameter that is never sent.

What has worked for me was not using the alias and importing the correct type hint at the top so FastAPI will always find it. I have created a new image and deployed it to my cluster and it works correctly.

With 'from __future__ import annotations' active, FastAPI resolves type
annotations as strings at startup. Importing 'Request as _Request' inside
the enable_streaming block caused FastAPI to see the annotation '_Request'
as an unknown type and treat 'request' as a required query parameter,
returning 422 Unprocessable Content on every SSE connection attempt —
showing the 'Disconnected' badge in the UI.

Fix: import Request at module level without alias so FastAPI can resolve
it correctly as fastapi.Request regardless of annotation evaluation mode.
Verifies that GET /stream/ui-updates returns 200 and text/event-stream
content type. Without the fix (importing Request at module level),
FastAPI resolves the '_Request' annotation as a required query parameter
and returns 422 on every connection attempt.
Copy link
Copy Markdown
Contributor

@krisztianfekete krisztianfekete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the PR! Added two smaller comments.

Comment thread tests/test_api.py Outdated
def test_sse_endpoint_returns_200_not_422(self):
"""GET /stream/ui-updates must return 200, not 422."""
app = self._make_streaming_app()
client = TestClient(app, raise_server_exceptions=False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop raise_server_exceptions=False?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course. Thank you very much!

Comment thread src/agentevals/api/app.py Outdated
raise ValueError("enable_streaming requires a trace_manager")

from fastapi import Request as _Request
from fastapi import WebSocket
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please do the same for WebSocket as well for consistency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely. Thank you very much!

@krisztianfekete krisztianfekete merged commit 29957b1 into agentevals-dev:main Apr 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants