Skip to content

refactor(sdk): plan, apply, and destroy each deployment as one OpenTofu root - #13286

Merged
cv merged 5 commits into
v1from
feat/single-root
Oct 15, 2026
Merged

cv merged 5 commits into
v1from
feat/single-root

Conversation

@cv

@cv cv commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #13254. Builds on #13264, #13265, #13282 and #13283, all merged.

Failure

The SDK ran each deployment as two OpenTofu roots: a runtime stage (managed gateway, model servers, storage) and an OpenShell stage (workspace, inference, sandboxes, Fabric agents). Each had its own state, plan, apply, destroy, export and recovery markers. Every operation ran OpenTofu twice, with stage-specific deferrals, markers and rules in between. Hand-written HCL never needed any of that.

Decision

Compile, plan, apply, export and destroy one root, with one state in the deployment's state directory.

  • Compilation: compile::deployment_graph merges the runtime graph into the object graph.

    • Gateway reads: the runtime's gateway read, which waits for the gateway it installs, replaces the plan-time read. On a fresh install or a pending gateway change it moves to apply; otherwise it runs at plan.
    • Ordering: every object already waits on the apply-time gateway read, which now waits on every runtime resource and readiness read. So the runtime settles before any object changes, within one apply. A spike with the bundled OpenTofu confirmed that destroy follows the same chain, removing objects before the runtime.
  • Plan and apply: one saved plan, checked against runtime bindings (bound process specifications, retained storage) and object targets together.

    • Docker models: the protection against disrupting a running model applies to that plan.
    • Lost creations: only OpenShell and Fabric creations are recorded, since OpenTofu saves every other ID. After a failed apply, the record forgets creations this apply added but OpenTofu never started; a failure stops OpenTofu before everything that depends on what failed. A creation whose apply started, or whose address OpenTofu didn't report, stays pending, and so does any earlier unresolved one.
  • Teardown: one teardown graph and one destroy, with Helm checkpointing around it as before. The retained workspace binding is required only once OpenShell objects are bound.

  • Export: one refresh-only observation over the single state.

  • Removed:

    • the runtime stage and its state subdirectory;
    • the runtime pending and destroy markers;
    • the gateway-not-running deferral and its message;
    • OperationResult::deferred_resources, and the CLI section that printed it;
    • the Kubernetes "unfinished platform apply" rule.

    Per the decisions on Compile one OpenTofu root instead of separate runtime and OpenShell graphs #13254: no compatibility work, and a gateway that's down is an ordinary failure.

Validation

  • cargo ci passes locally: 1527 unit tests, 145 lifecycle tests.
  • cargo ci live-docker passes: 9 tests, including the managed gateway's plan, apply, no-op, destroy and recovery with real Docker and OpenTofu.
  • cargo ci live-kind passes: all 5 Kubernetes tests, after a follow-up fix. Helm checkpointing and recovery now check only the runtime's bindings and read the shared state with the deployment's graph; the live test re-initializes after switching to the teardown graph.
  • New unit test: a_failed_apply_forgets_only_new_creations_it_never_started.
  • Updated tests:
    • Two-stage expectations: the Helm recovery, remote-service and Kubernetes interruption tests used the second state directory, stage-specific command scripts and runtime-only markers. They now use one state; tests of removed rules are deleted.
    • Live tests: Brev, Spark, hosted parity and the dummy agent now expect one plan that creates runtime and objects together. These need their own hardware and weren't run here.

The architecture, apply-flow and state docs still describe two stages; the docs PR for #13254 updates them.

cv added 4 commits October 15, 2026 12:20
Objects took the gateway data source's ref, which a single root would
leave unknown at plan time whenever the read waits for apply, planning
objects as changed. They now take the same ref as a literal, known while
planning; the gateway reads still gate them through depends_on and a
compatibility precondition.
Planning a new OpenShell object connected to its gateway to check that
the name wasn't already taken. On a fresh install with one root, the
gateway doesn't exist until the same apply installs it, so every first
plan would fail.

Planning now only validates the gateway ref. reconcile already refuses a
name owned by someone else before every mutation, so the ownership
check moves to apply.
…fu root

The SDK ran a runtime stage and an OpenShell stage as separate roots,
with separate state, plans, markers, deferrals, and teardown. Compile
one graph instead: the runtime's gateway read replaces the plan-time
read, and the apply-time gateway read that every object waits on now
waits on every runtime resource and readiness read, so the runtime
settles first within one apply and destroy removes objects first.

Plan, apply, export, and destroy use one state. Only OpenShell and
Fabric creations are tracked for lost replies, and a failed apply
forgets new creations OpenTofu never started. The runtime stage, its
markers, the gateway deferral, deferred_resources, and the Kubernetes
unfinished-platform rule are removed.
Helm checkpointing and recovery checked every saved binding against the
runtime's targets, which now share the state with OpenShell and Fabric
objects, so destroying a Kubernetes deployment refused its own objects.
Check only the runtime's bindings, and initialize recovery with the
deployment's graph so OpenTofu can read the objects in the checkpoint.
The live Kubernetes test re-initializes after switching to the teardown
graph, which needs more providers than the runtime graph.
@github-actions

Copy link
Copy Markdown
Contributor

@cv
cv merged commit dbff29a into v1 Oct 15, 2026
@cv
cv deleted the feat/single-root branch October 15, 2026 21:23
cv added a commit that referenced this pull request Oct 15, 2026
Closes #13254. Part of #13131. Stacked on #13286.

## Failure

After #13286, the docs still described two OpenTofu stages: separate
runtime and OpenShell plans, a `runtime/` state subdirectory, deferral
of OpenShell planning until the gateway exists, a gateway-running check,
both teardown plans, runtime-only recovery markers, and the removed
"Resources awaiting a complete plan" output.

## Decision

Describe what the SDK does now:

- **`design/architecture.md`:** "Why Managed Apply Has Two Stages"
becomes "Why Each Deployment Is One OpenTofu Root". It covers how
dependencies apply the runtime before objects and destroy in reverse;
why a fresh deployment can plan the gateway and its objects together;
and that a stopped gateway is an ordinary failure. The recovery rules
now describe the lost-creation tracking: OpenShell and Fabric creations
only, and forgetting creations OpenTofu never started.
- **`design/apply-flow.md`:** one plan → SDK checks → apply block in the
diagram and steps.
- **Reference and operations docs:** stage wording and stale paths in
`state.md` (no `runtime/` directory; the Helm checkpoint is at the state
root), `provider.md`, `reference/cli.md`, `usage.md`, and the
contributor testing docs.
- **Provider list:** `provider.md` and `apply-flow.md` no longer name
the removed `nemoclaw` provider.

## Validation

- `cargo run -p nemoclaw-build -- fern check`: 0 errors; the same single
warning as before this change.
- No remaining references to runtime or OpenShell stages, the `runtime/`
state directory, or the removed output. `design/recipes.md`'s
image-preparation "runtime stage" is unrelated and unchanged.
cv added a commit that referenced this pull request Oct 18, 2026
…pplied (#13408)

Closes #13005.

## Failure

Running `model_live` on a DGX Spark (GB10) for #13005 found a regression
from #13286. After `nemoclaw destroy`, re-applying the same
configuration with a managed gateway failed at its first plan with
`observation transport failed`:

- Destroy removed the managed gateway's container but kept
`openshell_workspace.deployment` in state.
- With one OpenTofu root, the next plan refreshes that workspace before
anything can reinstall the gateway.
- #13286 had removed the old deferral for a stopped gateway, so nothing
covered this case.

The lifecycle tests didn't catch it, because the fixture gateway never
goes away.

`model_live` also had stale assertions: a retained
`vllm_credential_storage`, which exists only with authentication, and a
recovery check filtering on the removed `nemoclaw_` prefix.

## Decision

- **Destroy deletes the workspace.** SDK destroy now keeps only data
(gateway storage, model caches, credentials) and deletes the workspace
with the deployment's other objects, as explicit HCL teardown does since
#13262. The workspace lives in the gateway destroy removes, and by then
its sandboxes, registrations and agents are gone. Re-applying reinstalls
a managed gateway on its retained storage and recreates the workspace.
- **CLI output:** destroy's "Retaining the workspace does not preserve
sandbox files" warning is removed, since the workspace is no longer
retained.
- **`model_live`:** after destroy it expects the gateway storage and the
model cache volume, and through recovery it checks that `openshell_*`
and `docker_volume.*` identities are preserved.
- **Docs:** `state.md`, `usage.md`, `provider.md` and the CLI reference
describe the new retention.

## Validation

- The teardown unit tests failed before the change and pass after.
Lifecycle tests now expect no workspace after destroy, and a recreated
one on re-apply.
- `cargo ci` passes locally: 1552 unit tests and 153 lifecycle tests.
- On a DGX Spark, with `examples/spark/vllm.yaml` adapted to Deep
Agents, because OpenClaw is blocked by #13372:
-
`model_live::selected_model_apply_export_and_watchdog_recovery_preserve_data_and_identity`
passes (658 s);
- `model_live::selected_model_continues_from_retained_state` then
re-applies the same configuration against the retained state and passes
(317 s). Before this change it failed at its first plan.
gaveezy added a commit that referenced this pull request Oct 18, 2026
#13131 superseded the stacked cluster work:

- the `nemoclaw` provider is gone (#13224);
- one OpenTofu root replaces the separate state files (#13286);
- off Docker, the platform owns keys and readiness (#13225, #13226);
- NemoClaw adds no address policy (#13232).

This merge takes v1's tree, so the branch now carries only the
in-cluster routing change that follows. #13061 and #13062 are parked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cv added a commit that referenced this pull request Oct 18, 2026
## Failure

On rootless Podman 5.8.8, applying `examples/managed-podman.yaml`
created the gateway and then failed:

```
Gateway capability observation failed
observation transport failed
```

The gateway itself was healthy, listening on its endpoint within a
second. In the single root (#13286), `data.openshell_gateway.apply` runs
during apply right after the gateway starts, with no wait. Docker
gateways have a separate readiness check that holds the read back until
the gateway listens; Podman gateways have none. So the read raced the
gateway's startup, failed on its first attempt, and didn't retry. Run on
its own against the running gateway, the same read succeeded.

## Decision

For a managed gateway, the apply-time read waits up to 90 seconds, as
the plan-time read already does. The wait ends as soon as the gateway
answers, so on Docker, where the readiness check runs first, it costs
nothing. External gateways are unchanged.

The docs now say that managed rootless Podman needs Podman 5 or later,
since the `pasta` networking report it requires first appeared there,
and that Ubuntu 24.04's Podman 4.9.3 fails the prerequisite.

## Validation

- **New test:**
`the_apply_time_gateway_read_waits_for_a_managed_gateway` failed before
the change (`Null` instead of `90`, for Podman) and passes for Podman
and Docker.
- **Live, on rootless Podman 5.8.8 with `pasta`:** with the rebuilt
bundle, `nemoclaw apply` of the Podman example, with a fresh UID and the
Hermes image, completes: gateway, workspace, provider, sandbox and
agent. Destroy then deleted the agent, sandbox and gateway, and the
documented removal procedure left nothing behind.
- `cargo ci` passes locally: 1,571 unit tests and 153 lifecycle tests.
gaveezy added a commit that referenced this pull request Oct 19, 2026
PR-6 merged v1 up to #13411. Three v1 changes move code this branch
builds on:

- #13224 removed the `nemoclaw` provider, which served this branch's
  cluster model types. They become `openshell_kubernetes_service` and
  `openshell_kubernetes_service_storage`, served by the openshell
  provider beside the Kubernetes gateway installation types: two more
  `INSTALLATION_TYPES` entries, and `cluster_services::definitions()`
  in `all_definitions()`. Their contract tests move to
  `openshell-provider::contract` with the Kubernetes gateway tests,
  their schema to the openshell snapshot, and the docs name the new
  types.
- #13286 plans and applies each deployment as one OpenTofu root. The
  cluster image preflight moves from the removed runtime stage into
  `Deployment::run`, before compilation. #13286 also removed the
  "unfinished Kubernetes platform apply" rule, so this branch's
  exception to it (`revises_only_model_workloads`), its test, and its
  usage.md paragraph go too. The compile test now checks that the
  apply-time gateway read, which every object waits on, waits on the
  cluster service, instead of checking that agents compile into a
  separate graph.
- #13184 added `Definition::derived`: a computed attribute kept out of
  backend rows. This branch's `derived` is an optional input checked
  against the spec and kept in the row, so ownership checks still see
  `owner` and `generation`. It is renamed `derived_input`.

Smaller follow-ups:

- #13093 added `ServiceDefinition::Container`; the cluster matches
  cover it. The cluster service is no longer a `runtime_process` kind:
  that flag now also selects Docker readiness and compute, which decode
  a Docker spec. Its only other readers handle the cluster kind first.
- #13223 dropped the `org.nemoclaw.runtime.spec` label everywhere; the
  cluster image check no longer requires it.
- #13369 removed `model_metadata` from OpenClaw routes, since Fabric
  v0.5.0's adapter rejects it; the cluster fixtures and docs drop it.

The remaining conflicts keep both sides.

`openshell-provider::contract`'s summed budget rises from 105 to 130 s,
keeping v1's margin: the 8 moved cluster model tests add 23.2 s in a
local linux_arm64 run (slowest 3.9 s, within the 6 s limit), about 17 s
at CI speed. `nemoclaw-provider::contract` keeps its v1 budget; this
branch's earlier raise to 150 s went with the tests.

Validation on linux_arm64: the `cargo ci` fmt, clippy, test, schema,
bundle and lifecycle steps pass (161 lifecycle tests, among them the 8
cluster model contract tests), as does `nemoclaw-build docs --check`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wscurran wscurran added area: architecture Architecture, design debt, major refactors, or maintainability area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery feature PR adds or expands user-visible functionality v1 NemoClaw v1 branch labels Oct 26, 2026
cv added a commit that referenced this pull request Nov 11, 2026
- inference.md: state only what was observed about Hermes's context
  window: Qwen/Qwen3-4B can't meet the 64,000-token minimum, and Hermes
  replied with qwen3:0.6b at 32,768 tokens in the live case; drop the
  unverified mechanism.
- provider.md: each deployment is one OpenTofu root (#13286), so
  OpenShell objects wait for every runtime resource and readiness read;
  #13256 is by design.
- Overrides.model doc comment: name each managed service's served model
  (vllm/config.rs served_model, services/registry.rs); regenerated.
- models.md: NemoClaw checks only a parser name's form; vLLM rejects an
  unknown parser at startup (#14397 reports its error).
- limits.md: split the #12651 row and add other harnesses to the managed
  Ollama row; inference.md and models.md say the several-GPU statements
  apply once #14384 lifts the one-entry limit.
cv added a commit that referenced this pull request Nov 11, 2026
Each deployment plans and applies as one root since #13286, so the provider reference no longer calls the managed gateway graphs runtime graphs.
cv added a commit that referenced this pull request Nov 11, 2026
Corrects the inference, model, recipe, SSH placement, and limits pages,
the inference parts of the provider reference, and the generated
configuration reference where they disagree with `v1`, for users who
configure managed or external inference.

## Problem

An audit of these pages against the commits since `v0.1.0-rc9` and the
current code found statements that `v1` contradicts. For example,
`inference.md` says a model change restarts the runtime inside the
existing sandbox, but a changed agent configuration replaces the sandbox
and deletes its files and conversations. Several limits link issues that
are resolved or decided, and two describe gaps that CI's live cases now
cover.

## Change

Each change and what makes it necessary:

- **Sandbox replacement** (`inference.md`, twice): a model, settings, or
image change replaces the agent's sandbox. `compile.rs` sets
`replace_triggered_by` on the agent configuration (#13375), and
`usage.md`'s change path already says so.
- **Default memory limit** (`inference.md`,
`ServiceContainer.memoryLimitGiB` doc comment): NemoClaw sets the 104
GiB limit (`DEFAULT_MEMORY_LIMIT_GIB`); Docker has no such default.
- **Fields Ollama rejects** (`inference.md`): `kind: ollama` has no
`kvCacheGiB`, `batchTokens`, `recipe`, `serving.modelName`, or
`authentication`, and its schema objects set `additionalProperties:
false`, so a zero value is rejected too; the page said only nonzero
values were.
- **GPU selection** (`inference.md` managed Ollama prerequisites,
`models.md` Nemotron example): a host with several GPUs works when
`container.gpuDevices` selects one (#13929).
- **Managed Ollama replies** (`inference.md`, `limits.md`): CI's
`docker-openclaw-hermes-ollama` live case gets a Hermes reply through
managed Ollama with `qwen3:0.6b` on the Linux AMD64 GPU runner, so "GPU
inference and agent replies have not been tested" is replaced by what
the case covers; tool use and other GPUs stay limits. The Hermes context
section now says only what was observed: `Qwen/Qwen3-4B` can't meet
Hermes's 64,000-token minimum, and Hermes replied with `qwen3:0.6b` at
32,768 tokens in that case; it no longer states an unverified mechanism.
The limits row also covers harnesses other than Hermes.
- **Linux AMD64 row removed** (`limits.md`): the hosted live cases reach
agent replies on Linux AMD64 on every CI run.
- **SSH engines** (`remote-service.md`, `limits.md`): retained-data
removal on SSH engines is verified and the Docker procedure covers it
(#12640, completed); the SSH capacity collector is a POSIX shell script,
not Python (`hardware/ssh.rs`); SSH placement on GPU hardware has no
live test (#12641).
- **Decided issues** (`inference.md`, `limits.md`): a managed NIM
service is not planned, and NIM works as an external endpoint (#12649);
network-request approval and policy explanation belong to OpenShell's
policy advisor, and `grants` replace presets (#12651), now two rows. The
DGX Station rows, whose issues closed for replanning, point to #12641.
- **Provider reference** (`provider.md`): `openshell_inference` takes a
readiness `ref` as `server` (#13252), so the "until inference
registrations take the ref" workaround is gone. Each deployment is one
OpenTofu root (#13254, #13286), so the readiness and gateway sections
describe one generated graph, in which OpenShell objects wait for every
runtime resource and readiness read, instead of separate runtime and
OpenShell graphs. Not checking external servers is by design (#13256).
- **Plan-time configuration checks** (`agents.md`): #13319 is closed;
#14148 tracks checking at plan time.
- **Diagnostic limit** (`models.md`, `limits.md`): once a command's
OpenTofu diagnostics exceed 16 KiB, the SDK replaces them with `child
output exceeds the supported limit` (`process.rs`, #14399), which can
hide vLLM's exit excerpt.
- **Parser names** (`models.md`): NemoClaw checks only a parser name's
form (`PARSER` in `vllm/constraints.rs`); vLLM rejects an unknown parser
at startup, and the stop detail carries its error (#14397).
- **Several GPUs** (`inference.md`, `models.md`): the statements about
several selected GPUs apply once #14384 lifts `container.gpuDevices`'s
one-entry limit, and the pages say so.
- **Speculative tokens** (`recipes.md`): `serving.speculativeTokens`
works only with a recipe and passes `--speculative-config` with the
`mtp` method (`arguments.rs`, `vllm/schema.rs`); no guide described it.
- **Configuration reference**: the container descriptions mention GPU
selection, and the guide links for `ServiceContainer`,
`ServiceUpdatePolicy`, the Ollama types, `ExternalOllama`, and
`ServiceAuthentication` point to their sections instead of the general
usage page. `Overrides.model` names each managed service's served model
(`served_model` in `vllm/config.rs`, `services/registry.rs`); it named
only vLLM's. The generator's dead `OllamaProxy` arm is removed.
Regenerated with `nemoclaw-build schema`.

Checked and left unchanged: the recent multi-GPU changes (#14388 to
#14401), the vLLM bearer route filter, timeout budgets, profile catalog,
memory reserves, hardware profiles, onboarding catalogs, Ollama and vLLM
pins, image tags, interface pages, and the OAuth-refresh guide match
`v1`.

Left for follow-up, because no open issue tracks them:

- Limits and `inference.md` sentences link issues closed for replanning
with no successor: #12035 (llama.cpp, Model Router, Gemini), #12038
(hosted-provider guides), #12144, #12037, #12137, and #12042.
- `agents.md` links #13313 for Hermes not sending API placeholders to
MCP servers; #13313 tracked the `api` credential type.
- The OpenClaw walkthrough row links #13372, which is fixed; whether the
walkthrough was rehearsed afterward is unrecorded.
@cv cv added this to the Roadmap: GTC DC 2026 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: architecture Architecture, design debt, major refactors, or maintainability area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery feature PR adds or expands user-visible functionality v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants