Skip to content

feat(sdk): restart Docker gateways after the gateway or host restarts - #13265

Merged
cv merged 1 commit into
v1from
feat/gateway-restart-policy
Oct 15, 2026
Merged

cv merged 1 commit into
v1from
feat/gateway-restart-policy

Conversation

@cv

@cv cv commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Part of #13254. Part of #13131.

Failure

Generated graphs start the Docker gateway with restart policy no. After a host reboot or a gateway crash, the gateway stays down until someone applies again. Until then, plans can't refresh the OpenShell resources, which is why the two-stage apply has a gateway restore step. #13254 wants that recovery to be an exception rather than part of every apply.

Decision

The Docker gateway container gets the restart policy unless-stopped.

  • What it restores: Docker starts the gateway again after it or the host restarts. A gateway stopped deliberately with docker stop stays stopped.
  • Why the old policy didn't apply: no came from the inference containers, where a protective stop under memory pressure must not become a restart loop (docs/design/runtime.md). That reason doesn't apply to the gateway. Managed vLLM, Ollama, and the Ollama proxy keep no.
  • Podman unchanged: the Podman gateway keeps no. Rootless Podman only restarts containers at boot through a systemd unit, so the policy alone wouldn't help there.
  • Existing deployments: the policy is updated in place on their next apply, with no replacement and no gateway downtime. The SDK's plan rules already accept in-place updates to the gateway container.

Validation

  • A compile test pins restart = "unless-stopped" on the generated gateway. It failed before the change.
  • cargo ci passes locally (1540 unit tests, 144 lifecycle tests).
  • With the bundled OpenTofu and Docker provider against a real Docker engine, changing an existing container's restart from no to unless-stopped planned an in-place update (0 to add, 1 to change, 0 to destroy). The applied container then reported unless-stopped.
  • The live tests that stop containers use docker stop, which this policy respects.

Generated graphs started the Docker gateway with restart policy no, so a
host reboot left it down until the next apply. The gateway now uses
unless-stopped; an explicit docker stop still keeps it stopped.
Inference containers and the Podman gateway keep no.
@github-actions

Copy link
Copy Markdown
Contributor

@cv
cv merged commit 04b548f into v1 Oct 15, 2026
@cv
cv deleted the feat/gateway-restart-policy branch October 15, 2026 18:50
@wscurran wscurran added area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery feature PR adds or expands user-visible functionality platform: container Affects Docker, containerd, Podman, or images labels Oct 15, 2026
cv added a commit that referenced this pull request Oct 15, 2026
…fu root (#13286)

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 #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.
- **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.
@wscurran wscurran added the v1 NemoClaw v1 branch label Oct 28, 2026
@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: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery feature PR adds or expands user-visible functionality platform: container Affects Docker, containerd, Podman, or images v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants