fix(server): failed threads no longer scan every tool item for errors #18628
main fromrefs/pull/18628/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubFailed threads scan and sort every tool item in the run just to find their root error. Shell reads force the broad thread/run index, and usage-limit recovery has the same expensive lookup.
Add a partial index for failed errors, ordered by thread, run, root node and the existing error tie-breakers. Remove the shell's broad-index hints. Completed tool output no longer enters this lookup; null roots and newer child errors keep the same behavior.
A 50,000-tool fixture returns the same root error before and after:
| Root-error lookup | Before | After |
|---|---|---|
| Median of 9 warm queries | 12.672 ms | 0.0025 ms |
| SQLite VM steps (rounded to 100) | 250,000 | <100 |
| Temporary sort | Yes | No |
These are lookup timings, not a whole-app speedup. Live shell and recovery traces confirmed this is a hot path.
Validation: 51 focused tests pass, including existing shell/recovery query plans and fresh-ledger/preview upgrades; server typecheck passes on the M4 mini. The earlier isolated client displayed the right root failure with 50,000 valid tools and passed search, settled-thread and PR navigation without page errors.
Test cleanup: removed both added migration-local lookup cases and their 54-line fixture file. They repeated SQLite behavior with a hand-written query instead of exercising the caller. Existing product-query plan checks remain; deliberate mutations to the partial-index predicate and forced broad shell index fail those checks. Types/static analysis cover the query/service shape, not index selection. No production code, dependencies or runner configuration changed. Independent Codex review of the deletion slice found no actionable regression.
No client, provider or wire changes; the shared server path covers web, desktop, mobile and remote connections. The installed app was not updated, and verification servers used separate state.
Fixes #18610.
Completion: 5/5.
Model: GPT-6.1-Sol (high). Harness: Codex in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
66bebfaMacroscope's review found this PR approvable — This is a narrowly scoped server performance fix that adds a partial index and lets existing failed-thread queries use it without changing their filtering or results. The accompanying changes are migration and query-plan test updates, with no product-default, API, security, billing, or static-analysis changes.
Notes:
- No code objects were reviewed. Approvability was decided on eligibility alone.
juliusmarminge added labelsmacroscope-review
💡 Codex Review#
Here are some automated review suggestions for this pull request.
Reviewed commit:
080173be4dℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
apps/server/src/persistence/Migrations.ts line 154Resolvedby realhasanshoaib(GitHub profile, opens in a new tab)@@ -150,3 +151,4 @@150151 [59, "McpAppModelContext", Migration0059],151152 [60, "ThreadSnapshotWindowIndexes", Migration0060],152153 [61, "PullRequestReviewGuides", Migration0061],154+ [62, "ThreadFailureLookupIndex", Migration0062],Update migration expectations for migration 62
Whenever the persistence suite runs, this new entry makes both
migrationEntriesandrunMigrations()include migration 62, butMigrations/055_OrchestrationV2.test.tsstill expects IDs and history to end at 61 andreconcileV2PreviewMigration.test.tsstill expects preview upgrades to return only through 61. Those exactdeepStrictEqualassertions now fail deterministically, so CI's full suite cannot pass until the expected arrays and history includeThreadFailureLookupIndex.AGENTS.md reference: AGENTS.md:L100-L100
Useful? React with 👍 / 👎.
Confirmed and fixed in 0dae90dca8: both fresh-ledger expectations and both preview-upgrade arrays now include migration 62. Re-ran the complete focused scope on Node 24.13.1 (M4 macOS): 53 tests passed, server typecheck passed, and lint found no warnings or errors. This includes the fresh migration ledger, upgrade/idempotence, and preview rollback/retry paths.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2c533bcc-6a02-4ee7-b0cb-6dd081ea8168
📥 Commits
-
Reviewing files that changed from the base of the PR and between 080173be4d5aafa02c0e2c6e43b26a845012e183 and 0dae90dca81c99d5536332ecbf971b8e4fda198c.
📒 Files selected for processing (2)
-
apps/server/src/persistence/Migrations/055_OrchestrationV2.test.tsapps/server/src/persistence/reconcileV2PreviewMigration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
-
📝 Walkthrough
-
📝 Walkthrough
-
📝 Walkthrough
-
📝 Walkthrough
-
📝 Walkthrough
-
📝 Walkthrough
-
Walkthrough#
The change adds and registers migration 62 with a partial index for failed-error lookups. Failure queries no longer force the broad thread/run index. Tests check lookup ordering, migration registration, and index use in query plans.
Changes#
Failed-error lookup optimization
Layer / File(s) Summary Create and register the failed-error index
apps/server/src/persistence/Migrations/062_ThreadFailureLookupIndex.ts,apps/server/src/persistence/Migrations.ts,apps/server/src/persistence/Migrations/062_ThreadFailureLookupIndex.test.ts,apps/server/src/persistence/Migrations/055_OrchestrationV2.test.ts,apps/server/src/persistence/reconcileV2PreviewMigration.test.tsMigration 62 creates and registers a partial index on thread, run, node, and descending update time, ordinal, and turn-item ID. Migration tests check lookup ordering and query-plan behavior, and expect migration 62 in upgrade and retry results. Use the failed-error index in lookups
apps/server/src/orchestration-v2/ProjectionStore.ts,apps/server/src/orchestration-v2/ProjectionStore.test.ts,apps/server/src/orchestration-v2/ProjectionSettlement.test.tsThe terminal and blocking failure lookups no longer force the broad thread/run index. Query-plan tests check that qualifying lookups use the failed-error index with thread, run, and node constraints. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
-
-
-
-
-
Merge Risk: ⚪ Minimal · up to
2a9b2The supplied evidence shows the migration and lookup tests cover the intended index path and ordering. No concrete merge-blocking issue is established.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
0dae9The change adds a database index while preserving which failures are selected and how recovery eligibility is determined. No introduced security issue was identified, but interrupted upgrades and simultaneous startup were not fully verified.
Retained concerns No architecture-level concerns identified.
-
Security review details
-
Security Blast Radius
- inferred — The evidenced change affects index creation in the server database and existing shell and recovery failure reads. No expanded data exposure or privilege is demonstrated by this diff; this does not establish complete security coverage outside that surface.
Trust Boundaries and Controls
- observed — Removing index hints does not remove the existing thread, run, failed-error or root-node restrictions. The index predicate matches those restrictions rather than replacing them as a control.
Resilience and Maintainability Implications
- observed — Existing preview reconciliation has explicit transactional rollback and retry coverage. That counterevidence supports its own recovery path but does not prove atomic rollback or interruption recovery for migration 62.
-
Pre-merge checks |
4-
✅ Passed checks (4 passed)
-
Check name Status Explanation Description check The description covers the problem, change, scope, linked issue, and verification. It contains a material inconsistency: it says the 54-line migration test was removed, while the changes add that test… Linked Issues check The description references and closes issue #18610, and the implementation directly addresses the issue objectives.Out of Scope Changes check The changes are focused on the server migration, failure lookup queries, and related tests. No unrelated client, provider, wire, dependency, or runner changes are reported. Title check The title clearly and concisely describes the primary change: failed threads no longer scan every tool item for errors.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- 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.-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
66bebfaℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.