Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): failed threads no longer scan every tool item for errors #18628

Mergedrealhasanshoaib(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/18628/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Failed 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 lookupBeforeAfter
Median of 9 warm queries12.672 ms0.0025 ms
SQLite VM steps (rounded to 100)250,000<100
Temporary sortYesNo

These are lookup timings, not a whole-app speedup. Live shell and recovery traces confirmed this is a hot path.

Reproduction scripts.

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. chatgpt-codex-connector[bot](GitHub profile, opens in a new tab)commented

      Codex Review Summary

      This comment shows the latest Codex review activity on this pull request.

      ReviewStatusCommitReview trigger
      📝 Code Review✅ Completed 2026-10-12T12:28:28.621938Z66bebfaNew commits
      ℹ️ 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" or "@codex security review".

      Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 66bebfa

      Macroscope'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.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge added labelsmacroscope-review

    5. 💡 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".

    6. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/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.ts
      Migration 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.ts
      The 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 2a9b2

      The 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 0dae9

      The 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 | Passed 4
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Description checkPassedThe 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 checkPassedThe description references and closes issue #18610, and the implementation directly addresses the issue objectives.
      Out of Scope Changes checkPassedThe 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 checkPassedThe 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.

Sign in to join this conversation.