fix(transport): forward max_turns=0 to the CLI instead of dropping it#1119
Open
VihaanAgarwal wants to merge 1 commit into
Open
fix(transport): forward max_turns=0 to the CLI instead of dropping it#1119VihaanAgarwal wants to merge 1 commit into
VihaanAgarwal wants to merge 1 commit into
Conversation
The command builder guarded max_turns with a truthiness check, so max_turns=0 was treated the same as the None "unset" sentinel and the --max-turns flag was never emitted. A caller that sets 0 (for example a turn budget decremented down to zero) silently got the CLI default of no turn limit instead. Every other numeric option in _build_command already guards on `is not None` (max_budget_usd, task_budget, max_thinking_tokens), so 0 is forwarded there. Match that here and let the CLI decide what 0 means.
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.
What breaks
ClaudeAgentOptions(max_turns=0)is silently ignored. The built command omits--max-turnsentirely, so the CLI runs with its default (no turn cap) instead of the 0 the caller asked for.Confirmed against current
main:Root cause
_build_commandguarded the flag with a truthiness check:max_turnsis typedint | None = None, soNoneis the "unset" sentinel and0is a real caller value. Bare truthiness collapses the two. Every other numeric option in the same method already guards onis not Noneand forwards0correctly:max_budget_usd(0.0 is emitted),task_budget,max_thinking_tokens.max_turnswas the lone exception.A concrete way to hit it: a caller that computes a turn budget and decrements it (
options.max_turns = max(0, remaining)) expects 0 to mean "stop", but instead gets an unbounded run.Fix
Guard on
is not None, matching the sibling numeric options, and let the CLI decide what0means rather than dropping it in the SDK.Test
Added
test_build_command_max_turns_zerointests/test_transport.py: asserts--max-turns 0is emitted formax_turns=0and thatNonestill emits no flag. It fails on the old truthiness check and passes with the fix. Full suite stays green (ruff, format, mypy clean).