Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): PR sync stops reading pull requests closed over a day ago #30071

Mergedadvaitpaliwal(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/30071/headmerged by maria-rcks View on GitHub

The PR sync sweep never stops polling a closed pull request on an unsettled thread. This is a small, focused fix for that bug, so I'm submitting it without a prior issue.

Problem

The sweep stops reading an unsettled thread's link once the PR is merged and has a mergedAt. There's no equivalent stop for a closed PR, so every closed link on an unsettled thread is read from the host every 15 minutes for as long as the thread stays unsettled.

On a 0.1.2 server with 2,187 threads, the links on unsettled threads were 105 closed, 208 merged and 3 open. The server's trace files each cover 3–10 minutes, and each showed about 108 PullRequestSyncReactor.syncGroup spans. Each span made one GitHubPullRequestApi.getPullRequestSummary call. In one ~4 MB slice, those 108 syncGroups took 415 s in total (max 8.5 s each). PullRequestService.persistedRead accounted for 369 s and PullRequestReadCache.get for 342 s. This work shares the event loop with synchronous SQLite (see #30065) and added to stalls that made T3 Connect report "reconnecting".

Change

isDue now treats a closed snapshot as final once its closedAt is at least a day old, the same way it already treats merged with mergedAt. Three things still read such a link immediately, so a reopened PR is picked up:

  • a requested sync
  • a reader or gh lookup that sees the PR's state change
  • the refresh after a merge or close command

A closed link with no closedAt, or one closed within the last day, keeps the 15-minute cadence. Settled threads are unaffected, because isDue already skips them.

Verification

  • New test: "stops reading a pull request a day after it closed, until a refresh asks". One unsettled thread has 4 closed links: closed 8 days ago, closed 2.5 days ago, closed 1 hour ago, and one with no closedAt. Over 16 sweeps, only the recent link and the one with no closedAt are read. A requestSync on the 8-day-old link then reads it once. Against the unchanged reactor the test fails (1 failed, 52 passed). With this change the file passes 53/53.
  • Checks: tsc --noEmit (apps/server), vp lint and vp fmt are clean.
  • Full apps/server suite: 10 of 6,364 tests failed. All 10 also fail on unmodified main on this macOS machine, and none of them involves PR sync. They are browser, npm-prefix and home-path environment tests.
  • Not checked: running a patched build on the affected install.

Related: #17799 and #17800, where pull requests GitHub can't find are read every sweep. That PR touches the same function, so whichever of the two lands second needs a small rebase, but the logic doesn't conflict. Also #24098, where merged or closed branch PRs re-read git state every minute. That goes through a different path and this change doesn't fix it.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — Automatic synchronization will stop reading PRs closed for at least 24 hours, while explicit refresh remains available. Human review is required for this default-behavior change and its tradeoff between fewer requests and potentially stale reopened-PR status.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Walkthrough

      The sync reactor treats closed pull requests at least 24 hours old as final during scheduled due checks. Close-command completion and terminal-run handling now request refreshes for open and closed links.

      Changes: Pull request sync behavior

      Layer / File(s)Summary
      Closed pull request finality and scheduled reads
      apps/server/src/orchestration-v2/PullRequestSyncReactor.ts, apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
      The due check treats merged snapshots with a merge time and closed snapshots at least 24 hours old as final. Tests cover scheduled sweeps, recent or undated closed links, and explicit sync requests.
      Refresh unmerged links after commands
      apps/server/src/orchestration-v2/PullRequestSyncReactor.ts, apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
      Close-command completion and terminal-run handling request refreshes for open and closed links. Tests verify that a merge command syncs merged state for initially open and closed links.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Possibly related issues

      • pingdotgg/t3code#24098: The issue reports recurring costs for closed or merged branch pull requests. This change reduces scheduled reads for old closed pull requests, but does not change the branch lookup path described in the issue.

      Suggested labels: bugfix

      Suggested reviewers: t3dotgg, realdoc06, macroscopeapp

      Merge Risk: Minimal · up to cbb81

      Old closed pull requests stop being polled but remain eligible for requested refreshes. No merge-blocking issue was identified.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title is concise, conventional, and clearly identifies the main change: stopping polling for pull requests closed over one day ago.
      Description checkPassedThe description covers the problem, implementation, scope rationale, verification results, known failures, and related work. It provides sufficient detail even though the Scope and approval heading is…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description covers the problem, implementation, scope rationale, verification results, known failures, and related work. It provides sufficient detail even though the Scope and approval heading is not included explicitly.

      Finishing Touches
      Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      CodeRabbit Verify

      • Run CodeRabbit Verify to test the changes in this pull request.
      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 2cb1c45fae44896115db07c1996270cc5dfeaaa6 and cbb81afc7953c57baa618362c55cfd77dfa68d97.

      Files selected for processing: 2
      • apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
      • apps/server/src/orchestration-v2/PullRequestSyncReactor.ts

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

      • Fix comments: Fix CodeRabbit comments on this PR
    4. Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified cbb81afc7953c57baa618362c55cfd77dfa68d97 on linux with the real dev server, repo playwright, google chrome, and codex gpt-6.1-sol turns. the project and thread were created through the client; links used real host data.

      • reproduced on github/main: the sweep read an unsettled thread's old closed pr, recent closed pr, and open pr. the original pr head skipped the old closed link, preserving the other two. merged links stayed excluded.
      • found and fixed command refresh excluding closed snapshots. a real codex timeout 30 gh pr close --help command triggered the normal command-end and run-end paths without changing any remote pr. both now read all three unmerged links, compared with only the open link before the fix.
      • opened the old closed pr in the client's native panel and clicked refresh. the server performed a requested read despite the scheduled cutoff.
      • blacksmith check:changed passed formatting, lint, knip, graphql, affected typechecks, and 55 tests. the added old-closed command-refresh case failed before the fix. both independent reviews approved this head. github ci is green on this head.

      server command transcript

      old closed pr refresh through the running web client

      Not verified

      native ios/android, electron shell behavior, macos/windows, tunnel or multi-device connections, and non-codex providers. no remote pr was closed, reopened, or merged; the command integration used help only. no full 24-hour wait or production latency claim.

    5. One question on the reopen side of the tradeoff Macroscope flagged, now that the close-command refresh also covers closed links.

      A closed PR can come back two ways that this change no longer catches:

      1. From the agent's shell. GitHub's changeRequestCloseCommand is /\bgh\s+(?:pr\s+(?:merge|close)|stack\s+merge)\b/u (definition.ts#L123), so gh pr reopen 7 on a link that closed more than a day ago doesn't reach refreshUnmergedLinks (PullRequestSyncReactor.ts#L632).
      2. On the host's web UI. Nothing in the sweep reads the link again once isFinal holds (L357-L362).

      In both cases the stored snapshot stays closed. If that PR is later merged on github.com, I think the thread won't auto-settle until something else (a watch, or someone opening the PR panel) happens to read it. Before this change, the 15-minute sweep caught it. Am I missing another path that picks this up?

      If not, would a slow cadence for old closed links (say once every 24h instead of never) keep most of the savings? On the install in the description, that's about 105 reads a day instead of about 10k (105 links × 96 sweeps), and it puts a bound on how stale a reopened PR can get. Matching reopen in the command patterns would also cover the shell case.

    6. maria-rcks merged thisffa39e2

    7. maria-rcks closed this

Sign in to join this conversation.