Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): pull request sync reads only threads with linked pull requests #13704

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

PullRequestSyncReactor 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 joins projection_thread_pull_requests to active (not deleted, not archived) threads. This is the same thread filter as the shell snapshot.
    • It returns id, projectId, settledOverride, settledAt and pullRequests. 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 linkedPullRequest field, and the reactor does not read it.
  • The reactor reads this query instead of getShellSnapshot(). Its archivedAt check is gone because the query already skips archived threads.
  • The other test files only add the new method to their full ProjectionSnapshotQuery mocks.

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, and getShellSnapshot runs 0 times. It fails against the old reactor code.
  • vp test run on all touched test files: 284 of 285 pass. The 1 failure (AgentSessionScanner symlink test) also fails with main's copy of that file on this Mac.
  • vp lint and vp fmt on the changed files, and vp 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

    2. 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 wire13.5 KiB13.5 KiB+12 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire7.1 KiB7.1 KiB−5 B (−0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.5 KiB+17 B (+0.3%)7.8 KiB✅
      CodexLive turn WebSocket decoded56.3 KiB56.3 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.5 KiB13.5 KiB−15 B (−0.1%)15.1 KiB✅
      ClaudeThread snapshot wire7.1 KiB7.1 KiB−4 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.4 KiB6.4 KiB−11 B (−0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.0 KiB57.0 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages990 (0.0%)21✅

      Baseline: 2a9832b · PR result: e2cb766 · 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: 114.0 KiB
      • Claude decoded thread snapshot: 114.7 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

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

      Approvability

      Verdict: Approved at e2cb766

      Macroscope'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).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      Adds 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.ts
      The 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 links

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to e2cb7

      The 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 nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      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.
      Title check✅ PassedThe title clearly and concisely describes the main performance change: pull request synchronization now reads only threads with linked pull requests.
      Description check✅ PassedThe 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.

Sign in to join this conversation.