perf(server): merged-PR threads no longer re-read git state every minute#24099

open6
main
GitHub fork: fix/pr-sweep-git-reads
opened2d agobyBBatuhan1999
View on GitHubTwo-way sync enabledPR last imported 1d ago

Problem

Merged or closed branch PRs caused warm periodic background lookups to reread git state even when no thread settlement or PR-link update was needed. In a real Linux dev-server fixture with a saved merged PR and automatic merge settlement disabled, each of two minute-spaced PR-sync lookups issued five git operations.

Change

Reuse the reporter's fix: detection lookups may return the cached terminal answer. Settlement checks whether it would act before requesting fresh git state; PR-link persistence retains its fresh-state identity check. Other callers retain terminal confirmation, including worktree cleanup.

Scope and approval

Fixes https://github.com/pingdotgg/t3code/issues/24098 GitCafe: https://git.cafe/pingdotgg/t3code/issues/24098

Triaged bug via the automated issue flow. This updates the existing reporter PR and preserves its commit ancestry. No setting, persisted state, or wire contract is added.

Verification

  • Three regression tests fail on main for the unnecessary git reads; the settlement freshness guard passes before and after.
  • Focused suite: from apps/server, vp test run src/git/GitManager.test.ts src/orchestration-v2/ThreadSettlementService.test.ts src/orchestration-v2/ThreadPullRequestService.test.ts — 140/140 passed on the reviewed implementation.
  • Four persistence cases reject fresh reopened/different/missing PR results and permit the matching merged result. Disabling the guard makes the three stale cases fail.
  • Scoped server typecheck, formatting, and lint passed apart from an existing unused-variable warning outside the changes. Two independent reviewers returned MERGE; proof audit returned SUFFICIENT.
Runtime fixtureBeforeAfter
Saved merged PR, unsettled thread, two completed warm PR-sync lookups about 60 seconds apart5 git operations per lookup0 git operations per lookup

The saved reference and unsettled state were unchanged, with no sync writes in either window. Samples remain inside the existing five-minute git-state TTL. Runtime evidence covers PR sync; deterministic tests cover branch-only settlement and both freshness guards. Visual matrix is empty: server-only changes with no changed render path.

Evidence index, revision provenance, red/green transcripts, runtime extracts, checksums, and reproduction drivers. Environment: Linux; server port 15301, browser/web port 7261. Runtime revision attribution uses reload records, reflog, and production blob correspondence; exact command arguments are labeled as source-derived templates. No platform-specific behavior changed.

Implemented and verified with Claude Opus 5.5 via Claude Code and GPT-6.1 Sol via Codex, running in T3 Code.

Checks

All checks passed

Added 1 commit

  • perf(server): merged-PR threads no longer re-read git state every minute91038c0
Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — This server-side performance change alters recurring settlement and pull-request synchronization paths to skip fresh git reads unless an action is possible. Fresh confirmation remains before settlement or persistence, but the new autonomous work gate spans shared orchestration behavior and merits human review.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between 91038c0093e4a5d77e13edf791cd6e5005a273cf and a1e2f80ed48ee7cb8ce11b8705d596bec619dfab.

External image Files selected for processing: 3
  • apps/server/src/git/GitManager.ts
  • apps/server/src/orchestration-v2/ThreadPullRequestService.test.ts
  • apps/server/src/orchestration-v2/ThreadPullRequestService.ts

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

Walkthrough

Branch pull-request lookups can skip fresh confirmation of cached terminal results. Pull-request discovery uses this option for initial lookups. Thread settlement checks remembered results first and requests fresh Git state when a terminal result would settle the thread.

Changes: Terminal pull-request lookup flow

Layer / File(s)Summary
Terminal lookup confirmation
apps/server/src/git/GitManager.ts, apps/server/src/git/GitManager.test.ts
branchPullRequest adds confirmTerminal. When it is false, terminal results return without a fresh-state lookup. The test covers this path and the default confirmation path.
Pull-request discovery lookup
apps/server/src/orchestration-v2/ThreadPullRequestService.ts, apps/server/src/orchestration-v2/ThreadPullRequestService.test.ts
The initial lookup sets confirmTerminal: false. Tests cover repeated sweeps and verify that a sync write occurs only when a fresh lookup finds the same merged PR.
Settlement lookup decisions
apps/server/src/orchestration-v2/ThreadSettlementService.ts, apps/server/src/orchestration-v2/ThreadSettlementService.test.ts
Settlement checks remembered Git state first. It skips a fresh lookup when a terminal result would not settle the group, and requests fresh state when it would. Tests cover both outcomes.

Priority: External image Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • pingdotgg/t3code#23702 — The PR skips terminal-result confirmation in the periodic discovery lookup. It does not change the GitHub API budget or rate-limit retry behavior described by the issue.

Suggested reviewers: maria-rcks, sunkenintime, t3dotgg

Merge Risk: External image Minimal · up to a1e2f

Cached results avoid unnecessary Git reads, while settlement and sync writes retain fresh-state checks. The change is ready to merge after normal checks.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the main performance change: merged-PR threads no longer reread Git state during periodic server lookups.
Description checkPassedThe description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the issue, implementation, linked issue, focused tests, observed results, limitations…
Linked Issues checkPassedIssue #24098 requires warm background sweeps to use cached terminal branch-PR answers when no action is needed. It requires fresh Git state before settlement or PR-link persistence. `GitManager.branch…
Out of Scope Changes checkPassedThe production changes are limited to terminal-answer confirmation, the settlement sweep, and the PR synchronization sweep named by issue #24098. The tests support these behaviors. No unrelated settin…
Full details: Description check

Explanation

The description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the issue, implementation, linked issue, focused tests, observed results, limitations, and runtime evidence.

Full details: Linked Issues check

Explanation

Issue #24098 requires warm background sweeps to use cached terminal branch-PR answers when no action is needed. It requires fresh Git state before settlement or PR-link persistence. GitManager.branchPullRequest now supports confirmTerminal: false. Settlement uses that option and performs a fresh lookup only when the thread can settle. PR synchronization uses the option for detection and retains its fresh-state check before persistence. The default terminal confirmation remains for other callers. Regression tests cover cached merged results, settlement confirmation, and stale PR-link results.

Full details: Out of Scope Changes check

Explanation

The production changes are limited to terminal-answer confirmation, the settlement sweep, and the PR synchronization sweep named by issue #24098. The tests support these behaviors. No unrelated setting, persisted state, wire contract, settlement rule, link rule, or worktree-cleanup behavior is changed.

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

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

Added 5 commits

  • test(server): reproduce issue 24098 terminal branch PR sweeps rereading git statea403d94
  • perf(server): merged-PR threads no longer re-read git state every minute849e62d
  • test(server): fresh git state gates saving a remembered merged branch PR43cb3e3
  • Merge existing reporter fix into verified issue-24098 branchf6e79b5
  • Merge remote-tracking branch 'origin/main' into fix/issue-24098a1e2f80