fix: default to first-party model alias when none specified (#1416)#1432
Open
farmer-data wants to merge 1 commit into
Open
fix: default to first-party model alias when none specified (#1416)#1432farmer-data wants to merge 1 commit into
farmer-data wants to merge 1 commit into
Conversation
…cs#1416) When no model was specified, the action passed model: undefined through to the Agent SDK, which fell back to its bundled default snapshot. In the currently-pinned version that resolves to the retired claude-sonnet-4-20250514, producing a 404 not_found_error and (with an OAuth token) retrying until the job timeout. Set an explicit default in parseSdkOptions using the "sonnet" alias (resolved server-side to the current snapshot) so the action never inherits a stale SDK/CLI default. Precedence is preserved: an explicit options.model wins, then --model in claudeArgs (extraArgs), then the default. The default is gated to the first-party provider and skipped for Bedrock/Vertex/Foundry, whose model id formats make a first-party alias invalid. Fixes anthropics#1416 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65cd8bd to
1f0468f
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1416
Problem
When no model is specified, the action passes
model: undefinedall the way through to the Agent SDK, so the SDK/CLI falls back to its own bundled default model. In the currently-pinned version that resolves to the retiredclaude-sonnet-4-20250514, producing:Nothing in this repo hardcodes the bad id — it's inherited from the pinned SDK/CLI default, so it broke silently when that snapshot was retired server-side. With an OAuth token the 404 retries until the job timeout, so the run never completes. Every consumer currently has to add
--modelto their workflow by hand to avoid it.How I solved it
Flow that produced the bug:
action.ymldefines nomodelinput and never exportsANTHROPIC_MODEL.src/entrypoints/run.ts→runClaude(..., { model: process.env.ANTHROPIC_MODEL })→undefinedbase-action/src/parse-sdk-options.ts→sdkOptions.model = options.model(undefined)base-action/src/run-claude-sdk.ts→query({ options })→ SDK supplies its stale defaultThe fix sets an explicit default in
parseSdkOptionsvia a newresolveModel()helper. Key decisions:"sonnet"), not a dated snapshot. The alias resolves server-side to the current model, so the action can't rot the same way a pinned id did.options.modelwins → then--modelinclaudeArgs(kept inextraArgsand passed to the CLI, so we deliberately returnundefinedto avoid specifying the model twice) → then the default alias.CLAUDE_CODE_USE_BEDROCK/CLAUDE_CODE_USE_VERTEX/CLAUDE_CODE_USE_FOUNDRYis set, since"sonnet"isn't a valid Bedrock/Vertex/Foundry model id — those providers resolve their own default.After this, users no longer need per-repo
--modelworkarounds.Tests
Added a
model defaultingsuite inbase-action/test/parse-sdk-options.test.ts(env-isolated to avoid provider-var leakage):"sonnet"options.modelpreserved (and trimmed)--modelinclaudeArgsstill overrides;sdkOptions.modelstays undefinedAll 761 tests pass;
tsc --noEmitandprettier --checkare clean.🤖 Generated with Claude Code