perf(server): PR watches spend ~90% fewer GitHub points by checking a 1-point fingerprint first #16270
main fromrefs/pull/16270/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubEvery machine on one GitHub account shares one GraphQL quota of 5,000 points an hour, and PR watching was the largest spender. A watch pass reads the PR's detail (1 point) and activity (15 points, 11 of them for review threads × comments) every two minutes while checks run. One PR under CI cost about 480 points an hour, so a handful of busy PRs across the fleet could use the whole quota.
Now each pass first sends one batched "did anything change?" read for every watched PR on the host. It costs 1 point for up to 25 PRs (measured with rateLimit(dryRun: true)). The watch then reads only what moved:
- The status part (state, mergeability, head commit, check counts by state) moving reads the detail, 1 point. While a check is still running, the detail is read every pass as before: counts by state cannot tell which check finished.
- Before any read made with a fingerprint, the PR's cached reads are dropped (without signaling clients), so a read cannot answer from before the fingerprint it is recorded against.
- The remarks part (comment, review, and thread counts, plus the newest edit on comments and reviews) moving also reads the activity, 15 points. A reply in a review thread is a new review, so it moves this too.
- The activity is read every 30 minutes regardless, because edits to comments inside review threads leave no trace in the fingerprint. Detecting those would cost a point per PR per pass.
- A rate-limited fingerprint skips the pass. A PR with no fingerprint answer falls back to today's snapshot-gated reads, which still count failures toward giving up.
- Hosts without a fingerprint (GitLab, Azure DevOps, Bitbucket, Forgejo) keep today's behavior.
| Watched PR | Before | After |
|---|---|---|
| Checks running | ~480 points/hour | ~30 points/hour for the detail, a shared 1-point fingerprint per pass, and 15 per new comment |
| Quiet | ~96 points/hour (10-minute reread) | ~32 points/hour (30-minute reread) plus the shared fingerprint |
Wakes arrive on the same two-minute cadence as before. Verified live today:
- An issue-comment edit (how bots rewrite their summaries, #15415) moves
lastEditedAt. - A thread reply creates a review.
- The real query and decoder return correct fingerprints for live PRs.
Also: T3's rate-limit error now points at gh api graphql -f query='{rateLimit{remaining resetAt}}'. gh api rate_limit showed 30 GraphQL points used at a moment when GraphQL's own rateLimit reported 1,307, so it sent agents to the wrong number.
Considered and left out:
- Pacing in the budget: reads from the client UI and from background reactors are not told apart, so pacing would slow the UI.
- A slimmer activity query: the same query serves the PR page, which #13841 addresses.
- REST ETags for sync: sync summaries already cost 1 point per 25 PRs per minute.
- Slower branch-PR discovery: it would delay PRs opened outside T3.
Tests:
- The new reactor test fails on the old reactor (6 detail + 6 activity reads against 1 + 1).
- Decoder and builder tests, plus a CLI test that two reads share one request.
Reviewed with sol-loop: 3 rounds with GPT-6.1 Sol on high.
Created with Claude Opus 5.5 in Claude Code.
- 1
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/pullRequest/gitHubPullRequestJson.ts lines 2010 to 2010OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1993,3 +1993,18 @@19931993 return Result.succeed(summaries);19941994 }199519951996+const WATCH_FINGERPRINT_EDITS = "totalCount nodes { lastEditedAt }";1997+const WATCH_FINGERPRINT_CHECK_COUNTS =1998+ "checkRunCountsByState { state count } statusContextCountsByState { state count }";1999+2000+/**2001+ * What a pull request watch needs to notice, priced by GitHub at one point for twenty-five pull2002+ * requests, where the detail and activity reads it gates cost sixteen for one. Counts and the2003+ * newest edit cover new comments, reviews (a reply in a review thread is a review), threads, and2004+ * a bot rewriting its summary; check counts by state move whenever a check starts or finishes.2005+ * Edits to comments inside review threads are not covered: asking for those costs a point for2006+ * each pull request.2007+ */2008+const PULL_REQUEST_WATCH_FINGERPRINT_SELECTION =2009+ "state mergeable headRefOid " +2010+ `comments(last: 100) { ${WATCH_FINGERPRINT_EDITS} } ` +
🟡 Medium
pullRequest/gitHubPullRequestJson.ts:2010Edits to issue comments beyond the first 100 are invisible to
remarks, soplanReadskips the activity read and the watcher stays asleep until the 30-minute fallback.comments(last: 100)has no ordering, so its page is not guaranteed to contain the newest edit across the connection; request the newest comment withorderBy: UPDATED_ATinstead.Suggested change2010- `comments(last: 100) { ${WATCH_FINGERPRINT_EDITS} } ` +2010+ `comments(last: 1, orderBy: { field: UPDATED_AT, direction: DESC }) { ${WATCH_FINGERPRINT_EDITS} } `🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/pullRequest/gitHubPullRequestJson.ts around line 2010: Edits to issue comments beyond the first 100 are invisible to `remarks`, so `planRead` skips the activity read and the watcher stays asleep until the 30-minute fallback. `comments(last: 100)` has no ordering, so its page is not guaranteed to contain the newest edit across the connection; request the newest comment with `orderBy: UPDATED_AT` instead.Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Fixed in 6748ce93a8, slightly differently. Comments are now
first: 100ordered byUPDATED_ATdescending. An edit always movesupdatedAt, so an edit to any comment on a long PR lands in that page.last: 1would miss it when a reaction, which also movesupdatedAt, lands on another comment in the same pass. Still 1 point for 25 PRs, verified withrateLimit(dryRun: true).Reviews have no
orderBy, so an edit to a review older than the last 100 still waits for the 30-minute full read. The comment above the selection now says so. Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR changes the default GitHub pull-request watch behavior by adding batched fingerprinting, cache invalidation, and conditional detail/activity reads that affect when agents are woken. It also adds a directive suppressing a static-analysis diagnostic, so the change requires human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
fc4ecc8· PR result:6748ce9· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Team
- Run ID:
c42be8a6-de67-435b-bf1a-28ca4a216848
📥 Commits
Reviewing files that changed from the base of the PR and between fc4ecc835e6d54eb411c333d737f2c4881884338 and 6748ce93a82f6f93475b72fdc450e78294a1f02f.
📒 Files selected for processing (12)
apps/server/src/git/GitManager.test.tsapps/server/src/orchestration-v2/PullRequestWatchReactor.tsapps/server/src/orchestration-v2/runtimeLayer.test.tsapps/server/src/pullRequest/GitHubPullRequestCli.test.tsapps/server/src/pullRequest/GitHubPullRequestCli.tsapps/server/src/pullRequest/GitHubPullRequestProvider.tsapps/server/src/pullRequest/PullRequestProvider.tsapps/server/src/pullRequest/PullRequestService.tsapps/server/src/pullRequest/gitHubPullRequestJson.test.tsapps/server/src/pullRequest/gitHubPullRequestJson.tsapps/server/src/sourceControl/GitHubCli.tsdocs/user/source-control.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Walkthrough#
Pull request watching now uses optional GitHub fingerprints to plan detail and activity reads separately. GitHub fingerprint requests are batched, and the reactor tracks read completeness and fingerprint state. Rate-limit guidance distinguishes GraphQL quota checks from REST quota information.
Changes#
Fingerprint-based pull request watching
Layer / File(s) Summary Fingerprint contract and GraphQL decoding
apps/server/src/pullRequest/PullRequestProvider.ts,apps/server/src/pullRequest/gitHubPullRequestJson.ts,apps/server/src/pullRequest/gitHubPullRequestJson.test.tsThe provider fingerprint separates status and remarks. The GraphQL query builder and decoder create fingerprints from pull request state, checks, comments, reviews, and thread data. Tests cover aliases, invalid selectors, changed fingerprint values, and missing pull requests. Batched fingerprint provider and service
apps/server/src/pullRequest/GitHubPullRequestCli.ts,apps/server/src/pullRequest/GitHubPullRequestProvider.ts,apps/server/src/pullRequest/PullRequestService.ts,apps/server/src/pullRequest/GitHubPullRequestCli.test.tsThe CLI batches fingerprint requests by host and credential scope. The provider and service expose the read, and the service caches successful and null results. The CLI test checks a batched request and a missing pull request. Fingerprint-aware watch read planning
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts,apps/server/src/orchestration-v2/runtimeLayer.test.ts,docs/user/source-control.mdThe reactor uses fingerprints to decide whether to read detail, activity, or both. It handles rate limits and other lookup failures, updates saved read state, and retains a 30-minute activity reread interval. Tests cover polling behavior, and the documentation describes the changed polling flow. GraphQL quota guidance
Layer / File(s) Summary Rate-limit error guidance
apps/server/src/sourceControl/GitHubCli.ts,apps/server/src/git/GitManager.test.tsThe rate-limit error detail directs GraphQL quota checks to a GraphQL query and identifies gh api rate_limitas the REST quota endpoint. The test expectation reflects the guidance.Priority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Refactor
Sequence Diagram(s)#
sequenceDiagram participant PullRequestWatchReactor participant PullRequestService participant GitHubPullRequestProvider participant GitHubPullRequestCli participant GitHubGraphQL PullRequestWatchReactor->>PullRequestService: request watch fingerprint PullRequestService->>GitHubPullRequestProvider: getChangeRequestWatchFingerprint GitHubPullRequestProvider->>GitHubPullRequestCli: getPullRequestWatchFingerprint GitHubPullRequestCli->>GitHubGraphQL: query batched fingerprints GitHubGraphQL-->>GitHubPullRequestCli: return fingerprint results GitHubPullRequestCli-->>PullRequestWatchReactor: return fingerprint or null PullRequestWatchReactor->>PullRequestService: read planned detail and activitySuggested reviewers:
bil0000,juliusmarmingeMerge Risk: ⚪ Minimal · up to
6748cNo issue requiring a fix before merge was established; normal validation remains appropriate.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)#
Check name Status Explanation Resolution Description check ⚠️ Warning The description explains the problem, implementation, trade-offs, and verification in detail. It does not provide the scope approval required by the template: a triaged issue or discussion with explic… Add a link to the triaged issue or discussion and identify the maintainer's explicit approval of the direction and scope. If no prior approval exists, explain why this behavior change qualifies as a small, focused fix of an obvious bug with… Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 11 files. (1 skipped: … 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 identifies the main change: reducing GitHub API usage for PR watches through a 1-point fingerprint check. It is specific and relevant, though somewhat long. Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Full details: Description check
Explanation
The description explains the problem, implementation, trade-offs, and verification in detail. It does not provide the scope approval required by the template: a triaged issue or discussion with explicit maintainer approval, or a reason this behavior change qualifies as a small, focused fix that needs no prior approval.
Resolution
Add a link to the triaged issue or discussion and identify the maintainer's explicit approval of the direction and scope. If no prior approval exists, explain why this behavior change qualifies as a small, focused fix of an obvious bug without it; otherwise, obtain approval and document it.
Full details: Docstring Coverage
Explanation
Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 11 files. (1 skipped: 1 unsupported.)
- Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
🧰 Additional context used
📚 Code guidelines (2)
docs/internals/effect-services.md — auto-discovered AGENTS.md — auto-discovered
Comment `@coderabbitai help` to get the list of available commands.t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed