Fix: Raise error when agentic workflow hits max-turns limit #2235
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.
Problem
When an agentic workflow hits its configured
max-turnslimit, the execution stops but no error is raised. This leads to silent failures where:This is particularly problematic for workflows using safe-outputs, as the incomplete execution can result in missing or partial results.
Solution
Modified the Claude log parser to detect when the max-turns limit is hit and fail the workflow with a clear error message.
The parser now:
num_turnsfrom the final log entry equals or exceeds the configuredGH_AW_MAX_TURNSenvironment variablemaxTurnsHitflag in the parse resultcore.setFailed()with a descriptive error message when the limit is detectedChanges
pkg/workflow/js/parse_claude_log.cjs:maxTurnsHitboolean flag to theparseClaudeLog()return valuenum_turns >= GH_AW_MAX_TURNSwhen both values are availablemain()function to callcore.setFailed()when max-turns limit is detectedpkg/workflow/js/parse_claude_log.test.cjs:parseClaudeLog()functionmain()functionExample
When a workflow now hits the max-turns limit, users will see:
This makes it immediately clear that:
Implementation Notes
>=instead of==to handle edge cases where turns might exceed the limitGH_AW_MAX_TURNSvariable set by the workflow compilerTesting
✅ All 24 tests in
parse_claude_log.test.cjspassing✅ All Go unit tests passing
✅ JavaScript linter clean
✅ Code review completed with no issues
Fixes #[issue-number]
Original prompt
Fixes #2225
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.