Skip to content

Enhanced PR Rescue: resolve threads + request reviews + rebase behind-main #116

@microsasa

Description

@microsasa

Enhanced PR Rescue Workflow

Problem

Agent PRs can get stuck at multiple stages of the pipeline. Current rescue only handles "behind main." Need to unstick PRs at any stage, prioritize ones closest to merging, and run regularly.

Triggers

  • push: branches: [main] — fires when a PR merges, immediately rescues others
  • schedule: cron: '*/15 * * * *' — catches anything stuck between merges
  • workflow_dispatch — manual trigger

Scope

Only processes aw-labeled PRs with auto-merge enabled. PRs without auto-merge or without the aw label are ignored.

Processing Order

Process PRs closest to merging first. For each PR:

Check 1: No Copilot review

  • Condition: Zero reviews from copilot-pull-request-reviewer
  • Action: gh pr edit --add-reviewer @copilot
  • Then: Stop processing this PR. Let Copilot review, quality-gate, approval flow run. Next rescue cycle picks it up if stuck again.

Check 2: Unresolved threads

  • Condition: Has unresolved review threads
  • Action:
    1. Query real thread IDs via gh api graphql (not hallucinated)
    2. For each unresolved thread, check:
      • Has a reply from github-actions[bot] (responder addressed it)
      • AND isOutdated: true (referenced code changed, fix was applied)
    3. If both: resolve the thread
    4. If not: leave it (not addressed, needs human attention)
  • Then: If any threads still unresolved after this pass, stop processing this PR. Otherwise continue.

Check 3: Behind main

  • Condition: Approved + all threads resolved + merge state is BEHIND
  • Action:
    1. Rebase onto latest main
    2. Push (force-with-lease)
    3. Remove review-response-attempted label so responder can run again on any new Copilot comments from the re-review
  • Then: CI reruns, approval survives (dismiss_stale_reviews: false), auto-merge fires.

Error Handling

  • Each PR is independent — one failure doesn't abort the loop
  • git fetch, git checkout, git push wrapped in error guards
  • git rebase --abort guarded with || true
  • cancel-in-progress: false — don't kill mid-rebase

Edge Cases

  • Copilot doesn't review after request: Harmless. Next rescue cycle will see it's still missing and skip (already requested, Copilot is in requested reviewers).
  • Thread resolved but not outdated: Not safe to auto-resolve. Could be a reply saying "I disagree" without a code change. Leave it.
  • Rescue runs while responder is in progress: Resolve calls succeed or fail harmlessly. Responder's later resolve fails (already resolved). No conflict.
  • New Copilot comments after rebase: review-response-attempted label removed, so responder runs again. If responder hallucinates IDs again, next rescue cycle resolves them.

No Permission Changes Needed

All API calls use GH_AW_WRITE_TOKEN which already has write access.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions