Skip to content

fix(invoke): preserve model maxTokens when overriding model at harness invoke#1287

Merged
jesseturner21 merged 2 commits into
previewfrom
fix/harness-model-maxTokens-invoke-override
May 18, 2026
Merged

fix(invoke): preserve model maxTokens when overriding model at harness invoke#1287
jesseturner21 merged 2 commits into
previewfrom
fix/harness-model-maxTokens-invoke-override

Conversation

@jesseturner21

@jesseturner21 jesseturner21 commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix buildHarnessBaseOpts to forward model inference parameters (temperature, topP, topK, maxTokens) from the harness spec when constructing invoke-time model overrides
  • Import HarnessModel type from schema instead of maintaining a local duplicate interface
  • Add unit tests for buildHarnessBaseOpts covering all provider branches, param omission, and CLI precedence

Fixes #1290

Test plan

  • Unit tests added for all 3 providers (bedrock, open_ai, gemini) with inference params
  • Unit tests for omission of undefined params
  • Unit test for CLI apiKeyArn precedence over harness spec
  • Unit test for harness-level execution limits (maxTokens, maxIterations, timeoutSeconds)
  • Manual end-to-end: deployed harness with maxTokens:500, invoked with --model-id, confirmed stopReason: "max_tokens" and outputTokens: 500

… harness invoke time

When --model-id was passed to `agentcore invoke --harness`, the CLI
constructed a new model config override that dropped maxTokens,
temperature, and topP from the harness spec's model configuration.
Since the server treats invoke-time model overrides as a full
replacement of the deployed model config, this silently removed the
model's token limit — allowing unbounded output.

Also expands the HarnessModelConfiguration type to properly declare
inference parameters (temperature, topP, topK, maxTokens) instead of
relying on spread operators to bypass the narrow type at deploy time.
@jesseturner21 jesseturner21 requested a review from a team May 18, 2026 17:16
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label May 18, 2026
@github-actions

github-actions Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.56% 10111 / 23208
🔵 Statements 42.83% 10747 / 25087
🔵 Functions 40.4% 1703 / 4215
🔵 Branches 40.41% 6610 / 16354
Generated in workflow #3072 for commit 36a88c1 by the Vitest Coverage Report Action

@agentcore-cli-automation agentcore-cli-automation left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this — silently dropping maxTokens on invoke-time model overrides is a real correctness/safety bug, and the fix in buildHarnessBaseOpts matches what harness-mapper.ts already does at deploy time.

Main ask before merging: please add a unit test for buildHarnessBaseOpts. The PR description notes that 125 existing tests pass, but none of them exercise this code path — the regression that this PR fixes was not caught by the existing suite, and without a test the same regression could re-emerge. A small test that asserts the produced baseOpts.model includes the spec's temperature / topP / topK / maxTokens (per provider) when --model-id is overridden would lock the fix down.

Also left a small note about reusing the existing HarnessModel schema type rather than duplicating the interface locally.

Comment thread src/cli/commands/invoke/action.ts Outdated
Comment thread src/cli/commands/invoke/action.ts
@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 18, 2026
…ldHarnessBaseOpts

- Replace local HarnessModel interface with imported schema type to
  prevent drift when new inference params are added
- Export buildHarnessBaseOpts for testability
- Add 8 unit tests covering all provider branches, param preservation,
  param omission, CLI precedence, and execution limits
Comment thread src/cli/aws/agentcore-harness.ts
Comment thread src/cli/aws/agentcore-harness.ts
@jesseturner21 jesseturner21 merged commit 4d7834a into preview May 18, 2026
21 checks passed
@jesseturner21 jesseturner21 deleted the fix/harness-model-maxTokens-invoke-override branch May 18, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants