Skip to content

fix(github): stop background PR polling once a PR is merged - #25774

Closed
ggbdpq wants to merge 1 commit into
stablyai:mainfrom
ggbdpq:fix/pr-polling-merged-stop
Closed

ggbdpq wants to merge 1 commit into
stablyai:mainfrom
ggbdpq:fix/pr-polling-merged-stop

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

ELI5

Orca keeps asking GitHub about a worktree's PR forever — even after that PR is merged, whose state can never change again. A GitHub Enterprise deployment's administrators flagged the request volume (#25746). This PR stops the background polling the moment a PR is merged; if you refresh manually, activate the worktree, or push to the branch, Orca looks again and resumes polling if there's a live PR to watch.

What Changed

  • The visible follow-up loop in pr-refresh-queue-drainer ends when an outcome resolves to a merged PR (previously it re-scheduled every 30 minutes indefinitely, and any scroll/focus report restarted it sooner).
  • enqueuePRRefresh in pr-refresh-coordinator skips budgeted background reports (visible rows, focus sweeps) for candidates whose cached PR state is merged, so the loop isn't restarted by scrolling around the sidebar.
  • Deliberately unchanged: manual refreshes, worktree activation and post-push refreshes bypass both gates (so a branch that later resolves to a different, open PR resumes polling the moment it's actually looked at); closed (unmerged) PRs keep the existing 30-minute confirmation poll because they can be reopened; no new settings; open PRs' polling frequency is untouched.

Why

A merged PR can never reopen and its checks/reviews are final — every background request for it is pure waste, and the volume scales with worktree count (the exact pattern that got an GHES deployment flagged in the report). Merged vs closed are treated differently on purpose: GitHub forbids reopening a merged PR, so hard-stopping is semantically safe there, while a closed PR can reopen and the existing 30-minute poll is the discovery path.

Linked Issue

Fixes #25746 (the merged-polling behavior — the first of the report's four items). The other three (concurrent same-request dedup, a polling on/off setting, GHES-specific throttling) are deliberately not packed into this PR; happy to take them as follow-ups if the maintainers want them.

Visual Proof

N/A for attached media in this environment (headless run). Behavior is pinned by tests: before the fix a merged candidate was fetched 8 times across a 31-minute simulated window; after the fix the follow-up loop ends at the merged outcome (0 further fetches), background re-reports are skipped instead of re-enqueued, and the closed-PR 30-minute confirmation behavior is pinned unchanged.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Commands actually run locally (macOS): new cases red→green (2 failed / 5 passed before, 7 passed after); 8 adjacent coordinator/queue suites (54 tests); PR client state/visibility/error-classification suites (41 tests); the IPC routing suite (5 tests); the full src/main/github directory 78 files / 802 tests passed; pnpm tc and pnpm run typecheck:node exit 0; oxlint/oxfmt --check clean on the three touched files. Real GitHub/gh traffic was not exercised — the gates are pinned at the coordinator/queue boundary where the fetch count is asserted.

AI Disclosure

Investigation, coding and verification by GLM-5.3-Flash (ZCode agent); orchestrated, reviewed and committed by a main agent with the same model, human overseeing.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Main-process only; the renderer's runtime-environment direct path has no timer self-loop (5-minute freshness gate, event-driven) and is untouched. SSH-connected worktrees go through the same coordinator (refresh keys are connection-scoped), so the stop applies there identically. Backwards compatible: nothing about stored state or wire shapes changes, and any merged worktree resumes normal polling the first time a manual/activation/post-push refresh resolves an open PR on its branch.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The visible follow-up loop kept polling a merged PR every 30 minutes
forever, and every visible-row report or focus sweep restarted it —
its state, checks and reviews are final, so all of those requests were
pure waste against the GitHub host (the volume that got a GitHub
Enterprise deployment's administrators asking questions in stablyai#25746).
The loop now ends when the outcome is merged, and budgeted background
reports skip re-enqueueing a candidate whose cached state is merged.
Manual refreshes, worktree activation and post-push refreshes bypass
both gates, so a branch that later resolves to a different, open PR
resumes polling the moment anyone actually looks at it. Closed PRs
keep the existing 30-minute confirmation poll — they can be reopened.

Generated-by: GLM-5.3-Flash (ZCode)
@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b43989e0-68e7-44dc-8e54-d52764680fd5
📥 Commits

Reviewing files that changed from the base of the PR and between 5f7c848 and d7f9779.

📒 Files selected for processing (3)
  • src/main/github/pr-refresh-coordinator-visible-follow-up.test.ts
  • src/main/github/pr-refresh-coordinator.ts
  • src/main/github/pr-refresh-queue-drainer.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The coordinator skips budgeted background refreshes when the cached PR state is merged. Other refresh reasons continue through the existing queue flow. When a refresh finds a merged PR, the queue drainer resets retry state and stops visible follow-up scheduling. Tests cover closed PR follow-up polling after 30 minutes.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d7f97

This change stops background GitHub polling for merged PRs while keeping manual, activation and post-push refreshes working. Closed, unmerged PRs keep their confirmation poll. No merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to d7f97

The change reduces automatic requests without adding permissions or endpoints. Explicit refresh, activation and post-push refresh remain available. The main remaining uncertainty is how cached merged status is invalidated when a worktree moves to different work.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effect is reduced refresh activity and potentially longer-lived cached PR information for registered repositories. The changed paths do not add a new request destination or increase lookup authority.

Trust Boundaries and Controls

  • observed — Renderer-supplied automatic refresh candidates pass through registered-repository validation before coordinator admission. Repository path, connection, execution host and local Git options are normalized from registered repository configuration rather than accepted unchanged from the candidate. These controls predate the PR and remain in place.

Resilience and Maintainability Implications

  • observed — The drainer removes the consumed queue entry and publishes the lookup outcome before applying the merged terminal state. The terminal branch resets retry state without creating a follow-up entry; upstream-error outcomes retain their existing visible retry path.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #25746 asks Orca to stop polling merged PRs or poll them rarely, reuse an in-flight request for the same branch or PR, and add a global or per-repository background-polling setting. This PR stop… Implement in-flight request reuse for matching branches or PRs, and add a global or per-repository setting to limit or disable background PR polling. Add automated tests for both behaviors.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: stopping background PR polling after a PR is merged.
Description check ✅ Passed The description covers the required sections, links the issue, explains the change and its rationale, and reports testing. It marks visual proof as not applicable and explains why.
Out of Scope Changes check ✅ Passed The coordinator and drainer changes and their tests directly implement the merged-PR polling reduction requested by issue #25746. No unrelated change is evident in the reviewed diff.
Full details: Linked Issues check

Explanation

Issue #25746 asks Orca to stop polling merged PRs or poll them rarely, reuse an in-flight request for the same branch or PR, and add a global or per-repository background-polling setting. This PR stops visible follow-up polling for merged PRs and skips budgeted background reports for cached merged state. Its tests also preserve the 30-minute confirmation poll for closed PRs. The queue removes an entry before its request starts, so a new report can enqueue the same work while that request is in flight; the new report does not reuse the in-flight result. The PR also adds no polling setting. The PR description's decision to defer these requested behaviors does not meet the active issue's remaining coding requirements.

  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

nwparker commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

oh no, looking at this! Thank you for discovering

@ggbdpq

ggbdpq commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #25788 — it covers this issue's behavior and a lot more across the polling surface. No hard feelings about the race: the report went up and two fixes ran, that's how discovery goes. One observation for what it's worth: the piece I'd have watched closest in the new policy model is merged PRs stopping the follow-up loop — on the old code, a test here pinned a merged candidate being re-fetched 8 times across a 31-minute window, so if that regression class ever resurfaces, that's its shape. Thanks for the quick turnaround on the report!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Background PR polling sends excessive GitHub API requests (merged PRs still polled, duplicate concurrent requests)

2 participants