perf(server): read pull request metadata from a lightweight snapshot#30356

merged2
main
t3/lightweight-pr-startup-snapshot
opened7d agobyYYash-Singh1
View on GitHubTwo-way sync enabledPR last imported 7d ago

Problem

Startup PR backfill used the full shell snapshot, which also reads message activity and historical item counts for every active thread. On a populated database, that work kept the reader busy and delayed other reads.

Change

Add a PR-specific snapshot that reads only thread metadata and the event sequence in one transaction. The PR service uses it for both backfill and per-thread refresh, while keeping the existing sync guards and backfill behavior.

With 6,873 synthetic threads and 7.04 million historical items, median PR initialization fell from 1,168 ms to 111 ms. Both versions dispatched 6,873 sync commands, made 64 branch lookups, and produced matching metadata and sequences.

Scope and approval

This is a focused performance fix. PR backfill needs active thread metadata, but the shell snapshot also loads history that PR discovery does not use.

Verification

Focused projection and PR service tests passed. check:changed passed, including 80 tests. A concurrent-write check confirmed that thread metadata and sequence came from the same snapshot.

Measurements used the installed Electron runtime with synthetic data. They measure PR snapshot reads and service initialization, not full desktop startup or network and dispatch costs. The fixture had less history than production.

Model: GPT-6 Codex.

Checks

22 successful · 17 skipped
All checks passed
988187f

Added 2 commits

  • perf(server): read pull request metadata from a lightweight snapshot6fb3790
  • Merge remote-tracking branch 'origin/main' into t3/lightweight-pr-startup-snapshot988187f
Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The pull-request service now obtains thread metadata and the maximum thread-event sequence through a projection-store snapshot API. The API supports global and thread-targeted reads, with filters for archived and settled threads.

Changes: Pull-request snapshot flow

Layer / File(s)Summary
Projection-store snapshot
apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProjectionStore.test.ts
The store adds a snapshot query that reads selected thread data and the maximum event sequence in one transaction. It applies thread and unsettled filters, and tests check query scope, transaction grouping, and returned metadata.
Orchestrator and service integration
apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/ThreadPullRequestService.ts, apps/server/src/orchestration-v2/ThreadPullRequestService.test.ts, apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
The orchestrator exposes the snapshot query, and the pull-request service uses it for global and thread-targeted reads. Tests cover snapshot filtering and the sequence guard in the sync command.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant ThreadPullRequestService
3 participant OrchestratorV2
4 participant ProjectionStoreV2
5 participant ReadOnlySQLiteClient
6 ThreadPullRequestService->>OrchestratorV2: Request pull-request snapshot
7 OrchestratorV2->>ProjectionStoreV2: Delegate snapshot options
8 ProjectionStoreV2->>ReadOnlySQLiteClient: Read selected threads and event sequence in one transaction
9 ReadOnlySQLiteClient-->>ProjectionStoreV2: Return rows and sequence
10 ProjectionStoreV2-->>OrchestratorV2: Return decoded snapshot
11 OrchestratorV2-->>ThreadPullRequestService: Return snapshot and sequence

Possibly related issues

  • pingdotgg/t3code#18618: The issue describes full-shell reads for PR discovery; this change uses a filtered metadata snapshot and sequence read.
  • pingdotgg/t3code#24895: The issue identifies a slow ThreadPullRequestServiceV2.synchronize shell read; this change replaces the PR-service read with a metadata snapshot.

Possibly related PRs

  • pingdotgg/t3code#25728: Adds a related PR-sync snapshot read path that this change extends with a PR-specific API and filters.
  • pingdotgg/t3code#25443: Moves PR discovery to thread metadata; this change implements a snapshot API with sequence and thread filters.
  • pingdotgg/t3code#13691: Replaces full thread-list reads with targeted snapshot reads for per-thread pull-request checks.

Suggested reviewers: juliusmarminge, macroscopeapp

Merge Risk: External image Minimal · up to 98818

No actionable issue is established from the supplied evidence; the change is mergeable after normal checks.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title "perf(server): read pull request metadata from a lightweight snapshot" matches the main change. The PR adds a PR-specific snapshot (getPullRequestSnapshot) that reads only thread metadata an…
Description checkPassedThe description follows the template's main sections: Problem, Change, Scope and approval, and Verification. The Problem section explains the slow startup backfill. The Change section describes the ne…
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 "perf(server): read pull request metadata from a lightweight snapshot" matches the main change. The PR adds a PR-specific snapshot (getPullRequestSnapshot) that reads only thread metadata and event sequence, and the PR service uses it for backfill and per-thread refresh. It uses a conventional commit prefix and plain language.

Full details: Description check

Explanation

The description follows the template's main sections: Problem, Change, Scope and approval, and Verification. The Problem section explains the slow startup backfill. The Change section describes the new snapshot and the service updates. The Verification section reports benchmark numbers (1,168 ms to 111 ms), sync command and branch lookup parity, focused test results, and the limits of the measurements. The Scope section explains why this is a focused performance fix. Two gaps remain: it does not link a triaged issue or maintainer approval, and the template asks for approval of direction and scope for changes like this. It also does not clearly state the reason for the performance fix's qualification under the approval rule beyond stating it is focused. The model line (GPT-6 Codex) is present as the template requests.

Resolution

Consider linking the triaged issue or maintainer discussion that approves this performance direction. If none exists, state why this small, focused performance fix qualifies without prior approval.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • 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.
External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between 260297b55fc97c5b10ff55511967f6d20c622e54 and 988187fdb93f9d0d55b86be5c91147710106a185.

External image Files selected for processing: 6
  • apps/server/src/orchestration-v2/Orchestrator.ts
  • apps/server/src/orchestration-v2/ProjectionStore.test.ts
  • apps/server/src/orchestration-v2/ProjectionStore.ts
  • apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
  • apps/server/src/orchestration-v2/ThreadPullRequestService.test.ts
  • apps/server/src/orchestration-v2/ThreadPullRequestService.ts

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

Synced from GitHub

Approvability

Verdict: Approved at 988187f

Macroscope's review found this PR approvable — Pull-request discovery now reads a lightweight metadata snapshot instead of full thread shells. The read-only transactional path retains existing update safeguards without changing product defaults or external operations.

Notes:

  • Diff unchanged. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wire5.0 KiB5.0 KiB−19 B (−0.4%)6.8 KiB✅
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
CodexLive turn WebSocket wire1.3 KiB1.2 KiB−19 B (−1.5%)2.0 KiB✅
CodexLive turn WebSocket decoded21.6 KiB21.6 KiB0 B (0.0%)24.4 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.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
ClaudeLive turn messages220 (0.0%)8✅

Baseline: 260297b · PR result: 988187f · 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.