GeezerVison is showing github.com — perf(server): provider-thread reads no longer walk a thread's node history by bowd · Pull Request #31844 · pingdotgg/t3code
Conversation
Problem
Several reads check whether a thread owns a provider thread through one of its nodes with owner_node_id IN (SELECT node_id FROM orchestration_v2_projection_nodes WHERE thread_id = ?). SQLite answers that by listing every node the thread has ever had, so the cost grows with the thread's history even when no provider thread has a node owner. Five reads use this pattern:
readCanonicalProjection, which serves getThreadRecords(..., ["providerThreads"]). The orchestrator's command read (readCommandProjection) calls it, so it runs for every command, inside the write transaction.
getProviderControlContext, getCheckpointCaptureContext and getCheckpointRollbackContext. Each looks up a single provider thread, but still builds the full node list whenever the thread doesn't own it directly, for example a subagent's provider thread.
On my server, one long-lived thread has 61,272 nodes, and no provider thread there has a node owner. The thread-records query took ~340 ms, and the single-thread control check took ~325 ms. In that server's traces, this query ran for about 192 ms of every Orchestrator.dispatchMessage and about 354 ms of each startNextQueuedRun that loads the command read. It added up to ~17 s of SQLite time an hour in a quiet period.
Change
I added one ownedProviderThreadIds(threadId) selector: direct ownership, node ownership found from non-null owner_node_id through the existing owner index and then the owner node's primary key, and subagent references. It's the selector runtime recovery already uses (#29429). All five reads use it, and recovery's own copy now uses the shared fragment too. Results, the optional providerThreadIds filter, deduplication and ordering are unchanged. There's no schema or index change.
Scope and approval
This is a focused query-planning fix for an existing read path, the same change #29429 made for runtime recovery, applied to the remaining copies of the predicate. It returns the same rows, so I believe it qualifies as a small, obvious performance fix that doesn't need a prior issue.
Verification
-
New case in ProjectionStore.test.ts: provider-thread reads find owned threads without walking the thread's nodes.
- It seeds direct, node-owned (foreign app thread and null app thread), subagent-referenced, duplicate-path, foreign-node-owned and unrelated provider threads.
- It asserts the ordered
getThreadRecords results with and without a providerThreadIds filter, and getProviderControlContext and getCheckpointRollbackContext for owned and foreign targets.
- It captures all six ownership statements and asserts that none of their plans searches
orchestration_v2_projection_nodes_thread_*.
- On
main, every result assertion passes and only the plan assertion fails (SEARCH orchestration_v2_projection_nodes USING INDEX orchestration_v2_projection_nodes_thread_run_idx (thread_id=?)). It passes with the change.
-
From apps/server: vp test run src/orchestration-v2/ProjectionStore.test.ts src/orchestration-v2/ProjectionRecovery.test.ts src/orchestration-v2/ProjectionControlReads.test.ts gives 74/74 passing. vp run check:changed passed lint, knip, typecheck (3 packages) and 2 test files. I fixed its formatting failure with vp fmt.
-
Runtime check: I ran the old and new statements for that thread with the sqlite 3.53.3 CLI, on a read-only open of my real statev2.sqlite (26 GB). Three paired runs each:
| Statement |
Before |
After |
Rows |
Thread records (providerThreads) |
333–352 ms |
17–26 ms |
838, identical |
| Single provider-thread check (a subagent's provider thread) |
316–337 ms |
7–8 ms |
1, identical |
Not checked:
- I didn't run it inside a server build. The timings are the CLI on the same statements and data.
- Databases with many non-null node owners walk the owner index across all threads. That's the same trade-off perf(server): bound runtime recovery reads by thread ownership #29429 accepted.
- Returned payloads and decode cost are unchanged. This removes the node walk only.
Model: Claude Opus 5.5, harness: Claude Code
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…story
Thread record reads and three provider/checkpoint control reads checked
node ownership with `owner_node_id IN (SELECT node_id FROM nodes WHERE
thread_id = ?)`, which enumerates every node the thread ever had. Reuse
the ownership selector runtime recovery already uses (pingdotgg#29429): start from
non-null owners and look up each owner node by primary key. Results,
filtering and ordering are unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Approvability
Verdict: Approved at 908a520
Macroscope's review found this PR approvable — Provider-thread reads now share an indexed ownership query instead of walking a thread’s node history. The change preserves existing ownership boundaries and filters without introducing writes or changing product defaults.
You can add or adjust custom eligibility rules. Learn more.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Walkthrough
-
Provider-thread ownership queries now use a shared SQL selector. Projection reads, runtime recovery, provider-control lookups, and checkpoint capture and rollback use the selector. Tests cover ownership paths, ID filtering, foreign-owner exclusion, and query plans.
Changes: Provider-thread ownership reads
| Layer / File(s) |
Summary |
Shared ownership selection and validation apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProjectionStore.test.ts |
A shared selector covers direct thread ownership, node ownership, and subagent ownership. Projection, recovery, control, and checkpoint reads use it. Tests cover ownership results, filtering, and query plans. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Possibly related issues
Possibly related PRs
- pingdotgg/t3code#31012: Both changes avoid scanning every node in a thread when reading provider-thread ownership.
Suggested reviewers: yash-singh1
Merge Risk: Minimal · up to 908a5
-
The changed reads retain their provider-thread ownership behavior. No actionable merge risk remains after normal checks.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title clearly describes the provider-thread query performance change. |
| Description check |
 |
The description covers the problem, change, scope, and verification. It also states the checks not performed. |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Finishing Touches
-
Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Tip
🎯 Customize your risk assessments
-
Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.
✅ Automatic approvals, with your rules
-
Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.
Recent review info
-
Run configuration
-
Commits
-
Reviewing files that changed from the base of the PR and between 5c004fd and 908a520.
Files selected for processing: 2
-
apps/server/src/orchestration-v2/ProjectionStore.test.ts
apps/server/src/orchestration-v2/ProjectionStore.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing this as a duplicate of #31012, which makes the same change (owner-first selector shared by the canonical read and the three point lookups) and was opened first. #29521 also covers this read. I've added the measurements from this PR to #31012 in case they help.
🤖 Claude Opus 5.5 (Claude Code), writing on behalf of bowd
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:M
30-99 changed lines (additions + deletions).
vouch:unvouched
Author is not yet trusted in the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|