fix(bedrock): give Claude an explicit, clamped output ceiling
Closes #623.
What Problem This Solves
Tool-calling scans against an adaptive-thinking Claude model on Bedrock Converse
(e.g. bedrock/global.anthropic.claude-opus-4-8, ...sonnet-4-6) can crash
mid-scan with:
litellm.APIConnectionError: Unable to convert openai tool calls ... to bedrock
tool calls. Received error=Expecting ',' delimiter: line 1 column NNNN
The tool-call arguments JSON is truncated one brace short, and the malformed
assistant message then poisons the next turn when litellm's OpenAI→Bedrock
converter runs json.loads(arguments).
Root Cause
make_model_settings never sets max_tokens. For an adaptive-thinking
Claude model, reasoning_effort maps to {"type": "adaptive"} with no fixed
budget_tokens, so litellm's update_optional_params_with_thinking_tokens
fallback (maxTokens = budget_tokens + DEFAULT_MAX_TOKENS) can't fire — and
no maxTokens reaches Bedrock at all. Converse then applies a low internal
default that "high" thinking exhausts, guillotining a long
create_vulnerability_report tool call.
The Fix
resolve_max_tokens(model_name, configured), threaded via a new
STRIX_MAX_TOKENS setting (default None) →
make_model_settings → ModelSettings.max_tokens → RunConfig.
Scoped deliberately, so it fixes the reported bug without touching anyone else's runs:
- Gated on the Claude family, not a version/tier list. The adaptive-thinking
bug spans
opus-4-6/4-8andsonnet-4-6today and will grow, whileopus-4-1is not adaptive — so tier is the wrong axis;"claude" in nameis stable. - Non-Claude models are untouched: a configured value passes through,
NonestaysNone(provider default). A local user on a small-context model (gpt/ollama/gemini) is never forced past its limit. - The chosen ceiling is clamped to the model's known
max_output_tokens, so it can never exceed what the provider accepts (older Claude tops out at 4096–8192). If a Claude model's ceiling is unknown (absent from litellm's cost map) and the user set nothing, it falls back toNonerather than guess.
Testing
- Added 7 cases to
tests/test_inputs.pycovering the resolver: non-Claude untouched, adaptive-Claude default acrossglobal./us.prefixes, clamp-to-small-ceiling (old Claude), clamp of an over-large explicit override, and unknown-Claude →None.pytest tests/test_inputs.py→ all pass; full suite unaffected. - Verified live end-to-end on Bedrock
opus-4-8andsonnet-4-6(thinking high): a repro target that previously crashed on the longest tool call now completes and reports every finding. Confirmed Converse acceptsthinking(high) + max_tokens + tooltogether (no 400). ruff check,ruff format --check,pyupgrade --py312-plus,bandit -c pyproject.tomlall clean on the changed files.- (mypy not asserted: the repo's pinned pre-commit mypy hook errors out on the
bundled
openaiSDK onmainas well, independent of this change. Verified clean under mypy 1.17 with the repo's own config.)
Greptile Summary
This PR adds an explicit output-token limit for Claude model runs.
- New
STRIX_MAX_TOKENSconfiguration. - Claude-specific default and model-limit lookup in
resolve_max_tokens. - Runner wiring into
ModelSettings.max_tokens. - Tests for defaults, clamping, unknown Claude models, and non-Claude pass-through.
Confidence Score: 4/5
The changed configuration path should reject nonpositive token values before merging.
STRIX_MAX_TOKENS=0or a negative value can reach provider requests.- That can make scans fail or produce no useful model output.
- The Claude defaulting and runner wiring otherwise look contained.
strix/config/settings.py
Important Files Changed
| Filename | Overview |
|---|---|
| strix/config/settings.py | Adds the optional STRIX_MAX_TOKENS setting, but does not reject nonpositive integer values. |
| strix/core/inputs.py | Adds Claude detection, litellm model-limit lookup, default selection, and resolved max_tokens assignment. |
| strix/core/runner.py | Passes the configured token value into make_model_settings after model resolution. |
| tests/test_inputs.py | Adds resolver tests for Claude defaults, configured overrides, unknown models, and non-Claude behavior. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
strix/config/settings.py:45
**Nonpositive Token Limit Reaches Provider**
When `STRIX_MAX_TOKENS` is set to `0` or a negative number, this field accepts it as an integer and the resolver forwards it into `ModelSettings.max_tokens`. A scan can then send an invalid or zero output limit to the model provider, causing a request failure or immediate truncation instead of fixing the long tool-call path.
Reviews (1): Last reviewed commit: "fix(bedrock): give Claude an explicit, c..." | Re-trigger Greptile