Skip to content

fix(crabbox): keep active cloud worker leases alive - #124615

Merged
steipete merged 3 commits into
mainfrom
fix/crabbox-lease-heartbeat
Aug 16, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/crabbox-lease-heartbeat

Conversation

@steipete

@steipete steipete commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #124546

What Problem This Solves

Fixes an issue where active cloud-worker sessions could lose their Crabbox machine when the configured idleTimeout elapsed, even while turns, disk probes, workspace reconciliation, and SSH reconnects were still active. The live Hetzner reproduction measured a frozen last_touched timestamp until the lease flipped active to expired at 15m31s for a 15m timeout.

Why This Change Was Made

The bundled Crabbox plugin now owns a per-lease heartbeat for every successfully provisioned or re-adopted live worker. It matches Crabbox's own idleTimeout / 3 cadence with a 5–60 second clamp, aborts the heartbeat before provider teardown, and stops on terminal or missing leases. This remains entirely inside the provider boundary; no Gateway lifecycle or configuration surface changes.

The implementation uses the new crabbox heartbeat contract from openclaw/crabbox#1356 (ab0bca1c54e). Binaries without that command keep dispatch and normal operation working: OpenClaw logs one bounded warning per environment, explains that the machine may still be reaped after idleTimeout, and disables further heartbeat attempts for that lease. Other heartbeat failures warn once per failure streak and retry without failing dispatch, turns, or reconciliation.

User Impact

Cloud-worker machines now stay leased for as long as their OpenClaw session remains placed, then return to normal idle expiry as soon as teardown begins. Operators on Crabbox 0.43.0 or older keep existing behavior without a hard version gate, with one actionable upgrade warning instead of a broken dispatch.

