Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): PR cache invalidation no longer waits on other projects' reads (1,163 ms → 0.12 ms median) #30293

MergedYuruzuu(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/30293/headmerged by maria-rcks View on GitHub

Problem

Invalidating one PR's cached reads waits for every PR read in flight, in every project. That includes the invalidation after each turn, before each watch read, and around each PR action. One slow host read in another project held them all for the length of its network call.

Change

PullRequestReadCache.invalidate took all 512 permits of the semaphore that every get holds one permit of for its whole lookup. The exclusion exists because a read stores its result under the scope revisions it started with. If an invalidation of one of its scopes landed mid-read, that stale result could be served once the new revision expired.

Now scopes hash to 64 lock stripes:

  • A get takes one permit on each of its scopes' stripes, in sorted order, inside the existing 512-read cap.
  • invalidate takes the whole stripe for its scope only, then a separate one-permit lock that serializes revision-file writes.
  • The writer never waits on a stripe while holding that lock, so this cannot deadlock.

Same-scope reads are still excluded, so stale in-flight results are still rejected. Unrelated scopes wait only on a 1-in-64 stripe collision.

This is server-only and provider-independent, and every client benefits.

Scope and approval

This qualifies for the small, focused bug-fix exception in CONTRIBUTING.md. Work waiting on unrelated work is an obvious performance defect. There is no feature, product default, or contract change.

Verification

Benchmark: the real PullRequestReadCache.make with in-memory backing. A read for project:other runs a live gh api repos/pingdotgg/t3code/pulls/26011 call (about 1.1 s) while invalidate("project:target") is timed. main and this branch ran 7 times each, alternating which went first.

main medianThis branch median
Invalidation during an unrelated read1,163 ms0.12 ms
Invalidation with nothing in flight0.67 ms0.69 ms

Test: PullRequestReadCache.test.ts › clears in-flight reads before a new service can reuse them now also asserts two things while this PR's read is in flight. Another PR's invalidation completes, and this PR's invalidation is still waiting. It hangs on main. All 12 tests in the file pass, including restart, cancellation and corrupt-revision cases. vp run check:changed passes.

Not checked: how often stripe collisions happen with real scope names under load.

Split from #30288.

Made with Claude Opus 5.5 via Claude Code in T3 Code, from an audit by GPT-6.1 Sol via Codex.

🤖 Generated with Claude Code

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

    2. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Walkthrough

      PullRequestReadCache now coordinates reads and invalidations with 64 scope stripes. Reads acquire permits for distinct stripes in sorted order. Invalidation acquires all permits for its scope’s stripe, and revision writes use a separate semaphore.

      Changes: Pull request cache coordination

      Layer / File(s)Summary
      Stripe-scoped read and invalidation coordination
      apps/server/src/pullRequest/PullRequestReadCache.ts, apps/server/src/pullRequest/PullRequestReadCache.test.ts
      Reads acquire permits for distinct scope stripes in sorted order. Invalidation acquires all permits for its scope’s stripe, while revision writes are serialized separately. The test checks unrelated-PR invalidation during a pending read.

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

      Change: Bug fix

      Possibly related issues

      • pingdotgg/t3code#21888 — The stripe-scoped invalidation may reduce unrelated-read contention during concurrent PR sweeps. It does not change polling rates or the number of az processes.

      Suggested labels: bugfix, size:XS

      Suggested reviewers: juliusmarminge, macroscopeapp

      Merge Risk: Minimal · up to 09b7f

      The change is mergeable with no established merge-blocking risk; normal checks should still be completed.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title names the change: PR cache invalidation no longer waits on other projects' reads. It also gives the benchmark result (1,163 ms to 0.12 ms median). The raw summary and the PR description both…
      Description checkPassedThe description follows the template sections (Problem, Change, Scope and approval, Verification). Problem explains the global wait on every in-flight PR read. Change explains the 64-stripe design, th…
      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: Title check

      Explanation

      The title names the change: PR cache invalidation no longer waits on other projects' reads. It also gives the benchmark result (1,163 ms to 0.12 ms median). The raw summary and the PR description both describe lock striping in PullRequestReadCache that removes the global exclusion, so the title matches the main change. It uses the conventional commit format the template asks for. The title is long at 104 characters, but it is still specific and readable.

      Full details: Description check

      Explanation

      The description follows the template sections (Problem, Change, Scope and approval, Verification). Problem explains the global wait on every in-flight PR read. Change explains the 64-stripe design, the sorted-order acquisition, and the deadlock-avoidance rule. Scope and approval cites the small bug-fix exception and explains why it qualifies. Verification gives benchmark numbers, names the updated test, reports the 12 passing tests and the check command, and states what was not checked (stripe collision frequency). The description does not link a triaged issue or maintainer approval, which the template asks for, but it does explain the exception. The template also asks for the model and harness used, and the description includes that line. Overall the description is mostly complete.

      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 30724e2e9ae1c2f5da495b590e22e41e425b8db5 and 09b7f9ba92a91dcae78e683623de0a96704bd8c3.

      Files selected for processing: 2
      • apps/server/src/pullRequest/PullRequestReadCache.test.ts
      • apps/server/src/pullRequest/PullRequestReadCache.ts

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

    3. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified as-is at 09b7f9ba92a91dcae78e683623de0a96704bd8c3, against freshly fetched github/main (bff68fb6b6), with one development server running at a time on this linux vm.

      created two projects through the web app, pointing at real checkouts. used playwright from the repo with /usr/bin/google-chrome, real browser authentication, and real github-backed websocket requests. no mocks, fixtures, or replay provider.

      started a cold pullRequests.summary in one project, then sent pullRequests.invalidate for this pr in the other project 25 ms later:

                                         main        pr head
      source summary completed           737.4 ms    661.5 ms
      unrelated invalidation completed   739.5 ms     45.5 ms
      invalidation request duration       714.0 ms     20.1 ms

      main waited for the unrelated read. the pr completed invalidation while that read was still pending. these are individual real-server observations, not benchmark medians.

      nearby behavior also passed: same-scope invalidation waited for a cold stack read (read completed at 328.8 ms, invalidation at 329.4 ms), and a subsequent summary returned fresh data. real codex gpt-6.1-sol turns completed through the web composer on both revisions. the pr turn retried transiently, then returned successfully. the linked pr panel rendered its title, branch, checks and diff counts afterward.

      all 12 existing PullRequestReadCache.test.ts tests passed on blacksmith. the exact head has 30 successful ci checks, zero failing or pending. no source changes or pushes were needed.

      command transcript

      the checkpoint diff visible in the capture comes from switching this task checkout from main to the pr between turns. the working tree is clean.

      real codex turn and linked pr panel

      completed codex turn and linked pr data

      Not verified

      native desktop, ios/android, other providers, remote/relay/tunnel connections, extreme concurrency, stripe-collision frequency under production load, and live host state mutations were not exercised. this pass used the linux web client and real github reads. this server-only change has no visual layout change to compare.

    4. maria-rcks merged this8dbf262

    5. maria-rcks closed this

Sign in to join this conversation.