Skip to content

fix(ci): review loop stalls on pending and stale re-trigger starts a duplicate round #1621

Done

Description

@chaodu-agent

Summary

The automated PR review loop can stall with OpenAB PR Review stuck at pending, and the stale-pending re-trigger then opens a second, parallel review round on the same head SHA. Observed on #1616 at c8fb31c56818c9d9271d1561b744461f347c3c34.

What happened (#1616, 2026-11-24, UTC)

  1. 16:44 - the pull_request run of PR Review (Scheduled) set pending and sent the review webhook. The coordinator agent started round 3 and asked the reviewer agents for reports.
  2. Only some reviewers reported. The coordinator followed its rule to ask once more and then said it would publish "when the next message arrives". The coordinator is event-driven, so it only acts when a new message arrives. No further message came, so it never published and the status stayed pending.
  3. 17:32 - the scheduled poller found the status pending for 2815 s (> 30 min), treated it as stale, set pending again and re-sent the webhook (PR #1616: pending stale (2815s > 30m), re-triggering). A second coordinator session started another round 3 on the same SHA while the first one was still waiting.
  4. Both sessions are now idle, waiting for reviewer messages. If both resume, the PR could get two consolidated comments carrying the same round key, which the review spec forbids.

The PR's own diff and CI are fine. All checks pass. The problem is only in the review orchestration.

Root causes

1. The coordinator does not treat the watchdog poke as its deadline

The coordinator agent cannot schedule its own timer; it only wakes on a new message. The outer layer for this is an external watchdog agent that pokes a review thread after it has been pending for about 30 minutes. In this case the poke arrived at 17:21, but the coordinator answered by asking the missing reviewers again and saying it would publish on the next message. It should have published right away with the reports it had, because the poke is the only deadline signal it gets.

2. The stale re-trigger cannot tell a stalled round from one still in progress

.github/workflows/pr-bot-review.yml:100-112 re-triggers any pending status older than 30 minutes. That is meant to recover from a lost webhook or a crashed run. It cannot tell those cases apart from a coordinator that is alive and still waiting for reviewers, so it starts a duplicate round.

Refreshing pending as a heartbeat would not fix this on its own. The circuit breaker at pr-bot-review.yml:147-163 counts every pending status across the PR's commits and adds review-limit-reached at 30, so heartbeats would trip it.

Proposed fixes

  1. Publish on the watchdog poke. When the watchdog pokes a pending review thread, the coordinator publishes immediately with the reports it has and lists the reviewers that did not report. It must not send another reminder and wait. No self-scheduled timer is needed.

  2. Round ownership check before re-triggering (poller). Decide by the creator of the latest OpenAB PR Review status on the head SHA:

    Latest status Meaning Poller action
    none, or error Never reviewed, or the trigger failed Trigger (unchanged)
    pending by github-actions[bot], older than 30 min Webhook sent, but no coordinator took ownership Re-trigger (unchanged)
    pending by chaodu-agent A coordinator owns an active round Do not re-trigger. Only re-trigger after a long hard timeout (for example 2 h) to recover from a crashed coordinator
    success or failure Round finished Skip (unchanged)

    The jq filter at pr-bot-review.yml:100-112 only needs to also select .creator.login and branch on it. If the coordinator crashes before writing its own pending, only the bot's pending exists and the existing 30-minute re-trigger still applies, which is correct because no round is running.

  3. Idempotent start (coordinator). On every trigger, before delegating, the coordinator reads the latest OpenAB PR Review status for the SHA:

    • If it is a pending written by chaodu-agent, another round already owns this SHA. Reply in the new thread that a round is already in progress, and stop. Do not delegate, publish, or write status.
    • Otherwise, reconcile review keys as today, write its own pending first (this is the ownership marker), and only then delegate.

    The existing publish-time check (re-read keyed comments and never post a second comment for the same key) stays. It only prevents duplicates at the moment of publishing, so fixes 2 and 3 are still needed to stop two rounds from waiting on reviewers in parallel.

  4. Circuit breaker. Count review triggers, not every pending write, so the coordinator's own pending writes do not use up the budget.

Fix 1 stops the stall; fixes 2 and 3 stop the duplicate round (fix 2 prevents the second trigger, fix 3 makes a second trigger harmless). Today the watchdog poke and the 30-minute stale window are about the same length and race. With fix 2 the stale window no longer applies to coordinator-owned rounds, so that race goes away. Fix 4 is hardening.

Decision flow

Poller (fix 2)

flowchart TD
    A["Open PR, head SHA"] --> B{"Latest OpenAB PR Review status"}
    B -->|"none or error"| T["Trigger review"]
    B -->|"success or failure"| S["Skip: round finished"]
    B -->|"pending"| C{"Who wrote it?"}
    C -->|"github-actions[bot]"| D{"Older than 30 min?"}
    D -->|"no"| W["Skip: webhook just sent"]
    D -->|"yes"| T2["Re-trigger: no coordinator took ownership"]
    C -->|"chaodu-agent"| E{"Older than hard timeout, e.g. 2 h?"}
    E -->|"no"| O["Skip: coordinator owns an active round"]
    E -->|"yes"| T3["Re-trigger: coordinator presumed crashed"]
Loading

Coordinator (fixes 1 and 3)

flowchart TD
    M["Trigger message arrives"] --> P{"Latest status is pending by chaodu-agent?"}
    P -->|"yes"| X["Reply: round already in progress. Stop, no writes"]
    P -->|"no"| K["Reconcile review keys"]
    K --> Q["Write own pending: ownership marker"]
    Q --> R["Delegate to reviewers"]
    R --> N{"Next event"}
    N -->|"all reviewers reported"| PUB["Publish aggregate and final status"]
    N -->|"watchdog poke"| PUB2["Publish now with reports received, list missing reviewers"]
    N -->|"partial report"| N
    PUB --> PCHK{"Comment with same key already exists?"}
    PUB2 --> PCHK
    PCHK -->|"yes"| FIN["Only repair status and cleanup"]
    PCHK -->|"no"| POST["Post comment, then final status"]
Loading

#1616 timeline: observed vs. with fixes

sequenceDiagram
    participant P as Poller
    participant G as GitHub status
    participant A as Coordinator session A
    participant B as Coordinator session B
    participant W as Watchdog

    P->>G: 16:44 pending (github-actions[bot])
    P->>A: webhook
    A->>G: 16:45 pending (chaodu-agent)
    A->>A: delegate, partial reports
    W->>A: 17:21 poke
    Note over A: Observed: asks reviewers again, waits forever
    Note over A: With fix 1: publishes now, final status
    P->>G: 17:32 reads latest status
    Note over P: Observed: pending > 30 min, re-trigger
    P->>B: webhook (observed only)
    Note over B: Observed: second round 3 on same SHA
    Note over P: With fix 2: pending by chaodu-agent, skip
    Note over B: With fix 3: sees pending by chaodu-agent, stops
Loading

Acceptance criteria

  • A review round where no reviewer replies reaches a final success/failure status as soon as the watchdog pokes, before the poller's stale window expires.
  • A coordinator that is still waiting for reviewers does not trigger a second round on the same SHA.
  • No PR ends up with two consolidated comments carrying the same review key.
  • The circuit breaker still trips on real re-trigger loops.

Related

Activity

  1. added
    bug
    on Nov 24, 2026
  2. added
    p1
    on Nov 24, 2026
  3. github-actions commented on Nov 24, 2026

    @github-actions

    ⚠️ This issue is missing the following required information and will not be processed until completed:

    • Steps to Reproduce
    • Expected Behavior

    Please edit this issue to fill in the missing fields. Thank you!

    Tip: Use headings like ## Description or ### Description — common synonyms (e.g. ## Problem, ## Reproduction, ## Motivation) are also accepted.

  4. added a commit that references this issue on Nov 25, 2026
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

    bugincompleteneeds-triagep1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions