Repository navigation
fix(opencode): reject unknown --variant instead of silently dropping it - #40250
Closed
C0d3N1nja97342 wants to merge 2 commits into
Closed
C0d3N1nja97342 wants to merge 2 commits into
C0d3N1nja97342 wants to merge 2 commits into
Conversation
An interrupted tool run can leave a second tool part that reuses an existing callID (a "completed" part plus an "error"/"Tool execution aborted" part with metadata.interrupted). Serializing both to the provider yields a duplicate tool_call_id, which every provider rejects with a 400. Because compaction re-sends the full history head, the duplicate is always present, so the session can never compact again - every subsequent auto-compaction fails the same way and the token counter keeps growing. Deduplicate tool parts by callID in the assistant() lowering in to-llm-message.ts before building provider messages, keeping the most informative state (completed > error > running > pending) and preserving first-occurrence position so tool/text/reasoning order stays stable. Fixes anomalyco#40235
`opencode run --variant <value>` accepted any string. When the value was not among the model's declared variants, the LLM request prep did a bracket lookup `model.variants[variant]` that returned undefined and merged nothing - so the run proceeded at the default effort level while the session record claimed an effort level that was never applied. Exit was 0 with no warning or log line. Validate an explicit variant against the model's declared variants in `createUserMessage` (prompt.ts) before it is recorded on the session: fetch the full catalog model when a variant is supplied, and throw a NamedError listing the valid variants when the value is unknown. This makes `opencode run --variant <typo>` exit non-zero with an actionable message, and stops the unapplied value from being persisted to session metadata. Note: `withVariant` in packages/core/src/session/runner/model.ts already returns VariantUnavailableError for unknown variants, but the opencode `run` path uses its own LLM service (packages/opencode/src/session/llm/ request.ts) which never calls withVariant - it does the bracket lookup directly. So the core guard does not cover `opencode run`. Fixes anomalyco#40182
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Contributor
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
3 tasks done
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.
Issue for this PR
Closes #40182
Type of change
What does this PR do?
opencode run --variant <value>accepted any string. When the value was not among the model's declared variants, the LLM request prep did a bracket lookupmodel.variants[variant]that returnedundefinedand merged nothing - so the run proceeded at the model's default effort level while the session record claimed an effort level that was never applied. Exit was 0 with no warning or log line. The reporter captured the outgoing HTTP request body to confirmreasoning_effortwas absent for unknown values.Why
withVariantdidn't catch this:packages/core/src/session/runner/model.tsalready returnsVariantUnavailableErrorfor unknown variants - but the opencoderunpath uses its own LLM service (packages/opencode/src/session/llm/request.ts:80-83) which never callswithVariant. It does the bracket lookup directly, so the core guard does not coveropencode run. The two paths also use different representations of variants (array vs record).Fix: validate an explicit
--variantagainst the model's declared variants increateUserMessage(packages/opencode/src/session/prompt.ts) before it is recorded on the session. When a variant is supplied, fetch the full catalog model and throw aNamedErrorlisting the valid variants if the value is unknown. This makesopencode run --variant <typo>exit non-zero with an actionable message, and stops the unapplied value from being persisted to session metadata."default"is passed through unchecked (it is resolved later tomodel.request.variant), matching the existing semantics.How did you verify your code works?
Added a regression test in
packages/opencode/test/session/prompt.test.ts(mirroring the existing "applies agent variant" and "unknown agent throws typed error" tests): it suppliesvariant: "totally-invalid-xyz"against a model declaringvariants: { xhigh: {}, high: {} }and asserts the prompt fails with aNamedError.Unknownwhose message containsUnknown variant "totally-invalid-xyz", thetest/test-modelidentifier, and the valid values (high,xhigh).Caveat: I could not run the
packages/opencodetest suite locally - the package depends on@opentui/solid, whose transitive deps (@babel/core/gensync) fail to resolve under Bun on Windows + Docker volume mounts (symlink/EACCES issues). The test file and the change both transpile cleanly (bun build --no-bundle), and the test follows the exact assertion pattern of the existing variant/agent-error tests in the same file. I'd appreciate a maintainer runningbun test test/session/prompt.test.tsin CI to confirm.Checklist