fix(frontend): preserve path prefix in WebSocket URL for proxy deployments#12284
Merged
amanape merged 12 commits intoOpenHands:mainfrom Jan 9, 2026
Merged
Conversation
amanape
suggested changes
Jan 7, 2026
Contributor
amanape
left a comment
There was a problem hiding this comment.
Thanks for taking the time to open a PR! These changes make sense, thanks for adding test coverage too. I just have a few requests before merging:
|
+1 |
…ments
When deploying OpenHands behind a reverse proxy that routes
`/runtime/{port}/...` requests to agent-server containers, the V1
WebSocket connection fails because `buildWebSocketUrl()` only extracts
the host from `conversationUrl`, losing the required path prefix.
This fix:
- Adds `extractPathPrefix()` helper to extract the path before
`/api/conversations` from the conversation URL
- Updates `buildWebSocketUrl()` to include the path prefix
- Updates `buildHttpBaseUrl()` to include the path prefix for consistency
Example:
- conversationUrl: `https://example.com/runtime/55313/api/conversations/abc`
- Before: `wss://example.com/sockets/events/abc` (WRONG)
- After: `wss://example.com/runtime/55313/sockets/events/abc` (CORRECT)
This matches the behavior of the V0 socket.io provider in
`ws-client-provider.tsx` which correctly handles path prefixes.
Fixes OpenHands#12283
Tests cover:
- extractBaseHost: host extraction from various URL formats
- extractPathPrefix: path prefix extraction before /api/conversations
- buildHttpBaseUrl: HTTP base URL construction with path prefix
- buildWebSocketUrl: WebSocket URL construction with path prefix
All tests include scenarios for:
- Standard URLs without path prefix
- Proxy deployment URLs with path prefix (e.g., /runtime/{port}/)
- Fallback behavior for invalid/missing URLs
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
…l test The OpenHands project uses `#/*` as the path alias (configured in tsconfig.json), not `@/*`. This fix updates the import statement to use the correct alias.
800529f to
5337e9e
Compare
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
When deploying OpenHands behind a reverse proxy that routes
/runtime/{port}/...requests to agent-server containers, the V1 WebSocket connection fails becausebuildWebSocketUrl()only extracts the host fromconversationUrl, losing the required path prefix.Example:
conversationUrl:https://example.com/runtime/55313/api/conversations/abc123wss://example.com/sockets/events/abc123❌ (request goes to main app, not agent-server)wss://example.com/runtime/55313/sockets/events/abc123✅ (correctly routed to agent-server)Changes
Added
extractPathPrefix()helper function - Extracts the path before/api/conversationsfrom the conversation URL (e.g.,/runtime/55313)Updated
buildWebSocketUrl()- Now includes the path prefix when building WebSocket URLsUpdated
buildHttpBaseUrl()- Also includes path prefix for consistency with other API callsAdded comprehensive unit tests - Tests cover all scenarios including:
Context
This fix aligns V1 WebSocket behavior with the existing V0 socket.io provider in
ws-client-provider.tsx, which correctly handles path prefixes:Test Plan
Related Issues
Fixes #12283
Related to #12271 (App View never worked - same root cause for port accessibility)