Skip to content

feat(gateway): carry machine class through session moves - #125292

Merged
steipete merged 2 commits into
mainfrom
steipete/session-move-machine-class
Aug 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/session-move-machine-class

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

PR #125036 added sessions.move, and PR #124864 added per-dispatch machine selection for cloud worker profiles — but the two never met: a profile move target carried only profileId, so moving a session to a cloud profile always landed on the profile's configured default class. A session dispatched with a fast override, reclaimed, and moved back silently downgraded to standard, and there was no way to resize a running cloud session.

Live testing this surfaced a second, larger defect: chat.startup and chat.history built sessionInfo without the placement projection that sessions.list applies. Clients merge that row into the same store, so opening a chat erased a live worker placement and its move intent — the Runs on Cloud chip disappeared until a full page reload, making the move flow unreachable in normal use.

AI-assisted implementation; I reviewed the architecture, durable-intent persistence, recovery fencing, and live proof.

Why This Change Was Made

Profile move targets now accept an optional machineClass with exact new-session parity: validated in the protocol, persisted on the durable move intent as a bare nullable target_machine_class column (same-version additive via the canonical ensureColumn helper; reads stay no-create), CAS-matched by every exact-target completion/deletion statement, and replayed exactly by restart recovery — a recovered move dispatches the class the operator chose, never the profile default. The Control UI move dialog shows the machine picker under the selected profile, reusing the new-session menu components; choosing the default omits the override.

Moving a session to the profile it already runs on with a different class is the resize workflow: the normal drain → reconcile → dispatch lifecycle replaces the worker with one of the chosen size.

The placement fix applies the same projection at the chat.startup/chat.history producer, so every path that feeds the client store carries the recorded placement fact. The schema-ensure also gained a per-database-handle memo so the sessions read projection never runs DDL or PRAGMA per read.

User Impact

Operators moving a session to a cloud profile can pick the machine class in the move dialog (or pass machineClass in sessions.move), the choice survives Gateway restart mid-move, and resizing a cloud session is one move away. The placement chip no longer vanishes after opening a chat. No schema-version bump, no protocol version bump, no new config surface.

Evidence

Live proof — isolated dev Gateway (own OPENCLAW_STATE_DIR, port 19457), real Crabbox AWS worker profile, managed-worktree session:

  1. Dispatched on the profile default; turn ran on the worker: CLOUD-TURN-OK ip-172-31-47-53.
  2. Placement re-adopted across a full Gateway restart (same environment, still active).
  3. Opened Runs on Cloud → Move session…, selected Cloud · aws, then Fast, and submitted.
  4. Durable intent persisted the class mid-move: move:v1:DRBKfklX… | profile | aws | fast, placement draining, chip showing Moving session….
  5. Move completed provisioning → syncing → active; the new environment records machineClass = fast while the profile default stays standard, and the old environment is destroyed.
  6. Post-move turn ran on the new, larger machine with transcript continuity: MOVED-TURN-OK ip-172-31-45-32 64 (different host, 64 cores).

Machine picker under the selected profile:

Move dialog machine picker

Non-default class selected (default checkmark moves off Standard):

Fast selected

Session after the move, both turns in one transcript on two different machines:

After move

Automated: protocol schema (34), move schema/store (29 — persistence, exact-target join/conflict, invalid-row, restart recovery replaying the class), sessions dispatch (21), dispatch/recovery/reclaim (72), projection (31), Control UI move dialog unit + mocked-gateway E2E (13), plus a new chat.startup/chat.history placement regression that fails pre-fix. Typecheck lanes green (core, ui, core-test shards); Swift/Kotlin protocol generation checks; Kysely generated types verified; native schema-version guard unchanged (v9); assertion-safety ratchet green; oxfmt; git diff --check. Autoreview (Codex gpt-5.6-sol, high): clean, no actionable findings.

Production LOC: +141/−26 for the machine class (justified by durable class persistence + picker) plus a net-negative-shaped placement fix that reuses existing helpers; tests +236/−16 plus the new regression; docs updated (docs/gateway/cloud-workers.md, docs/web/control-ui.md).

Profile move targets accept an optional machineClass with new-session
parity: validated in the protocol, persisted on the durable move intent
(bare nullable column, lazy same-version ALTER), replayed exactly by
restart recovery, and selectable from the Control UI move dialog.
Moving to the current profile with a different class resizes the
session's worker.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 17, 2026
@steipete
steipete marked this pull request as ready for review August 17, 2026 14:11
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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 Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 17, 2026, 4:22 PM ET / 20:22 UTC.

ClawSweeper review

What this changes

The PR adds optional cloud-worker machine-class selection to session moves, persists it across recovery, adds a Control UI picker, and keeps placement data in chat responses.

Merge readiness

⛔ Blocked by patch quality or review findings - 5 items remain

Keep open: the prior P1 schema-compatibility blocker remains on the current head. An existing v9 database containing the previously shipped optional move table but not the new column is rejected during Gateway startup before the feature-local lazy migration can run.

Priority: P1
Reviewed head: d9d13cdbebeb00240f078103a8d6db48ea95d44d

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The reported real-flow evidence is strong, but the current patch has a startup-blocking upgrade defect.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body nevertheless records an isolated real Gateway and Crabbox move/restart run with visible before-and-after evidence.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body nevertheless records an isolated real Gateway and Crabbox move/restart run with visible before-and-after evidence.
Evidence reviewed 6 items Missing startup migration registration: The new canonical nullable column is not listed in the shared additive-column definitions, which are the sole source for startup-repairable missing-column classification.
Startup rejects the upgrade shape: Preflight compares an existing v9 database with the canonical schema and returns incompatible for issues that are neither startup-repairable nor first-use; Gateway bootstrap throws before opening the database for the feature-local ensure.
Feature-local ensure is too late: The PR adds target_machine_class to the canonical optional-table schema and ensures it only from placement-move operations, after Gateway startup preflight has already rejected the older table shape.
Findings 1 actionable finding [P1] Register the lazy column with startup compatibility
Security None None.

How this fits together

A Control UI session move becomes a Gateway request that records durable move intent, drains the source worker, and dispatches the destination. Chat responses project that durable placement state back into the client store so the move control remains available.

flowchart LR
  A[Control UI move dialog] --> B[Gateway move request]
  B --> C[Durable move intent]
  C --> D[Drain and recovery lifecycle]
  D --> E[Worker dispatch]
  E --> F[Placement projection]
  F --> G[Chat client store]
Loading

Before merge

  • Register the lazy column with startup compatibility (P1) - The added canonical column is absent from the shared additive-column registry. A v9 database that already has worker_session_placement_moves from feat(gateway): move sessions between Gateway and runners #125036 but lacks this column is classified as incompatible during startup preflight, before ensureWorkerPlacementMoveSchema can repair it; Gateway therefore refuses to start. Add the column to the startup additive definitions and cover that old-table preflight shape.
  • Resolve merge risk (P1) - Merging would make Gateway startup fail for an existing same-version database whose worker-session move table predates target_machine_class, preventing operator recovery until manual database intervention.
  • Complete next step (P2) - A concrete P1 repair is clear, but this protected maintainer PR should be updated and revalidated on its existing branch before merge.
  • Improve patch quality - Register target_machine_class with the shared startup additive-column owner.
  • Improve patch quality - Add an old move-table preflight regression and verify the subsequent writable open repairs it.

Findings

  • [P1] Register the lazy column with startup compatibility — src/state/openclaw-state-schema.sql:2270
Agent review details

Security

None.

PR surface

Source +119, Tests +274, Docs 0, Generated +1, Other +6. Total +400 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 8 145 26 +119
Tests 7 289 15 +274
Docs 2 3 3 0
Config 0 0 0 0
Generated 1 1 0 +1
Other 1 8 2 +6
Total 19 446 46 +400

Review metrics

Metric Value Why it matters
Production vs test LOC production +144/-25; tests/test support +290/-16; docs +3/-3; generated protocol +9/-2 The feature has substantial justified production growth, while the remaining blocker is a missing shared migration registration rather than insufficient UI or move-flow coverage.
Persistent schema surface 1 nullable column added to an existing optional table Same-version startup and upgrade behavior must accept and repair databases created before the column existed.

Stored data model

Persistent data-model change detected: database schema: src/gateway/worker-environments/placement-move-schema.test.ts, database schema: src/state/openclaw-state-schema.sql, durable storage schema: src/gateway/worker-environments/placement-move-intent.ts, durable storage schema: src/gateway/worker-environments/placement-move-schema.test.ts, durable storage schema: src/gateway/worker-environments/placement-store.move.test.ts, serialized state: packages/gateway-protocol/src/schema/session-placement.test.ts, and 9 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #125292
Summary: This PR is the canonical remaining implementation for carrying machine selection through the previously merged move flow; its two predecessors establish adjacent parts of the same operator workflow.

Members:

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

Merge-risk options

Maintainer options:

  1. Repair the startup upgrade path (recommended)
    Add the nullable move column to the shared startup additive-column registry and prove an existing v9 move table opens and repairs without a schema-version bump.

Technical review

Best possible solution:

Register target_machine_class as a startup additive column and add a preflight regression that starts from the old move-table shape, reports startup-repairable, then verifies the writable open adds the column.

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

Yes—source establishes a focused current-head path: retain the v9 move table from the already-merged move feature without target_machine_class, then start Gateway; preflight rejects it before the feature-local ensure can run. The read-only review environment did not run that test.

Is this the best way to solve the issue?

No—the feature-local ensure is appropriate after startup, but it cannot repair an existing table that startup preflight refuses first; the shared startup additive-column owner is the required repair location.

Full review comments:

  • [P1] Register the lazy column with startup compatibility — src/state/openclaw-state-schema.sql:2270
    The added canonical column is absent from the shared additive-column registry. A v9 database that already has worker_session_placement_moves from feat(gateway): move sessions between Gateway and runners #125036 but lacks this column is classified as incompatible during startup preflight, before ensureWorkerPlacementMoveSchema can repair it; Gateway therefore refuses to start. Add the column to the startup additive definitions and cover that old-table preflight shape.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 248966d30081.

Labels

Label justifications:

  • P1: The missing upgrade registration can reject Gateway startup for existing databases using session moves.
  • merge-risk: 🚨 compatibility: A same-version database created before this column exists is not accepted by the new canonical schema preflight.
  • merge-risk: 🚨 availability: The incompatibility is detected before Gateway startup can reach the lazy repair path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body nevertheless records an isolated real Gateway and Crabbox move/restart run with visible before-and-after evidence.

Evidence

What I checked:

  • Missing startup migration registration: The new canonical nullable column is not listed in the shared additive-column definitions, which are the sole source for startup-repairable missing-column classification. (src/state/openclaw-state-db-additive-columns.ts:10, d9d13cdbebeb)
  • Startup rejects the upgrade shape: Preflight compares an existing v9 database with the canonical schema and returns incompatible for issues that are neither startup-repairable nor first-use; Gateway bootstrap throws before opening the database for the feature-local ensure. (src/state/openclaw-database-preflight.ts:265, d9d13cdbebeb)
  • Feature-local ensure is too late: The PR adds target_machine_class to the canonical optional-table schema and ensures it only from placement-move operations, after Gateway startup preflight has already rejected the older table shape. (src/gateway/worker-environments/placement-move-intent.ts:68, d9d13cdbebeb)
  • Existing tests cover the analogous contract but not this column: The preflight suite proves a different same-version missing column is startup-repairable; the PR's move-schema test mutates the table only after a fresh candidate database has already opened, so it cannot cover startup preflight of the old move table. (src/state/openclaw-database-preflight.test.ts:181, d9d13cdbebeb)
  • Current-main and ownership provenance: Current main does not contain this PR head; blame attributes the compatibility and preflight paths on the current head author, who also authored the merged session-move and machine-selection foundations. (src/state/openclaw-state-schema-compatibility.ts:31, d9d13cdbebeb)
  • Docs inventory check blocked by read-only infrastructure: Direct source docs were reviewed, but the required docs inventory command could not run because Corepack attempted to create its cache in the read-only filesystem.

Likely related people:

  • steipete: Authored the current head and the two merged foundations for cloud machine selection and session moves. (role: feature author and recent area contributor; confidence: high; commits: d9d13cdbebeb, 78beccf05397, f59e945013db; files: src/state/openclaw-state-db-additive-columns.ts, src/state/openclaw-database-preflight.ts, src/gateway/worker-environments/placement-move-intent.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-17T14:26:12.679Z sha 50024a0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-17T14:54:59.136Z sha 50024a0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-17T20:03:04.992Z sha d9d13cd :: needs changes before merge. :: [P1] Register the lazy column with state-schema compatibility

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 17, 2026
chat.startup and chat.history built sessionInfo without the placement
projection sessions.list applies, so clients merging that row erased a
live worker placement and its move intent — the Runs on Cloud chip
disappeared after any turn until a full reload.

Reuse the canonical ensureColumn helper for the move table's additive
column instead of a hand-rolled PRAGMA read.
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 17, 2026
@steipete
steipete merged commit 57e8629 into main Aug 17, 2026
240 checks passed
@steipete
steipete deleted the steipete/session-move-machine-class branch August 17, 2026 21:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
…5292)

* feat(gateway): carry machine class through session moves

Profile move targets accept an optional machineClass with new-session
parity: validated in the protocol, persisted on the durable move intent
(bare nullable column, lazy same-version ALTER), replayed exactly by
restart recovery, and selectable from the Control UI move dialog.
Moving to the current profile with a different class resizes the
session's worker.

* fix(gateway): project placement facts on chat startup

chat.startup and chat.history built sessionInfo without the placement
projection sessions.list applies, so clients merging that row erased a
live worker placement and its move intent — the Runs on Cloud chip
disappeared after any turn until a full reload.

Reuse the canonical ensureColumn helper for the move table's additive
column instead of a hand-rolled PRAGMA read.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. size: M 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