Skip to content

fix(automations): stop a long automation pass from silently dropping the next scheduled minute - #50151

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-41722
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-41722

Conversation

@nwparker

@nwparker nwparker commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

The automation scheduler checks once a minute for automations that are due. If one check took longer than a minute, the next check was skipped entirely, and the minute it was meant to catch was lost. Now a check that arrives mid-run waits its turn and runs as soon as the current one finishes.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1

What Changed

  • Before: AutomationService.evaluateDueRuns had an evaluating boolean guard. A tick that fired while a pass was still running returned straight away. An every-minute automation whose pass took over 60 s (slow prechecks, a stalled store flush) silently lost that minute's occurrence, and nothing showed up in run history.
  • After: the pass runs through the existing createCoalescingKeyedRunner (src/shared/concurrency/coalescing-keyed-runner.ts) under a single key. A tick during a pass queues one follow-up pass, which runs right after the current one and picks up the occurrence. Any further ticks during the same pass join that queued follow-up, so at most one extra pass is ever waiting. The stopped / wake-gate checks now run when each pass starts, so a pass queued before stop() does nothing. A rejected pass is now logged as [automations] scheduler pass failed instead of being lost.

Why

The scheduler already finds due occurrences from the current time, so running one more pass after an overrun is enough to recover the dropped minute. It doesn't start overlapping passes, which the old guard was there to prevent. This reuses the shared coalescing runner rather than adding a second "dirty" flag and loop by hand.

Linked Issue

Refs #41722

Visual Proof

N/A: this is main-process scheduler timing with no UI change. The fix shows up as an extra run-history entry for the minute that used to be dropped, and the regression test covers that directly.

Testing

  • Repro: the new src/main/automations/automation-tick-overrun.test.ts sets up an every-minute automation and stalls the 08:01:30 pass's run write for 70 s, so the 08:02:30 tick lands mid-pass. On main the test fails: run history is missing 08:02. With this change it records 08:01, 08:02, 08:03.

  • pnpm exec vitest run src/main/automations/: 9 files, 19 tests pass.

  • oxfmt, oxlint, the anti-slop, native code-quality and type-aware oxlint configs, ast-grep, and the changed-code-quality gate all pass on the touched files.

  • Platform: macOS (unit level). The change is platform-neutral (timers and promises only, no paths or subprocesses).

  • 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

Performance

None that matters. This runs once per 60 s scheduler tick in the main process. Microbenchmark (Node 24, 100k sequential ticks): the old boolean guard took about 0.55 us per tick and the coalescing runner takes about 3.3 us per tick. Adversarial case: 10,000 ticks arriving while one pass is stalled take 1.8 ms in total to enqueue (0.44 ms before), and they collapse into a single queued follow-up pass, so the queue can't grow. When a pass finishes within the minute, it does the same work as before. After an overrun there is exactly one extra pass, which is the intended recovery. No new I/O, subprocesses or polling.

Risk

Level: Low

The riskiest part is the extra pass after an overrun. It finds due occurrences from the current time, and run creation is unchanged, so it can't double-fire an occurrence the previous pass already claimed. stop() still blocks a queued pass because stopped is checked when the pass starts. Revert with a plain revert. No saved data or settings change.

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.

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)

Reported by @ellwangermp

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

AutomationService now uses a coalescing keyed runner for due-run passes. A tick during an active pass queues one follow-up pass, and later ticks replace the queued pass so it uses the newest captured time. The scheduler retains its stopped and wake-gate checks and logs pass failures. A new test delays a run write across ticks and verifies that runs are recorded for 08:01, 08:02, and 08:03.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 24ed1

The scheduler now queues a follow-up pass instead of dropping ticks during a long pass, so every-minute automations no longer miss occurrences. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: a long automation pass no longer causes the next scheduled minute to be silently dropped. It matches the changeset, which replaces the evaluating guard with a coalesc…
Linked Issues check Passed Issue #41722 asks that a scheduler tick that arrives during a running pass is not silently dropped. Suggested fix 2 is to set a re-evaluate flag and run again after the pass. At head, `AutomationServi…
Out of Scope Changes check Passed The changed production file is src/main/automations/automation-service.ts. Its changes are limited to the due-pass guard, the coalescing runner field and call, the pass-start stopped and wake-gate che…
Description check Passed The description covers every required section of the repository template: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure, Review, Agent skill upstream b…
Full details: Title check

Explanation

The title states the main change: a long automation pass no longer causes the next scheduled minute to be silently dropped. It matches the changeset, which replaces the evaluating guard with a coalescing runner that queues a follow-up pass, and adds a regression test for the overrun case. The title uses the conventional fix(scope) form and is specific. It is 94 characters, which is slightly long but acceptable.

Full details: Linked Issues check

Explanation

Issue #41722 asks that a scheduler tick that arrives during a running pass is not silently dropped. Suggested fix 2 is to set a re-evaluate flag and run again after the pass. At head, AutomationService.evaluateDueRuns (src/main/automations/automation-service.ts) no longer returns early on a running pass. It calls this.duePasses('due', 'due', ...), where duePasses is createCoalescingKeyedRunner<void>(). A tick during a pass queues one follow-up pass. The pass reads now at tick time and calls runDueAutomations, so the missed occurrence is considered. The stopped and wake-gate checks run when the pass starts, so stop() still blocks a queued pass. Rejected passes are logged as [automations] scheduler pass failed. The regression test at head (src/main/automations/automation-tick-overrun.test.ts) covers three start-time and stall combinations (70 s from 08:00:30, 70 s from 08:00:55, 95 s from 08:00:30). Each asserts run history for 08:01, 08:02, and 08:03. The test result is taken from the test source and the PR description, not from a test run. The whole-PR diff read failed, so the incremental change since the previous head was checked only through the file contents at head. Issue suggestions 1, 3, and 4 are optional or alternative remedies and are not required. Under the issue's run_once_within_grace policy, a pass that spans several ticks catches up only the newest occurrence. This matches the issue's policy and is not a gap in this PR.

Full details: Out of Scope Changes check

Explanation

The changed production file is src/main/automations/automation-service.ts. Its changes are limited to the due-pass guard, the coalescing runner field and call, the pass-start stopped and wake-gate checks, and the pass-failure log. Each change relates to the dropped-tick behavior in #41722. The added test file src/main/automations/automation-tick-overrun.test.ts supports the fix and tests its behavior. The whole-PR diff read failed, so no diff-based check of unrelated hunks was possible. The file contents at head show no unrelated functional change in the reviewed sections.

Full details: Description check

Explanation

The description covers every required section of the repository template: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure, Review, Agent skill upstream boundary, and Checklist. The ELI5 is plain language. What Changed gives the before and after and the mechanism (the coalescing keyed runner replaces the evaluating guard, at most one queued follow-up pass, stopped and wake-gate checks at pass start, and logging of rejected passes). Why explains the choice over a second dirty flag and loop. Linked Issue references #41722. Visual Proof is N/A with a reason. Testing names the regression test, the exact before and after run history, the vitest command and macOS unit-level platform. Performance gives microbenchmark numbers and the once-per-tick reasoning. Risk states Low level, the riskiest part, and a plain revert. Minor gaps: the Linked Issue uses 'Refs' rather than 'Fixes', the Review section and the AI Disclosure section are empty, the Notes and Remote SSH/Windows cross-platform considerations are only partly addressed, and the 'pnpm lint, typecheck, test, build' checklist item is unchecked. These are non-critical, so the description is mostly complete.

  • 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: c09b215f-0ec3-409d-8f82-f225d5c2bfeb
Commits

Reviewing files that changed from the base of the PR and between af59430 and 24ed1fa.

Files selected for processing: 2

  • src/main/automations/automation-service.ts
  • src/main/automations/automation-tick-overrun.test.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.

@nwparker nwparker closed this Nov 27, 2026
@nwparker nwparker reopened this Nov 27, 2026
…ing a long pass

The scheduler dropped any tick that fired while the previous pass was
still running (the `evaluating` guard), so an every-minute automation
whose pass took over 60 s lost that minute's occurrence for good.

A tick during a pass now queues one follow-up pass through the shared
coalescing keyed runner, evaluated at that tick's time, so the missed
occurrence runs as soon as the current pass finishes. Later ticks during
the same pass replace the queued one. The stopped/wake-gate checks run
when each pass starts, and a failed pass is logged instead of dropped.

Refs #41722

Co-authored-by: Claude <[email protected]>
@nwparker
nwparker force-pushed the bugbash/issue-41722 branch from af59430 to 24ed1fa Compare November 27, 2026 04:00
@nwparker
nwparker merged commit 633c10a into main Nov 27, 2026
97 of 100 checks passed
@nwparker
nwparker deleted the bugbash/issue-41722 branch November 27, 2026 04:14
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.

1 participant