Skip to content

feat(gateway): ready workers for empty-workspace cloud sessions - #170929

Merged
steipete merged 4 commits into
mainfrom
steipete/empty-workspace-reserves
Oct 13, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/empty-workspace-reserves

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

New cloud sessions created with an empty workspace never get a ready worker. Every one of them provisions a machine, which takes about 70–90 s on AWS even with a warm image. Project and repository sessions already skip provisioning by claiming a prepared reserve.

User Impact

User impact: after one empty-workspace cloud session activates, the next one claims an already-enrolled ready worker instead of provisioning. Reserves follow the existing readyWorkers and preparedPool.maxTotal limits, and setting either to 0 disables them. The first empty session stays cold, and project and repository sessions are unchanged. Ready workers are running machines, so they incur the usual charges.

Why This Change Was Made

Since #168371, an empty committed tree yields no project snapshot, so empty sessions had no preparation identity and the pool could never key a reserve for them. This adds a runtime-only identity (profileSnapshot.runtimePreparation, source: "empty") and reuses the existing pool owner for demand, claim, refill, expiry and cleanup.

Identity. It is keyed by:

  • Gateway namespace
  • provider and profile
  • effective settings and target
  • execution mode
  • exact runtime artifacts

It contains no session path, owner or Git metadata, commit, or setup recipe. Its cache key and preparation key fence claims the same way project identities do.

Separation. Project checkout, prepared-workspace registration and the node tunnel's preparation key stay project-only. A project session cannot claim an empty reserve, or the reverse.

After a claim. The ordinary attach installs a fresh session credential, and workspace sync delivers the session's own empty repository. Reserves hold no session data.

No schema, protocol, or config changes. Production change: +150/−90.

Evidence

  • New prepared-pool-empty-workspace.test.ts, plus updated identity, pool, dispatch and retention tests.
  • 21 owning test files, 168 tests pass.
  • The three new regression cases fail on main (zero reserves) and pass here.
  • An authenticated empty-Git workspace transfer passes against the real transport.
  • Core and test typecheck, lint and format pass.
  • Two Codex autoreviews are clean, one at P0 and one at P1. The P1 review checked project/empty separation, capacity, drain, retention and refill.
  • Follow-up commit fix(gateway): report skipped prepared worker refills: the pool logs one concise line when it skips or defers a refill, including the effective limits (for example Prepared worker refill skipped (aws, worker:…): profile removed or capacity disabled (readyWorkers=0, maxTotal=1)). It also adds a test through production wiring: activate, reclaim during retention, the reserve is created, the next session claims it without provisioning, then refill.
  • Live AWS proof on a dev Gateway built from this branch, with readyWorkers: 1 and preparedPool.maxTotal: 1:
    • The first empty session activated (cold, 183 s, because of a fresh runtime).
    • The pool had an empty reserve provisioning within a minute and ready about a minute later.
    • The next empty session claimed it and went active in 3.1 s, with its turn passing, where a warm provision takes 70–100 s.
    • The consumed reserve was destroyed and a replacement refill started immediately.
    • An earlier attempt with the rig's maxTotal: 0 correctly prepared nothing, and the new log line made the reason visible.

Admit empty committed Git trees with a runtime-only preparation identity so
successful activation can fill the existing prepared pool for later empty
sessions. Keep the first session cold and honor existing ready-worker limits.

Preserve project-only checkout, workspace registration, and tunnel preparation
keys. Reuse ordinary session synchronization, atomic claims, demand retention,
expiry, and cleanup without new schema or protocol state.

Validate empty activation/refill, project isolation, disabled limits, and
persisted runtime artifacts. The owning suites pass 168 tests, and all three
empty-workspace regressions fail on the original sources and pass after repair.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T21:06:52.488580Z ad19ef4 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: L labels Oct 13, 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: 15c56e8a71

ℹ️ 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 +193 to 194
createOptions.emptyWorkspace) &&
provider.supportsProjectPreparation?.(profile, machineClass, os)

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 Disclose empty-workspace reserves in settings help

When a profile keeps the default readyWorkers: 1, activating an empty committed workspace now starts a billable reserve, but the Settings schema still describes this field as targeting workers “per eligible project” and describes the pool as following project demand (src/config/zod-schema.cloud-workers.ts:39-41,83-91). Because that metadata supplies the primary configuration help, operators can enable this new cost-incurring behavior without the empty-workspace trigger being disclosed; update both help strings alongside the new admission path.

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

Useful? React with 👍 / 👎.

Report disabled capacity and rejected retention or refill identities with the
profile and source environment. Suppress unchanged source diagnostics across
consecutive passes, resetting after recovery.

Cover activation, reclaim during retention, scheduled empty reserve creation,
subsequent claim, and replacement through the real placement and environment
services. Keep capacity, authorization, and cleanup policy unchanged.

Validation: 46 tests across five affected files; 25 affected tests rerun after
the diagnostic suppression change. Core and scoped test typechecks, focused
lint/format, and independent review passed.

@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: 8cfd947da7

