perf(server): pull request sync reads only threads with linked pull requests #13704
main fromrefs/pull/13704/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubPullRequestSyncReactor read the full shell snapshot on every 1-minute sweep and on every new PR link. On a server with about 5,000 threads and 130 projects, one full read runs 6 queries (most of them over every active thread), resolves repository identity for every project (git spawns on cache misses), and decodes the whole snapshot again. The reactor only uses the threads that have a linked pull request, and only 5 fields of each.
Fix#
- New
ProjectionSnapshotQuery.listThreadsWithPullRequests(). It is one SQL query that joinsprojection_thread_pull_requeststo active (not deleted, not archived) threads. This is the same thread filter as the shell snapshot.- It returns
id,projectId,settledOverride,settledAtandpullRequests. These are all the fields the reactor reads. - It keeps the shell snapshot's thread order and link order. So PR groups, and the project used for each host read, do not change.
- It does not resolve repository identity. Identity only feeds the legacy
linkedPullRequestfield, and the reactor does not read it.
- It returns
- The reactor reads this query instead of
getShellSnapshot(). ItsarchivedAtcheck is gone because the query already skips archived threads. - The other test files only add the new method to their full
ProjectionSnapshotQuerymocks.
Verification#
- New SQL test in
ProjectionSnapshotQuery.test.ts. It seeds active, settled, unlinked, archived and deleted threads across 2 projects. It checks that the new query gives the same threads, fields and order as the shell snapshot's linked threads, in 1 SQL statement, with 0 identity lookups. It fails if the sort order changes or if the archived filter is removed. PullRequestSyncReactor.test.ts: the sync still writes the snapshot to a linked PR thread, andgetShellSnapshotruns 0 times. It fails against the old reactor code.vp test runon all touched test files: 284 of 285 pass. The 1 failure (AgentSessionScannersymlink test) also fails with main's copy of that file on this Mac.vp lintandvp fmton the changed files, andvp run --filter t3 typecheck.
Related: #13691 (the same kind of fix for settlement and PR discovery).
Made by Claude Opus 5.5 (1M context) in Claude Code, running in T3 Code.
🤖 Generated with Claude Code
Summary by CodeRabbit#
- Improvements
- Pull-request synchronization now processes active threads with linked pull requests while preserving their established order and the thread, project, settlement, and pull-request details needed for processing. Syncing these links no longer requires loading a full project snapshot, while existing synchronization behavior remains unchanged.
- 1
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
Approvability#
Verdict: Approved at
e2cb766Macroscope's review found this PR approvable — This is a contained server-side performance optimization that replaces full shell hydration with a direct query for active threads that already have pull-request links. Existing synchronization and persistence behavior is preserved, with focused tests covering ordering, filtering, and the reduced query path.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
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:
1dbc9645-9799-45d0-8c0c-710209960672📥 Commits
Reviewing files that changed from the base of the PR and between b8cd22181f84134c7ca559f0d5999994216765c1 and e2cb7667e6fabcff5ce276c0a346f8de9cdaa8df.
📒 Files selected for processing (1)
apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
Limit details: You’ve used all 10 included reviews currently available.
📝 Walkthrough
Walkthrough#
The projection snapshot query now returns active threads with pull-request links. The pull-request sync reactor uses this query instead of reading a full shell snapshot. Tests cover the query results and verify that the sync sweep does not read a full shell snapshot.
Changes#
Pull-request projection and sync
Layer / File(s) Summary Define and implement the pull-request thread query
apps/server/src/orchestration/Services/ProjectionSnapshotQuery.ts,apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts,apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts,apps/server/src/checkpointing/CheckpointDiffQuery.test.ts,apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts,apps/server/src/project/*,apps/server/src/provider/Layers/*,apps/server/src/serverRuntimeStartup.test.tsAdds the query contract and implementation. It returns ordered records for active threads with pull-request links and maps query failures to persistence errors. Tests cover the results. Affected query test doubles add unused-operation stubs. Use the projection query in pull-request sync
apps/server/src/orchestration/PullRequestSyncReactor.ts,apps/server/src/orchestration/PullRequestSyncReactor.test.tsThe sync sweep reads projection thread records instead of a full shell snapshot. The test asserts that the sweep does not read a full shell snapshot. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Refactor
Sequence Diagram(s)#
sequenceDiagram participant PullRequestSyncReactor participant ProjectionSnapshotQuery participant Database PullRequestSyncReactor->>ProjectionSnapshotQuery: listThreadsWithPullRequests() ProjectionSnapshotQuery->>Database: select active threads and pull-request links Database-->>ProjectionSnapshotQuery: ordered query rows ProjectionSnapshotQuery-->>PullRequestSyncReactor: grouped thread records PullRequestSyncReactor->>PullRequestSyncReactor: group visible pull-request linksSuggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
e2cb7The sync sweep retains the verified thread eligibility behavior. No issue requiring a fix before merge was identified.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation 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. Title check ✅ Passed The title clearly and concisely describes the main performance change: pull request synchronization now reads only threads with linked pull requests. Description check ✅ Passed The description explains the problem, implementation, scope, and verification results. It omits the template headings and checklist, but it provides the required substantive information and is mostly … - 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
Comment `@coderabbitai help` to get the list of available commands.github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
2a9832b· PR result:e2cb766· 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.