Skip to content

fix(cloud-workers): Stop cannot release a dedicated worker whose computer driver is wedged - #168741

Closed
saftall wants to merge 1 commit into
openclaw:mainfrom
saftall:fix/166196-wedged-computer-teardown
Closed

saftall wants to merge 1 commit into
openclaw:mainfrom
saftall:fix/166196-wedged-computer-teardown

Conversation

@saftall

@saftall saftall commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #166196

What Problem This Solves

Fixes: Stop, idle reclaim, and environments.destroy { force: true } all fail and the paid machine keeps running when a dedicated cloud worker's attached computer-use driver can no longer release its session. Seen on native Windows after a UAC prompt stalled the agent; reproduced live on Linux below by keeping one turn's computer execution idle past the driver's 300 s idle TTL, after which every driver call, including the release, fails with authorization context expired / DriverError.Tool.

User Impact

User impact: a dedicated cloud worker whose computer driver is wedged is destroyed on Stop, reclaim, or force, instead of retrying for an hour and parking with "Run crabbox stop ". While its teardown is pending, environments.list reports stopping and no longer advertises a desktop that desktop.observe already refuses. Shared and unknown hosts keep today's behavior: their stop still waits for the computer session to be released.

Why This Change Was Made

Provider teardown already passes a reason (provider-destroying, then provider-destroyed) to the node tunnel for dedicated machines only, so a machine the provider is about to destroy does not need the worker's own stop acknowledgement. The attached-computer close joined that same teardown later without the reason, so one failed __close_execution rejected stopOwner before destroyLease on every attempt.

The computer owner now receives the same reason:

  • provider-destroying: closing still fences local input; a failed native release is logged instead of blocking the destroy, and the owner keeps custody so a failed provider destroy stays retryable.
  • provider-destroyed: the confirmed destruction releases those owners.
  • no reason (shared or unknown host): a failed release still fails the stop, as before.

The environment projection applies the existing desktop admission rule (destroyRequestedAtMs) to desktopAvailable, and the summary maps a pending teardown to the existing stopping status; recorded errors still report error. The desktop docs describe both.

Evidence

Live before/after with the shipped Stop flow: Crabbox on AWS (Linux desktop worker, profile class: small, dedicated), Gateway on a separate Linux host, model xai/grok-4.7. Same config and steps on both builds; only the checkout differs (main 4644b02 vs this patch at 9792aa67, which is patch-identical to the current head after the rebase below). Times are UTC; environment ids are replaced with <env>.

Trigger, no fault injection: one agent turn takes a computer screenshot of the attached desktop, runs exec sleep 115 three times, then takes another screenshot. The CUA driver session idles past its idle TTL (maxIdleTtlSeconds: 300n in extensions/cua-computer/src/driver-client.ts), so the second screenshot fails as in the issue, and the end-of-turn native release fails the same way:

[tools] computer failed: Error: COMPUTER_REFUSED_permission_denied: Permission denied: authorization context expired

(The same on @trycua/cua-driver 0.32.0 directly: after the idle TTL an action returns permission_denied: authorization context expired and endSession throws DriverError.Tool.)

Then Stop (environments.session.destroy) while an in-process client samples environments.list for 75 s, about 150 samples/s, printing only changes.

main 4644b02:

01:23:38.883 {"status":"available","desktop":true,"state":"ready"}      <- unchanged for all 11,661 samples
01:23:43.551 res ✗ environments.session.destroy 34ms errorCode=INVALID_REQUEST errorMessage=Attached computer cleanup failed
01:24:14.035 [worker-environments] Conversation environment cleanup will retry (worker:<env>): Attached computer cleanup failed | Session computer cleanup failed | Error: DriverError.Tool
01:25:14.070 [worker-environments] Conversation environment cleanup will retry (worker:<env>): Attached computer cleanup failed | Session computer cleanup failed | Error: DriverError.Tool
01:25:16.300 res ✗ environments.destroy {force: true} 27ms errorCode=UNAVAILABLE errorMessage=worker environment destruction failed
environments.list afterwards: {"status":"error","desktop":true,"state":"ready","error":"Worker result abandoned by forced operator teardown"}

The lease kept running until a manual crabbox stop.

This PR:

