Skip to content

fix(cron): avoid delaying condition checks when capacity frees up - #197099

Merged
hannesrudolph merged 3 commits into
openclaw:mainfrom
daniel-lxs:fix-cron-condition-check-capacity
Nov 12, 2026
Merged

hannesrudolph merged 3 commits into
openclaw:mainfrom
daniel-lxs:fix-cron-condition-check-capacity

Conversation

@daniel-lxs

@daniel-lxs daniel-lxs commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Related: #196859

What Problem This Solves

Fixes: five-minute conditional automations go more than an hour without being checked when more than three of them are due at the same moment.

A check that finds all three evaluations busy is turned away and retried after 30 seconds, doubling up to five minutes. A check that finds nothing new never resets that retry count, so after a few busy moments every retry is five minutes long. Five minutes is also the schedule, so the retry arrives a fraction of a second after the next round of on-time checks has taken the three evaluations, and it is turned away again, round after round. The automation also keeps showing an old "waiting" warning after it has been checked successfully.

User Impact

  • Conditional automations that come due together are checked in due-time order, three at a time, as soon as an evaluation is free. None is turned away and retried later.
  • A successful check that finds nothing new clears the waiting warning.
  • A queued timed occurrence survives a graceful Gateway shutdown and runs after the restart.
  • A scheduled occurrence of a job that runs inside the conversation that created it (session:<key>) waits until that conversation is idle, as it does today. While it waits it stays queued and uses neither a run slot nor one of the three evaluations, so it cannot hold up other automations. Two visible differences follow: the job shows as queued rather than running during that wait, and a schedule change made meanwhile cancels the waiting occurrence, as for any queued run. If the conversation starts another turn straight away, the occurrence keeps waiting until the conversation is idle.

Still open in #196859 and not addressed here: when all eight run slots are busy with long work, checks wait until one ends; a watcher inside a busy conversation is not checked until that conversation is idle; the Automations page does not show when a check last ran.

Why This Change Was Made

The limit of three simultaneous condition checks moves from the evaluator, which could only refuse, into the durable run queue, which can make a check wait its turn. Checks beyond three stay queued with no running marker, so they hold no run slot, spend no time budget and keep their occurrence across a restart. A condition that fires stops counting as a check, so the next one starts while the payload runs.

A timed occurrence that has to wait for its conversation is left in the queue the same way the queue already leaves runs whose agent is still preparing, and the Gateway drains the queue again when the conversation goes idle. Without this, three watchers waiting behind one long turn would hold all three evaluations and stop every other check.

Accepted edges: runs started by hand or by an event take their slot before waiting for their conversation, as they do today, because an event's source needs its transfer acknowledged at once and only timed occurrences are recovered from the queue after a restart. A conversation turn that starts in the instant between the queue handing out a run and that run starting is waited out with the slot held.

Evidence

Live Gateway, 14 watchers on one five-minute schedule, 125 minutes. Isolated Gateways in a macOS VM, driven by the reproduction script from #196859 extended to run longer; no model, no channels. The branch build is this PR's first commit, d89ef4e; the second commit does not change how watchers outside a conversation are queued.

Build Each check takes Watchers checked every 5 minutes Longest time a watcher went unchecked
Base e9fcf00 1.2 s 3 of 14 107.6 minutes
Base e9fcf00 5 s 3 of 14 117.5 minutes
This branch 5 s 14 of 14 5.0 minutes

On the base, ten watchers (1.2 s) and eleven watchers (5 s) went more than an hour without a check, and all fourteen jobs ended the run holding a waiting record. On this branch every watcher completed 25 or 26 checks, the last of the fourteen started 21.5 seconds after each tick, and no job held a waiting record at the end.

Tests (targeted, not the full suite): 162 passed in 10 cron test files, none skipped. They include:

  • a scheduler test where three watchers wait behind a busy conversation and a fourth, independent watcher is checked meanwhile. It fails when the queue activates the waiting runs (expected [] to deeply equal ['free']) and passes with this change; it runs in under 0.1 s;
  • queue rows for due-order waiting beyond three checks, a fired condition freeing its check, and a quiet check ending the waiting state;
  • a graceful shutdown and restart with a check still queued;
  • the 34 scheduled-continuation tests. Their synchronisation step looks for the queued marker, because a continuation waiting for its conversation is queued, not marked running; their expectations about edits and authority are unchanged.

Formatting, lint, both typechecks (core and cron tests), docs formatting, the test-line budget and git diff --check pass.

Test-line allocation: config/test-lines-allocations/196859-condition-check-queue.txt records 138 lines, the exact net growth. The busy-conversation and shutdown regressions need the real scheduler and queue together, which no existing smaller test exercises.

Not tested: the conversation wait on a live Gateway with a real conversation (covered by the scheduler test only). A fired payload handing its check to the next watcher on a live Gateway. A hard kill while checks are queued. An upgrade from the latest stable release with existing automations; the only new stored field is the optional conditionCheckReceiptId in a job's state, absent on existing rows.

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
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Nov 11, 2026
@daniel-lxs
daniel-lxs marked this pull request as ready for review November 11, 2026 07:08
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR queues excess condition checks, clears waiting state after quiet success, and parks timed conversation continuations without occupying execution capacity.

