Repository navigation
feat(cloud): support repository environment recipes - #170862
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2ce0b40322
ℹ️ 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".
| @@ -213,9 +216,14 @@ export function createWorkerProviderIntent(options: WorkerProviderIntentOptions) | |||
| cached && | |||
| "source" in cached && | |||
| preparation && | |||
There was a problem hiding this comment.
Preserve replay compatibility for legacy preparations
When an environment persisted by the previous release has a setupRecipe but no new recipe field, this condition prevents knownRecipe from reusing it. A repeated repository request with the same idempotency key then resolves a full recipe, constructs a different preparation identity, and fails the existing-record comparison with Idempotency key belongs to another project preparation instead of returning or resuming the environment. Accept the legacy shape during replay or explicitly migrate it so upgrades do not strand existing repository environments.
AGENTS.md reference: AGENTS.md:L80-L81
Useful? React with 👍 / 👎.
7566671 to
a5619bd
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5619bd9e5
ℹ️ 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 result = await params.tunnel.runWorkspaceCommand({ | ||
| argv: ["node", "-e", script], |
There was a problem hiding this comment.
Bound lifecycle scripts before sending them as an argument
When an otherwise valid devcontainer contains enough postCreateCommand/postStartCommand text or lifecycle environment data to make this generated script exceed 128 KiB, passing it as the single node -e argument makes the worker reject it: src/worker/node-workspace-protocol.ts caps each argument at 128 KiB, while repository admission accepts devcontainer blobs up to 1 MiB and the local path has no corresponding bound. The recipe is therefore admitted and persisted but always fails before its lifecycle command executes; send the script through bounded stdin or reject oversized recipes during admission.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ee24ce39b
ℹ️ 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".
| @@ -235,7 +301,7 @@ const runSetup = (script, workspaceDir, homeDir) => { | |||
| // turn an interrupted setup into a reusable completed environment. | |||
| fs.writeFileSync(path.join(completionDirectory, preparedManifestRef.slice(7) + ".json"), preparedBytes, { flag: "wx", mode: 0o600 }); | |||
| } | |||
| return { workspaceDir, homeDir, sourceManifestRef, preparedManifestRef }; | |||
| return { workspaceDir, homeDir, sourceManifestRef, preparedManifestRef, recipePreparation, ...(captureSkipped ? { captureSkipped } : {}) }; | |||
There was a problem hiding this comment.
Persist capture suppression with the completion receipt
If the Gateway or provider dies after this script publishes the completion artifacts but before markPrepared records the returned captureSkipped, the next provisioning replay treats the workspace as a cache hit and returns only preparedWorkspace; Crabbox then uses preparedReplay to force capture. A workspace where the detected install failed can therefore become the shared warm image for future sessions. Persist the failure/suppression alongside the durable completion and restore it during inspection, or avoid publishing a reusable completion for this outcome.
AGENTS.md reference: AGENTS.md:L7-L8
Useful? React with 👍 / 👎.
| const enableCorepack = | ||
| 'mkdir -p "$HOME/.local/bin" && corepack enable --install-directory "$HOME/.local/bin" && PATH="$HOME/.local/bin:$PATH"'; |
There was a problem hiding this comment.
Bootstrap Corepack before invoking it
On a standard Node 26 worker—which satisfies this repository's >=26.1.0 engine and documented Node/npm worker prerequisites—this command fails before pnpm or Yarn runs because Node stopped distributing the corepack executable starting with v25 (official Node documentation). Since detected-install failures intentionally continue cold, these supported workers appear to provision successfully but start without dependencies for every pnpm/Yarn repository unless operators happened to install Corepack separately. Bootstrap a userland Corepack installation via the guaranteed npm prerequisite or explicitly make it a checked worker prerequisite.
AGENTS.md reference: AGENTS.md:L80-L80
Useful? React with 👍 / 👎.
9ee24ce to
4e73807
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e73807e97
ℹ️ 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 result = await params.tunnel.runWorkspaceCommand({ | ||
| argv: ["node", "-e", script], |
There was a problem hiding this comment.
Run daemonizing hooks under persistent process ownership
When postStartCommand daemonizes a server (for example, the documented npm run dev ... &), this ordinary foreground runWorkspaceCommand is marked as a native process owner by node-worker-tunnel.ts, and NodeWorkerWorkspaceProcesses.execute waits for descendant extinction before returning. Setting settleDescendants: false only prevents the inner wrapper from killing the server; the outer command still waits until its 10-minute timeout and then cancels the tree, so activation fails instead of leaving the service running. Dispatch this wrapper through the managed background-process contract so the command can return while its descendants remain owned.
AGENTS.md reference: AGENTS.md:L50-L53
Useful? React with 👍 / 👎.
| if (preparation?.recipe && preparation.runSetupScript !== false) { | ||
| await runWorkerProjectLifecycle({ |
There was a problem hiding this comment.
Refresh the base manifest after lifecycle hooks
When a synchronous postCreateCommand modifies a manifest-eligible file, it runs after syncSessionRepositoryWorkspace captured synced.manifestRef, while that pre-hook manifest is later stored as workspaceBaseManifestRef. Final reconciliation therefore attributes the hook's build or configuration output to the agent turn and can publish it back into the session repository even when the agent never touched it. Re-capture the workspace manifest after lifecycle hooks, or execute the hooks before the baseline manifest is captured.
AGENTS.md reference: AGENTS.md:L50-L53
Useful? React with 👍 / 👎.
Cloud project preparation now resolves one repository environment recipe, in this precedence: a committed .devcontainer/devcontainer.json or .devcontainer.json (JSONC, host-mode subset), then the existing executable .openclaw/worktree-setup.sh, then built-in JavaScript detection from the lockfile (pnpm, Yarn and npm via user-writable Corepack shims, Bun when present). Dev Container lifecycle maps onto snapshots: onCreateCommand and updateContentCommand run before capture and are baked in; a commit refresh reruns only updateContentCommand; postCreateCommand and postStartCommand run at workspace binding on every machine start, after enrollment and before activation. remoteEnv and containerEnv apply to lifecycle commands. Container-only properties (image, build, compose, features, hostRequirements, secrets) are ignored on cloud machines with one recorded note. A failing detected install continues cold without capture and records bounded diagnostics; a failing declared recipe fails visibly. Recipe source, per-phase durations and failure tails are exposed for the Cloud environments view. Recipe identity uses the declared file blob or a versioned digest of detected inputs. Refs: openclaw#170862
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
Scheduled main 38550286127 failed before declared recipe execution with ETXTBSY on fixture-bin/node. Even a close-on-exec writable descriptor can remain in a sibling fork until that child executes. Copy the fixture Node binary in a short-lived Node process so Vitest sibling forks cannot inherit its writable handle. Preserve the fixture binary path, library layout, file mode and all recipe assertions. The fixture originated in 1be6777 (#170862). The specific sibling process involved in the natural failure remains unknown. Proof: hosted run 38552498755 / job 115813582391 on Node 24.19.0 passes only the failing declared parallel setup case (1 passed, 5 skipped), changed-file oxfmt/oxlint, whitespace and exact-source provenance checks. Case 1.10s; test step 37s; complete job 122s. Codex P2 review round 1 clean. One test file +6/-2; no production changes or SQL measurement claim. A bounded Linux probe confirms inherited O_CLOEXEC write handles cause ETXTBSY before sibling exec and that child-owned copying avoids that inheritance. This synthetic mechanism probe does not identify the particular sibling responsible for the original transient failure.
…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
Scheduled main 38550286127 failed before declared recipe execution with ETXTBSY on fixture-bin/node. Even a close-on-exec writable descriptor can remain in a sibling fork until that child executes. Copy the fixture Node binary in a short-lived Node process so Vitest sibling forks cannot inherit its writable handle. Preserve the fixture binary path, library layout, file mode and all recipe assertions. The fixture originated in 10e69aa (openclaw#170862). The specific sibling process involved in the natural failure remains unknown. Proof: hosted run 38552498755 / job 115813582391 on Node 24.19.0 passes only the failing declared parallel setup case (1 passed, 5 skipped), changed-file oxfmt/oxlint, whitespace and exact-source provenance checks. Case 1.10s; test step 37s; complete job 122s. Codex P2 review round 1 clean. One test file +6/-2; no production changes or SQL measurement claim. A bounded Linux probe confirms inherited O_CLOEXEC write handles cause ETXTBSY before sibling exec and that child-owned copying avoids that inheritance. This synthetic mechanism probe does not identify the particular sibling responsible for the original transient failure.
Problem
What Problem This Solves
Cloud project preparation only understands an executable
.openclaw/worktree-setup.sh. Repositories cannot declare snapshot preparation and per-machine startup independently, and repositories with ordinary JavaScript lockfiles need manual setup.Solution
Resolve one committed environment recipe:
.devcontainer/devcontainer.json, then.devcontainer.json, then the executable worktree setup script, then built-in JavaScript detection. One core recipe owner supplies local and immutable GitHub repository admission, preparation identity, and command execution.The host-mode Dev Container subset supports shell strings, executable argument arrays, and named parallel commands. Initial preparation runs
onCreateCommandfollowed byupdateContentCommandbefore capture; an in-place commit refresh reruns onlyupdateContentCommandand preserves creation artifacts. Workspace binding ownspostCreateCommandbefore first activation andpostStartCommandat every binding, after enrollment and before the first turn. Idle reclaim destroys and provisions another worker, so there is no separate resume hook.Lifecycle commands retain the existing administrator-authorized dispatch gate and minimal worker environment, extended by lifecycle-only
containerEnvandremoteEnv. Unsupported container properties produce one concise note. Detection handles pnpm, Yarn Classic/Berry, npm, and available Bun. Detected Corepack-backed installs disable auto-pinning to preserve admitted package metadata (Corepack environment variables). Detected install failures continue cold and suppress capture, including later teardown; declared failures remain visible dispatch failures.Typed optional diagnostics include source, ignored properties, phase durations, and a failure tail bounded to 16 KiB, including invalid UTF-8. Crabbox v3 plugin-state records normalize existing records; no SQLite schema changes. A small runtime installation extraction keeps the provider within its existing line limit without changing its install order.
Impact
Repositories can commit a standard environment file and reuse prepared dependencies while running machine startup after workspace binding. Existing executable setup scripts retain their behavior and blob identity. Existing preparation records without a resolved recipe are rediscovered on admission; optional diagnostics preserve existing warm-image record compatibility. Recipe changes select a new preparation identity. Local managed worktrees on the Gateway host (
src/agents/worktrees/repository-setup.ts) are unchanged.Environment values are literal and lifecycle-only. Session-process environment propagation is a follow-up for its existing owner; this change does not modify the node-worker allowlist, supervisor, or launch descriptor. Node installation, secrets, features, host requirements, UI, and container execution remain sibling work. An interrupted first binding can retry before activation records completion, so declared commands should be idempotent. Integrated live AWS proof remains with the lead; no leases were used here.
Evidence
Dependencies prepared with
node scripts/worktree-setup.mjs full. The first build in that command caught an incomplete edit; focused checks below cover the completed candidate. Wall times include compilation and checkout artifact-lock contention.Focused tests (files passed as individual arguments):
pnpm test src/gateway/worker-environments/environment-recipe.test.ts src/gateway/worker-environments/project-preparation-environment.test.ts src/gateway/worker-environments/project-lifecycle.test.ts src/gateway/worker-environments/project-preparation.test.ts src/gateway/worker-environments/project-preparation-verification.test.ts src/gateway/worker-environments/repository-project-admission.test.ts src/gateway/worker-environments/provider-intent.test.ts src/gateway/worker-environments/provider-project-retention.test.ts src/gateway/worker-environments/placement-dispatch-prepared.test.ts --maxWorkers=1319.35s: 142 passed, 9 failed. Admission and provider-intent suites passed; failures identified script-wrapper failure reporting, original timeout validation, and the old script-only fixture. These were corrected and the affected suites rerun:
pnpm test src/gateway/worker-environments/environment-recipe.test.ts src/gateway/worker-environments/project-preparation-environment.test.ts src/gateway/worker-environments/project-lifecycle.test.ts src/gateway/worker-environments/project-preparation.test.ts src/gateway/worker-environments/provider-project-retention.test.ts src/gateway/worker-environments/placement-dispatch-prepared.test.ts --maxWorkers=1237.47s: 94 passed.
pnpm test extensions/crabbox/src/crabbox-worker-warm-image-store.test.ts extensions/crabbox/src/crabbox-worker-warm-image-lifecycle.test.ts extensions/crabbox/src/crabbox-worker-provider.test.ts extensions/crabbox/src/crabbox-worker-project.test.ts --maxWorkers=1148.18s: 159 passed, including declared failure diagnostics, detected-failure cold enrollment, capture suppression at teardown, and existing record normalization.
pnpm test src/gateway/worker-environments/environment-recipe.test.ts src/gateway/worker-environments/project-preparation-verification.test.ts src/gateway/worker-environments/project-lifecycle.test.ts src/gateway/worker-environments/placement-dispatch-prepared.test.ts --maxWorkers=1153.14s: 58 passed, including nullable lifecycle env and actual binding-before-command-before-activation ordering.
pnpm test src/gateway/worker-environments/project-preparation.test.ts src/gateway/worker-environments/project-preparation-verification.test.ts --maxWorkers=1532.32s: 38 passed after deleting the superseded script-only reader.
409.42s: regression reproduced (1 failed, 3 skipped). Decoding invalid bytes expanded the stored tail beyond 16 KiB; bounding serialized text fixed the actual preparation boundary.
pnpm test src/gateway/worker-environments/project-preparation-environment.test.ts src/gateway/worker-environments/project-lifecycle.test.ts --maxWorkers=1486.34s: 7 passed, including both UTF-8 cases and successful post-binding background processes surviving phase completion.
pnpm test src/gateway/worker-environments/environment-recipe.test.ts src/gateway/worker-environments/project-preparation-environment.test.ts --maxWorkers=1240.57s: 33 passed after the review-discovered Corepack auto-pinning repair, including pnpm and Yarn preparation regressions.
An earlier unfrozen-source test probe ran no tests (230.88s); reruns above used stable source generations. No full local test suite or cloud test suite was run.
Other checks:
pnpm tsgo(final repair: 10.82s),pnpm tsgo:extensions(1401.49s including artifact-lock queue), targeted core and Crabbox type-aware lint,pnpm format:checkfor all changed files,git diff --check, andpnpm check:max-lines-ratchet --base origin/mainpassed without changing baselines or caps. Documentation links, glossary, Markdown lint, and MDX checks passed.pnpm build:runtimepassed (695.56s); the full packaging/declaration build was cancelled after 1488.60s in its declaration phase, with no code failure reported, and broad package proof is left to PR CI. The subsequent UTF-8 runtime rebuild also passed (484.15s). The final Corepack repair runtime build passed (365.26s); independent Codex review finished scoped-clean at P0–P2 after resolving its actionable findings. Targeted repair lint passed (8.50s).CI initially found three failures in
provider-project-preparation.test.ts;pnpm test:ci-failed 170862 --jsonclassified the job as unknown because no matching job existed on main. The logs identified a synthetic preparation reply missing the new producer'srecipePreparationfield. The fixture was corrected without changing production code, audited against the other budgeted preparation replies, and independently reviewed scoped-clean.pnpm test src/gateway/worker-environments/provider-project-preparation.test.ts --maxWorkers=1463.50s: 13 passed, including all three dedicated-worker classification cases. Targeted fixture lint, format and
git diff --checkpassed. The PR context check initially required the exact “What Problem This Solves” heading; the subsection under Problem now satisfies the repository checker. No CI rerun was requested and no push was made just to chase green.After main landed runtime disk compatibility, GitHub reported a provider conflict. Rebased onto
fada6e0812ce163dfc39d4ca19dacf0acc3a4c1b, preserving main's runtime top-up conditions and enrolled replay behavior while retaining recipe diagnostics and capture suppression. No budget, baseline, guard, inventory, or cap files were changed by this lane; the diff against the pinned rebase base contains only its 34 files.pnpm test src/gateway/worker-environments/preparation-identity.test.ts src/gateway/worker-environments/project-preparation-environment.test.ts src/gateway/worker-environments/provider-project-preparation.test.ts extensions/crabbox/src/crabbox-worker-prepared-image.test.ts extensions/crabbox/src/crabbox-worker-warm-image-lifecycle.test.ts extensions/crabbox/src/crabbox-worker-provider.test.ts extensions/crabbox/src/crabbox-worker-project.test.ts --maxWorkers=1487.02s: 194 passed (37 Gateway, 157 Crabbox), including compatible forks topping up older runtimes. Rebased
pnpm tsgopassed (30.69s),pnpm tsgo:extensionspassed (50.32s), targeted provider/project lint and changed-file formatting passed, andpnpm build:runtimepassed (365.86s). Rebased branch review finished scoped-clean at P0–P2.The final caller audit removed the generated script's test-only error-reporting mode. Production always serialized the preparation receipt; core project preparation now owns failure recording and reporting without a second mode. Existing timeout/signal assertions now use the actual
project.prepareowner and budgeted transport.pnpm test src/gateway/worker-environments/project-preparation.test.ts src/gateway/worker-environments/project-preparation-environment.test.ts --maxWorkers=1262.81s: 37 passed. Final
pnpm tsgopassed (142.66s including queue), focused core lint/format andgit diff --checkpassed, independent cutover review finished scoped-clean, andpnpm build:runtimepassed (275.26s). An intermediate check/review was interrupted before results to correct the test transport override. The change reuses the existing transport fixture and timer cases; no Gateway boots or new timer cases were added. The initial failing CI ownership shard ran in 36.73s; final-head CI is the broad proof.Release-note context
Cloud sessions support committed host-mode Dev Container lifecycle recipes, retain executable worktree setup scripts as a fallback, and automatically attempt locked JavaScript dependency installation. Failed detected installs start cold with recorded diagnostics instead of blocking the session. Startup commands run after binding on cold provision and snapshot forks.