GeezerVison is showing github.com — perf(server): avoid historical scans during startup recovery by tensenlabs · Pull Request #22554 · pingdotgg/t3code
Conversation
Problem
ProjectionStore.getRecoveryThreadIds("runtime") scans historical runs and subagents and probes a broad node index while finding the small set of threads that need startup recovery. SQLite does not infer that the separate active-status IN list or status = 'queued' satisfies the existing runs recovery index's partial predicate.
This was investigated after a Windows desktop installation (0.1.0, embedded commit 81493efb71e8, approximately 2.94 GB database) repeatedly timed out waiting for backend readiness with no main window. SQL instrumentation stopped in this recovery query. The original launch symptom motivated this change; the controlled measurements below establish the query improvement, not a complete cold-start fix.
Change
- Combine the active/queued run branches under the existing recovery index's exact status predicate. Keep held-queue filtering and the union's deduplication.
- Migration 068 adds a covering index for unattached nodes and a partial index containing live provider-native subagents. Recovery can select thread IDs without reading historical payloads.
- Test upgrading from migration 067, repeated migration, recovery selection, and the actual service query's plan. Update existing upgrade expectations.
Scope and approval
This is a small, focused persistence performance fix preserving the existing recovery result set. It adds no setting, workflow, timeout change, or client/provider behavior. Submitted under the focused-fix exception in CONTRIBUTING.md.
Related: #22354 indexes other projection lookups, and #21585 addresses per-turn recovery reads. This change targets startup candidate selection and reuses the existing runs recovery index instead of adding another runs index.
Verification
Windows x64, Node 24.13.1, SQLite 3.51.2.
vp test run apps/server/src/persistence/Migrations/068_StartupRecoveryIndexes.test.ts apps/server/src/persistence/Migrations.test.ts apps/server/src/persistence/Migrations/055_OrchestrationV2.test.ts apps/server/src/persistence/reconcileV2PreviewMigration.test.ts apps/server/src/orchestration-v2/ProjectionStore.test.ts
# 5 files, 66 tests passed
vp fmt --check <the six changed files>
vp lint <the six changed files>
tsc-rs --noEmit -p apps/server/tsconfig.json
# All passed
The new test seeds 2,048 historical rows in each of runs, nodes, and subagents with 2 KB payloads. It exercises the real getRecoveryThreadIds method, including held queues, malformed queued metadata, a running run with queueHeld, deleted/archived threads, duplicate candidates, native versus app-owned subagents, and root nodes with/without an attached run. Replacing ProjectionStore.ts with the original main version makes the test fail because the runs recovery index is not used; restoring the patch passes.
I also extracted the full runtime candidate SQL, including the outer deleted-thread filter and ordering, from main and this branch and compared them on the same private pre-repair database copy. The copy contained 74,735 nodes, 87,101 turn items, 311 subagents, and 298 provider threads. Added main's existing runs recovery index where absent in the older snapshot, cleared planner statistics as current main does, and ran one initial execution plus 20 measured executions per version.
| Full startup candidate query |
Before |
After |
| Warm median |
22.849 ms |
0.801 ms |
| Warm range |
21.785–25.195 ms |
0.777–0.957 ms |
| Selected threads |
9 |
9 |
The ordered results were identical. Before: table scans for queued runs and native subagents, and a (thread_id, run_id) node lookup. After: the existing partial runs index, the new live-native subagent index, and a covering (thread_id, kind, status) node lookup. Building the final two indexes on the warmed copy took 285 ms.
Limits: these are warm-cache SQL measurements, not end-to-end desktop timing or a controlled cold-cache benchmark. An earlier contended build of a candidate index design was substantially slower; the warm build time is not a cold-migration estimate. Full production write-throughput impact was not measured. The database and raw logs are private and are not attached or committed.
Model: GPT-6. Harness: Codex.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Approvability
Verdict: Approved at 4e3e1ad
Macroscope's review found this PR approvable — This is a focused startup-recovery performance fix: it preserves candidate selection and adds targeted SQLite partial indexes to avoid scanning historical projection data. The accompanying test verifies migration behavior, result equivalence, and query-plan usage.
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.
coderabbitai
Bot
commented
Oct 20, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

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 8540e29 and 2dda29e.
Files selected for processing: 5
-
apps/server/src/orchestration-v2/ProjectionStore.ts
apps/server/src/persistence/Migrations.test.ts
apps/server/src/persistence/Migrations.ts
apps/server/src/persistence/Migrations/076_StartupRecoveryIndexes.ts
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
Limit details: You’ve used all 10 included reviews currently available.
Walkthrough
-
The runtime recovery query now includes eligible queued runs. Migration 076 adds partial indexes for startup recovery lookups and registers them with the migration loader. Tests cover recovery candidates, index use, and migration history.
Changes: Startup Recovery
| Layer / File(s) |
Summary |
Recovery query and indexes apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/persistence/Migrations/076_StartupRecoveryIndexes.ts, apps/server/src/persistence/Migrations.ts |
The recovery query includes queued runs unless valid payload JSON sets queueHeld to true. Migration 076 adds partial indexes for unattached projection nodes and live provider-native subagents, and the migration manifest includes it. |
Migration and query validation apps/server/src/persistence/Migrations.test.ts, apps/server/src/persistence/reconcileV2PreviewMigration.test.ts |
Tests verify recovery candidate IDs, migration application, query-plan index use, and migration 76 in upgrade and retry expectations. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Suggested reviewers: maria-rcks, juliusmarminge, t3dotgg
Merge Risk: Minimal · up to 2dda2
-
No actionable defect remains from this review; the change is mergeable after normal checks.
Security architecture risk: Low · up to 4e3e1
-
The changes preserve recovery eligibility and existing provider-session controls. No introduced security issue was identified. Remaining uncertainty concerns recovery from an interrupted database upgrade, rather than expanded access or privileges.
Retained concerns
No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The direct persistence and rollout scope is each server database receiving migration 068. Recovery candidate selection also feeds provider-session invalidation, but equivalent eligibility and unchanged downstream filters provide counterevidence against expanded session-control exposure.
Trust Boundaries and Controls
- observed — Recovery candidate membership does not itself authorize arbitrary provider-session release. Existing provider-auth logic checks instance identity and shared credential-binding key and owner, revalidating the binding for other provider instances before release. These controls predate this PR and remain unchanged.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title clearly and concisely describes the main change: preventing historical scans during server startup recovery. |
| Description check |
 |
The description includes all required sections. It explains the problem, the implementation, scope justification, detailed verification results, limitations, and tool attribution. It contains a minor … |
| 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. |
Full details: Description check
-
Explanation
The description includes all required sections. It explains the problem, the implementation, scope justification, detailed verification results, limitations, and tool attribution. It contains a minor migration-number inconsistency: it refers to migration 068, while the changes and latest objectives use migration 076.
Finishing Touches
-
Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Usage-based review receipt
Note This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note Written by gpt-6.1-sol on behalf of Maria
thanks @tensenlabs. matching the runs partial-index predicate and indexing live native subagents were the right fixes. i kept your commit and implementation, merged current main, and pushed ad46cba6602e1ce14bf64bd1829c8a5bf7c5359a to this branch without rewriting history.
- renumbered the migration to 70 because main now owns 68 and 69.
- preserved main's deletion of the old 055 test. moved your regression into the existing
Migrations.test.ts and updated preview-upgrade expectations.
- shortened the query comment. both indexes, held-queue filtering, malformed-json handling, and candidate deduplication remain. compared the original and final diffs; no functional part was dropped. the final diff against main is five files.
verification passed:
- the regression failed with main's run query even after installing the new indexes: the actual service query still scanned the historical run index. restoring the combined predicate passed.
- blacksmith
vp run check:changed: format, lint, knip, graphql checks, affected typechecks, and 59 tests passed. 14 additional provider recovery tests passed.
- github ci passed, including build/typecheck, lint, and all eight server shards.
- the real projection service migrated an isolated snapshot of this vm's database through 68/69/70, installed both indexes, and selected three runtime candidates. the source database was opened read-only; the snapshot was deleted.
- two independent gpt-6.1-sol reviews found no issues at this head. github reports the branch mergeable.
unverified: the original windows desktop startup failure, cold-start timing, and production-scale migration/write cost. no new end-to-end performance claim. coderabbit rate-limited its latest review; macroscope's approval covers the original head, so neither is presented as a fresh bot approval. no ui changes or ui evidence needed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
maria-rcks
commented
Oct 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Note Written by gpt-6.1-sol on behalf of Maria
Verified in a real dev environment
verified the exact head ad46cba6602e1ce14bf64bd1829c8a5bf7c5359a as-is on this linux boat vm. no code changes or pushes were needed.
- first ran
github/main (f17c9d202b) in a separate worktree after vp i. its actual recovery service query scanned the historical runs/subagents indexes. this reproduces the query-plan defect, not the original windows launch failure.
- then ran the exact pr head after
vp i, with an explicit isolated t3 home. used repository playwright and /usr/bin/google-chrome to add a project pointing at a real git checkout, create a thread, and send real codex gpt-6.1-sol turns. no mocks, fixtures, replay provider, or database seeding. main and pr servers ran sequentially.
- started a real long-running command, queued a follow-up with ctrl+enter, disabled automatic restart continuation in settings, killed the captured server pid, and restarted. recovery cancelled the active run and set
queueHeld=1. a second restart left the held queue unchanged, with zero additional terminalized runs. clicking "send now" completed the queued turn and displayed QUEUED_OK.
- spawned a real native codex child. before another crash/restart, its native roster and unattached root node were both running. recovery cancelled both; the client displayed "cancelled". a fresh parent turn then ran a git command and returned
RESTART_RESUME_OK. completed conversation history survived each restart.
- the actual pr recovery query used
runs_recovery_idx, nodes_unattached_recovery_idx, and subagents_live_native_idx. main and pr service queries selected the same two candidate threads on the same app-created native-running data, read-only.
- blacksmith: 59 migration/projection tests and 14 provider recovery tests passed. existing head ci has no failures (20 successful checks and 8 skipped). all task-owned dev servers, chrome, and the blacksmith worker were stopped.
short runtime transcript:
main: historical run index scans; broad native-subagent index scan
pr: runs_recovery_idx + nodes_unattached_recovery_idx + subagents_live_native_idx
crash restart: terminalizedRuns=1, stoppedSessions=1; queued run held
second restart: terminalizedRuns=0, stoppedSessions=0; queue still held
send now: queued -> completed, queueHeld=0, QUEUED_OK
native crash restart: native roster=cancelled, unattached root=cancelled
fresh user turn: completed, RESTART_RESUME_OK
blacksmith: 73 tests passed
full command transcript



Not verified
- the original windows desktop failure on the approximately 2.94 gb database, cold-start timing, production-scale migration/write cost, macos/windows electron, native ios/android, remote/relay connections, and other providers. this is correctness and index-selection evidence, with no end-to-end performance claim.
- integration with current main: github currently reports
CONFLICTING/DIRTY. current main assigns migration 70 to PeerLinks, while this exact head assigns it to StartupRecoveryIndexes. i used separate app-created databases to avoid skipping the pr migration. reconciliation is still required before integration; no merge, rebase, or force-push was attempted.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note Written by gpt-6.1-sol on behalf of Maria
merged github/main (cba30591f95859bc76154e5be97891ea4ae1b85a) into this head without rewriting history. pushed 8540e29eae5b4fa289648f864c941cf746d10780 to tensenlabs:fix/startup-recovery-indexes without force.
resolved the migration collision by moving startup recovery indexes from 70 to 74. preserved main's migrations 70–73, its manifest-file test, both recovery indexes, and candidate-selection coverage. scope remains five files, +192/-8 against main.
verification this pass:
- blacksmith
vp run check:changed: format, lint, knip, graphql checks, all three affected typechecks, and 59 tests passed.
- 15 additional provider recovery tests passed in blacksmith.
- isolated dev server applied migration 74 and completed startup recovery. a replay-provider turn completed through the running server; playwright with system chrome paired and opened the client. this is a startup/integration smoke check, not a repeat of the earlier real-codex crash/restart evidence.
- two independent gpt-6.1-sol reviewers found no findings at this exact head.
- github reports
MERGEABLE; there are no actionable existing bot findings.
not ready: six github workflows, including CI run https://github.com/pingdotgg/t3code/actions/runs/40979112834, ended action_required before starting any jobs. failed logs are unavailable because no jobs ran. workflow approval is needed; no approval was bypassed. coderabbit is still pending. stopped under the requested human-approval rule.
unverified at this new head: hosted CI, real-provider crash/restart, the original windows failure, and end-to-end performance. no new performance claim or UI change. no merge, rebase, force-push, or manual label changes.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note Written by gpt-6.1-sol on behalf of Maria
merged github/main (11df0cbc4a3726ca8ac4017cf6918329b91ad879) and pushed 2dda29e67d1e0c9b60238480b0ba70a88752932f to the existing head without force. resolved the migration collision by moving startup recovery indexes to 76, preserving main's 74/75. scope remains five files, +192/-8.
blacksmith vp run check:changed github/main passed format, lint, knip, graphql checks, three affected typechecks, and 59 tests. 15 additional provider recovery tests passed. two independent source reviewers found no findings at this head. an isolated dev server applied migration 76, completed startup recovery, and completed a replay-provider turn.
stopped for required workflow approval: six workflows ended action_required before running jobs. for example, https://github.com/pingdotgg/t3code/actions/runs/41171962990 has no jobs or failed logs. github reports this head mergeable, but it is not ready until hosted checks run and pass.
unverified: hosted CI at this head, browser client verification (playwright timed out), real-provider crash recovery, the original windows failure, and end-to-end performance. no UI change or new performance claim. task-owned server and blacksmith worker stopped.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR conflicts with main. Rebase it or merge main into it. If it still conflicts after 7 days with no activity, it will be closed automatically.
See the conflict window.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note 🤖 Claude Opus 5.5 responding on behalf of Theo
Closing. This PR has been open for more than 3 weeks, and main has moved a long way since then. If the change still matters, open a fresh PR from current main.
|
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
needs-rebase
Conflicts with its base branch. Closes after 7 days with no activity.
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.
|