perf(server): PR cache invalidation no longer waits on other projects' reads (1,163 ms → 0.12 ms median) #30293
main fromrefs/pull/30293/head·merged by maria-rcks View on GitHubProblem#
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
gettakes one permit on each of its scopes' stripes, in sorted order, inside the existing 512-read cap. invalidatetakes 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 median | This branch median | |
|---|---|---|
| Invalidation during an unrelated read | 1,163 ms | 0.12 ms |
| Invalidation with nothing in flight | 0.67 ms | 0.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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified as-is at
09b7f9ba92a91dcae78e683623de0a96704bd8c3, against freshly fetchedgithub/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.summaryin one project, then sentpullRequests.invalidatefor 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 msmain 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-solturns 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.tstests passed on blacksmith. the exact head has 30 successful ci checks, zero failing or pending. no source changes or pushes were needed.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.


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.
maria-rcks merged this8dbf262
maria-rcks closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review.
Walkthrough
PullRequestReadCachenow 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
apps/server/src/pullRequest/PullRequestReadCache.ts,apps/server/src/pullRequest/PullRequestReadCache.test.tsEstimated 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 ofazprocesses.Suggested labels:
bugfix,size:XSSuggested reviewers:
juliusmarminge,macroscopeappMerge Risk:
Minimal · up to
09b7fThe change is mergeable with no established merge-blocking risk; normal checks should still be completed.
Pre-merge checks:
4
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)
CodeRabbit Verify#
ab101d56-cc0b-494d-ae9d-f1ec5de81fa9Reviewing files that changed from the base of the PR and between 30724e2e9ae1c2f5da495b590e22e41e425b8db5 and 09b7f9ba92a91dcae78e683623de0a96704bd8c3.
apps/server/src/pullRequest/PullRequestReadCache.test.tsapps/server/src/pullRequest/PullRequestReadCache.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.