Skip to content

Select desktop backend port by sequential scan#1870

Merged
juliusmarminge merged 1 commit intomainfrom
feature/desktop-backend-port-scan
Apr 10, 2026
Merged

Select desktop backend port by sequential scan#1870
juliusmarminge merged 1 commit intomainfrom
feature/desktop-backend-port-scan

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 10, 2026

So that your host is more stable across restarts when doing remote

What Changed

Why

UI Changes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Changes desktop backend port selection during startup, which can affect app launch reliability and port-collision behavior if the preferred range is busy. Logic is straightforward and covered by new unit tests, but it touches the bootstrap path.

Overview
Desktop startup now selects the backend port by sequentially probing from a stable preferred port (default 3773) instead of reserving a random ephemeral loopback port.

This introduces resolveDesktopBackendPort (with validation and bounded scan) plus Vitest coverage, and updates main.ts bootstrap/logging to use the new resolver.

Reviewed by Cursor Bugbot for commit ca8118f. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Select desktop backend port by sequential scan from port 3773

  • Replaces NetService.reserveLoopbackPort with a new resolveDesktopBackendPort function in backendPort.ts that scans ports sequentially from a start port until it finds one available via canListenOnHost.
  • When T3CODE_PORT is unset, the desktop app now selects a backend port by scanning from DEFAULT_DESKTOP_BACKEND_PORT (3773) on the loopback host.
  • Validates startPort and maxPort inputs and throws if no available port is found within the range.
  • Behavioral Change: port selection now uses the first available port starting at 3773 rather than reserving an OS-assigned loopback port.

Macroscope summarized ca8118f.

- Add port scan helper with coverage
- Keep backend startup on a stable preferred port
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 53a1d1ab-b7f7-4d38-8c24-ef8214a0da6c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/desktop-backend-port-scan

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Apr 10, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 10, 2026

Approvability

Verdict: Approved

This PR refactors desktop backend port selection from ephemeral reservation to predictable sequential scanning starting at port 3773. The change is self-contained, includes comprehensive unit tests, and the author has recent ownership of the affected code. Low risk runtime behavior change with clear intent.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit e82b987 into main Apr 10, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the feature/desktop-backend-port-scan branch April 10, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant