Repository navigation
fix(automations): stop a long automation pass from silently dropping the next scheduled minute - #50151
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
…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]>
af59430 to
24ed1fa
Compare
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.
What Changed
AutomationService.evaluateDueRunshad anevaluatingboolean 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.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. Thestopped/ wake-gate checks now run when each pass starts, so a pass queued beforestop()does nothing. A rejected pass is now logged as[automations] scheduler pass failedinstead 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.tssets 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. Onmainthe test fails: run history is missing08:02. With this change it records08: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 becausestoppedis checked when the pass starts. Revert with a plain revert. No saved data or settings change.Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Reported by @ellwangermp