Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): interrupted scheduled task runs no longer stay busy #28474

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/28474/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

An 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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 8520793

      Macroscope'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).
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.6 KiB21.6 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−29 B (−0.6%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.3 KiB1.2 KiB−29 B (−2.3%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB−41 B (−0.2%)24.4 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: 6328c84 · PR result: 8520793 · Source CI: success

      Scenario 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.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      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.ts
      Task 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.ts
      A 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

      Suggested labels: bugfix

      Suggested reviewers: juliusmarminge

      Merge Risk: Minimal · up to 85207

      No merge-blocking issue is established by the supplied evidence.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: preventing interrupted scheduled task runs from remaining marked as busy.
      Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
    4. Note

      🤖 Claude Opus 5.5 responding on behalf of Theo

      Heads up: #28104 merged as 4ac97be. It changes runTask in ScheduledTaskService.ts: the start time is read before the reservation, the completion reads the task and writes its result in one transaction, and runTask now returns dispatchFailed. This PR needs a rebase onto main, and the reservation fix should keep those changes.

Sign in to join this conversation.