Fix: propagate max_tokens stop reason instead of throwing internal error#365
Merged
benbrandt merged 3 commits intozed-industries:mainfrom Mar 3, 2026
Merged
Conversation
When the Claude SDK reports stop_reason "max_tokens", the ACP adapter
now returns { stopReason: "max_tokens" } instead of throwing a JSON-RPC
internal error. This allows downstream ACP clients to properly detect
token exhaustion.
Fixes zed-industries#235
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
auto-merge was automatically disabled
March 2, 2026 18:57
Head branch was pushed to by a user without write access
Contributor
Author
|
@benbrandt got a linter error, please approve again |
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.
Summary
stop_reason: "max_tokens", the ACP adapter now returns{ stopReason: "max_tokens" }instead of throwing aRequestError.internalError(JSON-RPC-32603)successanderror_during_executionresult subtypes only —error_max_turns/error_max_budget_usdstill correctly map tomax_turn_requestsProblem
When tokens are exhausted, the SDK sends a
resultmessage withstop_reason: "max_tokens"andis_error: true. The adapter hit theis_errorcheck first and threw an internal error, so ACP clients never received thestopReasonfield. Downstream tools like toad saw a JSON-RPC exception instead of a clean stop reason.Fix
Check
stop_reason === "max_tokens"before theis_errorthrow in thesuccessanderror_during_executionbranches. Token exhaustion is a normal stop condition, not an internal error.Test plan
success+max_tokens+is_error: false→ returnsmax_tokenssuccess+max_tokens+is_error: true→ returnsmax_tokens(main bug)error_during_execution+max_tokens+is_error: true→ returnsmax_tokenssuccess+nullstop_reason → still returnsend_turn(no regression)success+is_error: true+ non-max_tokens → still throws (no regression)Fixes #235
🤖 Generated with Claude Code