You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): fixed-time scheduled tasks interrupted before dispatch no longer skip the slot - #49417
When a fixed_time scheduled task starts its on-time run (markRunning writes last_run_status = 'running' and last_run_at = startedAt, leaving next_run_at at the due slot) and the server restarts before orchestration dispatch commits, startup recovery in ScheduledTaskService skips the current occurrence even when the server comes back within the 10-minute grace window:
The existing fixed-time recovery branch only preserves slot when startedAt < slot, which is always false for the interrupted run of slot itself (startedAt >= slot).
task.nextRunAt is present and <= slot (guarding against re-firing an already-completed slot if a manual "Run now" during the grace window was interrupted after next_run_at already advanced).
If orchestration_command_receipts confirms no accepted receipt exists for the interrupted run's scheduled or manual command IDs, recovery re-arms next_run_at = iso(slot) and leaves run_count unchanged so the next poll runs the slot once.
If an accepted receipt exists, the receipt lookup errors, or the grace window has passed, recovery preserves existing behavior (advances next_run_at to the next future occurrence and increments run_count), preventing duplicate dispatches.
Interrupted before dispatch within the grace period → re-arms and dispatches once without double-counting run_count.
Interrupted after dispatch was already accepted → does not dispatch again and advances to the next slot.
Manual run interrupted before dispatch during the grace window after today's slot already completed (next_run_at already tomorrow) → does not re-fire today's slot.
Scope
Focused bug fix for lost fixed-time scheduled runs interrupted across a server restart before dispatch (a small fix for an obvious bug in the same recovery path as #49223, needing no separate issue). No other schedule types, handlers, or surfaces were modified.
Verification
1. Before-fix reproduction (against base 00599a7ba6a8715c56eb4a13a7aa88355ec4696c)
Ran vp test run apps/server/src/scheduledTasks/ScheduledTaskService.test.ts -t "fixed-time" with only the regression tests added:
❯ |t3| src/scheduledTasks/ScheduledTaskService.test.ts (15 tests | 1 failed | 12 skipped) 168ms
× a fixed-time run a restart interrupted before dispatch still sends its prompt within the grace period 78ms
✓ a fixed-time run a restart interrupted after dispatch is not sent again 47ms
✓ a fixed-time manual run interrupted before dispatch does not re-fire an already-completed slot 43ms
FAIL |t3| src/scheduledTasks/ScheduledTaskService.test.ts > a fixed-time run a restart interrupted before dispatch still sends its prompt within the grace period
AssertionError: expected [] to deeply equal [ 'Run task' ]
- Expected
+ Received
- [
- "Run task",
- ]
+ []
vp test run apps/server/src/scheduledTasks/ScheduledTaskService.test.ts: 15 passed (15) in 1.37s:
✓ |t3| src/scheduledTasks/ScheduledTaskService.test.ts (15 tests) 623ms
✓ loads only due tasks and skips corrupt due rows without decoding settled tasks 63ms
✓ releases interrupted runs on startup and still executes due tasks, skipping corrupt rows 51ms
✓ a one-time run a restart interrupted before dispatch still sends its prompt 43ms
✓ a one-time run a restart interrupted after dispatch is not sent again 40ms
✓ a fixed-time run a restart interrupted before dispatch still sends its prompt within the grace period 40ms
✓ a fixed-time run a restart interrupted after dispatch is not sent again 38ms
✓ a fixed-time manual run interrupted before dispatch does not re-fire an already-completed slot 38ms
✓ thread cleanup notifies subscribers and a finishing run cannot recreate the task 41ms
✓ an accepted run that ends failed (held: false) records it 39ms
✓ an accepted run that ends interrupted (held: false) records it 38ms
✓ an accepted run that ends completed (held: true) records it 38ms
✓ a one-time task is removed once its turn completes 41ms
✓ a fresh-session task launches one thread, then starts each later run fresh in it 39ms
✓ refuses saving an enabled task above the policy ceiling 39ms
✓ checks a task's destination thread only when the destination changes 37ms
Timezone checks: TZ=UTC (3 passed | 12 skipped) and TZ=America/Los_Angeles (3 passed | 12 skipped) both pass.
vp test run apps/server/src/scheduledTasks/ScheduledTaskService.test.ts apps/server/src/scheduledTasks/ScheduledTaskService.schedule.test.ts: 18 passed (18) across both files.
vp run check:changed on 05151d7cbb84663da5d28388f46faa526d0b66e1:
check:changed summary
pass format 0.2s
pass lint 0.3s
pass knip 5.1s
pass graphql (apps/server) 0.6s
pass typecheck (3 packages) 5.6s
pass test (5 files) 6.3s
CI also runs: full test suites, build
unused patch check skipped: no dependency files changed
(5 test files / 44 tests passed: ScheduledTaskService.test.ts, ScheduledTaskService.webhook.test.ts, ScheduledTaskService.schedule.test.ts, ScheduledTaskService.interval.test.ts, and AgentContextBudget.test.ts.)
Not shown
Full repository-wide test suite and production build (left to CI per AGENTS.md).
Live end-to-end process crash/restart against a real external provider CLI (covered deterministically in unit tests via SQLite persistence and TestClock).
Bug investigation assisted by Codex. Generated with Gemini 4 Neon in T3 Code (Antigravity).
Macroscope's review found this PR approvable — Interrupted fixed-time tasks can now retry their still-due slot after restart instead of skipping it. Recovery remains bounded by the existing grace period and checks for accepted dispatch receipts before retrying.
You can add or adjust custom eligibility rules. Learn more.
Reviewing files that changed from the base of the PR and between 05151d7 and 437b4eb.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Interrupted scheduled-task recovery now selects retry times for eligible fixed-time runs as well as one-time runs. Tests cover runs without accepted dispatch, runs with an accepted dispatch receipt, and runs whose fixed-time slot was already completed.
Changes: Scheduled-task recovery
Layer / File(s)
Summary
Retry selection and restart-recovery tests apps/server/src/scheduledTasks/ScheduledTaskService.ts, apps/server/src/scheduledTasks/ScheduledTaskService.test.ts
Recovery selects a retry time for eligible one-time and fixed-time runs, then uses it for next_run_at. Tests verify launch behavior, task status, next-run time, and run count across the covered interruption cases.
This change makes interrupted fixed-time scheduled tasks retry their current slot after a restart when dispatch never happened, and keeps the existing behavior when it did. Regression tests cover the changed paths, and no concrete merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix and the area: fixed-time scheduled tasks interrupted before dispatch no longer skip the slot. The raw summary and PR objectives confirm the change extends interrupted-run recov…
Description check
The description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem section gives the failure mode and root cause. The Change section lists the three guard cond…
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 fix and the area: fixed-time scheduled tasks interrupted before dispatch no longer skip the slot. The raw summary and PR objectives confirm the change extends interrupted-run recovery in ScheduledTaskService to fixed-time tasks and re-arms the current slot. The title is specific and matches the main change, though it is long (91 characters).
Full details: Description check
Explanation
The description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem section gives the failure mode and root cause. The Change section lists the three guard conditions and the test cases. The Scope section explains why no issue link is needed. The Verification section includes a before-fix failure and after-fix results, and it states what was not checked. The Scope section does not link a related issue, but it explains the omission as the template allows. The description also ends with the model and harness line the template asks for. The description is complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Real web app in Chromium 156 on Linux, 1280×800, light theme, UTC, fresh synthetic databases, built-in Replay (dev). Both commits ran the same scenario.
On each commit, start fresh real servers with UTC and Replay (dev), create Sample through t3.project, and create Daily repro task through scheduledTasks.upsert: enabled, daily fixed time, new thread each run, project checkout, prompt Say hello from the fixed-time slot. Schedule the next UTC minute (15:29 on base; 15:32 on head). Attach the Node inspector and break at const fireKey, after markRunning and before dispatch. At the breakpoint inspect persisted state, SIGKILL that owned server, wait two seconds, and restart it on the same database. Observe multiple real scheduler polls for 20 seconds after startup, capture Scheduled tasks, and check persisted status, run count, accepted root dispatch receipts across both receipt stores, and exact prompt-message count. On head, open the resulting thread and expand its Automation message.
The finished scenario reports classify base as failed on the expected status assertion and head as passed (exit code 0). The outer command wrapper exited with SIGTERM while head continued; proof.json was assembled from both finished reports using the runner's readSide/buildProof functions. The automatic failure screenshot taken after teardown is omitted from this table.
Not shown:
Interruption after dispatch acceptance and interruption of a manual run after its fixed-time slot already completed were not exercised; this proof targets the reported pre-dispatch lost-slot reproduction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:S10-29 changed lines (additions + deletions).vouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
fixed_timescheduled task starts its on-time run (markRunningwriteslast_run_status = 'running'andlast_run_at = startedAt, leavingnext_run_atat the due slot) and the server restarts before orchestration dispatch commits, startup recovery inScheduledTaskServiceskips the current occurrence even when the server comes back within the 10-minute grace window:slotwhenstartedAt < slot, which is alwaysfalsefor the interrupted run ofslotitself (startedAt >= slot).schedule.type === "once".As a result, recovery advances
next_run_atto the next day/weekday and incrementsrun_counteven though no prompt was ever dispatched.Change
apps/server/src/scheduledTasks/ScheduledTaskService.ts: Extend the fix(server): a restart no longer consumes a one-time task it never sent #49223 accepted command-receipt retry check during startup recovery to enabledfixed_timetasks when all of the following hold:currentFixedTimeSlot(task.schedule, now)returns a non-nullslot(restart is still within the 10-minute grace window).startedAt >= slot(preserving the existingstartedAt < slotbranch untouched).task.nextRunAtis present and<= slot(guarding against re-firing an already-completed slot if a manual "Run now" during the grace window was interrupted afternext_run_atalready advanced).orchestration_command_receiptsconfirms no accepted receipt exists for the interrupted run'sscheduledormanualcommand IDs, recovery re-armsnext_run_at = iso(slot)and leavesrun_countunchanged so the next poll runs the slot once.next_run_atto the next future occurrence and incrementsrun_count), preventing duplicate dispatches.apps/server/src/scheduledTasks/ScheduledTaskService.test.ts: Add three focused restart-recovery regression tests matching fix(server): a restart no longer consumes a one-time task it never sent #49223's pattern:run_count.next_run_atalready tomorrow) → does not re-fire today's slot.Scope
Focused bug fix for lost fixed-time scheduled runs interrupted across a server restart before dispatch (a small fix for an obvious bug in the same recovery path as #49223, needing no separate issue). No other schedule types, handlers, or surfaces were modified.
Verification
1. Before-fix reproduction (against base
00599a7ba6a8715c56eb4a13a7aa88355ec4696c)Ran
vp test run apps/server/src/scheduledTasks/ScheduledTaskService.test.ts -t "fixed-time"with only the regression tests added:2. After-fix verification (commit
05151d7cbb84663da5d28388f46faa526d0b66e1)vp test run apps/server/src/scheduledTasks/ScheduledTaskService.test.ts: 15 passed (15) in 1.37s:TZ=UTC(3 passed | 12 skipped) andTZ=America/Los_Angeles(3 passed | 12 skipped) both pass.vp test run apps/server/src/scheduledTasks/ScheduledTaskService.test.ts apps/server/src/scheduledTasks/ScheduledTaskService.schedule.test.ts: 18 passed (18) across both files.vp run check:changedon05151d7cbb84663da5d28388f46faa526d0b66e1:(5 test files / 44 tests passed:
ScheduledTaskService.test.ts,ScheduledTaskService.webhook.test.ts,ScheduledTaskService.schedule.test.ts,ScheduledTaskService.interval.test.ts, andAgentContextBudget.test.ts.)Not shown
AGENTS.md).TestClock).Bug investigation assisted by Codex. Generated with Gemini 4 Neon in T3 Code (Antigravity).