#8745: fix(gateway): respect gateway.port config and --port CLI flag
stale
Cluster:
Gateway and Session Fixes
The bug was in gateway-daemon.ts where the port resolution used an empty string as fallback instead of undefined. Since the nullish coalescing operator (??) only considers null and undefined as fallback triggers, an empty string would prevent the default port from being used correctly.
Changed:
(typeof cfg.gateway?.port === "number" ? String(cfg.gateway.port) : "")
To:
(typeof cfg.gateway?.port === "number" ? String(cfg.gateway.port) : undefined)
This ensures the port resolution chain properly falls through to the default port (18789) when the config port is not set, while still correctly using the config port when it is set.
Fixes #7626
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change fixes gateway port resolution on macOS by ensuring the config-derived `gateway.port` value participates correctly in the nullish-coalescing chain. The previous fallback produced an empty string, which prevented `?? "18789"` from applying; the update uses `undefined` instead so the default port is chosen when the config value is absent.
This logic lives in the `src/macos/gateway-daemon.ts` entrypoint that loads config, reads CLI/env overrides, validates inputs, and then launches `startGatewayServer(port, { bind })`.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Single-line change aligned with JavaScript `??` semantics; it corrects a clear bug without altering the precedence order of CLI/env/config/default inputs. No additional control flow or side effects introduced.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21459: fix(gateway): resolve port from profile config, not inherited env
by kkeeling · 2026-02-19
79.3%
#11147: fix(daemon): stop gateway by port when no daemon service is active
by jasonthewhale · 2026-02-07
79.3%
#19437: Gateway: respect custom bind host for local health/RPC target resol...
by frudas24 · 2026-02-17
77.6%
#18549: Fix: align DEFAULT_BROWSER_CONTROL_PORT with base+2 derivation logic …
by reza6ix · 2026-02-16
77.4%
#4653: fix(gateway): improve crash resilience for mDNS and network errors
by AyedAlmudarra · 2026-01-30
76.9%
#21000: fix: resolve option collision between browser and cookies set commands
by MisterGuy420 · 2026-02-19
76.8%
#23584: fix(daemon): improve gateway service detection to avoid false posit...
by mohandshamada · 2026-02-22
76.4%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
76.4%
#17835: Fix misleading gateway stop hints for standalone listeners
by ConnorCallison · 2026-02-16
76.3%
#19088: fix(gateway): allow startup with unset mode and fix pairing for local…
by mdanassaif · 2026-02-17
76.1%