Repository navigation
fix(sdk): recover from a gateway Helm install that failed or was interrupted - #14169
Conversation
…progress An interrupt during an apply or destroy sent SIGINT to OpenTofu and killed its process group 5 seconds later. OpenTofu was still waiting for the operations in progress, so a Helm install was left pending-install and the bindings of resources already created could be missing from the state (#14155). The first interrupt now lets OpenTofu stop by itself: it starts no further resource operations, finishes those in progress, and saves the state. The SDK emits Progress::Stopping while it waits, and Deployment::with_force_stop ends OpenTofu at once; the CLI cancels that token at a second interrupt, which its stopping notice explains. Other OpenTofu commands keep the 5-second grace. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OpenTofu 1.12.9 keeps an interrupted apply's progress only in a state directory that already holds a state file. In a new one, each update before the first write starts from an empty state, so the snapshot saved on interrupt lists only the last resource updated. An apply stopped during a managed gateway's Helm install kept the authentication binding but lost the storage binding, and plan and destroy then refused the deployment (#14155). Before an apply's first plan, the SDK now has OpenTofu create the file with a refresh-only apply, which changes no resource; creating it before the plan keeps the saved plan current. An interrupt ends that refresh after the 5-second grace that reads get. scope.md records the workaround. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a Helm install fails after Helm stored the release, for example when Helm's 600-second wait times out, the pinned Helm provider returns the error without the release's state, so OpenTofu binds nothing. Helm then refuses the name: the next apply failed with "cannot re-use a name that is still in use" after it had started, and destroy failed because authentication's removal waits for the release to go (#14155). Before an apply that installs the gateway release, the SDK now records the install in helm-install.json and keeps the record until destroy finishes. When the cluster records the release and the state does not bind it: - plan and apply stop before changing anything and name the release, as Error::LeftoverRelease when the record names it and Error::UnclaimedRelease otherwise; - destroy, when the record names the release, removes it through the Helm provider in a separate OpenTofu root under the state directory, then plans the rest of the teardown again; the preview lists the removal and why; - without a record, preview and destroy refuse before mutating and leave the release. The authentication resource's existing release observation, matched to the release's name and namespace, establishes that the record exists. The deployment's own state and graph stay as they were. docs/design/scope.md records the workaround. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Authoring session — opening
|
|
v1 documentation preview: https://nvidia-preview-nemoclaw-v1-pr-14169.docs.buildwithfern.com/nemoclaw |
The refresh-only apply that creates OpenTofu's state file before an apply's first plan ran with the deployment's configuration, so it read data sources such as data.openshell_gateway.current before the first apply had created the managed gateway. The first apply of every deployment with a managed gateway then failed with "observation transport failed"; the Live / Docker and Live / Kind checks caught it. The SDK now applies an empty configuration to create the file, before it writes the deployment's configuration and initializes OpenTofu. OpenTofu reads nothing and writes an empty state, which still avoids the 1.12.9 bug. The scripted OpenTofu now fails a refresh of a configuration that declares data sources, as OpenTofu does before the gateway exists. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The script that stands in for OpenTofu waited in an endless loop for the interrupt. A shell that starts with interrupts ignored, such as a job that a non-interactive shell runs in the background, cannot trap them, so the test hung there. The wait now ends after 30 seconds and the test fails instead. OpenTofu itself installs its interrupt handler even when it starts with interrupts ignored. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ll-recovery # Conflicts: # docs/troubleshooting.md
cv
left a comment
There was a problem hiding this comment.
Thanks for the careful write-up; the three causes are clear. I'd like to suggest a smaller shape for this change.
1. Merge the interrupt fix on its own. fix(sdk): let an interrupted apply finish the OpenTofu operations in progress stands alone and matches tofu apply: the first interrupt lets operations finish, a second stops at once. It also removes one of the three causes. It would be easier to review and land separately.
2. Let Helm clean up a failed install instead of recording it. The gateway release sets "atomic": false and "cleanup_on_fail": false (crates/nemoclaw-sdk/src/kubernetes/gateway.rs). That has been there since #12660, and I couldn't find a reason in its history or discussion. In Helm provider 3.3.0 (Helm 3.20.2), atomic sends every failed install through Helm's failure path: a hook failure, a create error, or the wait timing out. That path uninstalls the release and returns "release X failed, and has been uninstalled due to atomic being set: " (install.go). The provider still saves no state on a failed create (resource_helm_release.go), but with atomic there's no release left to bind.
A prototype on top of this branch is at proto/14169-atomic (one commit, 1b34ebc9e1):
- It sets
atomic = trueand keeps the first two fixes unchanged. - It keeps only the check that names a release the state doesn't bind, with the
helm uninstallcommand. It dropshelm-install.json, the separate OpenTofu root, and the teardown re-plan. - The third fix's production code goes from +309/-10 to +92/-1, and the whole change from +956/-58 to +809/-55. A stronger live test accounts for much of what remains.
- On kind, the extended
kubernetes_livegateway test reproduced #14155 withatomic = false(afailedrelease left behind). Withatomic = true, a refused StatefulSet, a failed pre-install hook, and the real 600 s wait timeout each left no release and no binding. The namespace, key Secret, and PVCs kept their UIDs, and the next apply installed cleanly.cargo cipasses.
The trade-offs:
- After a hard stop (second interrupt, crash, SIGKILL) during the install, or if the
atomicuninstall itself fails, a release is still left. The prototype names it and gives thehelm uninstallcommand, so those rare cases need the Helm CLI. Removing it without the CLI is what the record and separate root bought. - After a timeout, the rollback removes the gateway's pods, so the error says only "context deadline exceeded". The cause stays in the namespace's events, which the prototype's
usage.mdpoints to. - A failed in-place gateway upgrade now rolls back instead of staying failed.
upgrade_install = trueisn't an alternative: Helm refuses to upgrade apending-installrelease, and it would take over a release by name alone.
3. Keep the missing-state-file workaround small, and report it upstream. The empty-configuration apply is a reasonable stopgap. Before it merges, it would be good to file the OpenTofu report, plus a v1 issue to remove the workaround when the pinned version fixes it. The same goes for the Helm provider not saving state on a failed create.
I couldn't find existing upstream issues for either gap.
…ll-recovery # Conflicts: # docs/references/cli.md
|
Thanks, Carlos, for the review and the prototype. I agree with all three points:
From a first look, both upstream gaps are regressions: OpenTofu since v1.11.0 (opentofu/opentofu#3110), and the Helm provider since 3.0.0, where 2.x saved a failed release as tainted (hashicorp/terraform-provider-helm#727). The Helm one only shows up as a comment on hashicorp/terraform-provider-helm#1665. |
Prototype: replace the install record and destroy's removal of a leftover release with the Helm provider's atomic option. With atomic, Helm uninstalls a release whose install fails or whose wait times out before the Helm provider 3.3.0 returns, so a failed apply leaves no release that the state does not bind, and the error keeps Helm's reason. A hard stop during the install (a second interrupt, a crash, SIGKILL) can still leave the release pending-install; plan, apply, and destroy name it as Error::UnboundRelease before they change anything, and leave it. This drops helm-install.json, the separate OpenTofu root that removed the release, and destroy's second teardown plan. Refs #14155
…progress (#14224) ## Failure On an interrupt, an apply or destroy sent SIGINT to OpenTofu and killed it 5 seconds later, even when OpenTofu was still waiting for a resource operation in progress. On a managed Kubernetes or OpenShift gateway, that operation is often the Helm provider's install, which waits up to 600 seconds for the gateway and can't be cancelled: the provider runs Helm without a context (hashicorp/terraform-provider-helm#776, closed without a change). The kill then left the gateway's Helm release `pending-install` in the cluster without a binding in the state, which no later apply or destroy could recover (#14155, run r5). ## Decision After the first interrupt, an apply or destroy lets OpenTofu finish the resource operations in progress and save the state: OpenTofu's own interrupt handling stops it from starting new ones. The CLI shows a durable stopping notice that says how to stop at once, and a second interrupt (`Deployment::with_force_stop`) does. Other OpenTofu commands keep the 5-second grace. This matches `tofu apply`, where the first interrupt lets operations in progress finish and a second stops at once. Split from #14169, as its review suggested; #14169 carries the same two commits until this merges. `test(sdk): end the interrupted apply test's wait after 30 seconds` keeps the interrupt test from hanging where a shell starts with interrupts ignored. Refs #14155 ## Validation - `cargo ci` on macOS arm64 at 6f9bbba: every step passed, including 1771 tests in the test step and 101 in the lifecycle step. Live / Docker and Live / Kind run only on Linux, in this pull request's CI. - The behavioral tests were written first in #14169, where each failed before the fix: - `process::tests::an_interrupted_apply_waits_until_opentofu_exits`: with the former 5-second grace, "OpenTofu was stopped before it finished the operations in progress". - `kubernetes_interruption::stopping_now_after_an_interrupt_ends_opentofu_at_once`, with a scripted OpenTofu: "the apply took 5.01s to stop after it was told to stop now"; without the new progress event, "the caller was not told that the apply is stopping". - The CLI's `stopping_is_a_durable_warning_that_says_how_to_stop_now`: no notice without the new progress arm. - The interrupt tests take just over 5 seconds each by design: they outlast the former grace. - On the single-node OpenShift 4.22.18 cluster from #14139, with #14169's bundle at 8b2e84a, which contains these commits: one interrupt during the gateway's Helm install, with the OIDC issuer reachable again 2 seconds later. The CLI printed the stopping notice, Helm's install completed after 52 seconds, and the apply stopped with exit code 130. The state bound the release; a reapply created only the remaining resources, and the agent replied. - `v1` moved `docs/reference/cli.md` to `docs/references/cli.md` since #14169 began; the cherry-pick keeps both interrupt sentences with `v1`'s new link, as #14169 does after its merge of `v1`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ll-recovery Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for taking all three points on; the OpenShift runs are convincing. Three things before this can merge:
|
…ll-recovery v1 deleted the Rust gateway live test that carried the atomic install's refused-install check; the next commit moves that check into the kind-kubernetes-development case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Rust gateway live test that v1 retired carried the atomic install's check: an install refused after Helm stored the gateway release must leave no release record or binding. The kind-kubernetes-development case now runs it between destroy and redeploy. The hcl_live::admission probe creates a ValidatingAdmissionPolicy that refuses StatefulSets in the case's namespace and waits until the API server enforces it; the CLI's apply must then fail with the refusal. Once the probe removes the policy, no record of the release may remain and the state must still bind the retained storage but not the release, and the redeploy shows that storage was kept. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each workaround now names the upstream issue it waits for and the v1 issue that tracks removing it. Refs #14155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Carlos. All three points are addressed |
Bundles now pin OpenTofu 1.12.12, which keeps the resources that a killed first apply saved in its state, so the SDK no longer creates the state file with a refresh-only apply before a deployment's first apply. ## Problem In a new state directory, OpenTofu 1.12.9 saved each in-progress snapshot with only the latest change, so a first apply that was killed after a snapshot lost the bindings of the resources it had created before ([opentofu/opentofu#4809](opentofu/opentofu#4809)). #14169 worked around it by having OpenTofu create the state file before the first plan. OpenTofu 1.12.12 fixes the bug ([opentofu/opentofu#4811](opentofu/opentofu#4811), backported to 1.12 in [opentofu/opentofu#4813](opentofu/opentofu#4813)). Part of #14227: this completes its OpenTofu items. The Helm provider items stay open until hashicorp/terraform-provider-helm#1886 is fixed. ## Change - `versions.json` pins OpenTofu 1.12.12 for all five platforms, and the nine HCL test modules require it. Each archive's SHA-256 matches the release's `SHA256SUMS`, whose signature verifies with OpenTofu's signing key, and GitHub's asset digests. The pin stays on 1.12; 1.13 has breaking changes. - The SDK drops `create_state` and its call before `initialize`. Only that step ran an `apply -refresh-only`, so the CLI's "Creating infrastructure state" step and the 5 s grace for an interrupted refresh-only apply go too, along with the scripted OpenTofu's refresh-only handling. - `kubernetes_interruption::a_first_apply_starts_opentofu_with_a_state_file` checked the workaround against a script. The integration test `multi_agent::killed_apply::a_killed_first_apply_keeps_a_binding_for_every_object_it_saved` replaces it: through the bundled OpenTofu, a first apply of three agents saves a snapshot after one sandbox finishes, OpenTofu is killed while the other two are still being created, and every workspace, provider, and sandbox that the fixture gateway created must have a binding in the state. The OpenShell fixture gains `sandbox_create_permits` to hold sandbox creations. - The test takes about 22 s: OpenTofu saves a snapshot at most every 20 s, and an interrupt can't trigger one here, because the Rust providers exit on the interrupt and OpenTofu then writes the complete state at exit. - It kills OpenTofu's process group without an interrupt, so it runs on Unix only. Stopping through the SDK sends an interrupt first, and killing OpenTofu right after one can catch it while it rewrites the state file. - `internal-docs/design/scope.md` drops the workaround's entry. ## Beyond CI - The new test fails on OpenTofu 1.12.9 without the workaround, losing the workspace and provider bindings (`id-1`, `id-3`), and passes on 1.12.12 without it, including 8 copies run in parallel on linux_arm64.
…ms (#14413) The release notes now list every user-visible change on `v1` since the `v0.1.0-rc9` tag, including the breaking ones, and four example pages drop claims that later changes made false. ## Problem `docs/about/release-notes.md` listed three breaking changes and none of the features, fixes, and onboarding changes that reached `v1` after `v0.1.0-rc9`; it didn't name the configuration shapes the parser now rejects or the intent record version `v0.1.0-rc9` writes. Some example claims went stale: - `examples/spark/README.md` said the pinned OpenShell has the Podman TLS initialization blocker, ai-openshell/openshell#3427; its fix merged before OpenShell 0.1.0, and `v1` pins 0.1.7. - `examples/station/README.md` and `examples/gtc-dc/README.md` required exactly one visible GPU on the host; since #13929, `container.gpuDevices` lets a service on a host with more GPUs request one. - `examples/hcl/travel-team` said Fabric's Deep Agents adapter can't turn reasoning off, NVIDIA/NeMo-Fabric#433; NVIDIA/NeMo-Fabric#439 fixed that, and the pinned catalog's Deep Agents `reasoning_effort` accepts `none`. - The travel team cited #13313 for the booking key its service doesn't receive, but #13313 closed when `openshell_api` landed. ## Change - `docs/about/release-notes.md` gains "Changes Since v0.1.0-rc9", grouped by area, from the commits in `v0.1.0-rc9..origin/v1`; where a later commit changed an earlier one, the entry describes the current code, and changes added and removed after the tag aren't listed: - Agents and interfaces: #14037, #14038, #14269, #13981, #14024, #14186, #14052, #14385, #13971, #13858, #13947, #14039, #14042, #14044, #14343. - Inference: #13929, #14391, #14396, #14398, #14400, #13963, #13912, #13964, #14388, #14390, #14397. - Gateways and Kubernetes: #13909, #13970, #13922 (an existing namespace, refused at plan by #13756, is now bound; cluster-wide reads dropped), #14014, #14169, #13921. - Plan, apply, and diagnostics: #14224, #13756, #14141, #14133, #14135, #13775, #13744, #13701. - Onboarding: #13693, #13695, #13741, #13757, #13851, #13978, #14228, #14233, #14334, #14336. - Examples and builds: #14166, #14184, #14188, #14191, #14192, #14200, #13889, #14267, #14312, #14315, #14355, b30e9b4, #13781, #13813, #14246, and the pins in `versions.json` and `image/fabric/Dockerfile`. - Its breaking changes since the tag: - the intent record moving from 15, which `v0.1.0-rc9` writes, through 16 (#14266), 17 (#14343), 18 (#13929), 19 (#14391) and 20 (#14394); - name-keyed `sandboxes` and `inferenceProviders` (#13703, #13705); - a recipe `compatibility.gpu` outside every hardware profile (#13912); - model tuning the adapter doesn't accept (#14111), and Hermes's `max_tokens` losing its default (#14296); - `skills.paths` resolution (#14296); - endpoint and `networkCIDR` validation (#13847, #14081); - the HCL `gateway_values` attribute (#14014), and Kubernetes ownership receipts from before #13922 and #14014. The two earlier items stay, under their own heading. - `examples/spark/README.md` replaces the closed OpenShell#3427 blocker with the Podman and remote-model limits in `docs/resources/limits.md`. - `examples/station/README.md` and `examples/gtc-dc/README.md` require one GPU visible in the model container, and point to `container.gpuDevices` for a host with more. - `examples/hcl/travel-team/README.md` and `WALKTHROUGH.md` drop the NeMo-Fabric#433 limitation, and the travel team's booking-key statements link #14417 instead of #13313. Not listed, because both changes landed after the tag: Deep Agents Code (#14043, #14250), `compatibility.gpuCount` (#14391, #14394), and the "Creating infrastructure state" progress step (#14169, #14248). Checked and left unchanged: the root `README.md`, `crates/nemoclaw-onboarding/README.md`, `crates/nemoclaw-cli/assets/README.md`, `internal-docs/README.md`, the other example READMEs, and every example YAML header comment. The GPU autoscaling README and `load.sh` read the JSON fields `OperationResult` serializes, and ai-openshell/openshell#4287 is fixed only after the pinned 0.1.7. The two pre-tag release-note items still match the schema and SDK. `docs/README.md` is left to #14412, which retires the stale field reference snapshot it describes. Not verified: whether Hermes sends the booking key's placeholder to MCP servers; #14417 tracks the live check. ## Beyond CI Each relative link and anchor in the changed files resolves to an existing file and heading.
Managed Kubernetes and OpenShift gateways recover from an install that fails: Helm removes the failed release itself, a release that a stopped install leaves is named with the command that removes it, and an interrupted first apply keeps the bindings it created.
Problem
An apply that failed or was interrupted while Helm installed the gateway release left a deployment that neither apply nor destroy could recover (#14155):
failedin the cluster, but the pinned Helm provider (3.3.0) returned the error without saving the release in the state. The next apply failed withcannot re-use a name that is still in use, and destroy failed withobservation is incomplete; onlyhelm uninstall, then destroy and apply, recovered the deployment.Resolves #14155, with #14224, which lets the first interrupt finish the operations in progress.
Change
The gateway release sets
atomic: when its install fails or Helm's wait times out, Helm uninstalls the release before the Helm provider returns, and the error carries Helm's reason. The namespace, the credential key, and the gateway's volume claims stay. A failed upgrade now rolls back, ashelm upgrade --atomicdoes.A second interrupt, a crash, or a killed process can still stop the install and leave the release
pending-install. When the cluster records the gateway release and the state does not bind it, plan, apply, and destroy stop before changing anything, name the release, and give itshelm uninstallcommand (Error::UnboundRelease). NemoClaw can't tell that release from another owner's, so it leaves it.The
kind-kubernetes-developmentlive case refuses the gateway's StatefulSet with an admission policy between its destroy and redeploy (thehcl_live::admissionprobe): the install must fail with the refusal, leave no record of the release, and keep the retained storage bound. It replaces the same check in the Rust gateway live test that test(contract): render the pinned gateway chart with tofu test #14174 retired.When the state file is missing, a refresh-only apply of an empty configuration creates it before the first plan, which avoids the OpenTofu bug without reading the deployment's data sources before the managed gateway exists.
Rejected: the first version of this pull request recorded each install in
helm-install.jsonand let destroy remove a leftover release through a separate OpenTofu root;atomiccovers the common failures with much less code.upgrade_installdoesn't help: Helm refuses to upgrade apending-installrelease, and it would take over a release by name alone.Upstream boundaries: Helm's own
atomicoption removes a failed install, the existing authentication observation establishes that a release record exists, and NemoClaw removes no release that it can't establish as its own.internal-docs/design/scope.mdrecords both workarounds:atomicand the unbound-release check, until the Helm provider saves a failed install as tainted again, helm_release: a failed install is no longer saved as tainted, so the next apply fails with "cannot re-use a name that is still in use" hashicorp/terraform-provider-helm#1886 (since 3.0.0).Remove the Helm provider failed-install workaround when the pinned provider saves a failed install as tainted (hashicorp/terraform-provider-helm#1886) #14227 tracks removing both.
Beyond CI
On the single-node OpenShift 4.22.18 cluster from #14139, with this branch's bundle at 06be60b, which already carried #14224's change, and the document from #14155's runs (OIDC profile, one OpenClaw sandbox):
pending-installwithout a binding while the state kept storage and authentication. Plan and destroy stopped within 5 seconds, named the release and itshelm uninstallcommand, and left the release records unchanged. After that command, apply completed in 67 seconds, and the agent replied.