worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

review-pr: cannot dismiss approval on fork PRs, leaving stale approval when CI fails

Open worktrunk-bot opened this issue 8 months ago • 1 comments

Problem

When the review bot approves a cross-repository (fork) PR and CI subsequently fails, the bot cannot dismiss its own approval — GitHub's dismiss API returns HTTP 404 for cross-repo PRs. This leaves a stale "APPROVED" review contradicting red CI, which could mislead a human maintainer into merging.

Evidence

Run: 22847633269 PR: #1404 (cross-repository PR from ruudk/worktrunk) Session log: 89f4d777-42f9-4922-88f5-2c68f1c17509.jsonl

Sequence:

  1. Bot approved commit c9bdb36 at 09:50:45Z
  2. CI failed (cargo fmt formatting issue) — detected at 09:51:55Z
  3. Bot found review ID 3914195581 and called the dismiss endpoint
  4. Got HTTP 404:
    {"message":"Not Found","documentation_url":"https://docs.github.com/rest","status":"404"}
    
  5. Bot correctly identified "likely a permissions issue on fork PRs" and posted a COMMENT review with inline suggestion instead
  6. Stale APPROVED review remained on c9bdb36 until the author pushed a fix (b741d16) and a new run approved that commit

Secondary issue in same session: The bot also hit a 422 when trying to post an inline suggestion using gh api with -f 'comments[0][path]=...' syntax — gh doesn't parse bracket-indexed parameters as JSON arrays. The bot recovered by switching to a JSON payload file, costing 2 extra tool calls.

Impact

  • Stale approval window: Between the CI failure (09:51) and the author's fix commit being approved, the PR showed as "approved" despite failing CI. A maintainer checking at that moment could have merged broken code.
  • Wasted tool calls: The dismiss attempt + array syntax retry cost 3 tool calls that could have been avoided.

Suggested fix

Update the review-pr skill to handle cross-repository PRs:

  1. Detect fork PRs before approving. Add a pre-approval check:

    IS_FORK=$(gh pr view <number> --json isCrossRepository --jq '.isCrossRepository')
    
  2. For fork PRs, defer approval until CI passes. Since the bot can't dismiss on forks, the safer workflow is: post COMMENT review -> monitor CI -> approve only after CI passes. This eliminates the stale-approval window entirely.

  3. Document the gh api array syntax limitation. The skill's inline suggestion example uses -f 'comments[0][...]' syntax, which doesn't work with gh. The JSON payload approach (which the bot discovered on retry) should be the documented pattern.

Scope

This affects all cross-repository PRs reviewed by the bot. In the current codebase, the review-pr skill has no fork-specific logic — it follows the same approve-then-monitor path regardless of PR origin.

worktrunk-bot avatar Mar 09 '26 10:03 worktrunk-bot

Corrected root cause

The dismiss failure is not a fork PR limitation. It's a wrong HTTP method.

Evidence from run 22845135867 — the same fork PR (#1404), same bot, two dismiss attempts back-to-back:

  1. POST (default gh api method): gh api "repos/$REPO/pulls/1404/reviews/3913754420/dismissals" -f message="..." → 404
  2. PUT: gh api "repos/$REPO/pulls/1404/reviews/3913754420/dismissals" -X PUT -f message="..." → Success, state changed to DISMISSED

The GitHub dismiss endpoint requires PUT, not POST. When gh api is called with -f flags but no -X flag, it defaults to POST — which returns 404 on the dismiss endpoint.

In run 22847633269 (the one this issue was filed about), the bot only tried POST and gave up, concluding it was a fork permission issue. But the earlier run on the same fork PR proves PUT works fine.

Fix: Add -X PUT to the dismiss instruction in the review-pr skill (see #1407). PR #1406's deferred-approval approach works as a workaround but adds unnecessary complexity — the simpler fix is using the correct HTTP method.

worktrunk-bot avatar Mar 09 '26 11:03 worktrunk-bot