Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): skip the run history scan when finding a scheduled turn #48256

OpenUtkarshUsername(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48256/headopened View on GitHub

Problem

When a scheduled task posts to the same thread repeatedly, recording its outcome decodes every run in the thread to find the one it dispatched. The server repeats that work for each pending outcome it resumes at startup.

Change

Use a partial SQLite index to find the earliest run with the scheduled prompt ID. This preserves the original run selection if a queued message has since moved into another run as a steer. The waiter still follows restart continuations.

Scope

This is a server-side performance fix for the scheduled outcome lookup used by #47732.

Verification

I ran both lookup paths on the same in-memory SQLite fixture on InstaBox. The fixture had 5,000 runs, including two with the same scheduled prompt ID.

Lookup                     Run rows decoded   Selected ordinal
Full projection                        5000               4999
Indexed scheduled lookup                  1               4999
Indexed lookup, missing ID                0

SQLite sought the partial index on both the thread ID and the prompt ID. The counts cover the initial lookup. The shared waiter reads run history to follow restart continuations.

The projection, scheduler, thread-management, and migration suites passed 218 tests, including the promoted-steer and restart outcome cases. vp run check:changed passed on InstaBox.

Written and verified by GPT-6.2 Sol in Codex.

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

    2. Approvability

      Verdict: Approved at dd690a2

      Macroscope's review found this PR approvable — Scheduled-task outcome tracking now queries the earliest matching run directly instead of loading run history. The supporting migration adds only a partial index, without changing stored records or product defaults.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The projection store now supports filtering scheduled runs by message ID, backed by a new partial index. recordRunOutcome uses this filter instead of fetching all thread runs and searching locally.

      Changes: Scheduled run lookup

      Layer / File(s)Summary
      Message-ID query and index
      apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/persistence/Migrations/127_ScheduledRunPromptIndex.ts, apps/server/src/persistence/Migrations.ts, apps/server/src/orchestration-v2/ProjectionStore.test.ts, apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
      ProjectionRecordFilter accepts scheduledRunMessageId. The query matches scheduled-task message IDs and returns at most one result. Migration 127 registers an index on thread ID, extracted message ID, and ordinal. Tests check indexed lookup, missing IDs, and migration registration.
      Scheduled task outcome lookup
      apps/server/src/scheduledTasks/ScheduledTaskService.ts, apps/server/src/scheduledTasks/ScheduledTaskService.test.ts
      recordRunOutcome requests the run associated with its message ID. The test fixture now includes only the current run.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Refactor

      Suggested reviewers: gabrielelpidio, stienswout, yash-singh1

      Merge Risk: Minimal · up to dd690

      Scheduled-task outcome recording now looks up the run through an index instead of decoding every run in the thread. No concrete regression was found in the forwarding path, query, index or migration registration, so the change looks safe to merge.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: a scheduled-turn lookup no longer scans the full run history, and a partial SQLite index is used instead. It follows the conventional commit format with the perf(serve…
      Description checkPassedThe description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem and Change sections clearly explain the decoding cost and the partial index fix. Scope links…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the main change: a scheduled-turn lookup no longer scans the full run history, and a partial SQLite index is used instead. It follows the conventional commit format with the perf(server) scope. The title is specific and matches the summarized changes to ProjectionStore, the migration, and ScheduledTaskService.

      Full details: Description check

      Explanation

      The description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem and Change sections clearly explain the decoding cost and the partial index fix. Scope links to #47732 and describes a server-side performance fix, but does not explain why no separate issue is needed for a performance change, and it does not link a maintainer request. Verification gives concrete counts from the fixture and lists the suites run. It also names the model and harness as the template asks. The description does not state whether the change also needs a new test beyond the reported runs, though the summary shows one was added. These gaps are minor.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between a75e74eb48d6bb7b758401bc85a8d24d9c690bfa and dd690a2a14df6042bf44849738c86cf85af69cd5.

      Files selected for processing: 7

      • apps/server/src/orchestration-v2/ProjectionStore.test.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts
      • apps/server/src/persistence/Migrations.ts
      • apps/server/src/persistence/Migrations/127_ScheduledRunPromptIndex.ts
      • apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
      • apps/server/src/scheduledTasks/ScheduledTaskService.test.ts
      • apps/server/src/scheduledTasks/ScheduledTaskService.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.

Sign in to join this conversation.