Skip to content

fix(workers): stop cloud workers when computer cleanup hangs - #175189

Merged
steipete merged 4 commits into
mainfrom
steipete/cs-166196-1017
Oct 17, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/cs-166196-1017

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #166196

What Problem This Solves

Fixes cloud-worker Stop, idle reclaim, and forced destruction remaining blocked indefinitely when optional computer-driver cleanup never settles.

User Impact

Dedicated cloud machines can reach provider teardown after a wedged desktop cleanup. Each cleanup phase has a one-minute deadline, and failures log guidance to check the provider lease and retry Stop if it remains running. Shared or unknown hosts still require their worker's stop acknowledgement.

Why This Change Was Made

Environment teardown joined computer cleanup without a deadline before calling the provider. Bound the entire cleanup callback, including pending preparation, in-flight actions, and native close replies. The budget allows two normal 30-second node-command windows. Only dedicated-machine teardown tolerates computer cleanup failure; other transport errors continue to propagate. A stop reason alone never permits this bypass: the transport reads the stored environment and also requires nodeDeviceId !== null && sharedHost === false.

The simplification pass retained the existing transport owner and timeout helper: 31 net production lines and 108 test/fixture lines were added.

Evidence

  • Verified on main at 15a39da700dab0966debe2c033b4020e44fba1df: the new normal/forced teardown regressions failed because provider destruction was never invoked; the 12 existing cases passed. Wall time: 343.75s.
  • Follow-up regression against d530ceaba28: the two new shared/unknown-host boundary cases failed because cleanup resolved after the timeout instead of rejecting; the other 14 tests passed. Wall time: 244.39s.
  • pnpm test src/gateway/worker-environments/provider-node-teardown.test.ts --maxWorkers=1: 16 passed, wall time 272.24s, including compiled-worker preparation and cleanup. Shared (true) and unknown (null) hosts reject a never-settling driver cleanup after 60 seconds even when directly supplied a provider teardown reason, and do not log that teardown will continue. Dedicated normal/forced destruction and the existing host-isolation cases remain covered. Fake timers; no real sleeps.
  • pnpm exec oxfmt --check on all four changed files: passed.
  • Type-aware lint: node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/gateway/worker-environments/environment-access.ts src/gateway/worker-environments/provider-node-teardown.test.ts: passed (follow-up changed files; the unchanged fixture retained its prior passing check).
  • git diff --check: passed.
  • Independent Codex review through the repository autoreview workflow: initial change and follow-up both scoped clean through P2.
  • pnpm run tsgo:core was attempted but could not start TypeScript checking: the declaration wrapper rejects dependencies symlinked from another checkout (0.91s). Tests and lint used prepared dependencies with an identical lockfile. Full core typecheck and broad proof remain for PR CI; CI timing is pending.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T06:17:52.157719Z d0672cb 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 size: S labels Oct 17, 2026

@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: d530ceaba2

ℹ️ 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 +68 to +72
await withTimeout(
options.closeEnvironmentComputers(environmentId, ownerEpoch),
COMPUTER_CLEANUP_TIMEOUT_MS,
"Worker computer cleanup",
);

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.

P1 Badge Release timed-out computer owners before returning

When a computer driver truly never settles, withTimeout only stops awaiting closeEnvironmentComputers; it neither cancels that promise nor removes its owner. The unresolved owner remains in computer-service.ts's attachedOwners, so a later Gateway shutdown calls computers.close(), rejoins the same permanently pending PreparedWorkerComputer.close() promise, and blocks service.stop() before tunnel teardown. Thus Stop can now return, but the next restart or update still hangs for the exact failure mode this change handles; the timeout path must also detach/fence the abandoned computer owner or make shutdown bound that retained promise.

AGENTS.md reference: AGENTS.md:L83-L83

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR bounds computer cleanup to one minute per teardown phase and lets dedicated cloud-machine destruction continue after cleanup fails.

Example: Stop a dedicated cloud worker whose computer driver never finishes closing.

  • Before: Computer cleanup prevents provider destruction indefinitely.
  • After: Provider destruction proceeds after 60 seconds, and final cleanup receives another 60-second budget.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful focused recovery with reported baseline failures and passing harness tests, but retained computer custody leaves shutdown incomplete.
Proof confidence 🦐 gold shrimp (3/6) The supplied evidence exercises the real teardown service with deferred cleanup and mocked transport/provider boundaries; this maintainer-authored PR is outside the ordinary contributor runtime-proof gate.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A wedged computer driver prevents Stop, idle reclaim, and forced destruction from releasing a dedicated cloud machine.
Reason: The maintainer-authored direction addresses a reported operational failure without adding configuration; the linked report's desktop-availability problem remains outside this patch, so use Related rather than a closing reference.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it addresses a real teardown failure, but its timeout leaves a retained computer owner that can still block subsequent Gateway shutdown.

