Stacked on #11592. Until that merges, this diff also shows its commit; review only fix(server): scheduler writes no longer overwrite concurrent task edits.
Problem#
Run completion, stuck-run release, and dispatch each re-read the task and then wrote in a separate statement. An edit committed between the two had its next_run_at overwritten from the older schedule, and a pause, postpone, or delete landing after the dispatch re-read could still fire.
Fix#
Each re-read and its write now share one transaction, with the contention retry from #11592. The missed-run reschedule is guarded on the next_run_at it was computed from, so it loses to an edit instead of overwriting it.
Tests#
ScheduledTaskService.test.ts: the due-read to dispatch gap (pause, postpone, delete, and the no-edit case), an edit committed mid-run on both the success and interrupted paths, and a contended completion write that retries instead of stranding the task as running. The retry test fails with the retry disabled. Server typecheck: 0 errors.
Split from the original #11592 by Claude Fable 5.1 via Claude Code; original implementation with SWE-2 High via Devin CLI. One complete independent review by SWE-2 Max; its findings were fixed, and the fixes were then reviewed by Claude Fable 5.1 only.
🤖 Generated with Claude Code
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This production change spans MCP task mutation semantics, scheduler dispatch gating, run-state transactions, and SQLite contention retries across existing runtime paths. Its scope is broader than a self-contained bug fix, particularly because it changes when scheduled work is suppressed, so human review is warranted.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).