Example: Fourteen conditional automations share a five-minute schedule and each check takes five seconds.

  • Before: The supplied baseline results report that some watchers went 117.5 minutes without checking.
  • After: The supplied branch results report all fourteen checked every five minutes, with the last starting 21.5 seconds after each tick.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A coherent partial repair with no discrete introduced defect found; owner direction remains unsettled and existing-state upgrade compatibility is unverified.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Conditional automations miss their requested checking cadence and can retain a waiting warning after a successful check.
Reason: Recovery cleanup has clear value, but replacing deliberate backoff and changing waiting continuations from active to queued requires an owner decision; the broader linked issue remains partly unresolved.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR addresses a current scheduler defect with useful unique work; no discrete introduced bug was found, but the admission-policy change needs owner judgment.

Priority: P1
Reviewed head: fb02b123f9f166ca000128a3fd708adf72855977
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should condition-capacity waits use ordered queue admission, including queued cancellation semantics for timed conversation continuations?
  • Recommendation: Approve bounded queue admission: Keep the existing three-check and eight-run limits while accepting queued waiting and schedule-edit cancellation for timed continuations.
  • Why: The existing owner deliberately introduced admission backoff, and no human approval of this replacement policy appears in this PR or the linked issue.

Before merge

  • Add real behavior proof - The supplied macOS-VM Gateway results on d89ef4e support synchronized quiet-watch recovery, and removal of the obsolete busy result does not invalidate that scenario; the newer conversation-wait path, fired-condition handoff, and graceful shutdown recovery remain supported only by tests. Provide redacted terminal output or logs through those Gateway paths, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply Gateway output for busy-conversation resumption, fired-condition capacity handoff, queued shutdown recovery, and a latest-stable upgrade preserving existing automations; only the conversation regression explicitly reports red-before/green-after evidence.
Agent review details

How this fits together

The Gateway scheduler submits due occurrences to the durable cron worker, which controls admission and receipts; the host evaluates conditions, executes fired payloads, and finalizes results.

flowchart TD
  A[Due automation] --> B[Durable run queue]
  C[Conversation readiness] --> B
  B --> D[Condition evaluation]
  D --> E[Payload execution]
  D --> F[Result finalization]
  E --> F
  F --> B
Loading

Technical review

Best possible solution:

Use the existing durable queue to serve condition checks in due order, retaining bounded execution and truthful waiting-state cleanup.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes capacity refusal and retained waiting state, supported by the contributor's scheduled-Gateway comparison; this review ran no target code.

Is this the best way to solve the issue?

Moving admission into the existing queue fixes the refusal mechanism without a second scheduler, and the added tests cover distinct ordering, recovery, and conversation-wait boundaries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ba052b7ed712.

Provenance checked

  • Condition-evaluation capacity keeps the original intent (a6768d9: Condition watchers were limited to three concurrent evaluations as part of their resource budget.)
  • Admission backoff changes intended behavior with a stated reason (c3cdd6b: Bounded backoff reduced repeated admission attempts and receipt churn while making waiting visible.)
  • Conversation continuation waiting changes intended behavior with a stated reason (718bd3d: Continuations wait for their creating conversation to finish and then use the current job with scheduled authority.)
  • Queued timed occurrences at shutdown changes intended behavior with a stated reason (a97192d: Cancelled terminal slots had to advance so restart could not repeatedly reject their deterministic receipt identities.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit c730759 adds src/cron/service/timer-execution.ts:247 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c73075978be8; files: src/cron/service/timer-execution.ts)

PR surface

Source +173, Tests +138, Docs +6, Other +5. Total +322 across 28 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 18 230 57 +173
Tests 7 183 45 +138
Docs 2 9 3 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 5 0 +5
Total 28 427 105 +322

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: partial_overlap
Canonical: #196859
Summary: This PR addresses synchronized condition-capacity starvation and stale waiting state within the broader monitoring-reliability request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: The reported synchronized-watcher workload leaves existing five-minute monitoring workflows unchecked for over an hour.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the missing Gateway scenarios and latest-stable upgrade evidence.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-11T07:25:16.809Z sha d89ef4e :: needs real behavior proof before merge. :: none

Reviewed November 11, 2026, 7:34 PM ET / November 12, 2026, 00:34 UTC (Revision 2).

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
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.
@daniel-lxs
daniel-lxs force-pushed the fix-cron-condition-check-capacity branch from 6c70f95 to fb02b12 Compare November 12, 2026 00:23
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Nov 12, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@hannesrudolph
hannesrudolph merged commit db964b7 into openclaw:main Nov 12, 2026
151 of 152 checks passed
@hannesrudolph

Copy link
Copy Markdown
Member

Merged via squash.

daniel-lxs added a commit to daniel-lxs/openclaw that referenced this pull request Nov 12, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…enclaw#197099)

* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants