[PR #10358] feat: use incremental port assignment instead of random ports #13414

Open
opened 2026-02-16 18:18:16 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10358

State: open
Merged: No


Summary

When the default port 4096 is occupied, the server now tries incremental ports (4097, 4098, etc.) instead of falling back to a random OS-assigned port.

Changes

  • Modified server port selection logic in packages/opencode/src/server/server.ts
  • Server now tries up to 10 incremental ports before falling back to OS-assigned port
  • Works for both default port (4096) and custom ports via --port flag

Verification

Tested with multiple server instances:

Default port behavior:

  • Server 1: Port 4096 ✓
  • Server 2: Port 4097 ✓
  • Server 3: Port 4098 ✓

Custom port behavior (--port 5000):

  • Server 1: Port 5000 ✓
  • Server 2: Port 5001 ✓
  • Server 3: Port 5002 ✓

Verified with lsof that each server listens on the expected incremental port.

Fixes #10357

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10358 **State:** open **Merged:** No --- ## Summary When the default port 4096 is occupied, the server now tries incremental ports (4097, 4098, etc.) instead of falling back to a random OS-assigned port. ## Changes - Modified server port selection logic in `packages/opencode/src/server/server.ts` - Server now tries up to 10 incremental ports before falling back to OS-assigned port - Works for both default port (4096) and custom ports via `--port` flag ## Verification Tested with multiple server instances: **Default port behavior:** - Server 1: Port 4096 ✓ - Server 2: Port 4097 ✓ - Server 3: Port 4098 ✓ **Custom port behavior (--port 5000):** - Server 1: Port 5000 ✓ - Server 2: Port 5001 ✓ - Server 3: Port 5002 ✓ Verified with `lsof` that each server listens on the expected incremental port. Fixes #10357
yindo added the pull-request label 2026-02-16 18:18:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13414