Repository navigation
fix(agent): max-turns termination correctly classified as HTTP 422 (#361) - #365
Merged
Merged
Conversation
) When Claude Code hits the max_turns limit, it was being misclassified as an authentication failure (HTTP 503) because the fallback diagnosis message contained "setup-token" which triggered auth failure detection. Changes: - Detect terminal_reason="max_turns" and subtype="error_max_turns" in result messages before falling through to generic error handling - Return HTTP 422 with clear "Task exceeded turn limit" message - Raise max_turns_task default from 20 to 50 (matches max_turns_chat) - Add unit tests for max_turns error classification - Update feature flow documentation Closes #361 Co-Authored-By: Claude Opus 4.5 <[email protected]>
6 tasks
9 of 12 tasks
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
max_turns_taskdefault from 20 to 50 to accommodate complex multi-step tasksRoot Cause
When Claude Code hits max_turns, it returns
is_error=truewith emptyresult. The code fell through to_diagnose_exit_failure()which returned a message containing "setup-token", triggering auth failure detection on its own diagnosis message.Changes
claude_code.pyterminal_reason="max_turns"before fallback, return HTTP 422guardrails-baseline.jsonmax_turns_task: 20 → 50test_error_classification.pyparallel-headless-execution.mdTest Plan
pytest unit/test_error_classification.py unit/test_guardrails.py -v(57 passed)Closes #361
🤖 Generated with Claude Code