fix(scheduler): skip cron runs while an automation is active - #283
fix(scheduler): skip cron runs while an automation is active#283trungminhdo4-glitch wants to merge 3 commits into
Conversation
|
HUMAN: (Owner-authorized; posted by my agent on my behalf.) I am supervising this contribution, and it remains a draft by design. Before I decide it is ready for review, I want the concurrency contract to remain explicit: one batch query for due automations; |
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
HUMAN: I reviewed the scheduler changes and tested the overlap guard locally. I checked that cron runs are skipped when the same automation already has a PENDING or RUNNING run, while terminal runs still allow the next cron run. I also checked the batch rotation, telemetry and timestamp behavior, and that manual/event triggered dispatch is not affected.
Summary
PENDINGorRUNNINGrunWhy
A cron automation can currently schedule another run while its previous run is
still pending or running. Long-running automations can therefore stack multiple
concurrent sandboxes.
Concurrency contract
The guard is evaluated inside the scheduler transaction that already locks the
automation row with
FOR UPDATE SKIP LOCKEDon PostgreSQL.This PR intentionally applies the guard only to cron scheduling. Manual and
event-triggered dispatch behavior remains unchanged, and no database uniqueness
constraint is introduced, leaving room for an explicit per-automation override
later.
SQLite remains covered under the repository's existing single-process
assumption.
Behavior
Blocking statuses:
PENDINGRUNNINGNon-blocking statuses:
COMPLETEDFAILEDCANCELLEDSKIPPEDWhen a run is skipped:
last_polled_atis still updatedlast_triggered_atis unchangedTests
The functional behavior was tested with in-memory SQLite. PostgreSQL
multi-worker behavior was not exercised against a live PostgreSQL instance; the
serialization property follows the scheduler's existing automation-row lock.
Fixes #218
Disclosure: This contribution was prepared with AI assistance and independently
reviewed and tested locally before publication.