perf(server): skip the run history scan when finding a scheduled turn #48256
main fromrefs/pull/48256/head·opened View on GitHubProblem#
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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
dd690a2Macroscope'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).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.
recordRunOutcomeuses 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.tsProjectionRecordFilteracceptsscheduledRunMessageId. 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.tsrecordRunOutcomerequests 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 todd690-
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:
4-
Check name Status Explanation Title check 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(serve… Description check 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… 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: 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
#47732and 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: a75e74e
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
888d6ec0-040f-402d-880e-1c0eae48cc33
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.tsapps/server/src/orchestration-v2/ProjectionStore.tsapps/server/src/persistence/Migrations.tsapps/server/src/persistence/Migrations/127_ScheduledRunPromptIndex.tsapps/server/src/persistence/reconcileV2PreviewMigration.test.tsapps/server/src/scheduledTasks/ScheduledTaskService.test.tsapps/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.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes