-
Notifications
You must be signed in to change notification settings - Fork 52
fix(invoke): preserve model maxTokens when overriding model at harness invoke #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jesseturner21
merged 2 commits into
preview
from
fix/harness-model-maxTokens-invoke-override
May 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
src/cli/commands/invoke/__tests__/build-harness-base-opts.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { buildHarnessBaseOpts } from '../action.js'; | ||
| import type { InvokeOptions } from '../types.js'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('buildHarnessBaseOpts', () => { | ||
| describe('preserves model inference params from harness spec when overriding model', () => { | ||
| it('bedrock: includes temperature, topP, and maxTokens', () => { | ||
| const options: InvokeOptions = { modelId: 'anthropic.claude-v3' }; | ||
| const harnessSpec = { | ||
| provider: 'bedrock' as const, | ||
| modelId: 'anthropic.claude-v2', | ||
| temperature: 0.7, | ||
| topP: 0.9, | ||
| maxTokens: 500, | ||
| }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model).toEqual({ | ||
| bedrockModelConfig: { | ||
| modelId: 'anthropic.claude-v3', | ||
| temperature: 0.7, | ||
| topP: 0.9, | ||
| maxTokens: 500, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('open_ai: includes temperature, topP, maxTokens, and apiKeyArn', () => { | ||
| const options: InvokeOptions = { modelId: 'gpt-5' }; | ||
| const harnessSpec = { | ||
| provider: 'open_ai' as const, | ||
| modelId: 'gpt-4', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:key', | ||
| temperature: 0.5, | ||
| topP: 0.8, | ||
| maxTokens: 2048, | ||
| }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model).toEqual({ | ||
| openAiModelConfig: { | ||
| modelId: 'gpt-5', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:key', | ||
| temperature: 0.5, | ||
| topP: 0.8, | ||
| maxTokens: 2048, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('gemini: includes temperature, topP, topK, maxTokens, and apiKeyArn', () => { | ||
| const options: InvokeOptions = { modelId: 'gemini-2.5-pro' }; | ||
| const harnessSpec = { | ||
| provider: 'gemini' as const, | ||
| modelId: 'gemini-2.5-flash', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:gemini', | ||
| temperature: 0.3, | ||
| topP: 0.95, | ||
| topK: 0.5, | ||
| maxTokens: 1024, | ||
| }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model).toEqual({ | ||
| geminiModelConfig: { | ||
| modelId: 'gemini-2.5-pro', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:gemini', | ||
| temperature: 0.3, | ||
| topP: 0.95, | ||
| topK: 0.5, | ||
| maxTokens: 1024, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('omits undefined inference params', () => { | ||
| it('bedrock: only includes modelId when no inference params set', () => { | ||
| const options: InvokeOptions = { modelId: 'anthropic.claude-v3' }; | ||
| const harnessSpec = { provider: 'bedrock' as const, modelId: 'anthropic.claude-v2' }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model).toEqual({ | ||
| bedrockModelConfig: { modelId: 'anthropic.claude-v3' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('open_ai: omits apiKeyArn and inference params when not set', () => { | ||
| const options: InvokeOptions = { modelId: 'gpt-5', modelProvider: 'open_ai' }; | ||
| const harnessSpec = { provider: 'open_ai' as const, modelId: 'gpt-4' }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model).toEqual({ | ||
| openAiModelConfig: { modelId: 'gpt-5' }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('CLI options take precedence for apiKeyArn', () => { | ||
| it('uses CLI apiKeyArn over harness spec', () => { | ||
| const options: InvokeOptions = { | ||
| modelId: 'gpt-5', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:cli-key', | ||
| }; | ||
| const harnessSpec = { | ||
| provider: 'open_ai' as const, | ||
| modelId: 'gpt-4', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:spec-key', | ||
| maxTokens: 1000, | ||
| }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model!.openAiModelConfig!.apiKeyArn).toBe('arn:aws:secretsmanager:us-east-1:123:secret:cli-key'); | ||
| expect(result.model!.openAiModelConfig!.maxTokens).toBe(1000); | ||
| }); | ||
| }); | ||
|
|
||
| describe('does not set model when no model override options provided', () => { | ||
| it('returns empty opts when no model-related options are set', () => { | ||
| const options: InvokeOptions = {}; | ||
| const harnessSpec = { | ||
| provider: 'bedrock' as const, | ||
| modelId: 'anthropic.claude-v2', | ||
| maxTokens: 500, | ||
| }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options, harnessSpec); | ||
|
|
||
| expect(result.model).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('harness-level execution limits', () => { | ||
| it('forwards maxTokens, maxIterations, and timeoutSeconds from CLI options', () => { | ||
| const options: InvokeOptions = { | ||
| maxTokens: 100, | ||
| maxIterations: 10, | ||
| harnessTimeout: 30, | ||
| }; | ||
|
|
||
| const result = buildHarnessBaseOpts(options); | ||
|
|
||
| expect(result.maxTokens).toBe(100); | ||
| expect(result.maxIterations).toBe(10); | ||
| expect(result.timeoutSeconds).toBe(30); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.