ℹ️ 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 +333 to +334
if (preparation && lease.sharedHost !== false) {
throw new Error("Prepared worker requires a dedicated environment");

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 Gate empty reserves behind an advertised provider contract

For a third-party node provider that supports project preparation but omits sharedHost for ordinary dedicated leases, every empty committed workspace now fails after provisioning here: the new runtime preparation sets preparation, but core supplies no options.project.preparation, so the provider has no documented signal that an explicit sharedHost: false is required. The SDK documentation explicitly permits omission for ordinary leases and previously requires the explicit value only for prepared-workspace registration; either advertise the runtime-only preparation through the provider contract or opt existing providers out of empty reserves until they declare support.

AGENTS.md reference: AGENTS.md:L63-L63

Useful? React with 👍 / 👎.

Preserve main's v2 disk compatibility and repository environment recipes
while retaining the empty-workspace runtime identity and activation-driven
reserve flow. Keep project recipe execution and prepared-workspace binding
conditional on an actual project.

Resolve the four content conflicts and adapt the auto-merged identity tests
to the shared preparation helper and main's disk-cache contract.

Validation: 215 tests passed across 20 affected files with --maxWorkers=1
(427.30 seconds wall time); scoped typecheck, lint, format, and independent
review passed.
Move shared preparation validation and readers into a leaf module to break the store import cycle. Preserve identity hashing and empty-workspace reserve behavior.

Restore alphabetical ordering in the Gateway test inventory without weakening the exact ownership assertions.
@steipete
steipete merged commit 5f5e3d7 into main Oct 13, 2026
125 checks passed
@steipete
steipete deleted the steipete/empty-workspace-reserves branch October 13, 2026 21:32
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…claw#170929)

Empty-workspace cloud sessions now get ready-worker reserves through the existing prepared pool. An empty committed workspace gets a runtime-only preparation identity (profileSnapshot.runtimePreparation, source "empty") keyed by Gateway namespace, provider/profile, effective settings, target, execution mode and exact runtime artifacts, with no session path, owner/Git metadata, commit, or setup recipe. Activation demand, claim, refill, expiry and cleanup reuse the pool; project checkout, prepared-workspace registration and the node tunnel key stay project-only, and project and empty reserves never claim each other. The pool now logs one concise line when it skips or defers a refill, with the effective limits. Shared preparation schemas moved to a leaf module (preparation-identity.schema.ts) to keep the import graph acyclic.

Live AWS (readyWorkers 1, preparedPool.maxTotal 1): after one empty session activated, an empty reserve was ready within ~2 minutes and the next empty session claimed it, active in 3.1 s (warm provisioning takes 70-100 s); refill started immediately. No schema, protocol, or config changes.
steipete added a commit that referenced this pull request Oct 14, 2026
Cloud setup used to forward host environment values through plaintext `setupEnv`, which disabled automatic snapshots and prepared workers. `settings.setupSecrets` replaces it: up to 16 POSIX environment names mapped to protected shared-store SecretRefs. One job-scoped egress owner gives profile setup, recipe preparation and postCreate/postStart commands only sentinels plus public CA trust; Crabbox native egress keeps the authenticated upstream proxy on the Gateway host, allows public HTTPS package downloads, and substitutes each secret only for its store-bound destinations. Grants revoke before process termination on cancellation.

Devcontainer `secrets` requests resolve only through the operator-approved map; unmapped requests fail once, before repository commands run. Setup secrets no longer disable snapshots or prepared workers; images captured with protected egress use a distinct compatibility identity, so older plaintext images are never adopted.

Requirements: an owned coordinator Linux lease and Crabbox 0.77.0 or newer with its matching runtime helper. Unsupported targets, a missing helper or login, an unavailable proxy, missing bindings and old CLIs fail visibly; there is no plaintext or direct-egress fallback.

Update behavior: the Crabbox plugin's Doctor health repair migrates each `setupEnv` profile atomically, and only when every same-name protected store entry already has destination bindings and there is no conflicting host value or mapping. It writes through Doctor's backed-up config writer, never writes store values, never invents destinations, and stays lazy when no profile needs migration. Unrepaired profiles report a remedy (`openclaw doctor --fix`) instead of forwarding plaintext. No SQLite schema change.

Merged with main after #170929 (empty-workspace cloud sessions): empty workspaces still require project-preparation support, so they stay cold on setup-command-only providers.

Related: #170810, #170862, #170929
Refs: #171073
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…71073)

Cloud setup used to forward host environment values through plaintext `setupEnv`, which disabled automatic snapshots and prepared workers. `settings.setupSecrets` replaces it: up to 16 POSIX environment names mapped to protected shared-store SecretRefs. One job-scoped egress owner gives profile setup, recipe preparation and postCreate/postStart commands only sentinels plus public CA trust; Crabbox native egress keeps the authenticated upstream proxy on the Gateway host, allows public HTTPS package downloads, and substitutes each secret only for its store-bound destinations. Grants revoke before process termination on cancellation.

Devcontainer `secrets` requests resolve only through the operator-approved map; unmapped requests fail once, before repository commands run. Setup secrets no longer disable snapshots or prepared workers; images captured with protected egress use a distinct compatibility identity, so older plaintext images are never adopted.

Requirements: an owned coordinator Linux lease and Crabbox 0.77.0 or newer with its matching runtime helper. Unsupported targets, a missing helper or login, an unavailable proxy, missing bindings and old CLIs fail visibly; there is no plaintext or direct-egress fallback.

Update behavior: the Crabbox plugin's Doctor health repair migrates each `setupEnv` profile atomically, and only when every same-name protected store entry already has destination bindings and there is no conflicting host value or mapping. It writes through Doctor's backed-up config writer, never writes store values, never invents destinations, and stays lazy when no profile needs migration. Unrepaired profiles report a remedy (`openclaw doctor --fix`) instead of forwarding plaintext. No SQLite schema change.

Merged with main after openclaw#170929 (empty-workspace cloud sessions): empty workspaces still require project-preparation support, so they stay cold on setup-command-only providers.

Related: openclaw#170810, openclaw#170862, openclaw#170929
Refs: openclaw#171073
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 size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant