Skip to content

fix: reclaim cloud workers after cleanup acceptance - #182138

Merged
steipete merged 2 commits into
mainfrom
steipete/cs-fastreclaim-1023b
Oct 24, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/cs-fastreclaim-1023b

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #168454 and #173825.

What Problem This Solves

Stopping a cloud worker waits for the provider's full physical release, keeping session reclaim on a 40–120 second cleanup path.

User Impact

Reclaim can finish after session shutdown and accepted cleanup. The environment remains destroying until physical release is confirmed; billing can continue during that interval. Failed confirmation remains visible and retryable. Providers without the capability, unsupported direct Crabbox backends, and already-disconnected dedicated workers retain blocking cleanup.

Expected savings are the physical-release portion of the observed Azure 100–117s, GCP 66–77s, and AWS 4–58s waits, minus acceptance and session-cleanup overhead. These are estimates from the reported timings, not a new live benchmark; physical billing duration is unchanged.

Why This Change Was Made

The existing environment lifecycle owner now distinguishes cleanup acceptance from confirmation through an optional provider notification. Crabbox uses stop --wait=false for acceptance and a waiting stop within the same cleanup budget for confirmation. Terminal inspection alone is never release proof.

Warm-image capture still releases reclaim after capture admission, but its destroy promise now remains owned through confirmed stop and preserves late failures. The redundant post-reclaim tunnel wait and warning-only teardown observer are removed. No new environment states, configuration, or state stores are introduced. The provider contract and user documentation describe the handoff and continued billing window.

Against the merge base: non-test source +212/-86, tests and fixtures +388/-63, docs +7/-1. The remaining production growth is the optional acceptance contract, its existing-owner handoff, and Crabbox's bounded acceptance/confirmation sequence. The CI follow-up changes only ten test/fixture files (+37/-16); it adds no production logic.

The CI follow-up preserves the original lifecycle assertions. The dispatch fixture now shuts down its tunnel before returning reclaim acceptance, matching the existing production owner. The Move/Stop fixture holds recovery-source release after local publication instead of waiting at the removed post-completion tunnel stop. A real SSH-manager regression verifies that tunnel shutdown, credential revocation, and rejection of the old handle all precede provider cleanup acceptance. The existing tests still cover delayed destruction, visible confirmation failure/retry, and blocking providers.

Crabbox's classless lifecycle command sequence was already correct; its exact timeout assertion now uses a fixed monotonic clock. Test doubles retain the required reclaim contract, the acceptance fixture narrows to an attached lease, and extension tests use the public SDK test-fixtures entry point.

Evidence

CI follow-up validation on Node 24.22.1 with OPENCLAW_VITEST_RUNTIME=node; runtime checks use pnpm test <file...> --maxWorkers=1:

File Result Wall time
src/gateway/worker-environments/placement-dispatch-authority.test.ts 17 passed 195.73s
src/gateway/server-worker-placement-reclaim.preparation.test.ts 39 passed 308.82s
extensions/crabbox/index.test.ts 8 passed 212.47s
test/extension-test-boundary.test.ts 12 passed 197.81s
src/gateway/worker-environments/provider-reclaim-acceptance.test.ts 3 passed 131.03s
src/gateway/worker-environments/placement-dispatch-reclaim.test.ts 31 passed 71.45s
src/gateway/worker-environments/placement-reclaim-acceptance.test.ts 1 passed 28.30s
src/gateway/worker-environments/worker-turn-launcher-build-recovery.test.ts 27 passed 151.79s
src/gateway/worker-environments/worker-turn-shutdown.test.ts 2 passed 54.97s
extensions/crabbox/src/crabbox-worker-stop.test.ts with extensions/crabbox/index.test.ts 13 passed 135.74s
  • pnpm run tsgo:core: passed, 3.50s. Core test type graphs gateway-other and gateway-server via node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.<graph>.json --incremental: passed, 248.36s and 5.66s.
  • pnpm run tsgo:extensions:test: passed, 305.08s.
  • node --import tsx scripts/check-extension-plugin-sdk-boundary.mts --all: all three modes passed, 11.72s.
  • Scoped type-aware lint using the repository scripts/run-oxlint.mjs runner: core passed, 218.48s; Crabbox passed, 253.84s. Touched-file pnpm exec oxfmt --check: passed, 0.12s; git diff --check: passed.
  • Independent review through P2: no actionable findings. The only subsequent change was import ordering by the formatter.
  • Baselines reproduced all reported runtime failures on afa45c965d0: authority 1 failed/16 passed; Move/Stop 5 failed/34 passed; Crabbox lifecycle 2 failed/6 passed; boundary 1 failed/11 passed. The core test-type baseline reproduced all four reported diagnostics. The fixes retain the behavioral assertions rather than accepting new expected outcomes.
  • Wall times include compilation, source verification, and shared artifact-lock waits on the loaded host. The existing SQLite coordinator suites cover real cancellation/completion ownership and cannot be replaced by provider-only mocks. No live Gateway, cloud allocation, or Docker run was used.

Earlier implementation evidence:

  • Red on unchanged owner code at 094bbd6b153b (also unchanged on origin/main at 1fead915921e): the placement regression failed with expected 'waited-for-release' to be 'reclaimed'. One test, 364.88s wall / 6.948s test execution under Node 24.22.1.
  • Node 24.22.1, OPENCLAW_VITEST_RUNTIME=node: pnpm test src/gateway/worker-environments/provider-reclaim-acceptance.test.ts src/gateway/worker-environments/placement-reclaim-acceptance.test.ts src/gateway/worker-environments/provider-crabbox-runtime-preflight.test.ts src/gateway/worker-environments/placement-dispatch-reclaim.test.ts src/gateway/worker-environments/provider-node-teardown.test.ts extensions/crabbox/src/crabbox-worker-stop.test.ts --maxWorkers=1: 82 tests passed, 795.88s wall. Covers accepted reclaim, delayed physical confirmation, visible failure/reconciliation retry, unchanged blocking providers, direct-backend fallback, and detached capture.
  • Final Node 24.22.1 rerun after the dedicated-node fallback: pnpm test src/gateway/worker-environments/provider-node-teardown.test.ts src/gateway/worker-environments/provider-reclaim-acceptance.test.ts extensions/crabbox/src/crabbox-worker-provider.test.ts extensions/crabbox/src/crabbox-worker-warm-image.test.ts extensions/crabbox/src/crabbox-worker-warm-image-lifecycle.test.ts extensions/crabbox/src/crabbox-worker-stop-lifetime.test.ts --maxWorkers=1: 125 tests passed, 216.38s wall. This includes the capable-provider offline fallback, shared/unknown-host rejection, warm-image lifecycle, and late stop failure/timeout custody.
  • pnpm run tsgo:core, touched-file oxfmt --check, scoped core and Crabbox type-aware lint, and git diff --check passed. Independent review through P2 found no actionable issues in the final production change.
  • Inspected Crabbox v0.77.0/v0.78.1 stop semantics: asynchronous acceptance explicitly requires a follow-up waiting stop; direct backends reject the asynchronous flag with the exact diagnostic used for fallback.
  • No live cloud allocation or latency benchmark was run. PR CI supplies the broader checks. Local preparation was expensive on the heavily loaded host; timings above include worker compilation and module loading.

@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T03:37:40.403724Z dcbce62 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: crabbox size: L labels Oct 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR lets session reclaim finish after cleanup acceptance while retaining ownership until physical worker release is confirmed.

Example: An AWS worker accepts deletion while physical release is still pending.

  • Before: Stop waits for the waiting Crabbox stop command to finish.
  • After: Stop can finish after session shutdown and acceptance; the environment remains destroying until release is confirmed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The lifecycle design is coherent and supported by focused harness coverage, but patch-caused CI regressions prevent a clean verdict.
Proof confidence 🦐 gold shrimp (3/6) The supplied evidence exercises the real lifecycle and adapter with mocked provider/process I/O; maintainer authorship exempts ordinary shipped-entry-point proof, and the notification adds no authority-bearing capability.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Stopping a cloud worker waits through physical release after session work can already be shut down.
Reason: Maintainer-authored direction explicitly accepts the continued billing window and preserves visible, retryable cleanup ownership.

Merge readiness

⛔ Needs changes before merge - 3 items remain

Keep this PR open: the cleanup handoff is useful and maintainer-directed, but three patch-caused test regressions need repair.

Priority: P2
Reviewed head: afa45c965d0ccf9cdddc500f1db45b39643bddce

Before merge

  • Import withinTest through the public SDK testing surface (P2) - The new relative import reaches outside the Crabbox package into repository test helpers. This deterministically fails both the extension-import lint and test/extension-test-boundary.test.ts in exact-head CI. Import withinTest from openclaw/plugin-sdk/test-fixtures, which already exports it, instead.
  • Migrate the placement fixture to reclaim's shutdown contract (P2) - The new fixture reclaim only delegates to destroy, while production reclaim now owns session transport shutdown and the placement caller no longer calls stopTunnel afterward. Tests that override stopTunnel therefore never reach their cleanup hold or stop their real fixture tunnel. Exact-head CI reports five 'Move completed before cleanup hold' failures and the cancellation/reclaim authority case retaining a connected tunnel. Model shutdown inside the fixture reclaim and update the affected tests to distinguish shutdown, acceptance, and confirmation.
  • Update classless lifecycle tests for the remaining cleanup budget (P2) - Subtracting performance.now() before the first stop changes its timeout from exactly 1005000 ms to a slightly smaller remaining allowance. Both existing classless lifecycle cases in extensions/crabbox/index.test.ts:166 still require exact equality and fail in exact-head CI. Update those tests to check the bounded shared-budget contract or use a controlled clock; preserve the production deadline calculation.

Findings

  • [P2] Import withinTest through the public SDK testing surface — extensions/crabbox/src/crabbox-worker-stop.test.ts:2
  • [P2] Migrate the placement fixture to reclaim's shutdown contract — src/gateway/worker-environments/placement-dispatch-test-harness.ts:440
  • [P2] Update classless lifecycle tests for the remaining cleanup budget — extensions/crabbox/src/crabbox-worker-command.ts:283-284

Tests

  • Missing end-to-end proof: No shipped Gateway-to-Crabbox acceptance and delayed-confirmation run is supplied; maintainer authorship exempts this PR from the ordinary contributor proof gate.
Agent review details

How this fits together

Session placement sends Stop requests to the environment lifecycle owner, which shuts down session transports and asks the provider to release its lease.

flowchart TD
  A[Session Stop] --> B[Placement reconciliation]
  B --> C[Environment lifecycle owner]
  C --> D[Session shutdown]
  D --> E[Crabbox cleanup]
  E --> F[Reclaim completion]
  E --> G[Physical release confirmation]
  G --> C
Loading

Technical review

Best possible solution:

Keep the existing lifecycle handoff and repair the public test import, placement cleanup fixtures, and timeout assertions.

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

Current main awaits physical destruction during reclaim, and the PR records a failing baseline regression; no target code was executed during this review.

Is this the best way to solve the issue?

The existing environment owner is the appropriate place to separate acceptance from confirmation, with provider opt-in preserving other providers' behavior.

Full review comments:

  • [P2] Import withinTest through the public SDK testing surface — extensions/crabbox/src/crabbox-worker-stop.test.ts:2
    The new relative import reaches outside the Crabbox package into repository test helpers. This deterministically fails both the extension-import lint and test/extension-test-boundary.test.ts in exact-head CI. Import withinTest from openclaw/plugin-sdk/test-fixtures, which already exports it, instead.
    Confidence: 1
  • [P2] Migrate the placement fixture to reclaim's shutdown contract — src/gateway/worker-environments/placement-dispatch-test-harness.ts:440
    The new fixture reclaim only delegates to destroy, while production reclaim now owns session transport shutdown and the placement caller no longer calls stopTunnel afterward. Tests that override stopTunnel therefore never reach their cleanup hold or stop their real fixture tunnel. Exact-head CI reports five 'Move completed before cleanup hold' failures and the cancellation/reclaim authority case retaining a connected tunnel. Model shutdown inside the fixture reclaim and update the affected tests to distinguish shutdown, acceptance, and confirmation.
    Confidence: 1
  • [P2] Update classless lifecycle tests for the remaining cleanup budget — extensions/crabbox/src/crabbox-worker-command.ts:283-284
    Subtracting performance.now() before the first stop changes its timeout from exactly 1005000 ms to a slightly smaller remaining allowance. Both existing classless lifecycle cases in extensions/crabbox/index.test.ts:166 still require exact equality and fail in exact-head CI. Update those tests to check the bounded shared-budget contract or use a controlled clock; preserve the production deadline calculation.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Optional warm-image teardown capture changes intended behavior with a stated reason (1b07457: Avoid a measured 880-second reclaim wait after capture admission while preserving synchronous failure propagation for other paths.)
  • Physical teardown and local fencing keeps the original intent (8c6653a: Retain exact worker ownership and local fencing until provider teardown proves destruction.)
  • Monotonic Crabbox cleanup deadline keeps the original intent (9a7d4d1: Prevent wall-clock rewind from extending lease cleanup beyond its configured budget.)
  • Placement cleanup completion changes intended behavior with a stated reason (140d9e7: Repository workspace reconciliation and teardown drain physical operations before releasing placement ownership.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm lint:plugins:no-extension-test-core-imports
  • pnpm test test/extension-test-boundary.test.ts extensions/crabbox/src/crabbox-worker-stop.test.ts extensions/crabbox/index.test.ts --maxWorkers=1
  • pnpm test src/gateway/server-worker-placement-reclaim.preparation.test.ts src/gateway/worker-environments/placement-dispatch-authority.test.ts src/gateway/worker-environments/placement-dispatch-reclaim.test.ts src/gateway/worker-environments/placement-reclaim-acceptance.test.ts --maxWorkers=1
  • pnpm check:test-types
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c753bbd adds extensions/crabbox/src/crabbox-worker-provider.ts:256 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c753bbd1ced5; files: extensions/crabbox/src/crabbox-worker-provider.ts)

PR surface

Source +121, Tests +309, Docs +6. Total +436 across 25 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 10 207 86 +121
Tests 12 372 63 +309
Docs 3 7 1 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 25 586 150 +436

Labels

Label changes:

  • add P2: This improves cloud-worker Stop latency without changing physical billing duration; the identified repairs are focused test regressions.
  • add merge-risk: 🚨 compatibility: The public WorkerProvider contract gains an optional acceptance capability and callback; maintainer-authored direction accepts the handoff, and providers without it retain blocking behavior.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This improves cloud-worker Stop latency without changing physical billing duration; the identified repairs are focused test regressions.
  • merge-risk: 🚨 compatibility: The public WorkerProvider contract gains an optional acceptance capability and callback; maintainer-authored direction accepts the handoff, and providers without it retain blocking behavior.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed October 23, 2026, 11:16 PM ET / October 24, 2026, 03:16 UTC.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dcbce620e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +320 to +323
!acceptCleanup ||
!(error instanceof WorkerTunnelOwnerDisconnectedError) ||
r.nodeDeviceId === null ||
r.sharedHost !== false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fall back to blocking destruction when computer cleanup fails

For a dedicated Crabbox worker whose computer driver rejects cleanup or exceeds its 60-second cleanup deadline, reclaim now calls stopOwner without a teardown reason. createWorkerEnvironmentTransportLifecycle.closeComputers therefore propagates that ordinary error, but this fallback only accepts WorkerTunnelOwnerDisconnectedError. Stop consequently fails before calling the provider's destroy operation, leaving the machine billable until reconciliation retries. Previously, the provider-destroying path explicitly tolerated this failure for dedicated machines; the existing provider-node-teardown.test.ts cases for a driver that never settles protect that behavior, but do not exercise acceptance-enabled reclaim. Disable early acceptance and retain blocking physical destruction for this cleanup failure too, while preserving strict acknowledgement requirements for shared hosts.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit a23ba6f into main Oct 24, 2026
159 of 164 checks passed
@steipete
steipete deleted the steipete/cs-fastreclaim-1023b branch October 24, 2026 03:59
@steipete

Copy link
Copy Markdown
Contributor Author

Landing note for head dcbce620e599: the only failing check is checks-node-compact-small-3-2, where test/vitest-projects-config.test.ts ("covers each normal full-suite test file exactly once") reports scripts/control-ui-retention/dependency-retention.test.ts as not owned by any Vitest project. This PR does not touch that file; the same failure appears on other PRs based on current main, so it is inherited. The earlier failures on afa45c965d0 were this PR's and are fixed in dcbce620e59 (test/fixture repairs only: production logic, which awaits session shutdown before cleanup acceptance at provider-owner-lifecycle.ts, is unchanged and Codex autoreview was clean). All other required checks are green. Landing via the inherited-failure admin exception.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
Reclaim waited for full provider destruction (40-120 s live: Azure ~100-117 s, GCP ~66-77 s, AWS 4-58 s). The provider lifecycle now separates cleanup acceptance from release confirmation: providers that declare supportsCleanupAcceptance call the optional onCleanupAccepted after durable acceptance (Crabbox: stop --wait=false), reclaim completes once session shutdown (tunnel stop, credential revocation, stale-handle rejection) and acceptance are done, and the owner keeps the environment lock while a background waiting stop confirms physical release before marking it destroyed. Failures stay visible and retryable; providers without the capability, offline dedicated workers and shared hosts keep the blocking path; warm-image capture stays detached.
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

1 participant