Skip to content

feat(nemoclaw-tofu): pass resource identities between types as typed refs - #13138

Merged
cv merged 1 commit into
v1from
feat/tofu-object-refs
Oct 14, 2026
Merged

cv merged 1 commit into
v1from
feat/tofu-object-refs

Conversation

@cv

@cv cv commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #13140. Part of #13131.

Failure

Provider types identify each other through separately passed strings, such as a sandbox's workspace name. OpenTofu cannot check that those strings belong to one object, or which resource type they came from, and every consumer repeats the fields it needs.

Decision

Resource definitions gain two declarations in nemoclaw-tofu:

  • exports(kind, fields) adds a computed object attribute ref: { type = kind, <fields> }. The structured adapter derives it from the resource's row, so backends never see it. Parts the row doesn't know yet, such as an ID assigned on create, stay unknown in the plan.
  • references(attribute, kind, fields) adds one object input that takes another type's ref. Each declared attribute travels to the backend as an ordinary row field, and refresh rebuilds the object from what the backend observes. A changed carried field that is immutable replaces the consumer, and plans report the reference attribute as the replacement path.

OpenTofu drops object attributes that a consumer doesn't declare. Consumers therefore declare only what they carry, and every ref carries type, which consumers check: a ref of another type is rejected with "Expected a ref of X, not Y".

No production type uses this yet; the OpenShell types adopt it in the next slice. nemoclaw-provider now picks the structured adapter through Definition::is_structured().

Validation

  • Unit tests in structured.rs: schema shape, planning with known and partly unknown refs, backend rows, type rejection, and refresh rebuilding a reference from observed fields.
  • The fixture provider gains a ref-exporting workspace and a ref-taking sandbox. New contract tests in crates/nemoclaw-provider/tests/contract/references.rs run them through pinned OpenTofu 1.12.6: create, an unchanged plan, workspace replacement propagating to the sandbox with replace_paths == [["workspace"]], and rejection of a ref of another type during validation.
  • cargo ci passed locally on linux_arm64.

…refs

Provider types identify each other through separately passed strings,
such as a sandbox's workspace name, so OpenTofu cannot check that the
pieces belong to one object or say which resource type they came from.
The provider redesign in #13131 replaces these with a computed `ref`
object on the producing type and an object input on the consumer.

Definitions gain `exports` and `references`. The structured adapter
derives `ref` from the row, so backends never see it, and parts the row
does not know yet stay unknown. A reference input is one object
attribute whose declared attributes travel to the backend as row fields;
its `type` must match the exporting type, because OpenTofu drops object
attributes a consumer does not declare and would otherwise accept a ref
of another type with matching fields. A changed ref replaces its consumer
when the carried fields are immutable, and plans report the reference
attribute as the replacement path.

The fixture provider gains a ref-exporting workspace and a ref-taking
sandbox. Unit tests cover the schema, planning with known and unknown
refs, type checks, and refresh. A contract test through OpenTofu 1.12.6
covers create, an unchanged plan, replacement propagating to the
consumer, and rejecting a ref of another type.
@github-actions

Copy link
Copy Markdown
Contributor

@cv
cv merged commit 1e84213 into v1 Oct 14, 2026
@cv
cv deleted the feat/tofu-object-refs branch October 14, 2026 07:03
cv added a commit that referenced this pull request Oct 14, 2026
Closes #13141. Part of #13131. Stacked on #13138.

## Failure

OpenShell provider profiles, registrations, and sandboxes named their
workspace, scoped profile, and provider registrations with separate
strings. OpenTofu could not check that each name meant an object of the
right type, and graphs had to pass names in a fixed order through
`depends_on`.

## Decision

- Each OpenShell resource exports a computed `ref`: `type`, `name`,
`owner`, `generation`, `id`, plus `workspace` for objects inside a
workspace.
- Profiles, registrations, and sandboxes take `workspace =
openshell_workspace.<label>.ref`. Registrations take an optional
`profile` ref in place of `profile_name`. Sandboxes take `providers`, a
list of registration refs, in place of `provider_names`.
- `nemoclaw-tofu` gains list references (`references_list`) and a schema
version. The four OpenShell schemas move to version 1, so OpenTofu
rejects state from the earlier schema instead of upgrading it. The SDK
record version moves from 7 to 8 with a message pointing to the original
release for recovery or teardown.
- The SDK compiler emits ref expressions. `nemoclaw_openshell::flatten`
rewrites refs in state, plans, and planned values back into the row
fields the SDK compares, so plan gates, export, and binding checks are
unchanged. Sandbox readiness reads the workspace from the sandbox's ref.

## Validation

- New `nemoclaw-tofu` unit tests for list references: schema shape and
version, backend rows, unknown elements deferring planning, rejecting an
element of another type, and refresh.
- Regenerated the OpenShell contract fixtures
(`NEMOCLAW_REGENERATE_FIXTURES=1`) and schema snapshot; updated the
hand-written OpenShell and Fabric contract HCL; the SDK compile test now
checks workspace and provider refs.
- `cargo ci` passed locally on linux_arm64, including all 138 contract
and system tests.
@wscurran wscurran added area: architecture Architecture, design debt, major refactors, or maintainability refactor PR restructures code without intended behavior change v1 NemoClaw v1 branch labels Oct 22, 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 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