Repository navigation
feat: run and reclaim cloud worker sessions from Control UI - #108398
Conversation
4ccf167 to
d573f74
Compare
There was a problem hiding this comment.
💡 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".
| const destroyed = params.force | ||
| ? await placementService!.forceDestroyEnvironment!(params.environmentId) | ||
| : await service.destroyUnattached(params.environmentId); |
There was a problem hiding this comment.
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 👍 / 👎.
7b8a9f4 to
e134125
Compare
There was a problem hiding this comment.
💡 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 } : {}), | |||
There was a problem hiding this comment.
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 👍 / 👎.
3d86167 to
b8f1de0
Compare
There was a problem hiding this comment.
💡 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".
| const admissionProvider = createWorkerSessionTurnPlacementProvider({ | ||
| environments: params.environments, | ||
| placements: params.placements, | ||
| admitNewPlacements: params.admitNewPlacements, | ||
| workspaceOperations, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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()); |
There was a problem hiding this comment.
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 👍 / 👎.
|
Merged via squash.
|
…#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
…#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
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
sessions.reclaimrequest all passed on the pushed head.621e566c796a2f48965240b8058d1d5d07cf7762.openai/gpt-5.6-solturn ran on Crabbox, reconciled tracked edits, a tracked deletion, a new untracked file, executable mode0700, and a symlink back to the managed worktree. A raw environment destroy was correctly rejected while attached.sessions.reclaimRPC used by the Control UI. Placement reachedreclaimed; leasecbx_678492634316reacheddestroyed; attached sessions became empty; tunnel reachedstopped.Control UI Proof
Cloud worker target selection and managed-worktree settings:
Active cloud worker state and reclaim action: