Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): PR watches spend ~90% fewer GitHub points by checking a 1-point fingerprint first #16270

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/16270/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Every 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 PRBeforeAfter
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

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

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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).
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: fc4ecc8 · PR result: 6748ce9 · Source CI: success

      Scenario 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.

    5. Review in Change Stack →

      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.ts
      • apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
      • apps/server/src/orchestration-v2/runtimeLayer.test.ts
      • apps/server/src/pullRequest/GitHubPullRequestCli.test.ts
      • apps/server/src/pullRequest/GitHubPullRequestCli.ts
      • apps/server/src/pullRequest/GitHubPullRequestProvider.ts
      • apps/server/src/pullRequest/PullRequestProvider.ts
      • apps/server/src/pullRequest/PullRequestService.ts
      • apps/server/src/pullRequest/gitHubPullRequestJson.test.ts
      • apps/server/src/pullRequest/gitHubPullRequestJson.ts
      • apps/server/src/sourceControl/GitHubCli.ts
      • docs/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.ts
      The 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.ts
      The 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.md
      The 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.ts
      The rate-limit error detail directs GraphQL quota checks to a GraphQL query and identifies gh api rate_limit as 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 activity

      Suggested reviewers: bil0000, juliusmarminge

      Merge Risk: ⚪ Minimal · up to 6748c

      No issue requiring a fix before merge was established; normal validation remains appropriate.

      🚥 Pre-merge checks | ✅ 3 | ❌ 2

      ❌ Failed checks (2 warnings)

      Check nameStatusExplanationResolution
      Description check⚠️ WarningThe 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⚠️ WarningDocstring 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 nameStatusExplanation
      Title check✅ PassedThe 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✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck 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.

Sign in to join this conversation.