Repository navigation
test: pin recovery from interrupted and failed Kubernetes operations - #13081
Merged
Merged
Conversation
Check what the SDK saves, refuses and recovers when a managed Kubernetes apply or destroy is cancelled or fails. SDK tests run Deployment over a scripted OpenTofu: the unfinished-apply record and the refusals that follow it, the error class of a failed gateway connection, and the retry of an interrupted destroy, which must not reconnect, must refuse lost state, and must not apply a plan that deletes retained storage. e2e tests run destroy through the bundled OpenTofu and Helm provider under a deleted or truncated receipt, a Helm release record without a binding, a 401, a repeat, and a cancel at the first refresh. Refs #12731 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
v1 documentation preview: https://nvidia-preview-nemoclaw-v1-pr-13081.docs.buildwithfern.com/nemoclaw |
6 tasks
cv
added a commit
that referenced
this pull request
Oct 13, 2026
`v1` no longer compiles the SDK integration tests, so `cargo ci` and the Rust desired-state workflow fail at clippy on every platform except Windows. ## Why #13056 removed `Copy` from `ObservationError` to carry bounded rejection text. #13081 merged after it with `assert_failed_connection_keeps_its_class`, which passes its `class` argument by value twice: ``` error[E0382]: use of moved value: `class` --> crates/nemoclaw-sdk/tests/kubernetes_interruption.rs:431:9 ``` ## Change Clone `class` for the first assertion. No production code changes. ## Validation - `cargo test -p nemoclaw-sdk --test integration kubernetes_interruption`: 12 passed. - `cargo ci` on linux_arm64: all steps passed.
cuongdangn
added a commit
that referenced
this pull request
Oct 13, 2026
…it (#13101) Fixes the compile error that makes `Build and test` fail on `v1`. `kubernetes_interruption.rs`, added in #13081, reuses an `ObservationError` that #13056 made non-`Copy`; the helper now clones it. Production code is unchanged. ## Failure `cargo ci clippy` fails on `v1` with E0382, `use of moved value: class`, at `crates/nemoclaw-sdk/tests/kubernetes_interruption.rs:431`. `Build and test` fails on `linux_amd64`, `linux_arm64` and `darwin_arm64` in the `Rust desired-state` push runs for `922a0c0f6f`, `e42f120617` and `2319d4fd79`. The run for #13081's merge commit `ae914f26a8` was cancelled. #13056 made `ObservationError` `Clone` but no longer `Copy`. #13081 added `assert_failed_connection_keeps_its_class`, which passes its `class` argument by value to `assert_observation` twice. The CI of #13081 finished before #13056 merged, so neither pull request's CI ran with both changes. ## Decision The helper clones `class` for its first call, as the compiler suggests and #13056 prescribes for code that copied the value. The other call sites build the value inline and do not change. ## Validation Run on `89b74d4e46`, based on `v1` at `2319d4fd79`, macOS arm64. - Before the change, `cargo test --locked -p nemoclaw-sdk --test integration --no-run` fails with the same E0382 on `2319d4fd79`. - `cargo ci` passed (610 s): fmt, clippy, build, test (1397 passed), schema, bundle and lifecycle (136 passed). - The 12 `kubernetes_interruption::` tests pass after the change. - Linux and the live steps were not run locally; CI covers them. `linux_arm64 / Live / Kind` also failed on #13056's own push run (`5b93c969f3`), in `kubernetes_live::on_openshift_the_sandbox_runs_as_the_namespace_uid`, a test this change does not touch. Refs #12731 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
gaveezy
added a commit
that referenced
this pull request
Oct 13, 2026
PR-7 now includes v1 2319d4f, which contains the squash-merged PR-1 to PR-4, #13081's Kubernetes interruption and Helm recovery tests, and #13032's documentation change. docs/contributing/integration-tests.md conflicted in the system test table: #13081 rewrote the `helm_recovery` row next to the `cluster_credentials` row that PR-8 adds. The resolution keeps #13081's row and PR-8's row. testing.md and the `lifecycle` nextest filter merged cleanly and already select #13081's tests: `helm_recovery::` covers its new submodules, and its SDK tests run in the `test` step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cv
added a commit
that referenced
this pull request
Oct 13, 2026
`deployment.rs` and `scripted_tofu.rs` now share one test bundle writer. Stacked on #13112. ## Why Both tests wrote a bundle whose manifest verifies. `scripted_tofu.rs` (#13081) kept a copy of `deployment.rs::write_bundle` that differed only for `libexec/tofu`, because `deployment.rs` also runs on Windows and the scripted copy needs Unix. ## Change - `tests/support/bundle.rs` adds `write_bundle(directory, tofu: Option<&str>)`. Without a script, every file is a non-executable fixture. With one, `libexec/tofu` is that script, written with `write_executable` from #13111. Passing a script on a platform other than Unix panics. - `deployment.rs` and `scripted_tofu.rs` call it and drop their own copies. I left two other duplicates alone: - `Events` in `nemoclaw-e2e/tests/helm_recovery.rs`, which is two methods long. - `Snapshot` there and `Untouched` in `kubernetes_interruption.rs`, which check different state. Both sit in other crates, so sharing them would mean adding them to `nemoclaw-test-fixtures` for little gain. ## Validation - `cargo test -p nemoclaw-sdk --test integration`: 444 passed. - `cargo ci` on linux_arm64: all steps passed. GitHub CI checks the Windows build of `deployment.rs`; I couldn't cross-compile it here.
cv
added a commit
that referenced
this pull request
Oct 13, 2026
Removes the mutex that made scripted OpenTofu tests run one at a time. Stacked on #13111. ## Why `scripted_tofu.rs` (#13081) held a process-wide `ONE_AT_A_TIME` mutex for each `Scripted` fixture. Its comment gave the reason: a child that another thread forks while `Deployment` holds its lock file keeps the lock until it calls exec, so the next operation could find the deployment locked. #13056 fixed that cause in `Store::drop`, which now unlocks the file explicitly, so the lock is released when an operation ends even if a child still holds a copy of the descriptor. Nextest already runs each test in its own process. The mutex only slowed `cargo test`, which runs tests as threads of one process. ## Change Remove `ONE_AT_A_TIME` and the guard that `Scripted` held. ## Validation - `cargo test -p nemoclaw-sdk --test integration`: 12 rounds passed. The binary takes about 5 s instead of about 17 s. - `cargo test -p nemoclaw-sdk --test integration kubernetes_interruption -- --test-threads=32`: 20 rounds passed. - `cargo ci` on linux_arm64: all steps passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds 19 tests for a managed Kubernetes deployment whose apply or destroy is cancelled or fails part-way: 12 in the SDK's
integrationbinary, which runDeploymentover a scripted OpenTofu, and 7 innemoclaw-e2e'shelm_recoverymodule, which rundestroythrough the bundled OpenTofu and Helm provider. They cover scenarios 5, 6 and 7 and the deleted-receipt half of 4 on the list in #12731. Scenarios 1 to 3, 8 to 11 and the corrupt-receipt half of 4 are in #12825 and #12909; scenario 12 (live) is not in this change. Production code is unchanged.docs/contributing/testing.mdandintegration-tests.mddescribe the new tests.Failure
A Kubernetes apply or destroy can stop after OpenTofu has created or deleted resources: the user cancels, OpenTofu fails, or the host exits.
docs/design/scope.mdsays the SDK then refuses what it cannot verify, keeps enough state to recover, and keeps retained storage. #12731 asks for tests of these rules. Each item names the regression a test is written to catch.SDK tests, apply:
SDK tests, destroy:
e2e tests, destroy:
Decision
The SDK alone decides the stage order, the unfinished-apply and unfinished-destroy state it saves, and what it refuses, so its rules are tested without OpenTofu.
tests/support/scripted_tofu.rswrites a bundle whose manifest verifies and whoselibexec/tofuis a short shell script. The script logs each call, replays cannedshow -jsonstate and plans, and ends an apply as a control file says: succeed, fail, or block until the SDK interrupts it. A test cancels at a chosen progress event, then asks the public operations what the SDK kept. It compares the saved record's text before and after and decodes the record only for the resource generations that canned bindings must carry. These tests run in theteststep and need no bundle.What depends on OpenTofu and the providers (refresh, plan, state persistence, the Kubernetes provider's own observations, the Helm provider's handling of a rejected lookup, interrupts) cannot be scripted honestly, so the e2e tests run against the bundled ones and the in-memory Kubernetes API that the module's five tests already use. The harness gains a request log, a 401 fault (on every request, or on ConfigMap reads only),
prepare()andimport_release()that splitcreate(), and aSnapshot. TheSnapshotcompares the OpenTofu state's resources and lineage, the bindings, the cluster objects, the durable files, the receipt's bytes, and the writes the cluster received whether or not a fault rejected them, so a delete sent under a 401 shows. The tests copy, delete, truncate and restore the receipt's bytes and never decode it, and they read nointent.json. Each test that makes destroy fail or stop ends by removing the cause, if any, and running destroy again, which must finish. The five existing tests keep their assertions; they now read the write count from the request log and use the newfailing_after_planandassert_export_refusedhelpers.These are characterization tests: they pass on unchanged production code, so there is no failing test to observe first. Mutation probes (below) show that each test fails when the behavior it guards breaks.
Coverage
SDK,
crates/nemoclaw-sdk/tests/kubernetes_interruption.rs(12 tests, names shortened):cancelling_the_first_kubernetes_runtime_apply_...a_failed_first_kubernetes_runtime_apply_...a_revised_document_after_an_interrupted_kubernetes_apply_...cancelling_before_the_runtime_mutation_...cancelling_an_unchanged_kubernetes_runtime_apply_...cancelling_between_the_stages_..._while_the_cluster_is_silent_...a_missing_kubeconfig_...,a_missing_receipt_...,a_refused_connection_...Authentication,Incomplete,Transport), no OpenShell stage starts, and a revised document is not refused as unfinishedan_interrupted_kubernetes_destroy_blocks_apply_and_its_retry_...a_kubernetes_destroy_retry_is_refused_when_the_runtime_state_was_losta_kubernetes_destroy_plan_that_deletes_retained_storage_...e2e,
crates/nemoclaw-e2e/tests/helm_recovery/(7 tests, names shortened):receipt::a_deleted_or_truncated_receipt_stops_destroy_while_planning_...release_record::destroy_keeps_the_issuer_while_a_release_record_has_no_binding_...destroy_faults::a_second_destroy_after_completion_...destroy_faults::an_authentication_failure_before_planning_...destroy_faults::an_authentication_failure_after_the_saved_plan_...destroy_faults::an_authentication_failure_reading_the_issuer_...destroy_faults::cancelling_at_the_first_refresh_...Cancelledwith a healthy API and returns well before an unreachable API would fail the refresh; state, bindings, objects and writes are unchangedValidation
Run on
3a00cbda0e, based on v1 at29bb057949, macOS arm64.cargo ci: passed in 478 s: fmt, clippy, build, test (1356 passed), schema, bundle and lifecycle (134 passed).cargo ci(budgets apply on Linux CI only): theteststep took 29.0 s for 1356 tests (budget 45 s), and the 12 SDK tests sum to 32 s with 8 test threads, the slowest 4.0 s (limit 8 s). The 12 SDK tests alone run in about 5 s. In thelifecyclestep the 12helm_recoverytests sum to 63.7 s next to the other modules, the slowest 14.0 s (an existing test with an unreachable API); the new e2e tests take 2.6 to 4.4 s each.cargo run -p nemoclaw-build -- docs --checkandfern check: passed; the one fern warning also appears on v1.#![cfg(unix)]replaced by#![cfg(any())]in both new SDK files,cargo clippy -p nemoclaw-sdk --tests -- -D warningsis clean. This checks unused items and imports; it is not a Windows build./bin/sh, alinux_arm64bundle built from the same sources). Under nextest the SDK tests took 0.06 to 0.19 s each over 35 rounds without a failure, and the e2e tests 22 rounds with one failure, the cancel test at 2 CPUs under load, which led to the tolerance described below. The run also found the lock race described under Observations; this revision fixes it for the SDK tests and documents it for the e2e tests. This revision was not rerun on Linux.Mutation probes: temporary changes to production code, each reverted so the diff holds none. SDK tests: 28 changes, 27 make at least one test fail, and each of the 12 tests fails under at least one. They include a marker that is never saved, saved after OpenTofu returns, or saved after it even on failure; a marker that ignores a changed document; a settled apply that never clears the marker; a failed apply that clears it; a destroy that does not block apply, retries with a connection, applies a plan that deletes retained storage, or accepts lost state; a gateway connection that ignores a cancel, checks it only on entry, or lets the OpenShell stage run after a failure, also for a transport error; and a revision refused only when the OpenShell stage has no bindings. The survivor, a destroy that does not save its record before the stages, is equivalent for these flows: the same destroy saves it again before it returns. e2e tests: 20 changes, 17 make at least one test fail, and each of the 7 new tests fails under at least one; provider-side changes ran through a debug provider swapped into a copy of the bundle with its manifest hash updated. They include a bound storage read as absent, an unreadable receipt reported as another error class, a missing receipt recreated on read, the issuer removed while a release record exists, a delete sent before the reads, a 401 read as absence or as a permission failure, a failed issuer read taken as absence, the early return for a destroyed deployment dropped, the Helm binding restore skipped, a destroying record saved before planning, a cancel not observed while OpenTofu runs, and
applyallowed during an unfinished destroy. Three survive: an unreadable receipt read as a missing one (destroy stops either way; only the number of incomplete observations differs, which no test pins); a destroy that does not save its record before the stages (equivalent, as above); and no interrupt sent on cancel with the 5 s kill kept (see the next section).Limits of this evidence
IDs were not saved).docs/usage.md:294says that after a failed runtime apply, revised intent or teardown can proceed, which this rule refuses, anddocs/troubleshooting.md:41names a message that no code emits; both are corrected separately..terraform.tfstate.lock.info, which the file comparison ignores, so a regression that stops sending the interrupt but keeps the kill is not detected. If the refresh's own timeout fell below the bound, the unreachable row would stop testing the cancel. OpenTofu may also persist its state when interrupted (the serial rises and the check results are re-sorted), so the state comparison covers resources and lineage, not bytes.cfg(unix), so Windows runs none of them. Linux amd64 was not run. Not covered: a cancel during the OpenShell stage, destroy with the gateway down, a delete that Kubernetes rejects part-way, and the live cluster behavior of scenario 12.Observations for maintainers
Destroyed, uninstalls the Helm release, retires the authentication resource without deleting anything, and leaves the six issuer objects in the cluster. The receipt records none of them, and a second destroy reports nothing. An unrecorded issuer is not confirmed absence, so this looks like a defect; no test pins it.plan_destroylists the issuer's removal, anddestroythen stops before deleting it. The preview does not run the removal's own checks.Progress::MutationStartedis emitted for everytofu apply, including the destroys above that delete nothing, and as soon as the process exists, before it prints anything, so a cancel at that event interrupts the child before it writes. The SDK tests cancel at the first resource event instead.cargo test, which runs tests as threads of one process, a child that one thread forks keeps another test's deployment lock until it executes. On Linux the 9 SDK tests of an earlier revision then failed with "another operation holds the deployment lock" in 14 of 50 rounds, and the five existing e2e tests alone in 1 of 10 rounds at 5 threads (the twelve in 7 of 10 at 12 threads); macOS and nextest, which runs each test in its own process, showed none. A process-wide mutex now serializes the scripted SDK tests, and the documented e2e command passes--test-threads=4. The durable fix is to release the lock whenStoredrops, which the draft [tracking] feat(kubernetes): manage vLLM and Ollama services (split) #12736 adds.tokio::select!picks the failure or the cancel at random. The SDK test of a cancel during the connection therefore seeds a receipt and cancels once the cluster has accepted the request.Refs #12731
🤖 Generated with Claude Code