Skip to content

[Bug]: listActiveShellIndex scans every finished subagent thread, so shell reads slow down with history (3-8 s here) #37940

Closed

Description

@nkoynov

What happens

ProjectionStore.listActiveShellIndex reads every row of orchestration_v2_projection_threads that isn't deleted or archived, with nine json_extracts and six EXISTS subqueries per row. It backs the shell snapshot (app open, /api/orchestration/shell), t3_thread_list, agent awareness and startup. Subagent threads are never archived, not even when their root thread is, so on a long-lived server most of those rows are finished subagents and the read keeps getting slower.

Ours: 6,833 non-archived threads, 6,420 of them subagent threads. None of the subagent threads are archived, and 1,844 of them sit under a root that is. The database is 17.6 GB. On 0.1.10-nightly.20261115.4736, over one day, the query took p50 3.4 s and up to 7.9 s (35 calls), with its read transactions up to 10 s. In the same day 53 of 514 message.dispatch spans took over 1 s, against 6 of 145 the day before on 4669.

Steps to reproduce

  1. Use a server for a few weeks with subagents (a few thousand subagent threads).
  2. Open the app or call t3_thread_list.
  3. Look at the ProjectionStore.listActiveShellIndex span: it scales with all non-archived threads, finished subagents included.

Where

apps/server/src/orchestration-v2/ProjectionStore.ts, listActiveShellIndex, unchanged on main ccf96b2. #36146 made the worktree and family reads from #36139 cheaper but not this full scan.

Expected

The cost shouldn't grow with history. Any of these would do it: leave settled subagent threads out of the scan (or archive a subagent thread with its root), or keep the flags the index needs in indexed columns instead of json_extract over payload_json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions