Skip to content

Preserve an explicit max_turns=0 when building the CLI command#1132

Open
Osamaali313 wants to merge 1 commit into
anthropics:mainfrom
Osamaali313:fix/max-turns-preserve-zero
Open

Preserve an explicit max_turns=0 when building the CLI command#1132
Osamaali313 wants to merge 1 commit into
anthropics:mainfrom
Osamaali313:fix/max-turns-preserve-zero

Conversation

@Osamaali313

Copy link
Copy Markdown

Problem

When building the CLI command, --max-turns is gated on a truthy check, while every other numeric option uses is not None:

if self._options.max_turns:                       # truthy — drops 0
    cmd.extend(["--max-turns", str(self._options.max_turns)])
...
if self._options.max_budget_usd is not None:      # preserves 0
    cmd.extend(["--max-budget-usd", str(self._options.max_budget_usd)])
if self._options.task_budget is not None:
    cmd.extend(["--task-budget", str(self._options.task_budget["total"])])
...
elif self._options.max_thinking_tokens is not None:
    cmd.extend(["--max-thinking-tokens", str(self._options.max_thinking_tokens)])
if self._options.effort is not None:
    cmd.extend(["--effort", ...])

So a caller that explicitly sets max_turns=0 has the flag silently omitted, and the CLI falls back to its default turn limit — the opposite of the explicit request. An explicitly-provided option shouldn't be discarded just because its value is 0.

Fix

Match the sibling numeric options:

if self._options.max_turns is not None:
    cmd.extend(["--max-turns", str(self._options.max_turns)])

Reproduction

option value before after
max_turns=0 (flag omitted) --max-turns 0
max_budget_usd=0.0 --max-budget-usd 0.0 --max-budget-usd 0.0
max_thinking_tokens=0 --max-thinking-tokens 0 --max-thinking-tokens 0

(max_turns=0 is the only numeric option whose explicit 0 is currently lost.)

`_build_command` gates the `--max-turns` flag on a truthy check:

    if self._options.max_turns:
        cmd.extend(["--max-turns", str(self._options.max_turns)])

so `max_turns=0` is falsy and silently dropped — the flag is omitted and
the CLI falls back to its default turn limit, the opposite of what the caller
explicitly requested.

Every other numeric option in the same method preserves an explicit 0 by
checking `is not None`: `max_budget_usd`, `task_budget`, `max_thinking_tokens`,
and `effort`. Use the same `is not None` check for `max_turns` so an
explicitly-set value is always forwarded.
Copilot AI review requested due to automatic review settings July 19, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants