Skip to content

feat(cron): back automation off when a provider pushes back - #197395

Merged
hannesrudolph merged 24 commits into
openclaw:mainfrom
daniel-lxs:cron-adaptive-run-limit
Nov 22, 2026
Merged

hannesrudolph merged 24 commits into
openclaw:mainfrom
daniel-lxs:cron-adaptive-run-limit

Conversation

@daniel-lxs

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

Copy link
Copy Markdown
Member

Related: #196859

What Problem This Solves

Main adds an automation run on each queue drain when free memory allows. A provider can keep rate-limiting requests even while retries let individual jobs finish successfully.

User Impact

A rate limit or overload pauses extra work for the provider that reported it when more than eight automation and hook agent sessions share the budget. The provider response describes its own capacity, so other providers and command or script jobs can still use extra slots.

The eight default slots stay available. Running jobs fill those slots as they free up. One extra slot returns per quiet minute at the next drain. A parked occurrence keeps its receipt, completed condition check, and transferred event. Running jobs can finish, and an extra run that falls back counts against the provider it switches to.

Why This Change Was Made

The queue hands out slots in order and reassigns freed default capacity before applying provider allowances. Each charge follows its receipt while that receipt uses extra capacity. A provider waiting on an extra slot releases the provisional slot so other work can proceed. The Gateway logs each reduction and keeps the backoff in memory.

Compare main with this head

Evidence

  • A Gateway running OpenClaw 2026.11.6 wrote a recurring job and successful history. The candidate opened the same isolated state, retained the authored configuration, job definition and history, and ran that job again successfully.
  • Two loopback providers exercised real Gateway requests. Provider A returned HTTP 429 at 16 overlapping requests. The original eight default jobs finished, provider B used an extra slot, and the same parked A occurrence resumed as the ninth request in the first quiet minute while the eight former extra runs were still active.
  • 236 focused tests passed on macOS. The core, cron and messaging typechecks, targeted lint and formatting passed. The added regression lines cover the 16-run burst and the completion order that exercises slot reassignment.
  • The live run used loopback fixtures. Full CI and vendor services are outside this evidence.

@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 gateway Gateway runtime size: XL labels Nov 11, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 11, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature 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 maintainer review before merge.

What this changes

This PR pauses extra automation runs for overloaded providers and gradually restores capacity while preserving eight default slots.

Example: Provider A returns HTTP 429 with 16 automation requests active.

  • Before: Queue drains can continue admitting extra requests to A despite its pushback.
  • After: Extra A work waits, provider B can proceed, and A regains one extra allowance per quiet minute.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, production-path-proven scheduling behavior with resolved prior findings; broad CI remains incomplete with a verified inherited failure.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): A real isolated Gateway with loopback HTTP providers demonstrates provider-specific backoff and recovery; the reviewed-head trace additionally demonstrates foreground progress and fresh requester admission before the parked shared-session automation executes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Automation can keep adding requests to a rate-limited provider because successful retries conceal pressure from final job outcomes.
Reason: Maintainer authorship establishes direction, and provider-specific feedback offers clear value without a new setting or reduced default capacity.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR adds useful provider backoff, resolves the earlier findings, and introduces no new actionable defect.

Priority: P2
Reviewed head: 142328b4b72a7751477f69697c2e128baa705d5f

Before merge

None.

Findings

None.

Agent review details

How this fits together

The cron scheduler sends occurrences through its durable worker queue into isolated or shared-session execution; provider lifecycle failures now feed back into admission of extra runs.

flowchart TD
  A[Scheduled and event occurrences] --> B[Worker run queue]
  B --> C[Provider slot admission]
  C --> D[Agent execution]
  D --> E[Provider lifecycle events]
  E --> F[Provider backoff allowances]
  F --> B
Loading

Technical review

Best possible solution:

Retain provider feedback in the existing queue and execution owners, preserving receipt identity, default capacity, and fresh requester admission after waits.

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

This feature has supplied Gateway traces exercising actual HTTP 429 responses, provider-specific waiting, recovery, and shared-session resumption; this review ran no target code.

Is this the best way to solve the issue?

The change reuses durable queue admission and session settlement, with distinct regressions for receipt promotion, fallback accounting, event custody, cancellation, and requester removal.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Memory-based extra run admission keeps the original intent (c027899: Allow one additional run per drain when memory permits, above eight default slots and up to sixteen.)
  • Condition checks and occurrence custody keeps the original intent (1b8c08a: Keep condition checks independent of payload capacity and resume fired occurrences without evaluating their condition twice.)
  • Session-event readmission keeps the original intent (82b682c: Retain unstarted occurrences through temporary workspace disconnection and readmit through the existing settlement owner.)
  • Saved requester authority keeps the original intent (3ad2cce: Check saved requester authority when work starts while permitting already-admitted requests to finish.)
  • Serialized isolated-session preparation keeps the original intent (c42bd6e: Serialize session preparation with prior lifecycle publication to prevent compaction and scheduled execution from competing for session state.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Daniel: Raw commit c027899 adds src/cron/service/run-queue.ts:370 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c027899907ab; files: src/cron/service/run-queue.ts)

PR surface

Source +493, Tests +533, Docs +1, Other +2. Total +1029 across 34 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 26 747 254 +493
Tests 6 543 10 +533
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 34 1293 264 +1029

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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.

Label justifications:

  • P2: Provider backoff improves automation reliability under load while retaining the existing default capacity.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (25 earlier review cycles; latest 8 shown)
  • reviewed 2026-11-19T03:11:32.785Z sha 3d77a9d :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-19T03:45:11.835Z sha 3d77a9d :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-19T04:42:28.441Z sha 3d77a9d :: blocked before merge. :: none
  • reviewed 2026-11-20T22:53:34.463Z sha 43c10db :: blocked before merge. :: [P2] Reconcile extra-provider charges when default capacity opens
  • reviewed 2026-11-20T23:53:07.560Z sha b92c72a :: needs maintainer review before merge. :: none
  • reviewed 2026-11-22T08:49:18.349Z sha dd32801 :: blocked before merge. :: [P1] [P1] Restore requester authority before shared-session readmission
  • reviewed 2026-11-22T09:19:20.861Z sha 142328b :: needs maintainer review before merge. :: none
  • reviewed 2026-11-22T09:25:31.693Z sha 142328b :: needs maintainer review before merge. :: none

Reviewed November 22, 2026, 4:42 AM ET / 09:42 UTC (Revision 26).

@daniel-lxs

Copy link
Copy Markdown
Member Author

ff4a3eb: the VM trace reached 24 overlapping requests; HTTP 429 reduced the ceiling to 12, recovery reached 13 about 73 seconds later, and all 30 jobs finished ok.

The parent-replacement result from 1997e68 reflects existing main behavior for parents without a workspace binding. The slot wait lengthens the window; these PRs do not introduce it. Optional hardening is for maintainers and is not a blocker for this PR.

Proof used a synthetic model and focused integration harness. Authority testing at ff4a3eb and stored-data upgrade were not run; requester revocation remains inconclusive.

@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:feature Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Nov 12, 2026
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

openclaw#197394 landed as a fixed eight run slots plus one extra run per drain
while 1 GiB is free, up to 16. Take main's sizing everywhere and drop
this branch's earlier agent-limit and memory sizing (run-slots.ts,
host and exec memory readers, free-memory test helpers, the per-minute
recheck for queued runs).

Keep only the provider backoff, now in provider-backoff.ts: a rate
limit or overload while automation and hook turns hold more than eight
sessions stops runs past the eight default slots, and each minute
without pushback allows one more again. The host passes that ceiling
to the run-queue worker, which applies it to the extra runs only.
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

Verification at b92c72a87ec8b9bdd3f3ac03f9598e64b27ecfec

Stored data. A published OpenClaw 2026.11.6 Gateway created and ran a recurring job. After an orderly stop, the candidate opened the same isolated state and ran the same job again. The check compares authored settings by value, the full job definition, and the saved history entry’s identity. Startup regenerated its own configuration metadata and left the authored settings intact.