01:38:06.430 {"status":"available","desktop":true,"state":"ready"}
01:38:08.671 [worker-environments] Attached computer cleanup failed | Session computer cleanup failed | Error: DriverError.Tool; continuing provider teardown of the dedicated machine.
01:38:08.679 {"status":"stopping","desktop":false,"state":"ready"}
01:38:09.743 {"status":"stopping","desktop":false,"state":"destroying"}
01:38:09.749 res ✓ environments.session.destroy 1106ms
01:38:09.756 {"status":"unavailable","desktop":false,"state":"destroyed"}
environments.session.destroy -> {"stopped": true, "environment": {"status": "unavailable", "trust": "disposable", "worker": {"providerId": "crabbox", "state": "destroyed", "tunnelStatus": "stopped"}}}

EC2 reports the lease instance terminated at 01:38:09 (User initiated), from this Stop.

Regression tests through the real owners (computer service + transport owner with a deterministic native close failure; worker environment service + node tunnel manager):

  • computer-service.test.ts: strict without a reason, non-blocking and retained on provider-destroying, released on provider-destroyed.
  • provider-node-teardown.test.ts: a dedicated machine with a wedged attached computer reaches provider.destroy and destroyed; a shared host still rejects with Attached computer cleanup failed and never calls destroy; a pending dedicated teardown summarizes as stopping without desktop.
  • On main (4644b02) the three new behavior tests fail with the reported chain (Attached computer cleanup failed <- Session computer cleanup failed <- DriverError.Tool) and expected 'available' to be 'stopping'; the shared-host case passes on both.

Cost (local, Node 24.21, pnpm test <file> --maxWorkers=1): the new computer-service.test.ts case runs in about 0.07 s; the three new provider-node-teardown.test.ts cases take about 2.7-3.0 s each, in line with the file's existing cases that share its service fixture.

Checks: the pnpm check:changed plan for this diff (lanes core, coreTests, docs), run step by step: format, oxlint, tsgo:core, tsgo:core:test, import cycles, the SQLite worker, assertion-safety, mock-export and timeout ratchets, boundary and docs-config checks all pass.

Regression run (src/gateway/worker-environments, the computer tool, environments RPC, desktop, and the other summarizeWorkerEnvironment / desktopAvailable consumers): passing apart from the items below. One existing expectation changes on purpose: the environments.list fixture in environments.pool.test.ts has destroyRequestedAtMs set and now reports stopping instead of available. The Control UI already maps status: "stopping" (or destroyRequestedAtMs in details) to its releasing pool state.

Inherited on main 4644b02, reproduced without this diff and not changed here:

  • check:max-lines-ratchet step: OPENCLAW_* count 456 exceeds budget 455.
  • lint:tmp:tsgo-core-boundary: advisory ui-e2e: 722 test roots exceeds the advisory 720 limit.
  • Knip unused exports in files this diff does not touch (tools/solid-lint/index.mjs, update-command-post-activation-inspections.ts, sessions-channel-fixture.test-support.ts).
  • bootstrap.test.ts (npm archive bootstrap), workspace-sync-inventory.test.ts, placement-force-abandon.test.ts, local-workspace-template.test.ts, and the server.app-sdk-composed-resources.test.ts timeout.

worker-turn-execution.test.ts and live-chat.test.ts each failed once in a heavily loaded parallel run and pass when run alone (live-chat 3/3). destination-authority.e2e.test.ts and inference-authority.e2e.test.ts were not run locally: their E2E runtime build did not complete on this host.

Rebased onto main 3666e84 because the previous CI merge ref included #168635's lint and SDK-surface breakage (check-lint-core-2/-4 in src/plugin-state/plugin-state-observation-cache.ts and src/infra/sqlite-worker-plugin-comparison.test.ts, plugin-sdk-surface-report.test.ts), which main fixed in f9940dc. The patch is unchanged (same git patch-id); on the rebased tree computer-service.test.ts, provider-node-teardown.test.ts, and environments.pool.test.ts pass (22 tests).

Not changed here: the driver session expiring after 300 s idle inside one turn, after which later computer calls in that turn fail.

@clawsweeper

clawsweeper Bot commented Oct 10, 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: M labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR allows dedicated-worker destruction to proceed after a failed computer-session release and reports pending teardown as stopping without an available desktop.

Example: A dedicated AWS Linux desktop worker's CUA session expires after 300 seconds idle and release returns DriverError.Tool.

  • Before: Stop rejects with Attached computer cleanup failed, leaving the lease running and its desktop advertised as available.
  • After: Stop logs the release failure, reports stopping without a desktop, and completes confirmed provider destruction.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, useful repair with shipped Stop-flow evidence and meaningful owner-boundary regressions; no actionable findings remain.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied redacted logs exercise environments.session.destroy against a real dedicated Crabbox/AWS Linux desktop after native release fails from CUA idle expiry, showing stopping without desktop availability followed by confirmed destruction; GitHub patches verify the exercised repair matches this head and resolve the prior proof request.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users cannot stop a paid dedicated worker after computer-driver release fails, while clients continue advertising its desktop.
