Skip to content

fix(provider): prefer per-model temperature over agent override#27777

Closed
Alezander9 wants to merge 1 commit into
anomalyco:devfrom
Alezander9:fix/strict-temperature-required-models
Closed

fix(provider): prefer per-model temperature over agent override#27777
Alezander9 wants to merge 1 commit into
anomalyco:devfrom
Alezander9:fix/strict-temperature-required-models

Conversation

@Alezander9
Copy link
Copy Markdown

Problem

ProviderTransform.temperature(model) in src/provider/transform.ts returns the temperature value a given model family requires (kimi-k2.* -> 1.0 or 0.6; gemini / glm-4.6 / glm-4.7 / minimax-m2 -> 1.0; qwen -> 0.55). Several of these are hard requirements: Moonshot rejects any other value for the kimi-k2 family with HTTP 400 invalid temperature: only 1 is allowed for this model.

The call site in packages/opencode/src/session/llm.ts:172 consults that function in the wrong order:

input.agent.temperature ?? ProviderTransform.temperature(input.model)

The built-in title agent (packages/opencode/src/agent/agent.ts:253) hard-codes temperature: 0.5. Because ?? short-circuits on the first non-nullish operand, the agent default always wins and a temperature of 0.5 is sent to e.g. kimi-k2.6, which then 400s.

I observed this in production telemetry across multiple users on kimi-k2.6 (the most common case). The same code path will trip whenever an agent sets a temperature on any of the strict-required model families.

Fix

Swap the operands at the single call site:

ProviderTransform.temperature(input.model) ?? input.agent.temperature

The transform function exists precisely because it encodes model-aware knowledge of what each family expects; that knowledge should beat a generic agent default. For models not covered by the transform map (claude, openai, etc.), the function returns undefined and the agent preference still applies through normal ?? fallthrough - so the only behavior change is on the families already flagged as needing specific values.

This also aligns temperature with the adjacent topK (no agent override) and brings it closer to topP (still agent ?? transform, but topP has no known strict-required cases today).

Diff

 packages/opencode/src/session/llm.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Notes

This was originally fixed in a downstream fork (browser-use/browsercode#64) where it was hit in production telemetry. The same code is unchanged on dev here, so opening the equivalent upstream PR.

`ProviderTransform.temperature(model)` encodes per-model-family temperature
values that the model's provider requires (e.g. Moonshot's kimi-k2.* returns
HTTP 400 "invalid temperature: only 1 is allowed for this model" if any
other value is sent). The session/llm.ts call site consulted it in the wrong
order:

  input.agent.temperature ?? ProviderTransform.temperature(input.model)

so the built-in title agent's hard-coded `temperature: 0.5` (agent.ts:253)
won over the kimi-required 1.0, and Moonshot rejected the request.

Swap the operands. The transform value, when present, is the model-aware
answer and should beat a generic agent default. For models that aren't in
the transform map, the function returns `undefined` and the agent's
preference still applies through `??` fallthrough.

Affects: kimi-k2.* (incl. k2.6, thinking, k2-5), gemini, glm-4.6/4.7,
minimax-m2, qwen - anywhere the transform has an entry.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 15, 2026
@github-actions github-actions Bot closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant