Skip to content

Fix unbounded auto-retry loop when retry_max_attempts=0 - #48

Merged
kriserickson merged 2 commits into
add-historyfrom
copilot/sub-pr-46-again
Mar 16, 2026
Merged

Fix unbounded auto-retry loop when retry_max_attempts=0#48
kriserickson merged 2 commits into
add-historyfrom
copilot/sub-pr-46-again

Conversation

Copilot AI commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

shouldRetry treated RetryMaxAttempts <= 0 as "unlimited retries," but retry_max_attempts=0 is a valid config value explicitly meaning "disabled." With auto_check_on_error=true, a repeatedly failing command would recurse infinitely through runSession → retrySession until stack/memory exhaustion.

Changes

  • internal/runner/runner.go: Fix shouldRetry condition — replace RetryMaxAttempts <= 0 || RetryCount < RetryMaxAttempts with RetryMaxAttempts > 0 && RetryCount < RetryMaxAttempts so 0 disables auto-retry rather than enabling unbounded retries
// Before — 0 treated as "always retry"
if r.cfg.History.RetryMaxAttempts <= 0 || session.RetryCount < r.cfg.History.RetryMaxAttempts {
    return true
}

// After — 0 means disabled
if r.cfg.History.RetryMaxAttempts > 0 && session.RetryCount < r.cfg.History.RetryMaxAttempts {
    return true
}
  • internal/runner/runner_test.go: Add test case asserting shouldRetry returns false when AutoCheckOnError=true but RetryMaxAttempts=0

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: kriserickson <325934+kriserickson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add history and retry functionality to AI CLI Fix unbounded auto-retry loop when retry_max_attempts=0 Mar 3, 2026
@kriserickson
kriserickson marked this pull request as ready for review March 16, 2026 15:25
Copilot AI review requested due to automatic review settings March 16, 2026 15:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes an infinite auto-retry recursion when history.retry_max_attempts=0 by treating 0 as “auto-retry disabled” (instead of “unlimited”), preventing runaway runSession → retrySession loops under persistent command failures.

Changes:

  • Update Runner.shouldRetry to only auto-retry when RetryMaxAttempts > 0 and the retry count is still below the limit.
  • Add a regression test ensuring shouldRetry returns false when AutoCheckOnError=true but RetryMaxAttempts=0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/runner/runner.go Corrects auto-retry eligibility logic to prevent unbounded retries when max attempts is configured as 0.
internal/runner/runner_test.go Adds coverage for the retry_max_attempts=0 disabling behavior to prevent regressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kriserickson
kriserickson merged commit ad4954e into add-history Mar 16, 2026
7 checks passed
@kriserickson
kriserickson deleted the copilot/sub-pr-46-again branch March 16, 2026 15:28
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.

3 participants