Repository navigation
Add marina port: stable, collision-free ports per project/worktree - #16
Merged
Merged
Conversation
Parallel agents working in parallel git worktrees all default to the same
dev port. `marina port [name]` returns a port for the current project root
(each worktree and each monorepo package is its own root), the same one on
every call and never shared with another root:
pnpm dev --port $(marina port)
PORT=$(marina port api) cargo run
- First choice is FNV-1a(root + name) within the range (default
3100-3999, configurable via `[ports] range`); assignments are stored in
`$XDG_STATE_HOME/marina/ports.json`.
- The registry is updated under an exclusive flock and saved via
temp-file rename, so concurrent callers serialize instead of racing.
- Ports busy with another project's listener are skipped; a lease taken
over by a foreign process moves (noted on stderr, `moved` in --json),
while this project's own server keeps its port.
- Leases for deleted roots are dropped on every call; `--release [name]`
returns one explicitly; `--list` shows all with listening/idle/gone state.
- The allocator (`ports::allocate`) is pure, with I/O and the busy probe
injected. `logs::state_dir()` is factored out for shared use.
The README privacy section now lists ports.json as a second user-triggered
write; the agent skill tells agents to use `--port $(marina port)` instead
of hard-coding ports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Parallel coding agents working in parallel git worktrees all default to the same dev port (usually
:3000), so the second server fails withEADDRINUSEor silently lands on a random port.marina portgives every project root its own stable port:Design
3100–3999,[ports] rangein config); the lease is recorded in$XDG_STATE_HOME/marina/ports.json, so re-runs return the same port.flockand saves via temp-file rename; probing skips ports leased to other keys and ports busy with a foreign listener (netstat + bind probe). A busy port whose listener is a dev target inside this root is the project's own server and is kept; a lease taken over by another process moves (stderr note,"status": "moved"in--json).ports::allocateis pure (I/O and busy probe injected); stdout is only the port number so$(marina port)composes.Docs
README (usage + privacy:
ports.jsonis now a second user-triggered write), DESIGN, CONTEXT glossary, and the agent skill — agents are told to use--port $(marina port)rather than hard-coding ports and to--releasewhen done with a worktree.Testing
cargo fmt --check,clippy -D warnings,cargo test: 127 tests (10 new) — stability across calls and fresh registries, uniqueness across 200 roots × 2 names, foreign takeover → move, deleted-root GC, range exhaustion, release, name validation, range config, CLI usage errors, and 8 threads allocating concurrently through the real locked store (no duplicates, no lost updates).XDG_STATE_HOME): repeat calls stable; main / feat-a / feat-b /apiall distinct; 10 concurrentmarina portprocesses → 10 unique ports; the project's own server keeps its port; a foreign server taking feat-b's port moves it (3978 → 3979); removing the feat-b worktree drops its lease;--releasefrees and then reports nothing to release (exit 1).