Repository navigation
fix(cron): keep condition checks running when all run slots are busy - #197340
Conversation
A condition check that found all three evaluations busy was turned away and retried on the 30s-to-5min admission backoff, even when a slot freed at once, and a quiet (fire: false) success left the waiting episode and its retry count in place. - The run queue admits at most three runs that are still evaluating a condition. Further checks stay queued in due-time order with no running marker, so they hold no run slot, spend no run budget and keep their occurrence across a restart. The evaluator's own cap and its busy result are gone. - A fired condition stops counting as a check, so the next one starts while the payload runs. - A quiet check ends the waiting episode, like a payload run does. - While any job has a condition, scheduled runs without one leave one run slot free. - A queued timed occurrence survives a graceful shutdown: the host drain no longer activates timed work while the Gateway drains, service stop leaves it in the durable queue, and an activated launch the stopping host refuses is released for the next process instead of skipped. Refs openclaw#196859
A job that runs inside the conversation that created it waits for that conversation to be idle before it starts. The queue activated it first, so the wait held a run slot and, for a watcher, one of the three condition checks: three watchers behind one long turn stopped every other check until the turn ended. - The host tells the queue which jobs continue a conversation that is busy. Their timed occurrences stay queued, the way runs whose agent is still preparing do, and the host drains again when the conversation goes idle. A waiting occurrence therefore shows as queued, not running, and a schedule change cancels it like any queued run. - Requested and event runs keep their activation before the wait, and a turn that starts between the drain and the launch is still waited out at launch. - Scheduled runs without a condition can use all eight run slots; the slot held back for checks is removed. Refs openclaw#196859
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR separates scheduled condition checks from payload capacity and queues fired payloads until a run slot becomes available. Example: Eight long-running automations occupy all eight run slots while a watcher is due every minute.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a distinct current-main scheduling defect, and no actionable patch defect was found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe cron worker receives scheduled occurrences and owns durable receipts, ordering, and capacity; the Gateway executes admitted checks and payloads and returns completion outcomes. flowchart TD
A[Scheduled occurrences] --> B[Worker run queue]
B --> C[Three condition checks]
C --> D[Quiet completion]
C --> E[Fired payload waiting]
E --> B
B --> F[Eight payload slots]
F --> G[Receipt finalization]
Technical reviewBest possible solution: Keep condition checks independent of payload capacity while the existing worker queue alone assigns payload slots in due-time order. Do we have a high-confidence way to reproduce the issue? Current main directly blocks condition checks at full payload capacity, and the contributor supplies a live base-versus-branch reproduction; this read-only review executed no target code. Is this the best way to solve the issue? The patch fixes capacity accounting at its existing owner and preserves one evaluation per occurrence, rather than raising limits or adding a second capacity controller. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8608f8810a8e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +218, Tests +161, Docs +6, Other +6. Total +391 across 15 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)
Reviewed November 12, 2026, 4:48 PM ET / 21:48 UTC (Revision 3). |
The evaluator no longer returns a busy result, so nothing sets triggerEval.busy. Remove the field, its three readers and the tests that set it by hand.
A condition check took one of the eight run slots before it started, so eight long runs stopped every check until one of them ended. - A timed check counts against the three-check limit only. A run counts against the eight run slots once its condition fires. - A fired condition then waits, holding neither a check nor a slot, for the queue drain to hand it one. The drain gives freed slots to waiting payloads and queued runs in due-time order, so a run due before the check still starts first. The payload runs on the result of that one check. The wait pauses the run's time budget, grants nothing while scheduling is paused or the Gateway drains, checks active hours again, and ends without a payload if the service stops. A failed request for the slot is retried each time the queue moves. - Requested checks and the checks of script-payload jobs take a run slot at activation as before: a script payload's budget cannot pause. Refs openclaw#196859
d0b24c0 to
2c1c192
Compare
openclaw#197099 landed this branch's first three commits on main as one squash, so the resolution keeps main's version of them and reapplies only 'fix(cron): keep condition checks off the run slots' on top.
…load A cron config change hands scheduling to a replacement and lets runs already executing finish (openclaw#197606). A fired condition waiting for a run slot ended instead: its wait followed the scheduler scope, which the handover aborts, so the run was recorded as aborted without its payload. - The wait ends when the run is aborted or the scheduler stops, but not when it is handed over. A stop wakes waiters so they see it. - Slot waiters on a store wake on any owner's queue turn, and while a handed-over owner has waiters, a store wake also drains the live scheduler owners, so the replacement hands the waiting payload a slot. Refs openclaw#196859
|
I completed the requested VM proof for
Revocation, reset, reload and restart controls used scripted model responses through real Gateway and tool execution paths. The real-model phase used actual hosted inference. The OpenRouter proxy change—omitting Fired payloads and queued runs retain due-time ordering. Failed slot requests wait and retry without uncounted execution. The focused tests passed: 22 tests in two files, none skipped. The full suite, handoff-write fault injection, and multiple Gateways sharing a store were not run. The earlier two-hour soak belongs to |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…penclaw#197340) * fix(cron): queue condition checks instead of backing them off A condition check that found all three evaluations busy was turned away and retried on the 30s-to-5min admission backoff, even when a slot freed at once, and a quiet (fire: false) success left the waiting episode and its retry count in place. - The run queue admits at most three runs that are still evaluating a condition. Further checks stay queued in due-time order with no running marker, so they hold no run slot, spend no run budget and keep their occurrence across a restart. The evaluator's own cap and its busy result are gone. - A fired condition stops counting as a check, so the next one starts while the payload runs. - A quiet check ends the waiting episode, like a payload run does. - While any job has a condition, scheduled runs without one leave one run slot free. - A queued timed occurrence survives a graceful shutdown: the host drain no longer activates timed work while the Gateway drains, service stop leaves it in the durable queue, and an activated launch the stopping host refuses is released for the next process instead of skipped. Refs openclaw#196859 * fix(cron): keep checks running while a job waits for its conversation A job that runs inside the conversation that created it waits for that conversation to be idle before it starts. The queue activated it first, so the wait held a run slot and, for a watcher, one of the three condition checks: three watchers behind one long turn stopped every other check until the turn ended. - The host tells the queue which jobs continue a conversation that is busy. Their timed occurrences stay queued, the way runs whose agent is still preparing do, and the host drains again when the conversation goes idle. A waiting occurrence therefore shows as queued, not running, and a schedule change cancels it like any queued run. - Requested and event runs keep their activation before the wait, and a turn that starts between the drain and the launch is still waited out at launch. - Scheduled runs without a condition can use all eight run slots; the slot held back for checks is removed. Refs openclaw#196859 * refactor(cron): drop the unused busy trigger evaluation flag The evaluator no longer returns a busy result, so nothing sets triggerEval.busy. Remove the field, its three readers and the tests that set it by hand. * fix(cron): keep condition checks off the run slots A condition check took one of the eight run slots before it started, so eight long runs stopped every check until one of them ended. - A timed check counts against the three-check limit only. A run counts against the eight run slots once its condition fires. - A fired condition then waits, holding neither a check nor a slot, for the queue drain to hand it one. The drain gives freed slots to waiting payloads and queued runs in due-time order, so a run due before the check still starts first. The payload runs on the result of that one check. The wait pauses the run's time budget, grants nothing while scheduling is paused or the Gateway drains, checks active hours again, and ends without a payload if the service stops. A failed request for the slot is retried each time the queue moves. - Requested checks and the checks of script-payload jobs take a run slot at activation as before: a script payload's budget cannot pause. Refs openclaw#196859 * fix(cron): keep a fired condition's slot wait across a cron config reload A cron config change hands scheduling to a replacement and lets runs already executing finish (openclaw#197606). A fired condition waiting for a run slot ended instead: its wait followed the scheduler scope, which the handover aborts, so the run was recorded as aborted without its payload. - The wait ends when the run is aborted or the scheduler stops, but not when it is handed over. A stop wakes waiters so they see it. - Slot waiters on a store wake on any owner's queue turn, and while a handed-over owner has waiters, a store wake also drains the live scheduler owners, so the replacement hands the waiting payload a slot. Refs openclaw#196859
Related: #196859
Builds on #197099, which is on main.
What Problem This Solves
Fixes: conditional automations stop being checked while eight long automation runs are active.
A condition check takes one of the scheduler's eight run slots before it starts. When eight long runs hold those slots (work loops, long agent turns, manually started jobs), no check can start until one of them ends, so a watcher that should look every few minutes goes unchecked for as long as the long work lasts.
User Impact
Why This Change Was Made
The run queue counted a run against the eight run slots from activation, including the opening phase in which it only evaluates its condition. A timed check counts against the three-check limit only, and the run counts against the eight once its condition fires.
A fired timed condition then holds neither kind of capacity. The queue drain, which already hands out run slots in due order, hands the next free slot to it or to an older queued run, so the wait is ordered with queued runs instead of jumping ahead of them. The run asks the queue again each time it moves; a failed request for the slot is logged and asked again the same way. Keeping the first result, instead of checking again when a slot frees, preserves the existing rule that an evaluated condition consumes its occurrence: a condition script may act, so it must not run twice for one occurrence.
After the wait the run checks its active hours again, and it starts no payload while scheduling is paused, while the Gateway is draining for a restart, or after the service stops.
A cron config change hands scheduling to a new scheduler and retires the old one without aborting its runs. The wait ends only when the run is aborted or its scheduler stops, not when it hands over; a stop wakes waiting runs so they end at once. Waiting runs wake whenever any scheduler on the same store hands out slots, and while a handed-over scheduler still has runs waiting, a freed slot also makes the live scheduler go through the queue, since the handed-over one no longer does.
Script payloads are excluded because their time budget cannot pause during the wait; a script-payload watcher that waited longer than its budget would fail with a timeout.
Accepted edges: a Gateway restart during the wait interrupts the run like any run in flight, and the condition is evaluated again afterwards. During the wait the run keeps the job definition it started with, as any active run does. A condition that fires after the new scheduler has loaded its jobs, during a cron config change, may get its slot at that scheduler's next tick instead of the next freed slot.
Evidence
Live Gateway with eight long jobs holding every run slot. Isolated Gateways in a macOS VM, no model, no channels. Three quiet watchers and one watcher whose condition always fires, all on a one-minute schedule; eight scheduled command jobs of 240 seconds each start at +70 s and end at +310 s. Both builds ran side by side.
92e0afad0b24c0The condition that fired at 122 s waited for a run slot and its payload started at 310 s, when the long jobs ended, without another check in between. This live run used commit
d0b24c0, which reserved slots for waiting conditions ahead of queued runs; it has not been repeated on head2c1c192, where the drain hands out slots in due order. No queued run was due during that wait, so the table does not exercise the ordering.Tests (targeted, not the full suite), on head
e783d56: 223 passed in 13 cron and Gateway cron test files, none skipped. They include:expected [] to deeply equal ['quiet', 'fires']); it runs in about 0.15 s;expected [] to deeply equal [ 'older' ]);expected false to be true: the payload never runs). After a stop the wait ends and the payload never runs.Formatting, lint, both typechecks (core and cron tests), the test-line budget and
git diff --checkpass.Test-line allocation:
config/test-lines-allocations/196859-checks-off-run-slots.txtrecords 161 lines, the exact net growth. The regression needs the real scheduler, the queue and eight blocked runs together, which no existing smaller test exercises.VM proof at
e783d56:A live agent-turn payload using Haiku 4.5 through OpenRouter: one condition check while all eight run slots were occupied, model execution after capacity returned, and one tool effect with the original receipt finishing successfully.
A live cron config reload while a fired condition waited: the same receipt survived handover and its payload ran once after capacity returned.
A Gateway restart during the wait: the original run was interrupted, the condition was rechecked after recovery, and its payload ran once. The source-bound queued continuation also resumed.
See the recorded proof: #197340 (comment)
Not tested: