From 46ce1a03a902af5b973c9d75921e794b174680ac Mon Sep 17 00:00:00 2001 From: Maciej Szeszko Date: Mon, 11 May 2026 17:45:43 -0700 Subject: [PATCH] Cap Claude thinking budget (#14731) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: ### Motivation Claude's auto review workflow classifies the PR as complex and sets `MAX_THINKING_TOKENS`=**32000** in `.github/workflows/ai-review-analysis.yml:534`. The Claude action then sends a request where `thinking.budget_tokens` is **32000**, but the request `max_tokens` is not greater than that, so Anthropic rejects it before the review starts ([example](https://github.com/facebook/rocksdb/actions/runs/25691112276/job/75427435133)). ### Fix Reduce the "complex" thinking budget from **32000** to **24000** tokens and clamps manual overrides to the same ceiling, preventing the thinking budget from exceeding or equalling the action's effective `max_tokens`. 24k is still generous — enough for deep reasoning on complex PRs while guaranteeing the model can emit the formatted review. Pull Request resolved: https://github.com/facebook/rocksdb/pull/14731 Reviewed By: xingbowang Differential Revision: D104749426 Pulled By: mszeszko-meta fbshipit-source-id: bf94d0f50e7c2c9bc9e4d4cdffd61087d739018a --- .github/workflows/ai-review-analysis.yml | 22 ++++++++++++++++++---- .github/workflows/claude-review.yml | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ai-review-analysis.yml b/.github/workflows/ai-review-analysis.yml index 7cad645926..0e0250ca1a 100644 --- a/.github/workflows/ai-review-analysis.yml +++ b/.github/workflows/ai-review-analysis.yml @@ -531,7 +531,9 @@ jobs: core.warning( `Could not parse classifier output: ${error.message}`); } - const budget = label === 'simple' ? '16000' : '32000'; + // Keep Claude's thinking budget below the action's effective + // max_tokens so the API has room for the final review text. + const budget = label === 'simple' ? '16000' : '24000'; core.info( `Complexity classified as: ${label} ` + `-> MAX_THINKING_TOKENS=${budget}` @@ -1115,9 +1117,19 @@ jobs: } const override = (process.env.OVERRIDE || '').trim(); if (override && /^\d+$/.test(override)) { - core.info(`Using thinking_budget override: ${override}`); + const maxSafeBudget = 24000; + const requested = parseInt(override, 10); + const budget = Math.min(requested, maxSafeBudget).toString(); + if (budget !== override) { + core.info( + `Clamping thinking_budget override from ${override} ` + + `to ${budget} so max_tokens can exceed thinking tokens.` + ); + } else { + core.info(`Using thinking_budget override: ${budget}`); + } core.setOutput('label', 'override'); - core.setOutput('tokens', override); + core.setOutput('tokens', budget); return; } let label = 'complex'; @@ -1135,7 +1147,9 @@ jobs: core.warning( `Could not parse classifier output: ${error.message}`); } - const budget = label === 'simple' ? '16000' : '32000'; + // Keep Claude's thinking budget below the action's effective + // max_tokens so the API has room for the final review text. + const budget = label === 'simple' ? '16000' : '24000'; core.info( `Complexity classified as: ${label} ` + `-> MAX_THINKING_TOKENS=${budget}` diff --git a/.github/workflows/claude-review.yml b/.github/workflows/claude-review.yml index 7087330d9f..85acf93d4f 100644 --- a/.github/workflows/claude-review.yml +++ b/.github/workflows/claude-review.yml @@ -34,7 +34,7 @@ on: - claude-sonnet-4-6 default: claude-opus-4-6 thinking_budget: - description: Override MAX_THINKING_TOKENS (blank = auto-classify) + description: Override MAX_THINKING_TOKENS (blank = auto-classify, capped at 24000) required: false type: string default: ""