Skip to content

run.sh: auto-pick a free backend port for multi-instance dev#76

Open
logan-nc wants to merge 1 commit into
developfrom
feature/auto-port
Open

run.sh: auto-pick a free backend port for multi-instance dev#76
logan-nc wants to merge 1 commit into
developfrom
feature/auto-port

Conversation

@logan-nc

@logan-nc logan-nc commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

Running the GUI from several checkouts at once collided. The backend was hardcoded to :8000, so the second ./run.sh hit [Errno 48] address already in use, shut its backend down, and its GUI silently proxied to the first checkout's backend — showing stale data (e.g. a new device not appearing) with no obvious error.

Fix (fully automatic — no manual port picking)

  • run.sh (live path) now picks the first free port ≥ 8000 and wires VITE_API_BASE to it. Vite already auto-picks a free GUI port, so each repo's GUI talks to its own backend.
  • service/app.py:main() honors HOST/PORT env vars (default 127.0.0.1:8000). Override explicitly with PORT=NNNN ./run.sh.

Result: ./run.sh in repo A grabs 8000, repo B grabs 8001, etc. — no collisions, nothing to configure.

Verified

  • Port picker returns 8000 when free, skips to 8001 when 8000 is held.
  • Two magnetics-service instances run simultaneously (PORT=8000 and PORT=8001), both serving /api/devices independently.
  • Default (unset PORT) still binds :8000 — single-instance behavior unchanged.

Lane

Touches shared GUI tooling (run.sh) + the service entry point — flagging Interfacers for review. Kept separate from the HBT-EP device PR (#72).

🤖 Generated with Claude Code

Running the GUI from several checkouts collided: the backend was hardcoded
to :8000, so the second `./run.sh` failed to bind and its GUI silently
proxied to the first checkout's backend (stale data, no obvious error).

Now the live path picks the first free port >= 8000 (Vite already auto-picks
the GUI port) and wires VITE_API_BASE to it, so multiple repos just work.
`main()` honors HOST/PORT env vars (default 127.0.0.1:8000); override with
`PORT=NNNN ./run.sh`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@logan-nc logan-nc requested a review from matt-pharr July 1, 2026 20:55
@logan-nc logan-nc added the enhancement New feature or request label Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants