Skip to content

Fix enrolled host daemon port collisions - #1155

Merged
ymichael merged 4 commits into
mainfrom
bb/investigate-enrolled-host-daemon-collision-thr_m8wabcwfpi
Aug 7, 2026
Merged

Fix enrolled host daemon port collisions#1155
ymichael merged 4 commits into
mainfrom
bb/investigate-enrolled-host-daemon-collision-thr_m8wabcwfpi

Conversation

@ymichael

@ymichael ymichael commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • allocate and persist a distinct local API port for each enrolled host daemon, and pass it through foreground joins plus generated launchd/systemd services
  • validate readiness through /status, requiring the expected hostId, normalized serverUrl, and an active server connection
  • turn remaining EADDRINUSE and service startup failures into actionable bb-authored diagnostics
  • document the installer override and port-selection behavior

Testing

  • sh -n apps/server/src/assets/install-machine.sh
  • pnpm exec turbo run typecheck --filter=@bb/host-daemon --filter=bb-app --filter=@bb/server
  • pnpm exec turbo run test --filter=@bb/host-daemon --force -- --run src/local-api.test.ts
  • pnpm exec turbo run test --filter=bb-app --force -- --run test/index.test.ts
  • pnpm exec turbo run test --filter=@bb/server --force -- --run test/app/install-machine-script.test.ts test/app/skeleton.test.ts

Fixes #1121

@ymichael
ymichael marked this pull request as ready for review August 7, 2026 20:53
@SawyerHood

Copy link
Copy Markdown
Collaborator

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, duplication, and end-to-end behavior.

I will post one final review after the parallel checks finish.

Comment thread apps/server/src/assets/install-machine.sh Outdated
Comment thread apps/server/src/assets/install-machine.sh Outdated
Comment thread apps/server/src/assets/install-machine.sh Outdated
Comment thread apps/server/test/app/install-machine-script.test.ts Outdated

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

ELI5

Each daemon needs a different port.

This change chooses one, but some Linux and multi-install cases can still choose or use the wrong port.

Findings

I found four issues:

  1. High: An active Linux service does not restart after its unit changes.
  2. Medium: Custom BB_DATA_DIR daemons do not reserve their ports globally.
  3. Medium: Concurrent installers can select the same port.
  4. Medium: The tests require fixed ports that real enrolled daemons can already use.

I left an inline comment for each issue. I would fix these issues before merge.

Security and performance

I found no new critical security boundary.

The allocation race can still cause EADDRINUSE. A failed connection loop can also take about 105 seconds.

Architecture

The shell script now repeats port validation, allocation, URL normalization, and status parsing.

A typed bb-app allocation command could own this policy. A global registry and lock could make reservations complete and atomic.

The daemon protocol version does not need a change because this pull request does not change the server-daemon wire contract.

Validation

Three GPT-5.6-Sol agents reviewed security, quality, performance, architecture, and end-to-end behavior. A final GPT-5.6-Sol gate confirmed the four findings.

  • All affected Turbo type checks passed.
  • The host-daemon tests passed.
  • The bb-app launcher tests passed.
  • The server suite passed 1,344 tests and failed two installer tests.
  • One failure confirmed the fixed-port defect.
  • The other failure exposed incomplete PATH isolation in the npm fallback fixture.
  • The live launcher check accepted the correct enrolled daemon in 21 milliseconds.
  • The live launcher check rejected a wrong host identity in 207 milliseconds.
  • No browser test applied because this change has no browser route.

I used a comment-only review. I did not approve or request changes through GitHub.

@ymichael
ymichael force-pushed the bb/investigate-enrolled-host-daemon-collision-thr_m8wabcwfpi branch from 2014362 to 83d2be7 Compare August 7, 2026 22:47
@ymichael
ymichael merged commit 59f8466 into main Aug 7, 2026
17 of 18 checks passed
@ymichael
ymichael deleted the bb/investigate-enrolled-host-daemon-collision-thr_m8wabcwfpi branch August 7, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enrolled host-daemon has no collision handling for the default port (38887) when the desktop app is already running on the same machine

2 participants