Skip to content

refactor(sdk): give OpenShell and Fabric objects a literal gateway ref - #13282

Merged
cv merged 1 commit into
v1from
feat/literal-gateway-ref
Oct 15, 2026
Merged

cv merged 1 commit into
v1from
feat/literal-gateway-ref

Conversation

@cv

@cv cv commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Part of #13254. Part of #13131.

Failure

Generated graphs gave every OpenShell and Fabric object gateway = ${data.openshell_gateway.current.ref}. In one root (#13254), that read waits for apply on a fresh install and whenever a gateway resource has a pending change. The ref would then be unknown at plan time, so objects would plan as changed or replaced, sandboxes included. #13255 hit the same problem with server refs.

Decision

Objects take the gateway's ref as a literal, built from the same connection the data source receives, so it's known at plan time.

  • The gateway reads still gate the objects: every object already lists data.openshell_gateway.apply in depends_on and checks data.openshell_gateway.current.compatible in a precondition. Nothing about ordering or compatibility checks changes.
  • Teardown: the graphs already had literal refs, so their substitution is removed, along with gateway_ref_expression.
  • Test support: the OpenShell contract fixtures point each object's literal at the fake gateway through var.endpoint, as they already did for the data source. The fixture loader accepts the literal.

This changes the graphs but not what they do with today's two stages.

Validation

  • A compile test asserts:
    • every object's gateway is the literal openshell_gateway ref, equal field by field to what the gateway read receives;
    • each object still depends on data.openshell_gateway.apply.
    • It failed before the change.
  • cargo ci passes locally (1539 unit tests, 144 lifecycle tests).
  • cargo ci live-docker passes: all 8 live lifecycle tests plus the 3 standalone tests. These re-apply against a running gateway and require unchanged plans afterward.

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.
@github-actions

Copy link
Copy Markdown
Contributor

@cv
cv merged commit f1ae1d2 into v1 Oct 15, 2026
@cv
cv deleted the feat/literal-gateway-ref branch October 15, 2026 19:36
cv added a commit that referenced this pull request Oct 15, 2026
#13283)

Part of #13254. Stacked on #13282.

## Failure

When OpenTofu planned a new OpenShell object, the provider connected to
the object's gateway to check that its name wasn't already taken. On its
own that was only an early warning. But it stops runtime and OpenShell
resources from sharing one root: on a fresh install, the gateway doesn't
exist until the same apply installs it, so every first plan would fail.
For managed Kubernetes gateways, the connection even opened a
port-forward to a pod that doesn't exist yet.

## Decision

Planning an OpenShell object reaches no gateway. It still validates the
gateway `ref` locally; otherwise it does nothing.

Ownership checks don't weaken: before every create or update,
`reconcile` already observes the live object and refuses a name owned by
someone else. A conflicting name now surfaces at apply instead of plan,
which is how OpenTofu providers usually behave.

Fabric agents keep their plan-time check against their sandbox. It only
runs once the sandbox `ref` is known, by which point the gateway exists.

## Validation

- New contract test `new_objects_plan_without_reaching_the_gateway`:
plans standalone HCL whose gateway endpoint has nothing listening. It
failed before the change with `Resource planning failed`.
- All 59 OpenShell contract tests pass, including the ownership and
foreign-object cases, now enforced at apply.
- `cargo ci` passes locally: 1539 unit tests, 145 lifecycle tests.
- `docs/provider.md` says where ownership is checked.
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 area: architecture Architecture, design debt, major refactors, or maintainability area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery refactor PR restructures code without intended behavior change v1 NemoClaw v1 branch labels Oct 26, 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: architecture Architecture, design debt, major refactors, or maintainability area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery refactor PR restructures code without intended behavior change v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants