Skip to content

fix(cli): Honor explicit --port literally and fail fast on conflict... (#1079)#65

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1079
Draft

fix(cli): Honor explicit --port literally and fail fast on conflict... (#1079)#65
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1079

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1079

Issues

Root cause

getAgentPort() at config.ts:72-76 returns basePort + runtime array index; the --logs path (command.tsx:402) passes the user's -p as basePort and binds the shifted port via createDevServer, while only the secondary findAvailablePort shift is logged (command.tsx:417-418) and help text (command.tsx:174) omits the base-port semantics. Offset locked by config.test.ts:531-532.

The fix

Honor explicit --port literally and fail fast on conflict; when -p is implicit (default), keep the index offset but LOG it (mirror the existing command.tsx:417-418 shift message) and document it in --help. Use Commander's getOptionValueSource to distinguish explicit vs default. Apply consistently across the three server-side offset pathways: command.tsx:402 (--logs), web-ui/handlers/start.ts:103 (uiPort+1+index — this path ignores -p entirely today), and useDevServer.ts:157 (TUI path, which currently honors -p with NO offset — divergent). NOTE: command.tsx:262 (invoke) offset is NOT a bug to remove — invoke must target whatever port the server bound; make it consistent with the chosen server semantics, don't strip it. Closed (unmerged) PR aws#1158 implements this approach and can be revived/rebased; it also preserves getAgentPort as a deprecated wrapper for backwards-compat.

Files touched: src/cli/operations/dev/config.ts:72-76 (getAgentPort); src/cli/commands/dev/command.tsx:174 (help text), :402 (--logs offset), :262 (invoke — keep but make consistent); src/cli/tui/hooks/useDevServer.ts:157; src/cli/operations/dev/web-ui/handlers/start.ts:103; update test src/cli/operations/dev/tests/config.test.ts:531-532

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

see above

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…ing by runtime index

When running multiple `agentcore dev` runtimes, an explicit -p/--port was
silently offset by the runtime's index in agentcore.json (basePort + index),
so `agentcore dev -r AgentB -p 8788` bound 8789 with no explanation. Clients
targeting http://localhost:<-p>/invocations silently hit the wrong port.

Use Commander's getOptionValueSource to distinguish explicit vs default -p:
honor an explicit --port literally across the --logs, web-ui, and TUI paths;
when -p is implicit (default), keep the index offset but log it (mirroring the
existing findAvailablePort shift message) and document it in --help. invoke
continues to target whatever port the server bound, made consistent with the
chosen server semantics.

Scope: Surgical, unit-test-verified. tsc --noEmit clean, eslint clean (no new
warnings), 1002/1002 unit tests pass across src/cli/operations/dev and
src/cli/tui including the updated and new getAgentPort tests. The only failing
tests (4 in dev.test.ts) are pre-existing CLI-spawn failures that fail
identically on the clean baseline (require a built dist; environmental,
unrelated to this change). The web-ui path is a structurally multi-agent
server, so for the explicit -p case the SELECTED runtime binds exactly -p while
concurrently-served runtimes are offset relative to it -- the minimal way to
honor explicit -p there without redesigning the multi-agent port model.
@github-actions github-actions Bot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 37.15% 13593 / 36585
🔵 Statements 36.42% 14452 / 39675
🔵 Functions 31.79% 2333 / 7337
🔵 Branches 31.09% 9003 / 28951
Generated in workflow #119 for commit 823e55e by the Vitest Coverage Report Action

@github-actions github-actions Bot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant