Overview
When running multiple agents in parallel, each needs its own development server on a unique port. Uzi automatically finds and assigns available ports from the configuredportRange.
Port Range Configuration
Define the port range inuzi.yaml:
uzi.yaml
The port range is inclusive on both ends.
3000-3010 includes both 3000 and 3010.Port Allocation Strategy
Uzi uses a sequential allocation strategy to find available ports:- Parse the port range from
portRangeconfiguration (cmd/prompt/prompt.go:258) - For each agent, call
findAvailablePort()(cmd/prompt/prompt.go:271) - Iterate through the range from start to end port (cmd/prompt/prompt.go:90)
- Skip already assigned ports in the current execution (cmd/prompt/prompt.go:92-100)
- Check if port is available using
isPortAvailable()(cmd/prompt/prompt.go:104) - Return first available port or error if none found (cmd/prompt/prompt.go:105-108)
Port Availability Check
Uzi determines if a port is available by attempting to bind a TCP listener:- Another Uzi agent is using it
- Another application is using it
- It’s a privileged port (< 1024) and you lack permissions
Example: Creating 3 Agents
portRange: 3000-3010 configured:
- Agent 1: Uzi checks 3000 → available → assigns port 3000
- Agent 2: Uzi checks 3000 → already assigned → checks 3001 → available → assigns port 3001
- Agent 3: Uzi checks 3000 → assigned → 3001 → assigned → 3002 → available → assigns port 3002
Ports are assigned sequentially as agents are created. The assignment persists for the lifetime of each agent session.
What Happens When Ports Run Out
If you request more agents than available ports, Uzi handles it gracefully:uzi.yaml
- Agents 1-3: Successfully created with ports 3000, 3001, 3002
- Agent 4: Logs error
"Error finding available port"and skips dev server - Agent 5: Logs error and skips dev server
Tracked vs. External Port Usage
Uzi tracks two types of port conflicts:1. Internal Tracking (Current Execution)
Ports assigned to agents in the currentuzi prompt command are tracked in memory:
2. System-Level Availability Check
Uzi also checks if ports are actually available on the system usingisPortAvailable() (cmd/prompt/prompt.go:78).
This catches:
- Ports used by other Uzi sessions started separately
- Ports used by other applications
- Ports in TIME_WAIT state from recently closed connections
Choosing a Port Range
Recommended Ranges by Framework
Sizing Your Port Range
Calculate how many ports you need:- Running up to 5 agents:
portRange: 3000-3004(5 ports) - Running up to 10 agents:
portRange: 3000-3009(10 ports) - Heavy parallel usage:
portRange: 3000-3050(51 ports)
Err on the side of a larger range. There’s no downside to defining more ports than you need.
Avoiding Conflicts
Avoid port ranges that conflict with common services:- 3306: MySQL
- 5432: PostgreSQL
- 6379: Redis
- 8080: Common HTTP alternate
- 9200: Elasticsearch
Invalid Port Range Handling
Uzi validates the port range format and logs warnings for invalid configurations:Invalid Format
"Invalid port range format in config" warning (cmd/prompt/prompt.go:260)
Invalid Values
"Invalid port range in config" warning (cmd/prompt/prompt.go:267)
Missing Port Range
IfportRange is not configured:
"Port range not set in config, skipping dev server startup." (cmd/prompt/prompt.go:126)
Port Visibility in Agent Status
View assigned ports withuzi ls:
ADDR column shows the development server URL with the assigned port.
Related
- uzi.yaml Configuration - Full configuration reference
- Dev Command Configuration - How $PORT is used in devCommand