Priority: P1
Reviewed head: 6617fbad08a29a94e42b39424e969aaad5ba4390

Before merge

  • Release timed-out computer custody after dedicated teardown (P1) - When an attached computer close never settles, this timeout stops awaiting it but leaves its owner in computer-service.ts's attachedOwners map. Provider destruction and the second cleanup timeout can now finish successfully, yet computers.close() later rejoins that same permanently pending PreparedWorkerComputer.close() promise. service.stop() awaits it before inference and tunnel teardown, so the next Gateway restart or update remains blocked by the exact failure this PR handles. Complete recovery at the computer owner, safely retiring custody after confirmed dedicated-machine destruction or otherwise bounding its shutdown join, and cover Stop followed by shutdown without resolving the stalled driver.

Findings

  • [P1] Release timed-out computer custody after dedicated teardown — src/gateway/worker-environments/environment-access.ts:69-73

Tests

  • Missing end-to-end proof: The supplied regressions exercise service teardown with a deferred cleanup callback, but do not cover subsequent shutdown through the retained production computer owner.
Agent review details

How this fits together

The Gateway worker lifecycle joins computer and transport cleanup before destroying a provider lease; the computer service separately retains prepared owners for environment cleanup and Gateway shutdown.

flowchart TD
  A[Stop or idle reclaim] --> B[Worker lifecycle]
  B --> C[Transport cleanup]
  C --> D[Computer owner]
  C --> E[Provider destruction]
  D --> F[Retained close promise]
  G[Gateway shutdown] --> F
Loading

Technical review

Best possible solution:

Complete timeout recovery in the computer owner so confirmed dedicated-machine destruction cannot leave Gateway shutdown waiting forever.

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

Source establishes the failure path: retain an attached computer with a never-settling close, finish dedicated-machine destruction through the new timeout, then call service.stop; no runtime reproduction was executed during this review.

Is this the best way to solve the issue?

Bounding optional cleanup while preserving dedicated-host checks is useful, but the recovery must also settle the computer owner's shutdown responsibility.

Full review comments:

  • [P1] Release timed-out computer custody after dedicated teardown — src/gateway/worker-environments/environment-access.ts:69-73
    When an attached computer close never settles, this timeout stops awaiting it but leaves its owner in computer-service.ts's attachedOwners map. Provider destruction and the second cleanup timeout can now finish successfully, yet computers.close() later rejoins that same permanently pending PreparedWorkerComputer.close() promise. service.stop() awaits it before inference and tunnel teardown, so the next Gateway restart or update remains blocked by the exact failure this PR handles. Complete recovery at the computer owner, safely retiring custody after confirmed dedicated-machine destruction or otherwise bounding its shutdown join, and cover Stop followed by shutdown without resolving the stalled driver.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1062d2b530eb.

Provenance checked

  • Computer cleanup joined before lease teardown changes intended behavior with a stated reason (4d62efe: Attached applications and computer resources remain owned until confirmed cleanup; the earlier service split preserved shared serialization and shutdown draining.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/worker-environments/provider-node-teardown.test.ts src/gateway/worker-environments/computer-transport.shutdown.test.ts --maxWorkers=1
  • pnpm run tsgo:core
  • git diff --check

What I checked:

PR surface

Source +31, Tests +108, Docs +2. Total +141 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 32 1 +31
Tests 2 108 0 +108
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 142 1 +141

Labels

Label changes:

  • add P1: A reported cloud-worker failure prevents releasing paid machines, and the incomplete recovery can leave subsequent Gateway shutdown blocked.
  • add merge-risk: 🚨 availability: The new successful teardown path retains a permanently pending computer close that Gateway shutdown later awaits.
  • 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:

  • P1: A reported cloud-worker failure prevents releasing paid machines, and the incomplete recovery can leave subsequent Gateway shutdown blocked.
  • merge-risk: 🚨 availability: The new successful teardown path retains a permanently pending computer close that Gateway shutdown later awaits.
  • 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 17, 2026, 2:09 AM ET / 06:09 UTC.

@steipete
steipete merged commit 8457e29 into main Oct 17, 2026
127 checks passed
@steipete
steipete deleted the steipete/cs-166196-1017 branch October 17, 2026 06:25
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
A wedged computer (desktop) driver blocked every teardown of its cloud worker, including idle reclaim, Stop and force, because transport teardown awaited driver cleanup without a bound. Each computer cleanup phase now gets 60 s. On a provider-owned dedicated machine (sharedHost false with a node device) a failure or timeout logs a warning with recovery guidance and provider teardown continues; shared or unknown hosts still require cleanup acknowledgement and fail after the bound.

Fixes openclaw#166196
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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.

[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