Fix/sse request alias#116
Merged
krisztianfekete merged 3 commits intoagentevals-dev:mainfrom Apr 13, 2026
Merged
Conversation
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.
Contributor
krisztianfekete
left a comment
There was a problem hiding this comment.
Looks great, thanks for the PR! Added two smaller comments.
| 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) |
Contributor
There was a problem hiding this comment.
Can we drop raise_server_exceptions=False?
Contributor
Author
There was a problem hiding this comment.
Yes, of course. Thank you very much!
| raise ValueError("enable_streaming requires a trace_manager") | ||
|
|
||
| from fastapi import Request as _Request | ||
| from fastapi import WebSocket |
Contributor
There was a problem hiding this comment.
Can you please do the same for WebSocket as well for consistency?
Contributor
Author
There was a problem hiding this comment.
Yes, definitely. Thank you very much!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.