Skip to content

fix: validate maxTurns to prevent NaN from reaching SDK#87

Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/validate-max-turns-nan
Open

fix: validate maxTurns to prevent NaN from reaching SDK#87
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/validate-max-turns-nan

Conversation

@MaxwellCalkin
Copy link
Copy Markdown

@MaxwellCalkin MaxwellCalkin commented Mar 8, 2026

Summary

parseInt() returns NaN for non-numeric strings like "abc", which was silently passed to the SDK's maxTurns option. This could cause unpredictable behavior when users provide invalid max_turns input (e.g., a typo or misconfiguration in their workflow file).

Changes:

  • Added validation after parseInt() to check for NaN and negative values
  • Throws a clear, actionable error message instead of silently passing invalid values
  • Added 5 test cases covering valid input, missing input, non-numeric input, negative values, and text input

Before: max_turns: "abc" silently passes NaN to the SDK
After: max_turns: "abc" throws Invalid max_turns value: "abc". Must be a valid integer.

Test plan

  • All 123 existing tests pass
  • 5 new test cases added for maxTurns validation
  • TypeScript typecheck passes

AI Disclosure

This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).

parseInt() returns NaN for non-numeric strings like "abc", which was
silently passed to the SDK's maxTurns option causing unpredictable
behavior. Now validates the parsed value and throws a clear error
for non-numeric or negative values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant