perf(server): sidebar shell loads 3x faster and startup thread counts 80x faster#27106

merged3
main
perf/shell-subset-reads
opened12d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 12d ago

Shell subscriptions and ~9 internal callers read every thread's shell row, then filtered in JS.

Measured read-only on a real DB (2,923 threads):

PathBeforeAfter
Shell subscription, both opt-ins (current clients)~560 ms, +51 MB, 10 MB JSON built~190 ms, +23 MB (128 threads sent)
Shell subscription, idle-subagents only~560 ms, +51 MB~230 ms, +32 MB
Startup thread count~580 ms7 ms
Startup bootstrap~580 ms60 ms
Agent awareness relay~580 ms~230 ms
Branch rename (per pass)full shellthat worktree only (~150 ms on the busiest)
Project deletefull shellthat project only
  • listActiveShellIndex() reads a few fields per active thread plus a broad mayBeLive flag; full shells are built only for threads a subscriber can receive, inside one read transaction.
  • Snapshot output is byte-identical to main for all four opt-in combinations (static DB copy).
  • Index check runs in 6 existing ProjectionStore cases; 5 fail if mayBeLive is forced false.

Claude Opus 5.5 in T3 Code (Claude Code harness).

🤖 Generated with Claude Code

Checks

23 successful · 17 skipped
All checks passed
7adc73b

Added 2 commits

  • perf(server): shell subscriptions read only the threads they send0dac673
  • perf(server): internal callers read only the threads they need5c828e3
Synced from GitHub

Approvability

Verdict: Approved at 7adc73b

Macroscope's review found this PR approvable — This optimizes sidebar snapshots and startup reads by fetching only relevant thread shells and counting threads directly in SQL. Existing subscriber options and operation scopes remain unchanged, with reported snapshot-equivalence checks supporting the limited behavioral risk.

Notes:

  • No code objects were reviewed. 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 KiB0 B (0.0%)6.8 KiBâś…
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiBâś…
CodexLive turn WebSocket wire1.3 KiB1.3 KiB0 B (0.0%)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 KiB+29 B (+0.6%)6.8 KiBâś…
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiBâś…
ClaudeLive turn WebSocket wire1.2 KiB1.3 KiB+29 B (+2.3%)2.0 KiBâś…
ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB+41 B (+0.2%)24.4 KiBâś…
ClaudeLive turn messages12+1 (+100.0%)8âś…

Baseline: 08a463e · PR result: 7adc73b · 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.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between 5c828e3c1677dee041caafeb926e109700080037 and 7adc73b2c75e5e12b571e280d1961698f0280d83.

External image Files selected for processing: 1
  • apps/server/integration/transferBudgetV2.integration.test.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.

Walkthrough

The change adds thread-count and active-shell-index APIs. Subscriber snapshot loading uses the index to select shell data before decoding and applies subscriber trim options. Startup, relay, project, and thread-launch paths use the new APIs or scoped snapshots.

Changes: Active Shell Index and Subscriber Snapshots

Layer / File(s)Summary
Add the active shell index API
apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/ThreadManagementService.ts, apps/server/src/orchestration-v2/ProjectionStore.test.ts, apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
The projection store counts non-deleted threads, including archived threads, and lists active shell entries with a mayBeLive flag. The orchestrator and thread-management service expose both methods. Tests compare index entries with shell snapshots and update the relevant mock.
Select and trim subscriber snapshots
apps/server/src/orchestration-v2/ShellStream.ts
The loader uses index entries to select threads before reading shell data when trimming is enabled. Shared trim logic applies idle-subagent and older-settled filters.
Use the loader in HTTP and WebSocket routes
apps/server/src/orchestration-v2/http.ts, apps/server/src/ws.ts, apps/server/src/ws.test.ts
Both routes use the shared loader with subscriber options. They enrich projects from the returned snapshot; the WebSocket path also uses the returned subagent IDs.
Update other thread snapshot and index callers
apps/server/src/orchestration-v2/ThreadLaunchService.ts, apps/server/src/project/ProjectService.ts, apps/server/src/relay/AgentAwarenessRelay.ts, apps/server/src/relay/AgentAwarenessRelay.test.ts, apps/server/src/serverRuntimeStartup.ts, apps/server/src/serverRuntimeStartup.test.ts, apps/server/src/serverRuntimeStartup.autoPull.test.ts, apps/server/integration/transferBudgetV2.integration.test.ts
Startup telemetry uses the thread count, and auto-bootstrap searches the active-shell index. Other callers use project- or worktree-scoped snapshots, or request active top-level shells for the relay’s initial snapshot.

Priority: External image Normal

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

Change: Refactor

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant SubscriberRoute
3 participant loadSubscriberShellSnapshot
4 participant listActiveShellIndex
5 participant readThreads
6 SubscriberRoute->>loadSubscriberShellSnapshot: Pass trim options and readers
7 loadSubscriberShellSnapshot->>listActiveShellIndex: Read index when trimming is enabled
8 listActiveShellIndex-->>loadSubscriberShellSnapshot: Return active shell entries
9 loadSubscriberShellSnapshot->>loadSubscriberShellSnapshot: Select thread IDs and compute trim facts
10 loadSubscriberShellSnapshot->>readThreads: Read selected thread IDs
11 readThreads-->>loadSubscriberShellSnapshot: Return shell data
12 loadSubscriberShellSnapshot-->>SubscriberRoute: Return trimmed snapshot and subagent IDs

Possibly related issues

  • pingdotgg/t3code#23000 — The PR adds an active-shell index and targeted shell reads, which overlap with the issue’s shell-list read-cost objective. It does not add the proposed indexes.
  • pingdotgg/t3code#18618 — The PR narrows shell reads to selected rows, but does not change ThreadPullRequestService.
  • pingdotgg/t3code#25621 — The PR changes shell reads in named caller paths, but the diff does not show whether it removes the SQL variable limit.
  • pingdotgg/t3code#24895 — The PR reduces shell reads through index-based selection, but does not address the issue’s other recovery and canonical projection statements.
  • pingdotgg/t3code#9661 — The PR changes per-subscriber shell reads, which overlaps with the tracker’s S11 item. The tracker’s broader items are not fully addressed.

Suggested reviewers: t3dotgg, maria-rcks

Merge Risk: External image Minimal · up to 7adc7

The reviewed test mock change does not introduce a merge-blocking behavior or integration risk.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely summarizes the primary performance improvements: faster sidebar shell loading and startup thread counting.
Description checkPassedThe description clearly explains the problem, implementation approach, measured performance improvements, snapshot equivalence, and verification coverage. It does not include an explicit Scope and app…
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: Description check

Explanation

The description clearly explains the problem, implementation approach, measured performance improvements, snapshot equivalence, and verification coverage. It does not include an explicit Scope and approval section or linked approval evidence, but the core description is mostly complete and relevant.

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

Comment @coderabbitai help to get the list of available commands.

Added 1 commit

  • test(server): transfer budget stub serves the shell index7adc73b