Reason: The patch restores the existing dedicated-machine destruction contract and corrects observable availability without adding product options or public APIs.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current teardown defect that leaves paid dedicated workers running, preserves shared-host cleanup guarantees, and supplies relevant live evidence. No actionable introduced defect was found; CI remains pending.

Priority: P1
Reviewed head: ba79978a36c18c5dd8e7e77fb91dcaec7b93cac3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway worker lifecycle receives Stop, reclaim, and destroy requests, joins transport cleanup, invokes the lease provider, and projects environment availability to clients.

flowchart TD
  A[Stop or reclaim] --> B[Worker lifecycle]
  B --> C[Transport cleanup]
  C --> D[Computer owner]
  B --> E[Provider destruction]
  E --> D
  B --> F[Environment projection]
  F --> G[Client status]
Loading

Technical review

Best possible solution:

Use the existing dedicated-machine teardown contract to restore working Stop while retaining cleanup custody until confirmed destruction.

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

Current-main source establishes the failing cleanup-before-destroy chain, and the contributor supplies live baseline reproduction using CUA idle expiry; this read-only review ran no target code.

Is this the best way to solve the issue?

Forwarding the existing provider teardown reason repairs the shared lifecycle boundary without weakening shared-host cleanup or treating an unconfirmed lease as released.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3f97b146a5aa.

Provenance checked

  • Attached-computer cleanup changes intended behavior with a stated reason (4d62efe: Conversation attachments retain native computer cleanup ownership until release succeeds.)
  • Desktop availability projection keeps the original intent (4d62efe: Usable attached environments expose their desktop capability; desktop admission already refuses requested destruction.)
  • Pending cleanup status and errors keeps the original intent (5790b12: Bounded cleanup retains unconfirmed leases and exposes recorded errors for terminal failures or pending destruction.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4d62efe adds src/gateway/worker-environments/computer-service.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4d62efeccf7e; files: src/gateway/worker-environments/computer-service.ts)

PR surface

Source +35, Tests +191, Docs +7. Total +233 across 10 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 52 17 +35
Tests 5 192 1 +191
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 251 18 +233

Review metrics

Metric Value Why it matters
Production versus test growth Production +52/-17; tests and test support +192/-1 The focused production growth forwards the existing teardown reason and corrects availability; tests independently cover custody retention, host isolation, and pending teardown.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166196
Summary: This PR supplies the dedicated-machine teardown repair for the linked report, which remains unresolved until the repair lands.

Members:

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The current defect prevents Stop and forced teardown from releasing an affected paid dedicated worker.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-10T23:56:46.249Z sha 9792aa67a7b2a2f4923b08cb5a5db361c8ae6a1d :: needs real behavior proof before merge. :: none

Reviewed October 10, 2026, 9:51 PM ET / October 11, 2026, 01:51 UTC (Revision 2).

…uter driver is wedged

Provider teardown passes provider-destroying/provider-destroyed to the node
tunnel for dedicated machines only, but the attached-computer close joined the
same teardown without the reason. One failed native release rejected stopOwner
before destroyLease, so idle reclaim, Stop, and force retried for an hour,
parked, and left the paid machine running.

The computer owner now receives that reason: provider-destroying logs a failed
release and keeps custody so a failed destroy stays retryable;
provider-destroyed releases the owners. Shared and unknown hosts still require
the release. A pending teardown also projects stopping without a desktop,
matching desktop admission.

Closes openclaw#166196
@saftall
saftall force-pushed the fix/166196-wedged-computer-teardown branch from 9792aa6 to ba79978 Compare October 11, 2026 01:44
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@saftall

saftall commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one: #175189 (merged 2026-10-17, fixes #166196) covers the same bug. Stop, idle reclaim and forced destruction no longer wait on a computer-driver cleanup that never settles, which is what this PR addressed for the dedicated-worker Stop path. Thanks for picking it up.

@saftall saftall closed this Oct 26, 2026
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: A wedged computer driver blocks every cloud-worker teardown (idle reclaim, Stop and force) while the summary still reports the desktop as usable

1 participant