Skip to content

fix(server): load only due tasks during scheduler ticks - #9925

Open
saphid wants to merge 4 commits into
pingdotgg:t3code/codex-turn-mappingfrom
saphid:fix/v2-scheduled-due-query-20260905
Open

fix(server): load only due tasks during scheduler ticks#9925
saphid wants to merge 4 commits into
pingdotgg:t3code/codex-turn-mappingfrom
saphid:fix/v2-scheduled-due-query-20260905

Conversation

@saphid

@saphid saphid commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

The five-second scheduler tick reads and decodes every scheduled task, including disabled and future tasks. Select only enabled, due, non-running rows using the existing partial due-task index, preserving task order and lenient handling of malformed due rows. API listing and one-time startup recovery retain their full reads.

Validation: seven focused scheduler/query tests pass, including due, disabled, future, running, and malformed records. SQLite EXPLAIN confirms use of idx_scheduled_tasks_due. Server typecheck, formatting, targeted lint, and diff check pass. No schema changes or live state writes.

Targets Julius’s V2 branch in #2829 at 2ac9bfe; addresses audit F22. Direct Claude Opus 5 high review was attempted but exited 1 before model execution because OAuth expired; no Claude review is claimed.

Implemented with Codex workers and reviewed with GPT-6 in Codex/T3.

Current-base verification

Updated to exact V2 base 415ed0f73b97f1655b6282492f81d0b2bba3a9cc at head 6c21fce33e87b5e1c96c7ead729f4531990d9773. The original leaf plus this base synthesizes cleanly as tree 6b21f30c377ac1228d0ee443007977c1c8f3ee4e; current V2 base does not contain loadDueScheduledTasks or its service integration regression.

  • 7/7 focused schedule and due-task service tests pass.
  • Server typecheck and targeted lint pass.
  • Diff checks pass; the contribution remains limited to ScheduledTaskService.ts and its test.

The service still owns the captured SQL client and preserves full reads for API listing and startup recovery. No schema or live-state write was made. Fresh independent Claude review remains unavailable because OAuth is signed out; no Claude review is claimed. Refreshed by GPT-6 in the Codex harness.

Note

Load only due tasks in ScheduledTaskService.runDueTasks scheduler tick

  • Replaces the previous lenient helper that loaded every scheduled-task row with loadDueScheduledTasks, which selects only enabled rows with next_run_at at or before the supplied timestamp and excludes rows whose last run is already running.
  • runDueTasks now captures the local current time once and passes its ISO representation to bound the SQL query, while retaining the epoch-based due check on decoded task values.
  • Decode failures are logged and skipped individually rather than failing the entire due-task load.
  • Adds integration tests in ScheduledTaskService.test.ts verifying that only valid due tasks reach the launch boundary; disabled, future, already-running, and malformed rows do not.
  • Behavioral Change: disabled, future, and already-running rows are now excluded at the SQL level before decoding, whereas they were previously loaded and filtered in memory.

Macroscope summarized 6c21fce.


Note

Medium Risk
Changes scheduler polling and SQL filtering for when tasks fire; behavior should match prior filters but any query/index mismatch could miss or duplicate runs.

Overview
Scheduler ticks no longer scan every scheduled task row. Each poll now calls exported loadDueScheduledTasks, which selects only enabled rows with next_run_at set and not after the current time, excluding tasks already running, ordered like the API list. That path is meant to use the existing idx_scheduled_tasks_due index instead of a full-table read.

Lenient row decoding for the poller (skip bad rows with a warning) moves into loadDueScheduledTasks; the internal listTasksLenient helper that loaded all rows is removed. runDueTasks loads candidates through the new query, then still applies in-memory due/missed-run logic. API list and startup stuck-run recovery keep full-table reads with strict decoding.

A new ScheduledTaskService.test effect test seeds disabled, future, running, and malformed due rows and asserts only the valid due task is returned.

Reviewed by Cursor Bugbot for commit f106115. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor

cursor Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

This PR is too large for Bugbot to review. It changes 99,212 lines and 4,021,181 characters. Split the change into smaller pull requests to get a review.

@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Sep 5, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies.

@github-actions github-actions Bot added the size:XXL 1,000+ changed lines (additions + deletions). label Sep 5, 2026
@juliusmarminge
juliusmarminge force-pushed the t3code/codex-turn-mapping branch from b82facd to 2ac9bfe Compare September 5, 2026 04:56
@macroscopeapp

macroscopeapp Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at d05a0ba

Macroscope's review found this PR approvable — The production change narrows scheduler polling to enabled, non-running tasks whose next run is due while preserving existing dispatch, API listing, and recovery paths. A focused in-memory test covers the relevant task categories, and no defaults, schema, static-analysis overrides, or sensitive areas are touched.

You can add or adjust custom eligibility rules. Learn more.

@saphid
saphid force-pushed the fix/v2-scheduled-due-query-20260905 branch from aa837b8 to f106115 Compare September 5, 2026 05:11
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:XXL 1,000+ changed lines (additions + deletions). labels Sep 5, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Sep 5, 2026
Comment thread apps/server/src/scheduledTasks/ScheduledTaskService.ts Outdated
@macroscopeapp
macroscopeapp Bot dismissed their stale review September 6, 2026 05:00

Dismissing prior approval to re-evaluate d05a0ba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant