Skip to content

post-review.sh fails when GitHub API returns 0 changed_files for open PRs #2093

Description

@fullsend-ai-retro

What happened

Review agent was dispatched for PR #753 (a Pipfile.lock-only dependency update) on 2026-06-09 at 19:29 UTC (run 27230566881). The review agent itself completed successfully (exit code 0, valid schema output, ~39 seconds). The post-review script (scripts/post-review.sh) then failed with: Failed to fetch PR files or PR has no changed files — refusing to approve. The same failure recurred on run 27230989001. The PR was still open at the time (merged ~24 minutes later at 19:53 UTC). The GitHub API's changed_files summary field returned 0, triggering the safety guard. This made the entire review workflow report as failed despite the agent producing correct output.

What could go better

The post-review script uses a PR-level summary field (changed_files) to verify that the PR has files before approving. This field can return 0 in edge cases — likely when a merge commit temporarily makes the diff against the base branch empty (the PR branch had just merged main into it at 19:29 UTC). The safety guard is reasonable (preventing blind approvals) but its implementation is brittle. Confidence: high that this is a GitHub API data race — the timing (merge commit pushed at the same time as the review dispatch) strongly correlates. Two out of three review failures in the last 20 runs hit this exact error, suggesting it's not extremely rare.

Proposed change

In scripts/post-review.sh, replace the changed_files summary field check with a paginated call to the /pulls/{pull_number}/files endpoint (e.g., gh api repos/{owner}/{repo}/pulls/{pr}/files --paginate --jq 'length'). The /files endpoint enumerates actual file diffs and is more reliable than the summary field. If the /files endpoint also returns 0 files, add a short retry (e.g., 1 retry after 10 seconds) before failing, to handle transient API data races after merge commits are pushed. Keep the existing safety guard behavior (refuse to approve if truly no files) but make the file enumeration more robust.

Validation criteria

The next 10 review agent runs on PRs that have just received merge commits (rebase/merge from base branch) should not fail with 'Failed to fetch PR files'. Specifically, review runs on lock-file-only bot PRs in konflux-ci/tools should complete without post-review failures.


Generated by retro agent from konflux-ci/tools#753

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/reviewReview agentcomponent/dispatchWorkflow dispatch and triggerspriority/mediumNormal priority, plan for next cycleready-to-codeTriggers code agent dispatchtype/bugConfirmed defect in existing behavior

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions