fix(serve): prefer explicit --port over stale WS fallback (#8535)#9005
fix(serve): prefer explicit --port over stale WS fallback (#8535)#9005nwparker wants to merge 1 commit into
Conversation
When `orca serve --port <P>` is set, bind the pinned port before any persisted mobile-ws-fallback-port.json entry so clients dialing <P> are not stranded. Default auto/desktop keep STA-1511 fallback-first.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds a 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Agent handoffFixes: #8535 Reproduce (before / regression after merge)Branch with kits: Full issue kit (summary + re-run + file links): see the Agent handoff — reproduction kit comment on #8535. Writeup: https://github.com/stablyai/orca/blob/nwparker/bug-repro-handoffs/docs/bug-reproductions/8535.md This PRAlready includes Description / Evidence / ELI5 / User-regression-tradeoffs in the body. Review that section first; re-run the issue's |
Summary
Fixes #8535: when
orca serve --port <P>is set explicitly, bind<P>before any port stored inmobile-ws-fallback-port.json. Default desktop / auto port paths keep STA-1511 fallback-first binding so existing mobile pairings stay stable.Description
WebSocketTransport.start()previously always triedcandidatePorts = [persistedFallbackPort, preferredPort]. After a one-timeEADDRINUSEon the preferred port, STA-1511 persistence wrotemobile-ws-fallback-port.json, and every later launch bound that stale free fallback instead of the CLI pin — stranding clients (and health checks) that dial<P>.This change:
preferPinnedPorttoWebSocketTransport(preferred first, fallback second when set).preferPinnedWsPortfrom explicit serve CLI (--serve-port/orca serve --port) throughOrcaRuntimeRpcServer.Evidence
Focused vitest:
New coverage:
preferPinnedPortis set and both ports freepreferPinnedPortis set but preferred is takenELI5
If you say “always use door 6768”, Orca should open door 6768 when it’s free — not a sticky note from last time that said “use door 45175 instead”. Phone pairing that didn’t pin a door still trusts the sticky note first so old phones keep finding the house.
User-regression-tradeoffs
orca serve --port <P><P>get the pin when free.--portpnpm dev(6769)Tradeoff (explicit pin only): after a port conflict, mobile devices that only know the old fallback may need one re-pair / reconnect if serve later successfully binds the pin again (because we no longer prefer the fallback when free). That is intentional: an explicit pin means operators and health checks own that port. New pairing QR still advertises
resolvedPort. Default auto path does not take this tradeoff.Screenshots
No visual change.
Testing
ws-transport.test.ts,ws-fallback-port-store.test.ts(27 passed)pnpm lint(pre-commit oxlint/oxfmt on touched files)pnpm typecheckpnpm testpnpm buildAI Review Report
Reviewed for:
DEFAULT_WS_PORT(flag, not port equality).EADDRINUSEstill fatal; fallback failures still degrade.EADDRINUSE/EACCESpath is Node HTTP server (macOS/Linux/Windows); no keyboard shortcuts, path separators, or shell changes.No residual flags after plumbing + tests.
Security Audit
No new auth, secrets, IPC, or command execution. Only TCP bind candidate order changes when an operator explicitly requests a port. Fallback persistence and E2EE/device-token auth unchanged.
Notes
serveOptions.wsPort !== undefined(CLI passed--serve-port), not for default 6768 or dev 6769.mobile-ws-fallback-port.json.