Skip to content

feat: run and reclaim cloud worker sessions from Control UI - #108398

Merged
steipete merged 14 commits into
mainfrom
codex/control-ui-stop-cloud-worker
Jul 15, 2026
Merged

steipete merged 14 commits into
mainfrom
codex/control-ui-stop-cloud-worker

Conversation

@steipete

@steipete steipete commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users could dispatch a session to a cloud worker but could not safely reclaim it from the Control UI, preserve all workspace changes, or recover a completed result after a gateway restart.

Fixes #107962. Fixes #107964.

Why This Change Was Made

This adds the complete session placement lifecycle: durable workspace-result fencing, crash-safe SQLite journals, deterministic local reconciliation, coordinated forced teardown, and Control UI stop/reclaim actions. Cloud workers remain restricted to the supported Codex runtime and one attached session.

User Impact

Users can choose a configured cloud worker from the Sessions UI, run the session remotely, see its worker state, and stop it back to the local gateway without losing tracked, untracked, deleted, executable, binary, or symlink changes.

Evidence

  • Rebased HEAD: 487 changed tests passed across gateway, gateway-client, and Control UI shards.
  • Remote changed gate: AWS Crabbox run, exit 0.
  • Production build: AWS Crabbox run, exit 0; Control UI startup and asset budgets passed.
  • Browser E2E: cloud target selection, dispatch retry, active placement rendering, and the confirmed sessions.reclaim request all passed on the pushed head.
  • Autoreview: clean, no accepted/actionable findings.
  • Exact-head GitHub CI: 123 checks completed without failure on 621e566c796a2f48965240b8058d1d5d07cf7762.
  • Live ClawMac AWS end-to-end: a real openai/gpt-5.6-sol turn ran on Crabbox, reconciled tracked edits, a tracked deletion, a new untracked file, executable mode 0700, and a symlink back to the managed worktree. A raw environment destroy was correctly rejected while attached.
  • Live Stop proof: a second active AWS session was stopped through the same sessions.reclaim RPC used by the Control UI. Placement reached reclaimed; lease cbx_678492634316 reached destroyed; attached sessions became empty; tunnel reached stopped.
  • Restart recovery: a concurrent ClawMac gateway update reclaimed and destroyed the first worker without leaking a lease. All test sessions, worktrees, and fixture repositories were removed afterward.

Control UI Proof

Cloud worker target selection and managed-worktree settings:

Cloud worker target selection

Active cloud worker state and reclaim action:

Active cloud worker stop action

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Jul 15, 2026
@steipete
steipete marked this pull request as ready for review July 15, 2026 17:06
@steipete
steipete force-pushed the codex/control-ui-stop-cloud-worker branch from 4ccf167 to d573f74 Compare July 15, 2026 17:07

@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: 4ccf1679f5

ℹ️ 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 +215 to +217
const destroyed = params.force
? await placementService!.forceDestroyEnvironment!(params.environmentId)
: await service.destroyUnattached(params.environmentId);

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 Preserve forced cleanup for active draft workers

When a new cloud session is cancelled after sessions.dispatch has reached an active placement, ui/src/pages/new-session/cloud-target.ts still cleans up by calling environments.destroy with only { environmentId }. This new default routes that request to destroyUnattached(), which rejects attached workers, so normal cancel/recovery paths after dispatch now return cleanup errors and leave the cloud worker/session placement running instead of tearing it down. Please keep the non-force path compatible for those existing cleanup callers or update them to use the new force/session reclaim path before requiring unattached workers here.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added the app: android App: android label Jul 15, 2026
@steipete
steipete force-pushed the codex/control-ui-stop-cloud-worker branch from 7b8a9f4 to e134125 Compare July 15, 2026 17:26

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

ℹ️ 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".

@@ -1316,6 +1326,7 @@ export function createWorkerEnvironmentService(options: WorkerEnvironmentService
options.placementStore?.updateAckCursors({
...placement,
liveSeq: result.result.ackedSeq,
...(isTerminalLiveEvent(request) ? { workspaceResultPending: true } : {}),

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 Persist terminal workspace fence before live-event side effects

When a terminal worker live event is processed, the durable workspaceResultPending fence is only written after liveEvents.apply(...) has already accepted/emitted the event. If the Gateway process crashes in that small window, restart recovery sees an active worker turn claim with no pending workspace result and adoptActive() fences/tears down the placement, so the completed remote workspace can be destroyed instead of reconciled. Please make the terminal workspace-result fence durable before any terminal live-event side effects can be observed, or teach restart recovery to reconcile this pre-fence terminal window.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the codex/control-ui-stop-cloud-worker branch from 3d86167 to b8f1de0 Compare July 15, 2026 17:41

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

ℹ️ 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 458 to +462
const admissionProvider = createWorkerSessionTurnPlacementProvider({
environments: params.environments,
placements: params.placements,
admitNewPlacements: params.admitNewPlacements,
workspaceOperations,

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 Wire reclaimed placements back into turn admission

When a Control UI user uses the new Stop cloud worker action, sessions.reclaim persists the session as reclaimed, but this startup wiring still creates the turn placement provider without a redispatchReclaimed hook. The turn launcher’s reclaimed branch only proceeds when that hook is supplied and otherwise throws Reclaimed worker placement requires redispatch, so any later message in the stopped session fails instead of redispatching or returning to local execution; pass a redispatch callback here (or transition reclaimed sessions back to local) before exposing the stop action as a normal session menu operation.

Useful? React with 👍 / 👎.

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

ℹ️ 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".

) {
throw new Error(`Cannot finish stale worker reclaim for session ${sessionId}`);
}
return updateTransition(db, current, "reclaimed", {}, now());

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 Let reclaimed sessions archive after stopping workers

When the new stop flow reaches this transition, the session remains in reclaimed. The Control UI still enables Archive/Restore based only on canArchiveSessionRow, but sessions.patch calls resolveSessionWorkerPlacementPatchError, which rejects any archived patch unless the placement is local; so after successfully stopping an idle cloud worker, choosing Archive or Restore from the same session menu fails with INVALID_REQUEST instead of retiring the now-stopped session. Either make reclaimed follow the local patch policy or hide/replace those menu actions for reclaimed rows.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 126b549 into main Jul 15, 2026
123 checks passed
@steipete
steipete deleted the codex/control-ui-stop-cloud-worker branch July 15, 2026 18:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 16, 2026
…#108398)

* feat(gateway): finish cloud worker session reclaim

* chore(gateway): refresh cloud worker artifacts

* fix(gateway): preserve recovery environment narrowing

* test(gateway): complete worker tunnel mock

* fix(gateway): harden cloud worker recovery

* fix(gateway): serialize forced worker teardown

* fix(gateway): handle replaced workspace directories

* fix(gateway): preserve forced destroy receiver

* test(ui): cover cloud worker reclaim flow

* fix(gateway): close final worker recovery races

* fix(ci): align cloud worker generated surfaces

* test(gateway): satisfy worker queue lint

* fix(gateway): recheck remote workspace after lease fence

* chore: move cloud worker release note to PR
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…#108398)

* feat(gateway): finish cloud worker session reclaim

* chore(gateway): refresh cloud worker artifacts

* fix(gateway): preserve recovery environment narrowing

* test(gateway): complete worker tunnel mock

* fix(gateway): harden cloud worker recovery

* fix(gateway): serialize forced worker teardown

* fix(gateway): handle replaced workspace directories

* fix(gateway): preserve forced destroy receiver

* test(ui): cover cloud worker reclaim flow

* fix(gateway): close final worker recovery races

* fix(ci): align cloud worker generated surfaces

* test(gateway): satisfy worker queue lint

* fix(gateway): recheck remote workspace after lease fence

* chore: move cloud worker release note to PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud worker worktree results are discarded on teardown Control UI cannot stop an active cloud worker

1 participant