perf(server): sidebar shell loads 3x faster and startup thread counts 80x faster#27106
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):
| Path | Before | After |
|---|---|---|
| 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 ms | 7 ms |
| Startup bootstrap | ~580 ms | 60 ms |
| Agent awareness relay | ~580 ms | ~230 ms |
| Branch rename (per pass) | full shell | that worktree only (~150 ms on the busiest) |
| Project delete | full shell | that project only |
listActiveShellIndex()reads a few fields per active thread plus a broadmayBeLiveflag; full shells are built only for threads a subscriber can receive, inside one read transaction.- Snapshot output is byte-identical to
mainfor all four opt-in combinations (static DB copy). - Index check runs in 6 existing ProjectionStore cases; 5 fail if
mayBeLiveis forced false.
Claude Opus 5.5 in T3 Code (Claude Code harness).
🤖 Generated with Claude Code
Checks
Added 2 commits
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.
Thread transfer impact
âś… Thread transfer remains within every enforced ceiling.
| Provider | Metric | Main baseline | This PR | Impact | PR ceiling | |
|---|---|---|---|---|---|---|
| Codex | Total thread wire | 5.0 KiB | 5.0 KiB | 0 B (0.0%) | 6.8 KiB | âś… |
| Codex | Thread snapshot wire | 3.8 KiB | 3.8 KiB | 0 B (0.0%) | 4.9 KiB | âś… |
| Codex | Live turn WebSocket wire | 1.3 KiB | 1.3 KiB | 0 B (0.0%) | 2.0 KiB | âś… |
| Codex | Live turn WebSocket decoded | 21.6 KiB | 21.6 KiB | 0 B (0.0%) | 24.4 KiB | âś… |
| Codex | Live turn messages | 2 | 2 | 0 (0.0%) | 8 | âś… |
| Claude | Total thread wire | 5.0 KiB | 5.0 KiB | +29 B (+0.6%) | 6.8 KiB | âś… |
| Claude | Thread snapshot wire | 3.8 KiB | 3.8 KiB | 0 B (0.0%) | 4.9 KiB | âś… |
| Claude | Live turn WebSocket wire | 1.2 KiB | 1.3 KiB | +29 B (+2.3%) | 2.0 KiB | âś… |
| Claude | Live turn WebSocket decoded | 21.9 KiB | 21.9 KiB | +41 B (+0.2%) | 24.4 KiB | âś… |
| Claude | Live turn messages | 1 | 2 | +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.
No actionable comments were generated in the recent review.
External image Recent review info
-
External image Run configuration
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: perf/shell-subset-reads
- File: .coderabbit.config.ts
- Commit: 7adc73b
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
c41c6308-b2ff-4ecb-9010-bccc369287e2
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.tsThe projection store counts non-deleted threads, including archived threads, and lists active shell entries with a mayBeLiveflag. 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.tsThe 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.tsBoth 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.tsStartup 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)
mermaid1 sequenceDiagram 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 name Status Explanation Title check Passed The title clearly and concisely summarizes the primary performance improvements: faster sidebar shell loading and startup thread counting. Description check Passed The 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 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. 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