fix(#2852): re-stage and retry when pre-commit hooks auto-fix files - #2855
Conversation
Site previewPreview: https://2fd1afab-site.fullsend-ai.workers.dev Commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
E2E tests did not runE2E tests run automatically for org/repo members and collaborators on pull requests. For other contributors, a maintainer must add the See E2E testing guide for details. |
8928c02 to
1674813
Compare
1674813 to
2d85447
Compare
2d85447 to
a6f5a17
Compare
|
/review |
PR Reviewer Guide 🔍Warning
Here are some key observations to aid the review process:
|
When a pre-commit hook auto-fixes files (e.g. gofmt, ruff format, prettier), it exits non-zero but leaves the corrected files as unstaged modifications. Previously, post-code.sh and post-fix.sh treated any non-zero exit as a hard failure, wasting the entire agent run. After a failed pre-commit run, check git diff for unstaged changes. If hooks auto-fixed files, re-stage them, amend the commit, and retry once. If the retry still fails or no unstaged changes exist, exit 1 as before. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Re-run gitleaks secret scan and signed-off-by check after amending the commit with auto-fixed files, closing the bypass window where hooks could inject unscanned content. Scope git-add to only hook-modified files instead of the entire tracked tree. Rebuild the changed file list from merge-base after amend so the retry pre-commit runs on the correct set. Add SYNC cross-reference comments between post-code.sh and post-fix.sh retry blocks. Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
a6f5a17 to
186468d
Compare
waynesun09
left a comment
There was a problem hiding this comment.
LGTM — 4 rounds of multi-agent review (Claude, Gemini, Codex) with 0 verified MEDIUM+ findings remaining.
Round 4 (final): 4 agents, 3 produced findings. All MEDIUM+ findings are false positives, by-design choices, or self-downgraded by the agents after analysis. Key design decisions validated:
- Scoped
git diff/addtochanged_array— security defense against hook file injection - Single-retry cap with residual-unstaged guard — handles non-idempotent hooks correctly
- SYNC comments over shared helper extraction — different variable names make extraction complex
- SCAN_RANGE remains valid after amend —
HEADresolves dynamically
|
🤖 Finished Retro · ✅ Success · Started 9:28 PM UTC · Completed 9:36 PM UTC |
Retro: PR #2855 — pre-commit auto-fix retryTimeline:
Key finding: The code agent solved the functional requirement (retry on auto-fix) but missed that amending a commit in a security-critical post-script reopens the security boundary — requiring re-scanning for secrets, re-validating changed file scope, and guarding against hook file injection. Four rounds of automated review also missed these gaps. Existing issues considered:
1 proposal filed below. Proposals filed
|
When a pre-commit hook auto-fixes files (e.g. gofmt, ruff format, prettier), it exits non-zero but leaves the corrected files as unstaged modifications. Previously, post-code.sh and post-fix.sh treated any non-zero exit as a hard failure, wasting the entire agent run.
After a failed pre-commit run, check git diff for unstaged changes. If hooks auto-fixed files, re-stage them, amend the commit, and retry once. If the retry still fails or no unstaged changes exist, exit 1 as before.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Closes #2852
Post-script verification
agent/2852-precommit-autofix-retry)14b0b41dd016b3af0c10c288978708f4e37a4c2f..HEAD)