Problem
When a pre-commit hook auto-fixes files (e.g. gofmt, ruff format, prettier), the post-code script treats the non-zero exit code as a hard failure and blocks the PR — even though the hook already produced the correct output. The entire agent run (~11 minutes of compute) is wasted.
Example: Run 28527664156 failed on issue #2783. Every hook passed except gofmt, which auto-formatted the files:
gofmt....................................................................Failed
- hook id: go-fmt
- files were modified by this hook
The reformatted files are sitting in the working tree, ready to be staged. Instead, the script exits 1.
Root cause
post-code.sh lines 308-316 run pre-commit run --files once and exit on any failure, without checking whether the hooks auto-fixed the files:
if pre-commit run --files "${changed_array[@]}"; then
echo "Pre-commit passed — all hooks clean"
else
echo "::error::BLOCKED — pre-commit hooks failed on agent's changes" >&2
exit 1
fi
Proposed fix
After a failed pre-commit run, check git diff for unstaged modifications. If hooks auto-fixed files, re-stage them, amend the commit, and retry once:
if pre-commit run --files "${changed_array[@]}"; then
echo "Pre-commit passed — all hooks clean"
else
if git diff --name-only | grep -q .; then
echo "::warning::Pre-commit hooks auto-fixed files — re-staging and retrying"
git add -u
git commit --amend --no-edit
if pre-commit run --files "${changed_array[@]}"; then
echo "Pre-commit passed after auto-fix re-stage"
else
echo "::error::BLOCKED — pre-commit hooks still fail after auto-fix" >&2
echo "::error::The agent's code does not pass the repo's pre-commit hooks." >&2
echo "::error::Fix the issues and re-run, or update the pre-commit config." >&2
exit 1
fi
else
echo "::error::BLOCKED — pre-commit hooks failed on agent's changes" >&2
echo "::error::The agent's code does not pass the repo's pre-commit hooks." >&2
echo "::error::Fix the issues and re-run, or update the pre-commit config." >&2
exit 1
fi
fi
This is safe because:
- The retry is capped at one attempt — no infinite loops
- Only unstaged modifications from hooks are re-staged (not untracked files)
- The secret scan and all other gates already passed before this point
- If the second run still fails, the script exits 1 as before
Related issues
This fix is the cheap safety net: even if #1865 lands and agents learn to format, the harness should still handle auto-fixing hooks gracefully rather than discarding the work.
Problem
When a pre-commit hook auto-fixes files (e.g.
gofmt,ruff format,prettier), the post-code script treats the non-zero exit code as a hard failure and blocks the PR — even though the hook already produced the correct output. The entire agent run (~11 minutes of compute) is wasted.Example: Run 28527664156 failed on issue #2783. Every hook passed except
gofmt, which auto-formatted the files:The reformatted files are sitting in the working tree, ready to be staged. Instead, the script exits 1.
Root cause
post-code.shlines 308-316 runpre-commit run --filesonce and exit on any failure, without checking whether the hooks auto-fixed the files:Proposed fix
After a failed pre-commit run, check
git difffor unstaged modifications. If hooks auto-fixed files, re-stage them, amend the commit, and retry once:This is safe because:
Related issues
This fix is the cheap safety net: even if #1865 lands and agents learn to format, the harness should still handle auto-fixing hooks gracefully rather than discarding the work.