fix(desktop): refuse same-home port fallback #9003
main fromrefs/pull/9003/head·opened View on GitHubWhat Changed#
Packaged Desktop startup now uses the default backend port (3773) or fails before spawning the embedded server. It no longer scans to 3774+ while retaining the same T3 home.
An explicitly configured T3CODE_PORT still behaves as before.
Why#
If an older/background T3 backend already owns 3773, the sequential scan currently launches another backend on 3774 against the same state.sqlite, settings, and provider state. The second backend appears healthy but creates split-brain writers; with Codex single-writer thread persistence this can surface as thread <id> already has an active writer.
Failing before primaryBackend.start closes that Desktop-specific path without requiring process killing, database repair, or a speculative attach/auth lifecycle. The error explains that automatic fallback is intentionally refused and names the safe choices.
This is the small Desktop boundary from #6097. Generic server-level ownership remains separate in #8442/#8960.
Fixes #6097.
UI Changes#
Only the existing fatal-startup error box changes: when default port 3773 is occupied, it now explains that T3 will not start a second same-home backend on a fallback port. No ordinary-startup UI changes.
Verification#
pnpm exec vp test run apps/desktop/src/app/DesktopAppErrors.test.ts— 5 passedpnpm exec vp run --filter @t3tools/desktop typecheck- targeted lint and format checks
- exact committed two-file source review — GLM
GO, no findings
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (error-only startup path; not captured)
- I included a video for animation/interaction changes (n/a)
Scope check: no attach-to-existing flow, server lock, provider lifecycle, or live-state change is included.
Model: GPT-5.6 Sol Harness: T3 Code / Codex
Note
Medium Risk
Changes desktop startup behavior when the default port is busy—users see a fatal error instead of a silent fallback that could cause split-brain SQLite writers—but scope is limited to port resolution with explicit T3CODE_PORT unchanged.
Overview
Packaged desktop startup no longer scans from 3773 upward for a free backend port. When no T3CODE_PORT is set, it only uses the default port or fails fast if that port cannot bind on the usual probe hosts.
DesktopBackendPortUnavailableError is replaced by DesktopBackendPortInUseError, with a clearer multi-line message that explains T3 Code will not start a second backend on a fallback port against the same data directory. Bootstrap logging drops the “selected via sequential scan” path and only distinguishes configured vs default port.
resolveDesktopBackendPort is exported for testing. DesktopAppErrors.test.ts adds Effect tests with a stub NetService to cover default-port success, occupied-port refusal (probes only 3773, no scan), and explicit port passthrough.
Note
Refuse same-home port fallback in resolveDesktopBackendPort#
- When no explicit port is configured,
resolveDesktopBackendPortnow probes onlyDEFAULT_DESKTOP_BACKEND_PORTacrossDESKTOP_BACKEND_PORT_PROBE_HOSTS; if any host cannot bind, it throwsDesktopBackendPortInUseErrorwith{ port, hosts }instead of scanning for an alternative port. - Replaces
DesktopBackendPortUnavailableError(which carried{ startPort, maxPort, hosts }) withDesktopBackendPortInUseError(carrying{ port, hosts }), whose message advises stopping the running server or changingT3CODE_HOME. - Removes the
MAX_TCP_PORTconstant and theselectedByScanreturn field; updatesdesktop.bootstraplogging accordingly. - Risk: callers expecting
{ port, selectedByScan }or catchingDesktopBackendPortUnavailableErrorwill break — in-tree usages in DesktopApp.ts and DesktopAppErrors.test.ts are updated, but out-of-tree consumers are not.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
Note
This comment is posted by Julius' dot
This changes the desktop's visible startup failure, but the PR explicitly says the before/after evidence was not captured. The five tests check port selection and error text without showing the resulting startup experience, so the verification requirement is not met. Please attach before/after screenshots for an occupied default port and report the observed startup outcome, then request reconsideration. The duplicate-backend failure in #6097 remains established.
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This changes packaged desktop startup behavior for the default port, replacing automatic fallback with a fatal startup error before the backend is spawned. Because the product default behavior changes and startup is gated by the port probe, the change merits human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).