Description
When running multiple agentcore dev instances in parallel, getAgentPort() in
src/cli/operations/dev/config.ts silently offsets the port passed via
-p by the runtime's index in agentcore.json (basePort + runtimeIndex). The shift is not logged and the flag's help text ("Port for development server") gives no hint that -p is a base port.
Why this is a problem
The actual bound port depends on which other runtimes are configured in agentcore.json and which ones happen to be running, not just on the -p value.
This breaks local development and integration testing in practical ways:
- Downstream services (backend servers, integration tests, scripts) that target
http://localhost:<-p value>/invocations silently talk to the wrong port —
or get connection errors — depending on which runtimes are up.
- Which runtime owns which port changes if someone reorders, adds, or removes entries in
agentcore.json. A config-only change silently breaks every
developer's local setup.
- To hit a specific port, a user has to compute
-p = desiredPort - runtimeIndex and keep that in sync with agentcore.json. The -p value in
package.json / README / CI scripts no longer means what it says.
- A second free-port search (
findFreePort in src/cli/operations/dev/utils.ts) can shift the port again if basePort + index is occupied, and only
that shift is announced. The first, index-based shift is invisible.
Suggested Fixes (any one resolves the surprise)
- Treat
-p as the literal port; fail fast on conflict.
- Add a per-runtime
devPort field in agentcore.json so the mapping is explicit and stable across reorderings.
- Log the offset whenever
getAgentPort shifts the port, mirroring the existing Port ${ee} in use, using ${re} message.
- At minimum, document the current behavior in
--help and the README.
Steps to Reproduce
agentcore.json with two runtimes:
{ "runtimes": [{ "name": "AgentA", ... }, { "name": "AgentB", ... }] }
- Run both in parallel with the ports you actually want:
agentcore dev -r AgentA -p 8787 &
agentcore dev -r AgentB -p 8788 &
lsof -iTCP -sTCP:LISTEN -n -P — AgentB is on 8789, not 8788.
Expected Behavior
AgentB binds to 8788 (the value passed via -p).
Actual Behavior
AgentB binds to 8789 (8788 + index(AgentB) = 8788 + 1). No log line explains why.
CLI Version
@aws/agentcore@0.12.0; logic still on main / v0.13.0.
Operating System
macOS
Additional Context
No response
Description
When running multiple
agentcore devinstances in parallel,getAgentPort()insrc/cli/operations/dev/config.tssilently offsets the port passed via-pby the runtime's index inagentcore.json(basePort + runtimeIndex). The shift is not logged and the flag's help text ("Port for development server") gives no hint that-pis a base port.Why this is a problem
The actual bound port depends on which other runtimes are configured in
agentcore.jsonand which ones happen to be running, not just on the-pvalue.This breaks local development and integration testing in practical ways:
http://localhost:<-p value>/invocationssilently talk to the wrong port —or get connection errors — depending on which runtimes are up.
agentcore.json. A config-only change silently breaks everydeveloper's local setup.
-p = desiredPort - runtimeIndexand keep that in sync withagentcore.json. The-pvalue inpackage.json/ README / CI scripts no longer means what it says.findFreePortinsrc/cli/operations/dev/utils.ts) can shift the port again ifbasePort + indexis occupied, and onlythat shift is announced. The first, index-based shift is invisible.
Suggested Fixes (any one resolves the surprise)
-pas the literal port; fail fast on conflict.devPortfield inagentcore.jsonso the mapping is explicit and stable across reorderings.getAgentPortshifts the port, mirroring the existingPort ${ee} in use, using ${re}message.--helpand the README.Steps to Reproduce
agentcore.jsonwith two runtimes:{ "runtimes": [{ "name": "AgentA", ... }, { "name": "AgentB", ... }] }lsof -iTCP -sTCP:LISTEN -n -P—AgentBis on8789, not8788.Expected Behavior
AgentBbinds to8788(the value passed via-p).Actual Behavior
AgentBbinds to8789(8788 + index(AgentB)=8788 + 1). No log line explains why.CLI Version
@aws/agentcore@0.12.0; logic still onmain/ v0.13.0.Operating System
macOS
Additional Context
No response