Skip to content

feat(gateway): durable cloud worker environments, provider SDK contract, and lifecycle RPCs - #104401

Merged
steipete merged 9 commits into
mainfrom
claude/cloud-task-inferral-boxes-2915ca
Jul 11, 2026
Merged

steipete merged 9 commits into
mainfrom
claude/cloud-task-inferral-boxes-2915ca

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Part of #104294 (cloud workers, milestone 1, PR 1 of the series). Design: docs/plan/cloud-workers.md (included in this PR).

What Problem This Solves

Cloud workers need a durable, crash-safe foundation before any remote execution exists: a persistent environment lifecycle (so provisioned machines are never leaked or double-provisioned across gateway restarts) and a provider seam so lease backends live in plugins, not core.

Why This Change Was Made

First PR of the cloud-workers series. It adds only the durable substrate — no worker runtime, no tunnel, no session integration yet:

  • SQLite-owned worker environment records in the shared state DB (Kysely; DDL in the schema file), with a closed state machine: requested -> provisioning -> bootstrapping -> ready -> (attached|idle) -> draining -> destroying -> destroyed | failed | orphaned.
  • Crash-safe provisioning: the intent row (with a deterministic operation id) is persisted before the provider call; restart reconciliation adopts in-flight leases, an orphan sweeper reconciles provider inspect against local records.
  • WorkerProvider contract in the plugin SDK (provision/inspect/renew?/destroy), registered via manifest contracts.workerProviders; provider ids normalized and deterministically ordered. SSH key material is referenced only through SecretRef (validated recursively for any sensitive-looking key in provider settings).
  • Additive protocol RPCs: environments.create ({ profileId, idempotencyKey }, idempotent replay) and environments.destroy; environments.list/status gain worker metadata. No protocol version bump. Existing gateway/node projection unchanged; a damaged worker store never regresses it.
  • static-ssh dev-only provider in the QA Lab plugin (source-only, excluded from packaged distributions, documented warning).
  • Opt-in cloudWorkers.profiles config block; the RPC descriptors are not even registered when unconfigured and no durable rows exist.

User Impact

None until configured: clean installs see no new RPCs, no new behavior. Operators who opt in get durable environment records and provisioning/teardown RPCs that later PRs (bootstrap, tunnel, worker protocol) build on. Config reference and protocol docs updated.

Evidence

  • Testbox (Blacksmith) tbx_01kx8b638vc2zce843jja2dbpp: PR test suite green — 5 Vitest shards, 154 tests passed (worker-environments state/store/service, environments RPC handlers, provider registry, cloud-workers config schema, static-ssh provider, plugin auto-enable, protocol schema).
  • check:changed lanes on the same box: all lanes green except the npm shrinkwrap guard, which fails identically for 13 packages this PR does not touch (root, extensions/feishu, extensions/slack, ... with npm EOVERRIDE on @smithy/node-http-handler) — inherited from current origin/main dependency churn, no dependency-bearing file is in this diff.
  • Fresh autoreview: clean, no actionable findings.
  • Manual maintainer review: state machine/store/service/RPC/SDK surfaces read in full; one test assertion tightened (exact inventory pin for the damaged-store case) and one explanatory comment restored.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts extensions: qa-lab size: XL maintainer Maintainer-authored PR labels Jul 11, 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: f0c772f74e

ℹ️ 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 +689 to +693
const hasWorkerEnvironmentRecords = (workerEnvironmentStore?.list().length ?? 0) > 0;
// Durable rows can outlive profiles. Startup planning still enforces plugin trust/disable gates.
const listDurableWorkerProviderIds = () =>
uniqueStrings(
workerEnvironmentStore?.listForReconcile().map((record) => record.providerId) ?? [],

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 Guard worker store reads during startup

When a persisted worker row is corrupt or incompatible, store.list()/listForReconcile() throw while decoding rows, but these startup probes run before the gateway binds and outside the environments.list/status damage-handling path. In that case a bad worker table prevents even the existing gateway/node inventory from starting, so these probes should catch worker-store failures and treat them as no durable providers (or otherwise degrade) until the RPC handler can report worker status safely.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the claude/cloud-task-inferral-boxes-2915ca branch from f0c772f to 57e7e72 Compare July 11, 2026 10:41
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 7:47 AM ET / 11:47 UTC.

Summary
The PR adds durable cloud-worker lifecycle storage and reconciliation, a public worker-provider plugin contract, opt-in profiles, environment lifecycle RPCs and SDK models, documentation, and a QA-only static SSH provider.

Reproducibility: yes. for both patch defects from source. A malformed persisted worker row reaches strict pre-bind decoding and can abort gateway startup; a provider profile with a plaintext credential under an unrecognized name such as credential or accessKey passes the generic validator and is copied into the durable snapshot. The cloud-worker capability itself is a new feature, not a current-main bug.

Review metrics: 4 noteworthy metrics.

  • Pre-bind strict reads: 2 startup call sites. Record detection and durable provider activation decode persisted rows before gateway availability is established.
  • Public lifecycle surfaces: 1 plugin contract, 2 RPCs, 2 SDK methods. External plugins and clients can depend on these interfaces immediately after merge.
  • Persistent model: 1 shared-state table added. Lifecycle records and provider settings snapshots become durable, upgrade-sensitive state.
  • Config surface: 1 root block, 2 lifetime fields added. The profile and policy shape becomes an operator and plugin compatibility contract.

Stored data model
Persistent data-model change detected: database schema: packages/gateway-protocol/src/schema/environments.test.ts, database schema: src/state/openclaw-state-schema.generated.ts, database schema: src/state/openclaw-state-schema.sql, durable storage schema: src/gateway/worker-environments/service-contract.ts, durable storage schema: src/gateway/worker-environments/service.test.ts, durable storage schema: src/gateway/worker-environments/service.ts, and 24 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104294
Summary: This PR is the first implementation candidate for the canonical cloud-workers feature issue, not a duplicate or superseded branch.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Guard corrupt durable-row startup probes and add a gateway-availability regression test.
  • Replace name-heuristic secret enforcement with an explicit provider settings/secret contract and focused tests.
  • Post redacted live provision, restart-adoption, list/status, and destroy evidence.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR provides automated Testbox, tests, checks, and source review only; it still needs redacted live provision, gateway restart/adoption, list/status, and destroy output. After adding proof, update the PR body to trigger a fresh review; if it does not, ask a maintainer to comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging publishes a new plugin SDK, client SDK, gateway protocol, root configuration block, and durable storage model that external plugins, clients, and operator setups may begin depending on.
  • [P1] The provider and SSH credential boundary is foundational for later remote execution; incomplete SecretRef enforcement can place plaintext provider credentials in openclaw.json and the shared state database.
  • [P0] The current startup path can turn one damaged worker row into a full gateway outage rather than isolating the optional cloud-worker feature.
  • [P1] No real setup demonstrates provider allocation, crash/restart adoption, inventory projection, and teardown with sensitive values redacted.

Maintainer options:

  1. Repair and prove the foundation (recommended)
    Fix pre-bind corruption isolation and require explicit provider secret metadata or schema validation, then post redacted live lifecycle evidence.
  2. Keep the contracts experimental
    Narrow the PR so public SDK, protocol, configuration, and durable-data contracts are not frozen until real provider experience validates them.
  3. Accept permanent contract risk
    A maintainer may intentionally own the new compatibility and security contracts after the concrete defects are fixed and real proof is posted.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Guard the pre-bind worker-store list and reconciliation-provider reads so corrupt worker rows degrade worker functionality without preventing gateway bind; replace incomplete name-only secret detection with an explicit provider-owned secret/settings contract that rejects plaintext secret values before config acceptance and durable snapshot persistence; add focused regression tests for both defects.

Next step before merge

  • [P1] The branch has concrete code repairs, but it is maintainer-protected and also needs contributor-owned real proof plus explicit product and security contract decisions; coordinate those before any repair or merge path.

Maintainer decision needed

  • Question: Should OpenClaw freeze the proposed cloudWorkers configuration, WorkerProvider plugin SDK, durable shared-state model, and lifecycle RPCs as the permanent first cloud-workers milestone?
  • Rationale: These are new public, persisted, upgrade-sensitive, and security-sensitive contracts. The protected maintainer label and canonical issue's product/security gates require an explicit human decision even after the patch defects and proof gap are resolved.
  • Likely owner: steipete — The current assignee authored both the design and implementation and has the clearest context to own the permanent contract decision.
  • Options:
    • Approve after gates (recommended): Accept the foundation after the startup, secret-contract, upgrade, and live-proof requirements are satisfied.
    • Narrow the milestone: Keep the cloud-workers direction but defer public SDK/protocol/config contracts until a smaller internal experiment proves their shape.
    • Pause the series: Defer this PR until maintainers reconfirm the broader remote-execution architecture and security model.

Security
Needs attention: The public environment projection does not expose SSH or SecretRef data, but the generic settings validator can accept and durably persist plaintext provider credentials whose names evade its limited heuristic.

Review findings

  • [P1] Guard damaged worker rows before gateway bind — src/gateway/server.impl.ts:689-693
  • [P1] Require an explicit secret contract for provider settings — src/config/zod-schema.cloud-workers.ts:40-50
Review details

Best possible solution:

Before merge, make provider secret declarations explicit and schema-backed rather than relying on an incomplete key-name guess, isolate every pre-bind worker-store probe so corrupt rows cannot prevent gateway service, retain the generic plugin-owned provider and canonical SQLite boundaries, and add redacted live provision/restart-adoption/list-status/destroy evidence.

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

Yes for both patch defects from source. A malformed persisted worker row reaches strict pre-bind decoding and can abort gateway startup; a provider profile with a plaintext credential under an unrecognized name such as credential or accessKey passes the generic validator and is copied into the durable snapshot. The cloud-worker capability itself is a new feature, not a current-main bug.

Is this the best way to solve the issue?

No in its current form. The plugin-owned provider seam and SQLite lifecycle owner are the right architectural direction, but failure isolation and an explicit, complete secret contract are necessary before publishing these permanent surfaces.

Full review comments:

  • [P1] Guard damaged worker rows before gateway bind — src/gateway/server.impl.ts:689-693
    list() and listForReconcile() strictly decode persisted JSON, state, lease, and SSH fields, but both are called here before the gateway binds. A corrupt or incompatible worker row therefore prevents the existing gateway/node service from starting instead of degrading only cloud-worker functionality; catch these probes, log the damage, and add a startup regression test that preserves gateway availability.
    Confidence: 0.99
  • [P1] Require an explicit secret contract for provider settings — src/config/zod-schema.cloud-workers.ts:40-50
    This validator treats arbitrary provider settings as safe unless each field name matches a short heuristic. A plugin can reasonably name credentials credential, accessKey, sshKey, or clientCert; those plaintext values pass validation and are then persisted in the worker profile snapshot. Require providers to declare or validate secret paths, or use a closed settings schema that enforces canonical SecretRef values instead of guessing from names. This concern was equally visible on the earlier reviewed head and is being raised late after the dedicated security pass.
    Confidence: 0.93
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 651aab87f3ee.

Label changes

Label justifications:

  • P2: This is a substantial opt-in feature foundation with limited immediate user impact but normal-priority correctness, security, and product gates.
  • merge-risk: 🚨 compatibility: The PR publishes new plugin SDK, gateway protocol, client SDK, configuration, and persisted-data contracts.
  • merge-risk: 🚨 security-boundary: Arbitrary provider settings and SSH credential references cross plugin, config, and durable-state trust boundaries, and current enforcement can miss plaintext credential names.
  • merge-risk: 🚨 availability: Strict durable-row reads before bind can prevent the existing gateway from starting when optional worker state is damaged.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides automated Testbox, tests, checks, and source review only; it still needs redacted live provision, gateway restart/adoption, list/status, and destroy output. After adding proof, update the PR body to trigger a fresh review; if it does not, ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed

Security concerns:

  • [high] Plaintext provider credentials can enter durable state — src/config/zod-schema.cloud-workers.ts:40
    Provider settings are arbitrary JSON, while SecretRef enforcement is based on a short key-name pattern list; unrecognized credential names pass config parsing and are copied into profile_snapshot_json before provider allocation.
    Confidence: 0.93

Acceptance criteria:

  • [P1] pnpm test src/gateway/server*.test.ts src/gateway/worker-environments/*.test.ts.
  • [P1] pnpm test src/config/zod-schema.cloud-workers.test.ts src/plugins/worker-provider-registry.test.ts.
  • [P1] pnpm test src/gateway/server-methods/environments.test.ts packages/gateway-protocol/src/schema/environments.test.ts packages/sdk/src/index.test.ts.

What I checked:

  • Prior P1 remains on the latest head: Only docs/docs_map.md changed after the previous reviewed SHA; the two strict worker-store reads still occur before gateway bind. (src/gateway/server.impl.ts:689, eca2685142ea)
  • Strict persisted-row decoding: Worker rows parse JSON, lifecycle state, SecretRef data, and lease/SSH invariants synchronously; malformed durable data throws from list() and listForReconcile(). (src/gateway/worker-environments/store.ts:114, eca2685142ea)
  • Request paths already degrade damaged storage: The environment list and status handlers catch store failures, showing the intended invariant that damaged worker state must not regress the existing gateway/node inventory; startup does not preserve that invariant. (src/gateway/server-methods/environments.ts:92, eca2685142ea)
  • Generic secret validation is name-limited: Provider settings are arbitrary bounded JSON, but SecretRef enforcement only recognizes keyRef plus a short sensitivity-pattern list; values under names such as credential, accessKey, clientCert, or sshKey can pass and are then copied into the durable profile snapshot. (src/config/zod-schema.cloud-workers.ts:40, eca2685142ea)
  • Durable profile snapshot: The service validates settings with the same heuristic and persists the resulting settings object in the shared-state worker row before provider allocation. (src/gateway/worker-environments/service.ts:274, eca2685142ea)
  • Architectural fit: The implementation keeps provider execution plugin-owned, uses manifest ownership and normalized IDs, stores canonical lifecycle state in the shared SQLite database, and omits SSH and SecretRef material from public environment summaries. (src/plugins/worker-provider-registry.ts:66, eca2685142ea)

Likely related people:

  • steipete: Authored the cloud-workers design and every commit in this PR, is the live assignee, and has the strongest history across the affected gateway, plugin, SDK, and state surfaces. (role: feature owner and current assignee; confidence: high; commits: 1a5489486051, 9fa8efce0bc6, aa08cfae4d6f; files: docs/plan/cloud-workers.md, src/gateway/worker-environments/service.ts, src/plugins/types.ts)
  • Vincent Koc: Recent merged history includes plugin contract-registry work, bundled provider loading changes, and auth/security hardening adjacent to the new provider and credential boundaries. (role: recent plugin-contract and security contributor; confidence: medium; commits: 141c7f8eaa7a, c727388f937f, a0182574873e; files: src/plugins/contracts/registry.ts, src/plugins/registry.ts, src/gateway)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-11T10:54:52.615Z sha 57e7e72 :: needs real behavior proof before merge. :: [P1] Keep worker runtime out of shared gateway request types | [P1] Keep damaged worker rows from aborting gateway startup | [P2] Fix the incomplete plugin lookup test fixture
  • reviewed 2026-07-11T11:02:33.341Z sha 57e7e72 :: needs real behavior proof before merge. :: [P1] Keep worker runtime out of shared gateway request types | [P1] Keep damaged worker rows from aborting gateway startup | [P2] Fix the incomplete plugin lookup test fixture | [P3] Add braces around the provision operation-id guard
  • reviewed 2026-07-11T11:38:53.385Z sha 670c93e :: needs real behavior proof before merge. :: [P1] Guard damaged worker rows before gateway bind

@steipete steipete self-assigned this Jul 11, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 11, 2026
@steipete
steipete merged commit 90e4658 into main Jul 11, 2026
100 checks passed
@steipete
steipete deleted the claude/cloud-task-inferral-boxes-2915ca branch July 11, 2026 11:54
@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 12, 2026
…ct, and lifecycle RPCs (openclaw#104401)

* docs(plan): add cloud workers design plan

* feat(plugin-sdk): add cloud worker provider foundations

* feat(protocol): add worker environment lifecycle shapes

* feat(gateway): persist worker environment lifecycles

* test(gateway): pin environment inventory assertion for damaged worker store

* style(cloud-workers): satisfy lint and docs formatting

* fix(gateway): narrow worker environment type boundaries

* chore(plugin-sdk): account for WorkerProvider surface growth

* docs: regenerate docs map
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 extensions: qa-lab 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant