fix(api_server): add CORS headers to /v1/runs/{run_id}/events SSE endpoint - #6367
Open
kawanoii wants to merge 3 commits into
Open
fix(api_server): add CORS headers to /v1/runs/{run_id}/events SSE endpoint#6367kawanoii wants to merge 3 commits into
kawanoii wants to merge 3 commits into
Conversation
…point The _handle_run_events method was missing CORS headers on its StreamResponse, causing cross-origin requests to fail with: "No 'Access-Control-Allow-Origin' header is present on the requested resource" Root cause: StreamResponse flushes headers immediately on prepare(), so the CORS middleware cannot inject headers after that point. Fix: Pre-resolve the Origin header and compute CORS headers before constructing the StreamResponse, matching the pattern used in _write_sse_chat_completion. Fixes NousResearch#6358 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… endpoint - test_run_events_cors_headers_present_for_allowed_origin - test_run_events_cors_headers_absent_without_origin - test_run_events_returns_404_for_unknown_run - test_run_events_streams_sse_event Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kawanoii
force-pushed
the
fix/run-events-cors
branch
from
April 11, 2026 12:40
13cbdc3 to
57188ce
Compare
Collaborator
Contributor
|
Thanks for the focused CORS regression fix. Current main still exhibits the reported ordering problem: The handler has moved to Automated hermes-sweeper review. |
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.
Summary
Fixes CORS headers on the
GET /v1/runs/{run_id}/eventsSSE endpoint.Root cause:
StreamResponseflushes headers immediately onawait response.prepare(request), so the CORS middleware cannot injectAccess-Control-Allow-Originheaders afterward.Fix: Pre-resolve the
Originheader and compute CORS headers before constructing theStreamResponse, matching the pattern already used in_write_sse_chat_completion. Fixes issue #6358.Changes
gateway/platforms/api_server.py: In_handle_run_events, extractOriginheader, call_cors_headers_for_origin()upfront, merge CORS headers into SSE response headers beforeprepare().tests/gateway/test_api_server.py: 4 new tests inTestRunEventsCORS.Tests
Unit tests:
tests/gateway/test_api_server.py::TestRunEventsCORStest_run_events_cors_headers_present_for_allowed_origin PASSED
test_run_events_cors_headers_absent_without_origin PASSED
test_run_events_returns_404_for_unknown_run PASSED
test_run_events_streams_sse_event PASSED
4 passed ✅
Live server test (API_SERVER_CORS_ORIGINS=):
Access-Control-Allow-Origin: <frontend-origin>✅Notes
API_SERVER_CORS_ORIGINSmust match the browser'sOriginheader exactly (no trailing slash).message.delta,reasoning.available,run.completed.Closes #6358
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com