Redacted Gateway and provider trace from the same run on macOS. A and B are loopback model fixtures.

UTC Observed event
23:42:26.818 The 2026.11.6 Gateway saved a job and one successful run.
23:44:32.040 The candidate loaded the authored settings, the same definition, and the prior history entry.
23:44:35.147 The same saved job completed again. Both history entries were successful.
23:45:43.974 The fixture held 16 overlapping A requests, eight default and eight extra.
23:45:44.101 The Gateway classified A’s HTTP 429 and logged provider backoff.
23:45:47.583 The original eight default jobs finished. All eight former extra requests were still held.
23:45:50.577 Cron activated the new A occurrence but sent no provider request.
23:45:53.332 The fixture received B as the ninth request. The parked A request was still absent.
23:45:56.462 B finished successfully and returned its extra slot. The eight former extras were still held.
23:46:47.651 The same parked A occurrence became the ninth request 63.7s after the 429, with all eight former extras still held.
23:46:49.343 A and B each had one successful run. The parked A job made one HTTP request.

Regression and CI attribution. On 43c10db, the worker-level regression failed at the first quiet minute because the parked A job could not start. It passes with receipt promotion. The messaging typecheck also reproduced CI’s missing deliveryAttemptFence field and passes with the fixture fixed. The contemporaneous main run skipped both check lanes. The other PR failure was the excluded UI route-asset assertion, with 57 requests against a budget of 56. PR CI · Main CI

Coverage. 236 focused tests passed, with the recovery, shared-session resume, and shared-session cancellation cases repeated on the final source. The core, cron, and messaging typechecks, targeted lint, formatting, and ratchets passed. The extra test lines cover the 16-run burst and the completion order that exposes stale charges.

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

Live shared-session readmission on 142328b4b72a7751477f69697c2e128baa705d5f

The running Gateway reported build ID 2026.11.6-142328b4b72a-2026-11-22T09-28-55.368Z from /startupz, matching the build metadata from the pinned checkout. A loopback provider fixture returned HTTP 429 while the eight default cron slots were occupied. The shared-session automation was created through an authenticated Gateway connection and its stored job had a saved requester.

09:35:27.742Z Provider fixture returned HTTP 429 with 8 default slots occupied.
09:35:27.784Z Gateway cron warning  automation paused extra runs for provider smoke-a after it rate-limited a request; it adds one a minute without pushback
09:35:31.795Z Gateway SQLite  agent:main:proof-shared, receipt sha256:62fa07146b9d799b parked, 0 provider requests.
09:35:32.264Z Gateway chat  agent:main:proof-shared, foreground final event and reply committed, receipt sha256:62fa07146b9d799b still parked, 0 automation provider requests.
09:35:32.264Z Provider fixture released one default-slot request.
09:35:32.314Z Gateway readmission tracepoint  agent:main:proof-shared, freshAuthority=true.
09:35:32.447Z Provider fixture received the shared automation, attempt 1.
09:35:32.628Z Gateway SQLite  receipt sha256:62fa07146b9d799b status=ok, same activation, 1 receipt and 1 provider request.

The foreground turn finished before any provider request for the parked automation. Once a default slot opened, a non-pausing tracepoint in the compiled Gateway recorded fresh requester authority before the automation’s first provider request. The SQLite observations used read-only queries. The receipt is fingerprinted because its original encoding contains a local path.

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@daniel-lxs

Copy link
Copy Markdown
Member Author

Pre-existing failure attribution (verified before merge)

The only failing check on 142328b4b72a is checks-node-changed-compact-large-31: src/gateway/server-cron-failure-repair.final-effect.test.ts fails with 12 executionStarted assertions, with the underlying Cron failure repair was not accepted: Session event was not admitted error from src/gateway/server-cron-notifications.ts:131. openclaw/ci-gate is red only because of that job.

The same failures occur on main: commit 8d1e59c2 — checks-node-compact-large-16 (job 137257185108) fails with the identical annotations: same test file, same assertion, same notifications error. Merged under the maintainer authorized pre-existing-failure exception.

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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants