Skip to content

feat(gateway): auto-suspend idle cloud workers with suspendAfter - #130242

Merged
steipete merged 5 commits into
mainfrom
steipete/worker-auto-suspend
Aug 26, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/worker-auto-suspend

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

With warm images landed (#130087), stopping a cloud worker is cheap and the next dispatch is fast — but nothing stops an idle worker. A placed session keeps its lease heartbeating and billing until someone remembers to press Stop cloud worker. The product behavior operators actually want (maintainer-accepted): suspend the machine automatically after the session has been idle for a while, and wake it when the user sends the next message.

Why This Change Was Made

One knob delivers it: cloudWorkers.profiles.<id>.suspendAfter (duration string, minimum 1m, unset = current always-on behavior). It lives at the profile level — not in the provider settings bag — because idleness is a session/placement fact only core can see; providers own machines, not sessions.

The wake half already existed (a reclaimed placement auto-redispatches on the next message, warm via the profile image), so the only new machinery is a small idle sweep (placement-idle-sweep.ts) riding the existing placement-reconciliation cadence behind its fence. Idle is measured from durable placement updatedAtMs, which is refreshed exactly by placement activation and every turn-claim admission/release — a recorded fact at its owner, no multi-signal inference. The sweep suspends via the exact programmatic path sessions.reclaim uses (reconcile → capture → release), skipping anything with an active/queued turn, in-flight dispatch or move, pending workspace result, or reconciliation — with a CAS-style re-read plus the reclaim flow's pre-existing authorize fence aborting before drain if work arrives at the last moment. No new states, no schema, no protocol changes.

Two companion changes ride along: crabbox warm images flip to default-on (settings.warmImage: false is the opt-out; 2026.8.1 is unreleased so yesterday's opt-in boolean carries no compat weight, and with suspend in the picture a cold multi-minute wake is the wrong default), and a real bug found while wiring it — scrub and checkpoint-create each had their own 180s budget, stacking to ~6 minutes worst-case; they now share one end-to-end 180s deadline, making the documented teardown bound genuine.

User Impact

Set suspendAfter: "2h" on a cloud profile and idle workers park themselves to a snapshot (storage-priced) with a log line auto-suspended <session> after 2h idle; wakes on next message; the next chat message brings the session back on a warm machine with no user action. Unset means nothing changes. Docs updated: profile fields, config example, configuration reference, troubleshooting, and the plan doc's product update.

Evidence

Live proof (isolated dev gateway on this branch's dist, local-container backend, real Anthropic inference proxied through the Gateway, suspendAfter: "2m" test-scale):

  • Cold dispatch → active in 113s; a real model turn ran on the worker (its reply contained the on-box workspace path, proving worker-turn inference).
  • Then nothing: 1m53s after the turn's claim release, the sweep fired autonomously — auto-suspended agent:main:suspendproof after 2m idle; wakes on next message — placement reclaimed, container gone, lease released, warm checkpoint captured.
  • One chat.send to the suspended session, no manual dispatch: reply arrived 99s later from a fresh warm worker (new lease id; the container's image was byte-identically the checkpoint-commit image; zero warm-image fallback warnings). 99s send→reply includes the automatic redispatch, enrollment, bundle push, workspace sync, and the model turn — compared to 113s for the cold dispatch step alone.
  • Final reclaim, checkpoint deletion, zero leases/containers/images afterwards.

Tests: new sweep suite (suspends idle active placements via the real reclaim path; skips active-turn, in-flight-dispatch, pending-result, moving, and non-suspendAfter cases; never-ran sessions idle from activation; busy-abort via the authorize fence), config parse/floor coverage, crabbox default-flip coverage — 69 gateway + 38 config + 198 crabbox tests green; node scripts/check-changed.mjs fully green; pnpm build green; fresh Codex autoreview clean. Production LOC +205/−15 (one new sweep module + config key + wiring; the capability justifies the growth), tests +386/−9.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: crabbox size: L maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 17:26
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 2:11 PM ET / 18:11 UTC.

ClawSweeper review

What this changes

Adds optional cloudWorkers.profiles.&lt;id>.suspendAfter configuration to reclaim idle cloud workers and wake them through the existing next-message placement flow.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. The prior warm-image security finding was addressed: warm images remain opt-in, while idle suspension reuses the canonical reclaim path and rechecks session admission inside the lifecycle fence. The PR now needs only exact-head CI and normal maintainer merge handling.

Priority: P2
Reviewed head: fb23b8edc6ae86646ec05cb75f1bfd5746dd7620

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is coherent and the prior blocker is addressed; exact-head CI remains the material pre-merge check.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-member PR is exempt from the external-contributor proof gate; its body nevertheless describes an isolated after-fix Gateway run, but no inspectable artifact is attached here.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-member PR is exempt from the external-contributor proof gate; its body nevertheless describes an isolated after-fix Gateway run, but no inspectable artifact is attached here.
Evidence reviewed 7 items Idle decision and owner boundary: The new sweep considers only active, claim-free placements, uses durable updatedAtMs for idleness, excludes pending work and in-flight placement operations, then delegates teardown to the existing reclaim service.
Final admission fence: The reclaim barrier now invokes the supplied authorizer after acquiring the session lifecycle fence and before interrupting work; the reclaim implementation repeats authorization immediately before destructive effects.
Behavior-focused coverage: The new suite exercises durable placement state and the reclaim harness for idle activation, claim release, dispatch/move exclusion, pending results, reconciliation, and the admission race.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

$ node scripts/run-node.mjs --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 109.02 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 14.5s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4317ms (slowest: built plugin control-plane loads 3573ms)

OpenClaw 2026.8.1 (fb23b8e) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console (silent|fatal|error|warn|info|debug|trace)
  --no-color           Disable ANSI colors
  --profile ‹name›     Use a named profile (iso
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

Cloud-worker placement keeps an agent session bound to a provider machine while Gateway dispatches work. The idle sweep reads profile configuration and durable placement activity, then invokes the established reclaim lifecycle so a later message can provision a new worker.

flowchart LR
  A[Cloud worker profile] --> B[Gateway placement runtime]
  C[Placement activity and turn state] --> D[Idle sweep]
  B --> D
  D --> E{Safe to reclaim?}
  E -->|yes| F[Reclaim worker and release lease]
  E -->|no| G[Keep placement active]
  F --> H[Next message provisions worker]
Loading

Before merge

  • Complete next step (P2) - The prior concrete review blocker is fixed; remaining work is normal exact-head CI and merge handling, not an automated repair task.
Agent review details

Security

None.

PR surface

Source +178, Tests +343, Docs +16. Total +537 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 183 5 +178
Tests 2 343 0 +343
Docs 3 22 6 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 548 11 +537

Review metrics

Metric Value Why it matters
Production versus test delta production +183/-5; tests +343/-0; docs +22/-6 The production growth is the new profile setting, sweep, and lifecycle wiring; most added lines are focused boundary coverage.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/placement-dispatch-coordinator.ts, durable storage schema: src/gateway/worker-environments/placement-idle-sweep.test.ts, durable storage schema: src/gateway/worker-environments/placement-idle-sweep.ts, unknown-data-model-change: src/gateway/worker-environments/placement-idle-sweep.test.ts, unknown-data-model-change: src/gateway/worker-environments/placement-idle-sweep.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

  • The branch is behind current main and its supplied exact-head check rollup is still running or queued; merge only after the current three-way result receives green required checks.

Maintainer options:

  1. Refresh against current main (recommended)
    Rebase or otherwise refresh the exact merge result and require green exact-head checks before landing the opt-in lifecycle change.

Technical review

Best possible solution:

Land the opt-in profile-level sweep after exact-head CI confirms the current-main merge, preserving the final admission fence and the restored opt-in warm-image boundary.

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

Not applicable: this is an opt-in capability rather than a report of broken existing behavior; the relevant evidence is the after-change placement and reclaim path.

Is this the best way to solve the issue?

Yes. Core owns session idleness and placement authority, while provider behavior remains behind the existing generic reclaim flow; this avoids provider-specific policy or a parallel teardown path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a5537c6e4a13.

Labels

Label changes:

  • add P2: This is a bounded, opt-in improvement to cloud-worker operating cost rather than an urgent default-path regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-member PR is exempt from the external-contributor proof gate; its body nevertheless describes an isolated after-fix Gateway run, but no inspectable artifact is attached here.
  • remove P1: Current review triage priority is P2, so this older priority label is no longer current.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded, opt-in improvement to cloud-worker operating cost rather than an urgent default-path regression.
  • merge-risk: 🚨 compatibility: A new profile-level lifecycle setting changes runtime behavior for operators who enable it and must remain additive for existing configurations.
  • merge-risk: 🚨 security-boundary: Automatic reclaim can interrupt session work and release a worker, so its final admission and placement-authority checks are merge-critical.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-member PR is exempt from the external-contributor proof gate; its body nevertheless describes an isolated after-fix Gateway run, but no inspectable artifact is attached here.

Evidence

What I checked:

Likely related people:

  • steipete: History shows sustained authorship of cloud-worker placement, reclaim, and related warm-image lifecycle work. (role: feature owner and recent area contributor; confidence: high; commits: 7d5b986a82bc, b5880c09bc2d, fb23b8edc6ae; files: src/gateway/server-worker-placement-reclaim.ts, src/gateway/worker-environments/placement-dispatch.ts, src/gateway/worker-environments/placement-idle-sweep.ts)

Rank-up moves

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

  • Refresh the branch against current main as needed and wait for green exact-head required checks.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-26T17:33:41.535Z sha ad84b2f :: found issues before merge. :: [P1] Keep warm-image capture opt-in until its secret boundary is proven

Review finding: default-on capture would persist setup-created state outside
the scrubbed worker root into provider images for profiles that never opted
in. suspendAfter pairs with warmImage: true for warm wakes.
@steipete

Copy link
Copy Markdown
Contributor Author

The P1 is accepted and addressed in 1442ef470be + fb23b8edc6a: the warm-image default flip is reverted — settings.warmImage stays opt-in — because the finding is correct that default-on capture would persist whatever settings.setup wrote outside the scrubbed worker root (setup-created credentials included) into provider-account images for profiles that never chose it, and would change teardown cost/timing on upgrade. suspendAfter remains fully functional standalone (suspend always works; the next message provisions a replacement, warm only when the operator also sets warmImage: true). Docs now pair the two explicitly, state the setup-residue boundary plainly, and the plan doc records that default-on returns only behind a proven capture boundary.

Validation on the updated head: crabbox suite green, node scripts/check-changed.mjs fully green, fresh structured autoreview clean before the revert (the revert restores previously reviewed opt-in behavior).

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
@steipete
steipete merged commit d2d055b into main Aug 26, 2026
213 checks passed
@steipete
steipete deleted the steipete/worker-auto-suspend branch August 26, 2026 18:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…nclaw#130242)

* feat(gateway): auto-suspend idle cloud workers

* feat(crabbox): enable bounded warm images by default

* docs(gateway): explain idle worker suspension and warm images

* Revert "feat(crabbox): enable bounded warm images by default"

This reverts commit 546466e.

* docs(gateway): keep warm images opt-in pending a proven capture boundary

Review finding: default-on capture would persist setup-created state outside
the scrubbed worker root into provider images for profiles that never opted
in. suspendAfter pairs with warmImage: true for warm wakes.
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 gateway Gateway runtime maintainer Maintainer-authored PR 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. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant