Repository navigation
feat(gateway): auto-suspend idle cloud workers with suspendAfter - #130242
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 2:11 PM ET / 18:11 UTC. ClawSweeper reviewWhat this changesAdds optional Merge readinessKeep 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 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherCloud-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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +178, Tests +343, Docs +16. Total +537 across 12 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk options
Maintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
This reverts commit 546466e.
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.
|
The P1 is accepted and addressed in Validation on the updated head: crabbox suite green, |
|
Merged via squash.
|
…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.
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 providersettingsbag — 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 placementupdatedAtMs, 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 pathsessions.reclaimuses (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-existingauthorizefence 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: falseis 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 lineauto-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):activein 113s; a real model turn ran on the worker (its reply contained the on-box workspace path, proving worker-turn inference).auto-suspended agent:main:suspendproof after 2m idle; wakes on next message— placementreclaimed, container gone, lease released, warm checkpoint captured.chat.sendto 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.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.mjsfully green;pnpm buildgreen; fresh Codex autoreview clean. Production LOC +205/−15 (one new sweep module + config key + wiring; the capability justifies the growth), tests +386/−9.