fix(middleware): negotiate loopback debugger origins - #465
Open
avocado-cb wants to merge 1 commit into
Open
Conversation
Co-authored-by: Codex <codex-noreply@coinbase.com>
avocado-cb
force-pushed
the
fix/loopback-debugger-origin
branch
from
August 26, 2026 09:07
c20a6d2 to
d3b56b8
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.
Description
Negotiate the debugger WebSocket Origin for loopback Metro sessions instead of unconditionally rewriting numeric loopback addresses to
localhost.webSocketDebuggerUrlfirst.localhostor127.0.0.1Origin.ReactNativeApplication.enableandRuntime.enableCDP commands succeed, because an Expo Origin mismatch is terminated after the WebSocket upgrade.Related Issue
Closes #463
Context
The React Native and Expo layers validate different stages of this connection:
serverBaseUrl, Expo terminates the socket and the client sees close code 1006 even though the WebSocket emittedopen.Expo's configured hostname is environment-dependent.
REACT_NATIVE_PACKAGER_HOSTNAME=localhostmakes it expectlocalhost; with that variable unset, Expo's URL creator normalizes its localhost host type to127.0.0.1. Meanwhile,/json/listbuildswebSocketDebuggerUrlfrom the discovery request's Host header. The target URL therefore does not always identify the Origin Expo will accept.That explains why a localhost-only rewrite can fix one Metro process while breaking another. The fallback must work in both directions and must cover post-upgrade termination, not only HTTP handshake rejection.
Testing
pnpm release:planpnpm checks:affectedpnpm test:affected— 173 middleware tests passed; all affected tasks passedpnpm --config.verify-deps-before-run=warn --filter @rozenite/middleware exec vitest --run src/__tests__/agent-session.test.ts— 31 tests passedWaiting on http://localhost:8082REACT_NATIVE_PACKAGER_HOSTNAME=localhost: numeric Origin upgraded and then closed with 1006; localhost remained connected.