Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shell): cold connects skip idle subagent threads, a third of the thread list #24648

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

Every client downloads the whole active thread list on cold connect. On real data that was 2.94 MB of JSON (212 KB gzip) for 1,294 threads, and 360 of those rows were subagent child threads: a third of the bytes, for rows that never show in the sidebar.

Servers now advertise shellThreadFamilies. Clients that see it ask the shell snapshot to leave out idle subagent children. A child stays while it has a live or queued run, a pending request, background work, or a subagent child of its own. When a thread is open, the client reads that thread's subagent tree once with a new getThreadFamily read and merges those rows behind the shell rows. The Lineage panel, subagent rows, the open child's toolbar and diff, and the sidebar highlight work as before. Live deltas are unchanged, so a child that wakes up comes back by itself. Nothing is migrated.

Being missing from the shell no longer means "deleted":

  • The mobile outbox waits for the family read before it drops a queued message.
  • Related-thread links navigate instead of showing a "no longer available" toast.
  • The delete prompt asks the server (getWorktreeThreadIds) before it offers to remove a worktree.
Real data, branch server codeBeforeAfter
Shell JSON2,943,983 B1,969,561 B (-33.1%)
Shell gzip211,900 B156,547 B (-26.1%)
Rows1,294936
Family read per open treenonep50 6.7 KB, p90 32 KB, max 283 KB

Compatibility: old clients do not opt in and get the same shell. New clients on old servers see no flag and keep today's behavior. All new contract fields are optional.

After (cropped): the Lineage panel lists six idle children that the shell no longer sends, and a cold-opened idle child keeps its breadcrumb and panels.

Lineage panel lists six idle children the shell no longer sends Cold-opened idle child shows the breadcrumb back to its parent Cold-opened idle child shows its workspace and lineage panel

Proof:

  • vp run check:changed passes with 441 tests. New tests cover the omission rule, family and worktree reads on the SQL and memory stores, the shell generation, family retry, and the outbox rule.
  • Sizes were measured with this branch's server code on a read-only copy of real data.
  • A dev server seeded from real data serves 279 shell rows by default and 216 with the opt-in. The web client caches 216.
  • Headless web check: the omitted children open from Lineage, and a cold-opened idle child works.
  • Not run on a mobile device: the local emulator fails to boot.

Not fixed here: message.dispatch to a deleted thread is accepted. This bug existed before this change.

Created with Claude Opus 5.5 in Claude Code. A three-model council reviewed the design and the implementation.

🤖 Generated with Claude Code

    1. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This PR introduces a new thread-family RPC/state-management path and changes default shell synchronization, outbox, lifecycle, and worktree-cleanup behavior across server, web, and mobile code. Its cross-layer runtime impact and auth-surface change require human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    2. 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.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−7 B (−0.1%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−7 B (−0.6%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 6548c00 · PR result: 3b8d374 · 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.

    3. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 6548c006d429e7242ebc10c34946420418a276ec and 3b8d37487bd977dda1e3dba08bfe477703918eeb.

      Files selected for processing: 35
      • apps/mobile/src/features/threads/ThreadRouteScreen.tsx
      • apps/mobile/src/state/shell.ts
      • apps/mobile/src/state/thread-outbox-model.ts
      • apps/mobile/src/state/thread-outbox.test.ts
      • apps/mobile/src/state/threads.ts
      • apps/mobile/src/state/use-composer-drafts.test.ts
      • apps/mobile/src/state/use-thread-outbox-drain.ts
      • apps/server/src/auth/RpcAuthorization.ts
      • apps/server/src/observability/RpcInstrumentation.ts
      • apps/server/src/orchestration-v2/ProjectionStore.test.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts
      • apps/server/src/orchestration-v2/ShellStream.test.ts
      • apps/server/src/orchestration-v2/ShellStream.ts
      • apps/server/src/orchestration-v2/ThreadManagementService.ts
      • apps/server/src/orchestration-v2/http.ts
      • apps/server/src/ws.test.ts
      • apps/server/src/ws.ts
      • apps/web/src/components/ChatView.tsx
      • apps/web/src/components/chat/useThreadLifecycle.tsx
      • apps/web/src/composerDraftStore.test.ts
      • apps/web/src/hooks/useThreadActions.ts
      • apps/web/src/state/shell.test.ts
      • apps/web/src/state/threads.ts
      • docs/internals/connection-runtime.md
      • packages/client-runtime/src/state/orchestration.ts
      • packages/client-runtime/src/state/shell-sync.test.ts
      • packages/client-runtime/src/state/shell.ts
      • packages/client-runtime/src/state/shellSnapshotHttp.ts
      • packages/client-runtime/src/state/threadFamilies.test.ts
      • packages/client-runtime/src/state/threadFamilies.ts
      • packages/client-runtime/src/state/threads.ts
      • packages/contracts/src/environmentHttp.ts
      • packages/contracts/src/orchestrationV2.ts
      • packages/contracts/src/rpc.ts
      • packages/contracts/src/server.ts

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

      Walkthrough

      The change adds optional idle-subagent filtering to shell snapshots and subscriptions, plus RPCs for retrieving thread-family rows and worktree thread IDs. Clients track shell generations and removals, merge mounted family reads, and use these results when displaying threads, draining queued messages, and checking worktree cleanup.

      Changes: Thread Family Shell Synchronization

      Layer / File(s)Summary
      Shell filtering and query contracts
      packages/contracts/src/environmentHttp.ts, packages/contracts/src/orchestrationV2.ts, packages/contracts/src/rpc.ts, packages/contracts/src/server.ts
      Contracts add the omitIdleSubagents query and subscription options, thread-family and worktree-thread-ID RPC schemas, and the shellThreadFamilies capability.
      Server filtering and query handlers
      apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ThreadManagementService.ts, apps/server/src/orchestration-v2/ShellStream.ts, apps/server/src/orchestration-v2/http.ts, apps/server/src/ws.ts, apps/server/src/auth/RpcAuthorization.ts, apps/server/src/observability/RpcInstrumentation.ts, apps/server/src/orchestration-v2/*test.ts, apps/server/src/ws.test.ts
      Shell reads can filter by family or worktree path. HTTP snapshots and WebSocket subscriptions can omit idle subagents. The new RPC handlers return family rows with a snapshot sequence or worktree thread IDs.
      Client shell state and family merging
      packages/client-runtime/src/state/shell.ts, packages/client-runtime/src/state/shellSnapshotHttp.ts, packages/client-runtime/src/state/threadFamilies.ts, packages/client-runtime/src/state/orchestration.ts, packages/client-runtime/src/state/threads.ts, packages/client-runtime/src/state/*test.ts, apps/mobile/src/state/shell.ts, apps/mobile/src/state/use-composer-drafts.test.ts, apps/web/src/state/shell.test.ts, apps/web/src/composerDraftStore.test.ts, docs/internals/connection-runtime.md
      Client shell state tracks snapshot generations and removals. Family reads are mounted and merged with shell rows, subject to removal sequences. Shell synchronization requests idle-subagent omission when the server advertises support.
      Thread views, queued messages, and worktree cleanup
      apps/mobile/src/features/threads/ThreadRouteScreen.tsx, apps/mobile/src/state/threads.ts, apps/mobile/src/state/thread-outbox-model.ts, apps/mobile/src/state/thread-outbox.test.ts, apps/mobile/src/state/use-thread-outbox-drain.ts, apps/web/src/components/ChatView.tsx, apps/web/src/components/chat/useThreadLifecycle.tsx, apps/web/src/state/threads.ts, apps/web/src/hooks/useThreadActions.ts
      Thread views mount family reads. Queued messages wait for unsettled family reads before treating a missing thread as removed. Worktree cleanup checks server-reported thread IDs when family support is enabled.
      Priority: Normal

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Feature

      Sequence Diagram(s)

      sequenceDiagram
        participant ThreadView
        participant ClientRuntime
        participant WsServer
        participant ProjectionStore
        ThreadView->>ClientRuntime: mount thread family
        ClientRuntime->>WsServer: getThreadFamily(threadId)
        WsServer->>ProjectionStore: read family shell rows and snapshot sequence
        ProjectionStore-->>WsServer: family rows and sequence
        WsServer-->>ClientRuntime: family rows and sequence
        ClientRuntime-->>ThreadView: merged shell snapshot

      Suggested labels: size:XXL, 📱 Native Change, macroscope-review

      Suggested reviewers: juliusmarminge, maria-rcks

      Merge Risk: Minimal · up to 3b8d3

      No identified issue remains that should block merging after normal checks.

      Pre-merge checks: Passed 3 · Inconclusive 1
      Failed Failed checks: 1 inconclusive
      Check nameStatusExplanationResolution
      Description checkInconclusiveThe description covers the template sections. Problem: it explains that every cold connect downloads the full active thread list, including 360 idle subagent rows, with measured sizes. Change: it expl…Add a link to the triaged issue or maintainer discussion that approved this direction and scope, including the approval comment, or explain why this change qualifies as an exemption under the Scope and approval rules. The rest of the descri…
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title "perf(shell): cold connects skip idle subagent threads, a third of the thread list" matches the main change. The changeset adds the optional shellThreadFamilies capability, so shell snapshot…
      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(shell): cold connects skip idle subagent threads, a third of the thread list" matches the main change. The changeset adds the optional shellThreadFamilies capability, so shell snapshots omit idle subagent child threads, and clients load a thread's family on demand. The title follows conventional commit form and names the primary change and its effect. It is 81 characters, which is slightly long, but it is specific and clear.

      Full details: Description check

      Explanation

      The description covers the template sections. Problem: it explains that every cold connect downloads the full active thread list, including 360 idle subagent rows, with measured sizes. Change: it explains the shellThreadFamilies capability, the getThreadFamily read, and the mobile outbox, related-thread, and worktree-deletion adjustments. Verification: it lists check:changed with 441 tests, measured sizes, a dev-server check, a headless web check, and a note that mobile was not run. Scope and approval: the template asks for a linked triaged issue or maintainer approval, and the description has no such link or approval reference. It does say that the change is a performance fix with compatibility behavior, but it gives no issue link or approval. The description also includes a note on an unfixed bug and an agent attribution line. Those lines are acceptable.

      Resolution

      Add a link to the triaged issue or maintainer discussion that approved this direction and scope, including the approval comment, or explain why this change qualifies as an exemption under the Scope and approval rules. The rest of the description is complete.

      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.

Sign in to join this conversation.