Skip to content

fix(automations): resume a paused automation at its next future occurrence - #53266

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
AymanKhan9:fix/automation-resume-fresh-next-run
Nov 30, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
AymanKhan9:fix/automation-resume-fresh-next-run

Conversation

@AymanKhan9

Copy link
Copy Markdown
Contributor

ELI5

If you pause a scheduled automation and turn it back on later, Orca used to immediately run the time slot that passed while it was paused. Now turning it back on just waits for the next scheduled time.

What Changed

Before: pausing stops the scheduler from advancing nextRunAt. Resuming sent { enabled: true }, and updatedAutomationSchedule kept the stale nextRunAt because the rrule, dtstart and zone were unchanged. The next tick found the automation due and ran, or recorded as missed, the latest slot that fell during the pause.

After: updatedAutomationSchedule treats enabled: true on a currently disabled automation as a schedule change, and recomputes nextRunAt = nextAutomationOccurrenceAfter(rrule, dtstart, now, zone), the next future slot. One-off (once) automations are excluded and keep their existing timing.

Why

This puts the reseed where the schedule is already recomputed for every other "when it runs" change, and matches what the WSL-move undo does when it turns automations back on. The alternative, changing runScheduledOccurrence to ignore slots from before a resume, would need a resume timestamp stored on every automation.

Linked Issue

Fixes #53265

Visual Proof

N/A: no visual change. After a resume, the automation's next run shows the next future slot instead of a past one, and no surprise run starts.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Added automation-schedule-operations.test.ts. A paused daily automation whose nextRunAt lies in the past is resumed two days later, and nextRunAt must be the next future occurrence.

It fails without this change: the stale past slot is returned.

The existing wsl-move-local-automations-rewrite.test.ts (9 tests) and wsl-host-automation-disable.test.ts still pass.

On Linux, oxfmt and oxlint pass. A tsc run scoped to the changed files and their import graph also passes, using the repo's tsconfig.node.json settings. The full pnpm check:changed typecheck doesn't finish on a 4-vCPU, 8 GB machine, so CI covers the rest.

Performance

None, because one occurrence calculation runs only when an automation is re-enabled.

Risk

Level: Low

Someone who relied on a resume catching up a slot that passed during the pause will now wait for the next slot instead. That matches what pausing means, and the WSL undo path already behaves this way. One-off automations are unchanged. Back out with a plain revert.

AI Disclosure

Found and written with Claude Code (Claude Opus 5.5), then reviewed by me.

Review

  • Cross-platform: pure schedule logic.
  • SSH/remote: the same function serves desktop and runtime authorities.
  • Agents and integrations: no unexpected agent runs after a resume.
  • Performance: none.
  • UI quality: the next run shows the correct time.
  • Security: none.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

…rence

While an automation is paused the scheduler skips it, so nextRunAt
never advances. A bare { enabled: true } kept that stale value, the
next tick found it due, and runScheduledOccurrence ran (or recorded as
missed) the latest slot that fell while it was paused. Recompute
nextRunAt when a recurring automation is re-enabled, as the WSL-move
undo already does; one-off automations keep their own timing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When a recurring automation changes from disabled to enabled, updatedAutomationSchedule recalculates nextRunAt. One-time automations do not trigger recalculation from this condition. A test checks that resuming a daily automation between its second and third occurrences returns the third occurrence.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 8b9c4

Re-enabling a paused recurring automation now schedules its next run from the resume time instead of running or marking missed a slot that fell during the pause. One-off automations keep their timing. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a paused automation resumes at its next future occurrence. The raw summary confirms updatedAutomationSchedule now recomputes nextRunAt when a disabled recurring au…
Description check Passed The description follows the template. It has ELI5, What Changed (before and after with mechanism), Why (with alternatives considered), a linked issue (Fixes #53265), Visual Proof marked N/A with a rea…
Linked Issues check Passed [#53265] requires that re-enabling a paused recurring automation recompute nextRunAt from the time of resumption, and that one-off automations keep their timing. At the reviewed head, updatedAutomatio…
Out of Scope Changes check Passed The whole-PR source change is 4 added or changed lines in automation-schedule-operations.ts: a resumed flag, its OR into the changed condition, and a comment. The only other change is the added test f…
Full details: Title check

Explanation

The title names the main change: a paused automation resumes at its next future occurrence. The raw summary confirms updatedAutomationSchedule now recomputes nextRunAt when a disabled recurring automation is re-enabled. The title uses the conventional fix(scope) prefix and is 74 characters, which is within a normal length.

Full details: Description check

Explanation

The description follows the template. It has ELI5, What Changed (before and after with mechanism), Why (with alternatives considered), a linked issue (Fixes #53265), Visual Proof marked N/A with a reason, Testing with the new test and its fail-without-change claim, Performance, Risk with level and revert path, AI Disclosure, Review, and Checklist. Gaps: the template's Linked Issue placeholder is filled, but the 'pnpm lint/typecheck/test/build' checklist item is unchecked, and the 'I manually tested' box is unchecked with no explanation. The full typecheck did not complete locally, which the author states. The 'Fixes #53265' line is a real issue number, so the linked-issue requirement is met.

Full details: Linked Issues check

Explanation

[#53265] requires that re-enabling a paused recurring automation recompute nextRunAt from the time of resumption, and that one-off automations keep their timing. At the reviewed head, updatedAutomationSchedule in automation-schedule-operations.ts defines resumed = updates.enabled === true && current.enabled === false && !current.once and ORs it into the changed flag. When changed is true, nextRunAt = nextAutomationOccurrenceAfter(rrule, dtstart, now, zone), which is the next future occurrence. Otherwise nextRunAt stays current.nextRunAt. The caller mergeAutomationUpdate (automation-definition-update.ts) spreads updatedAutomationSchedule(current, definedUpdates, ...) after the merged updates, so an enabled: true patch reaches this function with the stored current record. The single-update and batch paths both use mergeAutomationUpdate. The added test in automation-schedule-operations.test.ts covers a paused daily automation resumed two days later. I did not execute the test; its result rests on the diff and the PR description's report that it fails without the change. The diff does not show the test body, so the exact assertion is not independently confirmed.

Full details: Out of Scope Changes check

Explanation

The whole-PR source change is 4 added or changed lines in automation-schedule-operations.ts: a resumed flag, its OR into the changed condition, and a comment. The only other change is the added test file automation-schedule-operations.test.ts. Both directly implement the resume-recompute objective of #53265. The PR description's notes on WSL tests, lint, and typecheck describe verification, not additional code changes. No unrelated code change was found in the inspected files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5ca3c2db-01e5-4357-9a14-a5938555cef8
Commits

Reviewing files that changed from the base of the PR and between d46bd2f and 8b9c401.

Files selected for processing: 1

  • src/main/persistence/scheduling-automations/automation-schedule-operations.test.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.

@Jinwoo-H
Jinwoo-H merged commit e5b903f into stablyai:main Nov 30, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Re-enabling a paused automation immediately runs (or marks missed) the slot that fell while it was paused

2 participants