Skip to main content
Back to Community & Earn Hub
Q&A Questionai-agents +150 pt Bounty

Autonomous Code-Review Agents in CI/CD: How to stop infinite fix-lint-retest loops without disabling auto-commits?

@liam_oconnor3 days ago 1698 views

We wired up an autonomous PR review-and-fix agent in GitHub Actions that inspects failing checks, edits the branch, and pushes a fix commit.

Most of the time it saves engineers 20 minutes of boilerplate cleanup. However, twice this week it got stuck in an expensive loop:

  1. Agent fixes a type error -> breaks a ruff import-sort rule.
  2. CI re-runs -> Agent runs ruff --fix, which accidentally removes an unused import needed by a dynamic mock.patch test.
  3. Unit test fails -> Agent restores the import -> ruff fails again.

Before we knew it, the PR had 14 auto-commits and burned through 400k reasoning tokens.

We still want the agent to push fixes automatically for genuine 1-2 step issues. What deterministic guardrails are teams using to detect and halt these CI agent cycles early?

1 Answers

Community Answers

@aditya_verma Accepted Answer3 days ago

You need three deterministic circuit-breakers in your CI wrapper outside the LLM prompt—never rely on the model to notice it's looping.


1. Tree-Hash Cycle Detection (Stop Ping-Pong Immediately)

Before allowing the agent to push a commit, compute the git rev-parse HEAD^{tree} (or patch SHA) against a sliding history of trees already seen on that PR. If the agent recreates a tree hash it already produced 2 commits ago, abort immediately and label the PR agent-needs-human.

bash
# In your CI fix wrapper before git push:
NEW_TREE=$(git write-tree)
if git log -n 10 --format="%T" | grep -qx "$NEW_TREE"; then
  echo "Cycle detected: agent reverted to a previous tree state. Halting."
  exit 0
fi

2. Hard Per-PR Budget + Deterministic Pre-Push Gate

  • Cap consecutive bot commits: Check git log -n 3 --format="%ae" — if the last 3 commits on the PR were all authored by ci-agent[bot], refuse to run again until a human pushes a commit.
  • Run fast checks inside the agent sandbox before pushing: Have the agent execute ruff check && pytest -q locally inside its runner before git push. That turns a 14-commit GitHub Actions storm into a single bounded 3-turn local loop with a strict max_turns=3 cap.

Have a solution or working configuration?

Sign in or create a free account to answer this question (+10 pts, +25 pts if accepted) and tag helpful AIStoreHub repositories.