Evidence

  • Live issue proof: last_touched remained frozen while idle_for reached 15m31s and the lease expired during an active session (Cloud worker machines are reaped mid-session: Crabbox idle timer is never refreshed #124546).
  • Pre-fix regression proof: the six new heartbeat lifecycle cases fail against origin/main with zero heartbeat calls.
  • node scripts/run-vitest.mjs extensions/crabbox — 106 tests passed, including 1s, 2s, and 5s interval boundaries.
  • Follow-up node scripts/check-changed.mjs — passed on Blacksmith Testbox tbx_01m05dzdgv6yb3e7tqhssypsts (run 31951448693), including Crabbox production/test typecheck and lint.
  • Post-boundary node scripts/check-changed.mjs was blocked before PR lanes by a current-main shrink-only assertion baseline mismatch (server.auth.control-ui.pairing.suite.ts: actual 6, baseline 11); no unrelated baseline was edited.
  • .claude/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean, no accepted/actionable findings.
  • node scripts/watch-pr-ci.mjs 124615 a1326618a4bed446020f32bae5d82e27f1b7e8fd — GREEN on exact-head CI run 31953222986, including production/test typecheck and lint.
  • CLI compatibility probe: installed Crabbox 0.39.0 exits 2 with unexpected argument heartbeat; a locally built upstream binary accepts the new flags and reaches lease lookup.
  • LOC: production +361/-147 (net +214, including the command-boundary extraction needed to bring the touched provider below 700 lines); tests +173/-3; docs net zero.

AI-assisted implementation; the code, upstream CLI contract, lifecycle boundary, and proof were reviewed directly.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 16, 2026 13:50
@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 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 16, 2026, 10:50 AM ET / 14:50 UTC.

ClawSweeper review

What this changes

This PR adds provider-owned Crabbox lease heartbeats for active cloud workers, fences them during teardown, and documents the required CLI capability.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open. The revised patch fixes the prior one-second cadence blocker, but still accepts sub-millisecond Go durations that the Node timer cannot renew before expiry.

Priority: P1
Reviewed head: a1326618a4bed446020f32bae5d82e27f1b7e8fd

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has a sound owner boundary and focused coverage, but the accepted-duration timing defect blocks merge readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body nevertheless records focused CI and incident evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body nevertheless records focused CI and incident evidence.
Evidence reviewed 6 items Unschedulable accepted duration: The profile parser accepts every positive Go duration, including nanoseconds and microseconds, while the new interval computation clamps its result to at least 1 ms.
Focused coverage gap: The new cadence table starts at 1s and advances fake timers by 0 for the initial heartbeat, so it does not exercise a real timer’s minimum-delay behavior for accepted sub-millisecond values.
Owner boundary and caller: Gateway reconciliation invokes provider inspection for durable leases, and the proposed provider starts heartbeats only after a successful provision or nonterminal inspection, keeping the behavior in the plugin-owned lifecycle boundary.
Findings 1 actionable finding [P2] Reject timeouts the scheduler cannot renew
Security None None.

How this fits together

Gateway worker lifecycle reconciliation calls the bundled Crabbox provider to provision, inspect, and destroy cloud-worker leases. The provider’s new scheduler calls the Crabbox CLI while a lease is active and stops before teardown.

flowchart LR
  A[Gateway worker lifecycle] --> B[Crabbox provider]
  B --> C[Provision or inspect lease]
  C --> D[Heartbeat scheduler]
  D --> E[Crabbox heartbeat command]
  E --> F[Coordinator lease liveness]
  B --> G[Destroy request]
  G --> H[Stop scheduler]
  H --> I[Release lease]
Loading

Before merge

  • Reject timeouts the scheduler cannot renew (P2) - parseCrabboxProfile still accepts sub-millisecond Go durations, but this calculation clamps the interval to 1 ms. A 500µs lease can therefore expire before the first timer callback runs; reject values below a scheduler-safe minimum (with headroom) and cover that boundary.
  • Resolve merge risk (P1) - A valid idleTimeout: "500µs" is accepted but cannot be renewed by a Node timer clamped to 1 ms, so the original mid-session expiry remains possible for that profile.
  • Resolve merge risk (P1) - The new behavior depends on the external Crabbox CLI contract; direct upstream source was unavailable for independent verification of its command and error semantics.
  • Resolve merge risk (P1) - Production code grows by net 214 lines for a bug fix; the provider-owned scheduler and command-boundary extraction explain most of it, but the final repair should avoid further lifecycle surface growth.
  • Complete next step (P2) - The remaining repair is concrete, but this protected maintainer-owned provider change also needs upstream CLI-contract verification before merge.

Findings

  • [P2] Reject timeouts the scheduler cannot renew — extensions/crabbox/src/crabbox-worker-profile.ts:89-93
Agent review details

Security

None.

PR surface

Source +214, Tests +170, Docs 0. Total +384 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 361 147 +214
Tests 1 173 3 +170
Docs 1 7 7 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 541 157 +384

Review metrics

Metric Value Why it matters
Production versus test delta production +361/-147 (net +214); tests +173/-3; docs +7/-7 The new lease scheduler and extracted command boundary add substantial production behavior to a bug fix, so the remaining timing boundary needs resolution before accepting that growth.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/crabbox/src/crabbox-worker-heartbeat.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #124546
Summary: This PR is the explicit candidate repair for the cloud-worker lease-expiry report, but it remains incomplete at the short-duration boundary.

Members:

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

Merge-risk options

Maintainer options:

  1. Repair the accepted-duration boundary (recommended)
    Reject idle timeouts below a proven scheduler-safe minimum and add regression coverage that demonstrates the boundary before merge.
  2. Pause for upstream contract confirmation
    Do not merge until the Crabbox CLI heartbeat command and failure-code contract can be checked against the referenced upstream revision.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Reject idleTimeout values below a proven scheduler-safe minimum, add a real-timer regression case, and retain the 1s/2s/5s cadence coverage.

Technical review

Best possible solution:

Keep the provider-owned scheduler, reject idle timeouts below a scheduler-safe minimum, add a real-timer boundary regression, and retain the explicit warning path for older Crabbox binaries.

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

Yes, from source: 500µs passes profile validation but the scheduler cannot run before its 1 ms minimum delay; the focused test can be extended to demonstrate it.

Is this the best way to solve the issue?

No. A provider-owned heartbeat is the right layer, but the implementation must not accept durations it cannot renew safely and still needs direct upstream CLI-contract confirmation.

Full review comments:

  • [P2] Reject timeouts the scheduler cannot renew — extensions/crabbox/src/crabbox-worker-profile.ts:89-93
    parseCrabboxProfile still accepts sub-millisecond Go durations, but this calculation clamps the interval to 1 ms. A 500µs lease can therefore expire before the first timer callback runs; reject values below a scheduler-safe minimum (with headroom) and cover that boundary.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: This addresses active cloud workers being reaped while an operator session is still running.
  • merge-risk: 🚨 compatibility: The provider now depends on a newer Crabbox CLI command while older installed binaries take a warning-only path.
  • merge-risk: 🚨 availability: An accepted timeout below the scheduler’s minimum delay can still allow an active lease to expire.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body nevertheless records focused CI and incident evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame assigns the Crabbox profile parsing boundary to Peter Steinberger, who also authored the active heartbeat work. (role: recent current-main contributor and adjacent owner; confidence: medium; commits: a118bfbf308b; files: extensions/crabbox/src/crabbox-worker-profile.ts, extensions/crabbox/src/crabbox-worker-provider.ts)

Rank-up moves

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

  • Reject or safely support every accepted idle-timeout value, including sub-millisecond inputs.
  • Add direct upstream Crabbox command-contract evidence for the referenced revision.

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 (4 earlier review cycles)
  • reviewed 2026-08-16T13:56:35.112Z sha e287348 :: found issues before merge. :: [P2] Keep heartbeat intervals below short idle timeouts
  • reviewed 2026-08-16T14:03:27.087Z sha e287348 :: found issues before merge. :: [P2] Keep heartbeats within every accepted idle timeout
  • reviewed 2026-08-16T14:25:21.347Z sha eb6c163b7e3fee1816677d4ba0eca8b93783da37 :: found issues before merge. :: [P2] Keep heartbeats within every accepted idle timeout
  • reviewed 2026-08-16T14:32:15.420Z sha eb6c163b7e3fee1816677d4ba0eca8b93783da37 :: found issues before merge. :: [P2] Keep heartbeats within every accepted idle timeout

@steipete
steipete force-pushed the fix/crabbox-lease-heartbeat branch from eb6c163 to a132661 Compare August 16, 2026 14:36
@steipete

Copy link
Copy Markdown
Contributor Author

The original short-timeout P2 is addressed at head a1326618a4bed446020f32bae5d82e27f1b7e8fd: 1s, 2s, and 5s profiles now schedule at 500ms, 1s, and 2.5s, all strictly before their effective idle deadline. Focused coverage passes 106/106 and exact-head CI is green.

Skipping the fresh suggestion to reject sub-millisecond profile strings. That would violate the intentional no-config-contract-change boundary, and its premise is not an effective Crabbox lease state:

  • coordinator requests serialize idleTimeoutSeconds with int(cfg.IdleTimeout.Seconds()) (internal/cli/coordinator.go);
  • direct AWS claims use the same whole-second conversion (internal/providers/aws/backend.go);
  • direct provider labels use duration.Round(time.Second) (internal/cli/provider_labels.go);
  • non-positive coordinator values are normalized to provider defaults rather than creating a sub-millisecond expiry (worker/src/config.ts, worker/src/fleet.ts).

So the shortest effective coordinator-idle deadline produced by a positive profile is one second, and that boundary is now explicitly covered at a 500ms heartbeat. No previously accepted profile value is rejected.

@steipete

Copy link
Copy Markdown
Contributor Author

Live acceptance test on real Hetzner cloud workers (dev gateway built from this branch at eb6c163b7e3, profile idleTimeout: "15m"). Both code paths exercised against live infrastructure.

Old Crabbox binary (0.41.6, no heartbeat command) — graceful degradation

Dispatch succeeded normally (active in 5m05s) and the Gateway logged exactly one warning, then stopped retrying that lease:

[plugins] Crabbox heartbeat is unavailable for worker lease cbx_92fff64bb913;
  upgrade Crabbox to a release that includes `crabbox heartbeat` (added after v0.43.0);
  cloud worker machines may be reaped after 15m of coordinator-idle time

No dispatch failure, no turn failure — existing operators keep today's behavior plus an actionable warning.

Heartbeat-capable binary (built from crabbox main ab0bca1c54e) — the fix

Dispatch active in 4m00s, zero unavailability warnings, and the coordinator idle timer was refreshed automatically with no manual intervention:

07:39:45  dispatch          (without heartbeat this lease dies ~07:55)
07:43:56  idle_for=13s
07:48:59  idle_for=59s
07:54:08  idle_for=47s      <- past the old death point
07:59:15  idle_for=33s
08:04:23  idle_for=7s       <- box 25 minutes old, still active
08:05     agent turn sent on the 25-minute-old box
08:09:35  turn completed, reconciled, `heartbeat-fix-verified` synced back, placement still active

Ten minutes past the window that destroyed three boxes while I was reproducing #124546, and the session was fully usable.

Note on scope: this run used the branch at eb6c163b7e3; the later a1326618a4b commit only bounds the interval for sub-5s idleTimeout values, which cannot affect a 15m profile.

@steipete
steipete merged commit 5a0fe22 into main Aug 16, 2026
159 checks passed
@steipete
steipete deleted the fix/crabbox-lease-heartbeat branch August 16, 2026 15:16
@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 17, 2026
* fix(crabbox): heartbeat active worker leases

* fix(crabbox): clarify heartbeat upgrade guidance

* fix(crabbox): bound heartbeat before idle expiry
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 extensions: crabbox gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud worker machines are reaped mid-session: Crabbox idle timer is never refreshed

1 participant