fix(anthropic-effort): clamp pre-set effort=max for constrained providers regardless of variant

Move the pre-set effort handling BEFORE the message.variant !== "max" early-return so that output.options.effort="max" set via session params or model-requirements fallback chains is always clamped to "high" on constrained providers (github-copilot, Anthropic OAuth), even when message.variant is not "max".

This addresses the cubic violation from PR #3608 where the clamp block was gated behind the variant-based return.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-18 12:36:45 +09:00
parent 34e6af1ae6
commit 96767b5d1a
+18 -6
View File
@@ -76,23 +76,35 @@ export function createAnthropicEffortHook() {
const { agent, model, message } = input
if (!model?.modelID || !model?.providerID) return
if (isEffortUnsupportedModel(model.modelID)) return
if (message.variant !== "max") return
if (!isClaudeProvider(model.providerID, model.modelID)) return
if (shouldSkipForInternalAgent(agent?.name)) return
if (output.options.effort !== undefined) return
const opus = isOpusModel(model.modelID)
const constrained = isConstrainedProvider(model.providerID)
if (output.options.effort !== undefined) {
if (output.options.effort === "max" && constrained) {
const clamped = clampVariant("max", opus, constrained)
output.options.effort = clamped
;(message as { variant?: string }).variant = clamped
log("anthropic-effort: clamped pre-set effort max→high", {
sessionID: input.sessionID,
provider: model.providerID,
model: model.modelID,
reason: "constrained-provider",
})
}
return
}
if (message.variant !== "max") return
const clamped = clampVariant(message.variant, opus, constrained)
output.options.effort = clamped
const shouldOverrideMessageVariant = !opus || constrained
if (shouldOverrideMessageVariant) {
// Override the variant so OpenCode doesn't pass "max" to the API.
// Non-Opus models cap at high; Anthropic OAuth (Claude Pro/Max) also
// caps at high even on Opus because the OAuth API only accepts
// low | medium | high.
;(message as { variant?: string }).variant = clamped
log("anthropic-effort: clamped variant max→high", {
sessionID: input.sessionID,