fix: route Harness invoke exec through command API - #2097
Conversation
|
Claude Security Review: no high-confidence findings. (run) |
Package TarballHow to installgh release download pr-2097-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.28.0.tgz |
There was a problem hiding this comment.
AgentCore Harness Review
Verdict: Looks good
Nice, focused fix. Previously invoking a harness with --exec (both --harness and --harness-arn paths) silently fell through to normal model invocation with the shell command as the prompt; this PR routes those cases through executeBashCommand via a new shared handleInvokeExec helper.
Points I verified:
- Runtime exec preserved. The extracted
handleInvokeExecinsrc/cli/commands/invoke/action.tsis a straight lift of the previous inline block (same stdout/stderr streaming, same JSON vs non-JSON return shape, samelogger.logResponse/logger.logErrorbehavior). The runtime call site at line 391 still runs after payment/auto-session validation, so no ordering regressions. - Harness path ordering is correct. In
handleHarnessInvoke, the exec branch (line 1056) sits after the deployed-state lookup, prompt validation, and theCUSTOM_JWTbearer-token auto-fetch, so an exec against a JWT-protected harness will still get its token injected.options.sessionIdis normalized at line 1013 before being forwarded, so the exec helper always sees a concrete session id. handleHarnessInvokeByArncorrectly gates onoptions.execafter prompt validation and generates a session id before delegating; it intentionally skipsbuildHarnessBaseOpts, which is fine sinceexecuteBashCommanddoesn't consume harness model options.- Test coverage exercises all three call sites (harness by name, harness by ARN, runtime) and asserts the exact
executeBashCommandpayload plus thatinvokeHarnessis not called — which is the actual invariant this bug requires.
Minor note (not a blocker): action-harness-exec.test.ts mocks the entire ../../../aws index and ../resolve, which is heavier than the "mock at I/O boundaries only" guidance. resolveInvokeTarget is pure enough to run against fixture InvokeContext data, and only executeBashCommand / invokeHarness truly need mocking. Worth tightening next time this file is touched, but the current mocks don't hide anything material for what's being asserted here.
No new telemetry needed — this is a bug fix that reuses the existing exec path; command-level telemetry at the CLI entrypoint continues to cover it.
Description
Route the documented
agentcore invoke --exec --harnessand--harness-arnpaths throughInvokeAgentRuntimeCommandinstead of sendingthe command as a conversational
InvokeHarnessmessage.This extracts the existing Runtime exec behavior into a shared invoke helper,
preserving streaming output, JSON envelopes, exit codes, timeout status,
headers, bearer tokens, and invocation logging for Runtime and Harness targets.
Related Issue
Closes #2096
Documentation PR
N/A. This fixes the CLI to match the existing AgentCore Harness documentation.
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsAdditional verification:
origin/mainworktree.npm run test:unit: 6,048 passed; 105 sandbox/baseline failures reproduce on untouchedorigin/main(spawned CLI output, read-only home, and unavailable ports).npm run test:integ: 34 passed, 251 skipped; 58 failures have the same empty spawned-CLI output signature and are unrelated to the changed invoke action.npm run build: passed.npm run format:check: passed.603141041947,us-east-1:invoke --exec --harness ExecHarness "printf harness-exec-ok"returnedstdout
harness-exec-ok, exit code0, and statusCOMPLETED.invoke --exec --runtime RuntimeExecFix "printf runtime-exec-ok"returnedstdout
runtime-exec-ok, exit code0, and statusCOMPLETED.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.