fix(server): interrupted scheduled task runs no longer stay busy #28474
main fromrefs/pull/28474/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubAn interrupt at the wrong moment could leave a scheduled task marked busy in memory until the server restarted. After that, Run now and run_scheduled_task_now failed with "Schedule task is already running.", scheduled polls skipped the task, and pending webhook rows for it never drained.
Cause: runTask reserved the task in activeRuns, and dispatchPending reserved it in pendingInFlight, before their cleanup was installed. An interrupt in that gap skipped the cleanup.
Fix: both reservations now use Effect.acquireUseRelease. The release removes the id only when this call reserved it. The webhook reservation moved into the forked worker, so the worker owns it through the permit wait and the drain. Busy triggers behave as before. releaseStuckRun, immediate webhook admission, and drain order did not change.
Proof: two focused tests fail on main for this reason (second Run now fails with "already running"; a coalesced webhook never launches) and pass with the fix. All 93 scheduled task tests and vp run check:changed pass.
Overlap: rebased onto main after #28104 landed; this keeps its start-time read before the reservation. Open #21793 and #23131 also edit runTask and will conflict there, because this PR moves the reservation into a bracket at the end of runTask. Neither closes this gap.
Reviewed with sol-loop: 1 pass with GPT-6.1 Sol. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code).
🤖 Generated with Claude Code
- 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
8520793Macroscope's review found this PR approvable — The change makes scheduled-run and webhook-worker busy reservations interruption-safe. Existing execution safeguards and queue processing remain intact, with no product-default changes or new data-handling behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.6 KiB 21.6 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −29 B (−0.6%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.3 KiB 1.2 KiB −29 B (−2.3%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB −41 B (−0.2%) 24.4 KiB ✅ Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅ Baseline:
6328c84· PR result:8520793· 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.
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: t3/df7c301f
- File: .coderabbit.config.ts
- Commit: 8520793
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
dededaad-8dc0-4d72-9efa-7849556d9db6
Commits-
Reviewing files that changed from the base of the PR and between 6376b4b3e887cb1909f2a30efa1c24236a39a46d and 8520793b46549b5511cc0b011828720af85985a6.
Files selected for processing: 1-
apps/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.
-
Walkthrough
-
Scheduled task runs and pending webhook dispatch now release their in-memory reservations when interrupted. Regression tests interrupt each flow and verify that a later attempt can dispatch the task.
Changes: Dispatch reservation lifecycle
Layer / File(s) Summary Scheduled task run reservation
apps/server/src/scheduledTasks/ScheduledTaskService.ts,apps/server/src/scheduledTasks/ScheduledTaskService.test.tsTask run reservations are acquired and released across all exit paths. Scheduled runs skip an active task, while non-scheduled runs fail if the task is already running. A test interrupts after reservation and verifies that the next run launches once. Pending webhook worker
apps/server/src/scheduledTasks/ScheduledTaskService.ts,apps/server/src/scheduledTasks/ScheduledTaskService.webhook.test.tsA per-task worker acquires the webhook permit and drains persisted deliveries in order. Its pending-dispatch reservation is released on interruption. A test interrupts the worker and verifies that a later poll launches once and removes the pending row. Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related issues
- pingdotgg/t3code#18810 — The issue concerns accepted webhook deliveries that remain undelivered after interruption. This change releases the pending-webhook reservation when the worker is interrupted.
Possibly related PRs
- pingdotgg/t3code#21791 — Both changes address scheduled-task run-state cleanup around reservation.
- pingdotgg/t3code#21793 — Both changes address scheduled-task run lifecycle and reservation cleanup.
- pingdotgg/t3code#28104 — Both changes address scheduled-task behavior when a run is interrupted.
Suggested labels:
bugfixSuggested reviewers:
juliusmarminge
Merge Risk:
Minimal · up to85207-
No merge-blocking issue is established by the supplied evidence.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main change: preventing interrupted scheduled task runs from remaining marked as busy. Description check The description clearly covers the problem, cause, fix, affected behavior, verification results, and overlap with other changes. The scope section does not include a direct triaged issue or maintainer… 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: Description check
-
Explanation
The description clearly covers the problem, cause, fix, affected behavior, verification results, and overlap with other changes. The scope section does not include a direct triaged issue or maintainer approval link, but the description is otherwise mostly complete and relevant.
-
Finishing Touches
-
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
-
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Heads up: #28104 merged as
4ac97be. It changesrunTaskinScheduledTaskService.ts: the start time is read before the reservation, the completion reads the task and writes its result in one transaction, andrunTasknow returnsdispatchFailed. This PR needs a rebase onto main, and the reservation fix should keep those changes.macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed