fix(server): serialize scheduled task run transitions #21793
scheduler-tasks-05/client-edits fromscheduler-tasks-05/dispatch-transactions·opened View on GitHubStack: #21791 → #21792 → #21793.
Problem#
A scheduled-task definition can change between its due read and reservation or between dispatch and completion. Runs should reserve and complete using a consistent live definition without overwriting a newer edit.
Change#
A task edit can commit between the scheduler’s due read and reservation, or between dispatch and completion. Read the live definition and write each reservation, completion, missed-run reschedule, and stuck-run release inside its write transaction. Keep provider execution outside the transaction and guard cleanup by the reservation timestamp. Manual runs recheck the live trigger and project before launching.
Scope and approval#
Maintainer takeover of @saphid’s #11592, announced in the takeover comment. This stack rebuilds the same atomic-edit and scheduler concurrency scope against current main. The publishing maintainer, @juliusmarminge, is listed in the explicit maintainer triage exemptions; contribution eligibility is separate from correctness approval. This work remains unmerged and subject to current-head CI and human review.
Verification#
Rebuilt from @saphid’s #11592.
After integrating main, bottom scheduler/webhook suites pass 44/44 and the full integrated scheduler/webhook suites pass 47/47. The project-ownership regression covers three timings: before the request, before the dispatch re-read, and immediately before the reservation update. The last timing failed before the predicate fix and passes now. On this layer its hook injects a synthetic nested mutation inside the write transaction; it checks the defensive predicate and rollback, not physical independent-connection contention.
Web/mobile builder suites were rerun and pass 72/72. Targeted service/test lint and the integrated server-only typecheck pass. Earlier web/mobile typechecks and MCP/contracts/runtime checks passed. No repository-wide checks were run.
The takeover adds 26 cases in five existing files (738 added/4 removed primary test lines), replacing the original 66 cases/2,071 lines. Main integration retains one additional existing webhook retry regression; it is not counted as a new takeover test. An earlier broader focused run passed 123 cases before later parameterized regressions; that broader run was not repeated.
This is the third takeover layer. The client layer embeds web proof captured before the nonvisual reservation fix and main integration, which leave those scheduler save flows unchanged. No live provider was launched for scheduler proof; native platforms, process-interruption injection, actual older-server runtime, relay/tunnel runtime, and physical multi-connection SQLite contention were not exercised.
Three independent review rounds addressed binding-mode, live-trigger, legacy-interval, model-selection, and project-scope findings. A later bot finding exposed a move between the dispatch re-read and reservation update. One additional timing case reproduced it, and the reservation now also matches the expected project. The fourth independent round (Claude Opus 5.5 and GPT-6 Sol) found no additional code blockers in each individual layer or the complete stack. Main was then integrated to retain its webhook acceptance claim cleanup; the fixture conflict preserves both incoming retry coverage and takeover credential/binding coverage. The fifth independent round (Claude Opus 5.5 and GPT-6 Sol) found no additional code blockers in each layer or the combined stack against the integrated main base. Current-head CI and bot reassessment remain required.
Implementation: GPT-6.1 Sol (high), Codex harness through T3 Code. Tests: GPT-6 Astra (high), Codex. Independent review: Claude Opus 5.5 and GPT-6 Sol through T3 Code.
- 1
juliusmarminge changed the title
juliusmarminge added labelsmacroscope-review
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:L
Approvability#
Verdict: Approved at
78fa3e5Macroscope's review found this PR approvable — This is a focused scheduler concurrency fix that serializes task-definition reads with run-state transitions and guards completion against stale reservations. The production change is localized, keeps provider execution outside database transactions, and includes targeted regression tests.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).169c0f3. Prior analysis still applies.No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
7ac4c01c-10a2-4a68-882c-0ca443a0b769
📥 Commits
-
Reviewing files that changed from the base of the PR and between bc26b219a5122c0b96ff862961e104b52cc6354c and 78fa3e5bdada82a70b698ce077dad65ba2bacd8a.
📒 Files selected for processing: 2
-
apps/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; 0 remain after this review.
-
📝 Walkthrough
-
Scheduled task reservation, completion, failure recovery, and missed-run rescheduling now check current task state within transactions. Regression tests cover task changes during reservation and completion.
Changes: Scheduled task execution
Layer / File(s) Summary Validate and reserve runs
apps/server/src/scheduledTasks/ScheduledTaskService.ts,apps/server/src/scheduledTasks/ScheduledTaskService.test.tsReservation rereads and validates the task before marking a run as running. Tests cover project changes and webhook conversion before reservation. Record completion and recover failed runs
apps/server/src/scheduledTasks/ScheduledTaskService.ts,apps/server/src/scheduledTasks/ScheduledTaskService.test.tsCompletion rereads the task in a transaction. Failure recovery updates only the matching running attempt. A test checks that a pause committed before completion is preserved. Reschedule missed runs
apps/server/src/scheduledTasks/ScheduledTaskService.tsMissed-run rescheduling proceeds only when the current task remains enabled and its next-run time and schedule match the polled snapshot. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Suggested reviewers:
maria-rcks
Merge Risk: ⚪ Minimal · up to
78fa3-
No confirmed issue blocks merging after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title is concise, specific, and accurately describes the main change: serializing scheduled task run transitions. 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. Description check The pull request includes all required sections: Problem, Change, Scope and approval, and Verification. It describes the concurrency issue, implementation, maintainer approval context, focused test re… Full details: Description check
-
Explanation
The pull request includes all required sections: Problem, Change, Scope and approval, and Verification. It describes the concurrency issue, implementation, maintainer approval context, focused test results, limitations, and agent details.
-
✨ Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
ℹ️ No successful
mainbaseline artifact is available yet. This run establishes the initial measurement.Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅ Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅ Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Codex Live turn WebSocket decoded — 20.9 KiB — 29.3 KiB ✅ Codex Live turn messages — 2 — 8 ✅ Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅ Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅ Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Claude Live turn WebSocket decoded — 21.2 KiB — 29.3 KiB ✅ Claude Live turn messages — 2 — 8 ✅ Baseline: unavailable · PR result:
169c0f3· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
#28474 merged as ce9e01640636c0884c4a7574a722bf1d773cfa07. It moves the
activeRunsreservation inrunTaskinto anEffect.acquireUseReleaseat the end of the function, so this PR now conflicts inrunTask. When you rebase, keep the run body in the bracket's use step so an interrupt still releases the reservation.Verified by two focused tests that fail on the old main, plus all 102 scheduled task tests and CI on the merged head.
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed