Skip to content

fix(sdk): classify 401 and 403 in Kubernetes storage preparation - #12825

Merged
cv merged 4 commits into
v1from
fix/12731-classify-storage-auth-failures
Oct 8, 2026
Merged

cv merged 4 commits into
v1from
fix/12731-classify-storage-auth-failures

Conversation

@cuongdangn

@cuongdangn cuongdangn commented Oct 8, 2026 •

Copy link
Copy Markdown

A rejected Kubernetes credential (HTTP 401) or a missing permission (HTTP 403) during the first apply is now reported as an authentication or permission failure, not as a transport failure.

Failure

Before it creates anything, the first apply makes four reads against the cluster. Two of them, in crates/nemoclaw-sdk/src/kubernetes/storage.rs, mapped every kube::Error to ObservationError::Transport:

  • identity() reads the kube-system namespace.
  • default_storage_class() lists StorageClasses.

With an expired or unauthorized kubeconfig token the server answers 401 or 403, and the user saw "observation transport failed". That message points at the network, but the credential or the RBAC role needs fixing. The Agent Sandbox probe between these two reads already classifies the same statuses through failure() in cluster.rs.

Decision

In these two reads only, HTTP 401 is Authentication and HTTP 403 is Permission. Every other failure, including a dropped connection and other HTTP statuses, is still Transport. A private read_failure(kube::Error) holds the mapping.

failure() is unchanged. Reusing it would also move other statuses from Transport to Query (and 409 to BindingMismatch), which this change does not need. No test pins those statuses.

Validation

Six tests in crates/nemoclaw-sdk/tests/kubernetes_storage.rs fail one request each, the identity read and the StorageClass list, with a 401, a 403 or a dropped connection. Each asserts the exact error, that the faulted request was made, that the cluster is unchanged, and that only GET requests were sent. The identity tests also assert that no receipt was written. The StorageClass tests do not assert on the receipt, because ensure_storage binds it before that read.

Red, on the unchanged production code: the four 401 and 403 tests failed on the class assertion, for example left: Err(Transport), right: Err(Authentication). The two dropped-connection tests passed; they pin the Transport behavior this change must keep.

Green, with the fix:

  • cargo test --locked -p nemoclaw-sdk --test integration -- kubernetes_storage::: 11 passed (6 new, 5 existing). The 6 new tests also passed 15 consecutive runs.
  • cargo test --locked -p nemoclaw-sdk --test integration -- kubernetes_: 83 passed, 6 ignored.
  • cargo test --locked -p nemoclaw-sdk --lib: 197 passed, 8 ignored.

cargo ci passed on 03295efa5f (darwin_arm64, 553 s), the branch head after the latest merge of v1: fmt, clippy, build, test (1245 passed), schema, bundle and lifecycle (108 passed). It also passed on 9e2fe2c6c5, before the first merge of v1.

Limits of this evidence: the fake Kubernetes API over plain HTTP shows how the SDK classifies the statuses it serves. It does not show real RBAC, TLS, token validation, or the kube client's retry of 429, 503 and 504. A credential that cannot be refreshed before the request is sent, such as a failing exec plugin, is not an API error and still reads as Transport here and in failure(). The tests ran on macOS arm64 only; they use no Unix-only API, but Windows was not run locally.

Refs #12731. This is one of several changes for that issue and does not close it.

🤖 Generated with Claude Code

cuongdangn and others added 2 commits October 8, 2026 17:13
The first apply reads the kube-system namespace and lists
StorageClasses before it creates anything. Both reads mapped every
Kubernetes error to a transport failure, so a rejected credential
(HTTP 401) or a missing permission (HTTP 403) was reported as
"observation transport failed" and sent the user to check the network.

Report a 401 as an authentication failure and a 403 as a permission
failure in these two reads. Every other failure, including a dropped
connection and other HTTP statuses, is still a transport failure.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@cv
cv merged commit 4ff1756 into v1 Oct 8, 2026
18 of 19 checks passed
@cv
cv deleted the fix/12731-classify-storage-auth-failures branch October 8, 2026 17:56
cv pushed a commit that referenced this pull request Oct 12, 2026
…12909)

Adds 40 tests: 30 for how the SDK's Kubernetes operations behave when
the cluster API fails or an earlier run was interrupted, 8 for the fault
helper that they use, and 2 for document validation and the plan check.
It also renames and extends one OpenTofu test. Together they cover
scenarios 2, 3, 8, 9, 10 and 11, and the corrupt-receipt half of 4, on
[the list in
#12731](#12731 (comment));
scenario 1 is done in #12825. Scenarios 5, 6, 7 and 12 and the
deleted-receipt half of 4 are not in this change. Production code is
unchanged; `src/deployment/plan.rs` gains only a `#[cfg(test)]` module.

## Failure

Applying the storage and authentication resources creates a Namespace, a
KEK Secret and a development issuer (six objects) in the user's cluster
and records each by UID in a local receipt.
`docs/design/architecture.md` says a failed or incomplete observation
stops and preserves the prior binding, and that ownership is checked
during observation and again before mutation. #12731 asks to verify that
authentication, transport and incomplete-observation failures preserve
resource bindings and persistent state, and that ownership is verified
before recovery changes resources. The tests group this as three
invariants, each with a regression they are written to catch:

- A failed observation is not confirmed absence. A read error turned
into `None` would pass as absence (the gateway StatefulSet, an issuer
object during teardown, the Agent Sandbox CRD), and an answer without a
`uid` would pass as an identity.
- Ownership is verified before mutation. A re-run after a lost create
response could delete, replace or adopt an unrecorded object, and a
changed OpenShift UID or group range could let a re-apply write issuer
objects.
- Persistent state is retained. A corrupt receipt could be replaced or
deleted, expired development certificates could be regenerated, and a
plan that replaces a bound resource could be accepted.

## Decision

Most tests call `Operations` and `Development` against the fake
Kubernetes API that SDK tests already use, wrapped by
`tests/support/kube_faults.rs`. A rule decides per request whether to
fail it with an HTTP status or a dropped connection, to apply a write
and then drop the connection (a lost response), or to apply it and
answer without the object's `uid`. The wrapper logs every request, and
`Snapshot` compares the cluster objects and the contents of every state
file before and after. `check_plan` and document validation are tested
directly. `kube_api.rs` changes only by making `status` public. The
older fault tests in `kubernetes_storage.rs` and
`kubernetes_operations.rs` keep their own fixtures; moving them onto
`kube_faults.rs` is a separate change.

The tests are characterization tests: they pass on the unchanged
production code, so they pin current behavior and need no production
change. No behavior changes, so there is no failing test to observe
first; instead, temporary changes to production code show that the tests
fail when the behavior they guard breaks (see Validation). Where
production is inconsistent, a test pins what it finds and says so: a 500
on the kube-system read and on the StorageClass list is `Transport`,
where the other reads report `Query`.

## Coverage

Paths are under `crates/nemoclaw-sdk` unless noted. Scenario numbers are
those on #12731.

| File | Scenarios | Tests | Covers |
|---|---|---|---|
| `tests/support/kube_faults.rs` | helper | 8 | Fault server, request
log, `Snapshot`, platform fixtures |
| `tests/kubernetes_read_failures.rs` | 2 | 16 | Platform reads under
401, 403, 500 and a dropped connection (#12825 covers the kube-system
and StorageClass reads for 401, 403 and a dropped connection); answers
without a `uid`; a client TLS Secret missing one entry |
| `tests/kubernetes_lost_create_response.rs` | 3 | 8 | Re-run after a
lost create: Namespace, KEK Secret, six issuer objects |
| `tests/kubernetes_corrupt_receipt.rs` | 4 (corrupt receipt) | 2 |
Truncated JSON and an unknown field, in every operation that reads the
receipt |
| `tests/kubernetes_expired_authentication.rs` | 9 | 2 | Expired
development certificates in `Development` and `Operations` |
| `tests/kubernetes_openshift_reapply.rs` | 10 | 2 | Re-apply after
authentication is removed, with a changed or missing UID or group range,
and an unchanged control |
| `tests/deployment.rs` | 8 | 1 | An invalid document stops `plan` and
`apply` before the bundle opens or state is created |
| `src/deployment/plan.rs` | 11 | 1 | `check_plan` rejects replacing a
bound platform resource |
| `crates/nemoclaw-e2e/tests/provider_protocol.rs` | 11 | 0 (1 extended)
| OpenTofu taints a create that returns state with an error and plans
delete plus create |

## Validation

Run on `0906b1b03d`, based on `v1` at `a46f63be1d`, darwin_arm64:

- `cargo fmt --check` and `cargo clippy --locked --workspace
--all-targets -- -D warnings`: clean.
- The 40 new tests (39 in the `integration` binary, 1 in the library
unit tests) under `cargo nextest run --locked --profile ci -p
nemoclaw-sdk`, filtered to them: 40 passed in each of 5 consecutive runs
and in 3 runs with all 40 at once (`--test-threads 40`).
- `NEMOCLAW_TEST_TOFU=<absolute path to dist/darwin_arm64/libexec/tofu>
cargo test --locked -p nemoclaw-e2e --test integration
provider_protocol::real_tofu -- --ignored`: 3 passed, including the
extended test. `tofu version` reports OpenTofu v1.12.6. The `lifecycle`
step of `cargo ci` runs all of `provider_protocol`, including these
three.
- Windows approximation: with `cfg(unix)` forced false in the SDK tests,
`cargo clippy -p nemoclaw-sdk --tests -- -D warnings` is clean and the
11 tests that remain pass. This checks unused items and imports; it is
not a Windows build.
- `cargo ci`: passed on `0906b1b03d` (856 s): fmt, clippy, build, test
(1311 passed), schema, bundle and lifecycle (112 passed).

Mutation probes: 25 temporary changes to production code, each reverted
so the diff holds none. Each made at least one new test fail, and every
new test outside `kube_faults.rs` failed under at least one of them.
They include a read error mapped to `None`, a 409 on create mapped to
`Query`, a re-run that adopts, or deletes and re-creates, the object
that a 409 reports, a 401 mapped to `Query`, a receipt that does not
parse treated as empty, the certificate validity check ignored, expired
material regenerated, a changed OpenShift identity accepted, a
StatefulSet or cluster identity without a `uid` adopted, a failed read
mapped to `Incomplete` at each of five reads, `connect` writing the
private key first, validation errors ignored, and `check_plan` relaxed
for every provider resource.

## Limits of this evidence

- The fake API serves plain HTTP on loopback. It does not show RBAC,
TLS, token validation, how an API server answers, or the kube client's
retries of 429, 503 and 504, which are not injected. A response cut off
mid-body is not covered. The OpenShift tests write the range annotations
themselves.
- No faulted read is retried after its fault clears, and no test shows
how an operator recovers from a refusal. The controls in the
lost-create, OpenShift and expiry tests (unrecorded object removed,
ranges unchanged, a certificate window that has not ended) show only
that each refusal comes from its stated cause.
- The answers without a `uid` are synthetic: an API server assigns every
object a `uid`. They show that the SDK refuses to record or adopt such
an answer, not that one occurs. The client TLS Secret that lacks a key
is stored in the fake API; whether the chart can leave one out is not
tested.
- Three reads of a path that a call reads more than once (two OpenShift
Namespace reads and the second StatefulSet read in teardown) are chosen
by the request before them. A change that puts another request in
between makes those tests fail with "the fault must fire exactly once".
- The expiry tests rewrite certificates for the same keys with a window
in the past, because the SDK reads the system clock and offers no way to
set it. Only the combined expiry of the CA and server certificates is
covered; a CA that expires alone, and how the gateway behaves with
expired certificates, are not.
- The OpenTofu test uses the fixture provider, so it shows OpenTofu's
behavior only; no test here drives the Kubernetes provider's own partial
create. Reading the code, not running it: when a create fails after the
receipt records an object, `KubernetesBackend::ensure` returns that
object's identity with the error, OpenTofu taints the instance, and
`nemoclaw apply` stops at the plan check before it reaches the refusal
that the lost-create tests pin.
- Windows was not run locally. Windows CI (`Test / windows_amd64`) runs
11 of the 40 tests. The other 29 are `cfg(unix)`: 28 in
`kubernetes_read_failures.rs`, `kubernetes_lost_create_response.rs`,
`kubernetes_corrupt_receipt.rs` and `kubernetes_openshift_reapply.rs`
(`#![cfg(unix)]`, as `kubernetes_operations.rs` is), and 1 in the
`operations` module of `kubernetes_expired_authentication.rs`.

## Observations for maintainers

- A lost create response leaves an unrecorded object. A re-run refuses
it with `BindingMismatch`, and no SDK path deletes an unrecorded object
(`Cluster::delete` runs only for recorded issuer objects), so it stays
until someone removes it. The tests pin the refusal; a change that adds
adoption or cleanup after ownership verification will change them.
- OpenTofu taints an instance after a create that returns state with an
error, and the next plan is delete plus create. The SDK rejects a plan
with those actions for bound platform resources (tested with a
constructed plan, not OpenTofu output); how a user recovers from it is
not tested.
- The first `ensure` of storage saves the cluster binding (server
address and kube-system `uid`) before it reads the Agent Sandbox CRD,
controller and StorageClass, so a failed read of one leaves a receipt
that holds only that binding. The scenario list on #12731 left this
unselected; three tests pin it.
- A 500 on the kube-system read and on the StorageClass list is
`Transport` (`read_failure` in `storage.rs`); `Cluster::get` and the
Helm release listing report `Query`. A recorded gateway whose
StatefulSet has no `uid` is `BindingMismatch`, where first adoption of
the same answer is `Incomplete`; only the latter is pinned.
- Development certificates are valid for 365 days and the SDK does not
rotate them. After expiry, `read` and `ensure` of the authentication
resource and `connect` fail with `Authentication`; teardown does not
load the certificates, and no test covers it.
- `connect` writes each credential it decodes to `state/client` before
it reads the next, so a Secret that lacks one leaves the earlier ones.
The private key is written last.

Refs #12731

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
@cv cv added the v1 NemoClaw v1 branch label Oct 12, 2026
cv pushed a commit that referenced this pull request Oct 13, 2026
…13081)

Adds 19 tests for a managed Kubernetes deployment whose apply or destroy
is cancelled or fails part-way: 12 in the SDK's `integration` binary,
which run `Deployment` over a scripted OpenTofu, and 7 in
`nemoclaw-e2e`'s `helm_recovery` module, which run `destroy` through 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](#12731 (comment)).
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.md` and
`integration-tests.md` describe 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.md` says 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:
- The record must mark an apply unfinished before OpenTofu starts. A
later save leaves resources that no record covers if the host exits
first.
- Until the same document settles the stage, a revised document, a
destroy and an export must be refused, and a refusal must not run
OpenTofu or change the record.
- A gateway connection that fails after the runtime stage settled must
keep its error class, must not start the OpenShell stage, and must not
leave the apply unfinished. A cancel while it waits for the cluster must
end it.

SDK tests, destroy:
- A cancelled destroy must block apply until destroy runs again. Its
retry must not reconnect once the OpenShell stage is done and must
report the retained storage and workspace.
- A retry whose OpenTofu state was lost must be refused instead of
reported as finished, and a destroy plan that deletes the retained
storage must be refused before anything is applied.

e2e tests, destroy:
- A deleted or truncated receipt must stop destroy and its preview while
OpenTofu plans, with nothing changed, the damaged receipt included. A
bound storage read as absent, or a receipt recreated empty, would let
destroy go on without a verified identity.
- A Helm release record that OpenTofu does not bind must stop destroy
before it deletes any issuer object: the release may still run, and its
gateway authenticates against that issuer.
- An authentication failure (HTTP 401) must stop destroy before
planning, after the saved plan, and when only the issuer's ConfigMaps
are read. The Helm provider drops its release binding under a 401, so
the SDK must restore it, and a retry must finish.
- A second destroy must launch no plan or apply, and a cancel at the
first refresh must return without waiting for the refresh to fail.

## 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.rs` writes a
bundle whose manifest verifies and whose `libexec/tofu` is a short shell
script. The script logs each call, replays canned `show -json` state 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
the `test` step 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()` and `import_release()` that split
`create()`, and a `Snapshot`. The `Snapshot` compares 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 no `intent.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 new `failing_after_plan` and `assert_export_refused` helpers.

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):

| Test | Checks |
|---|---|
| `cancelling_the_first_kubernetes_runtime_apply_...` | A cancel while
OpenTofu applies the runtime stage: the record was saved before OpenTofu
started; plan and apply of another namespace, destroy and export are
refused; the same document resumes |
| `a_failed_first_kubernetes_runtime_apply_...` | The same after
OpenTofu fails, with its diagnostic kept |
| `a_revised_document_after_an_interrupted_kubernetes_apply_...` | The
refusal runs no plan or apply and changes neither the record nor the
OpenShell stage's state |
| `cancelling_before_the_runtime_mutation_...` | A cancel before the
runtime plan saves no record, so another document is not refused |
| `cancelling_an_unchanged_kubernetes_runtime_apply_...` | An unchanged
runtime stage still applies, sets no unfinished marker, and keeps the
saved record |
| `cancelling_between_the_stages_..._while_the_cluster_is_silent_...` |
A cancel while the gateway connection waits ends the apply, starts no
OpenShell stage, and leaves the runtime settled |
| `a_missing_kubeconfig_...`, `a_missing_receipt_...`,
`a_refused_connection_...` | The connection error keeps its class
(`Authentication`, `Incomplete`, `Transport`), no OpenShell stage
starts, and a revised document is not refused as unfinished |
| `an_interrupted_kubernetes_destroy_blocks_apply_and_its_retry_...` |
apply, plan and export are refused until destroy runs again; the retry
makes no connection, plans no finished stage, applies the runtime stage
once, and reports the retained storage and workspace |
|
`a_kubernetes_destroy_retry_is_refused_when_the_runtime_state_was_lost`
| A retry whose runtime state is missing is refused and changes nothing
|
| `a_kubernetes_destroy_plan_that_deletes_retained_storage_...` | The
plan is refused before the record is marked destroying and before any
apply |

e2e, `crates/nemoclaw-e2e/tests/helm_recovery/` (7 tests, names
shortened):

| Test | Checks |
|---|---|
|
`receipt::a_deleted_or_truncated_receipt_stops_destroy_while_planning_...`
| Destroy and its preview fail while OpenTofu plans with an incomplete
observation and change no state, binding, object, write or the receipt;
the restored receipt lets destroy finish |
|
`release_record::destroy_keeps_the_issuer_while_a_release_record_has_no_binding_...`
| Destroy stops at authentication's removal with no write; apply and
export stay refused; once the record is gone destroy removes the issuer
and keeps storage |
| `destroy_faults::a_second_destroy_after_completion_...` | A second
destroy and its preview report the retained storage, launch no plan or
apply, and change nothing |
| `destroy_faults::an_authentication_failure_before_planning_...` |
Destroy and its preview stop on the 401; nothing changes and no write is
attempted; a retry finishes |
| `destroy_faults::an_authentication_failure_after_the_saved_plan_...` |
The dropped Helm binding is restored, no write is attempted, and the
retry consumes the recovery checkpoint |
| `destroy_faults::an_authentication_failure_reading_the_issuer_...` |
With only ConfigMap reads rejected, Helm uninstalls the release and the
issuer's objects stay; a retry removes them |
| `destroy_faults::cancelling_at_the_first_refresh_...` | A cancel
returns `Cancelled` with a healthy API and returns well before an
unreachable API would fail the refresh; state, bindings, objects and
writes are unchanged |

## Validation

Run on `3a00cbda0e`, based on v1 at `29bb057949`, macOS arm64.

- `cargo ci`: passed in 478 s: fmt, clippy, build, test (1356 passed),
schema, bundle and lifecycle (134 passed).
- Timing in `cargo ci` (budgets apply on Linux CI only): the `test` step
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 the `lifecycle` step the 12 `helm_recovery`
tests 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 --check` and `fern check`:
passed; the one fern warning also appears on v1.
- Windows approximation: with `#![cfg(unix)]` replaced by
`#![cfg(any())]` in both new SDK files, `cargo clippy -p nemoclaw-sdk
--tests -- -D warnings` is clean. This checks unused items and imports;
it is not a Windows build.
- Linux aarch64: an earlier revision ran in an Ubuntu 24.04 container
(dash as `/bin/sh`, a `linux_arm64` bundle 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 `apply` allowed 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

- A script stands in for OpenTofu in the SDK tests. They show what the
SDK saves and refuses for the plans and states the tests write, not what
OpenTofu or a provider produces. The script reports no bindings after a
settled runtime stage, so a revised document that no unfinished state
refuses is not shown to be accepted by a deployment with bindings, which
also compares the revision with them. The e2e tests cover destroy only;
the apply-side cases have no real-OpenTofu counterpart here.
- The tests pin the current rule that a deployment whose first runtime
apply failed or was cancelled cannot be destroyed or revised until the
same document settles the stage (`IDs were not saved`).
`docs/usage.md:294` says that after a failed runtime apply, revised
intent or teardown can proceed, which this rule refuses, and
`docs/troubleshooting.md:41` names a message that no code emits; both
are corrected separately.
- The fake Kubernetes API serves plain HTTP on loopback. It shows no
RBAC, TLS or token validation, and 429, 503 and 504 are not injected
because the client retries them for minutes. It holds no
PersistentVolumeClaims, so retained state in the e2e tests is the
Namespace, the KEK Secret and the receipt; scenario 12 covers the claims
on Kind.
- The 401 tests depend on Helm provider 3.3.0 treating a rejected
release lookup as an absent release: it drops the binding and sends no
delete. A provider upgrade can change them.
- The cancel test bounds the return at 8 s from the cancel: the SDK
kills OpenTofu after 5 s without an answer to the interrupt, and an
unreachable API fails the refresh after about 10.5 s (measured on macOS
arm64). OpenTofu normally exits within 0.1 s of the interrupt. On a
loaded host the kill is reached, and the OpenTofu it kills leaves
`.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.
- Cancellation is tested at progress events, not by killing the host, so
"the record is saved before OpenTofu starts" is shown by what the script
finds when it starts.
- The new files are `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

- Observed, not pinned: with a receipt written before the issuer was
recorded (storage objects only), destroy returns `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.
- With a Helm release record that OpenTofu does not bind, `plan_destroy`
lists the issuer's removal, and `destroy` then stops before deleting it.
The preview does not run the removal's own checks.
- `Progress::MutationStarted` is emitted for every `tofu 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.
- Under `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 when `Store`
drops, which the draft #12736 adds.
- With no receipt, the gateway connection fails at once, and
`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](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
@wscurran wscurran added area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery bug-fix PR fixes a bug or regression platform: k8s Affects Kubernetes deployments security area: security Security controls, permissions, secrets, or hardening and removed security labels 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 area: security Security controls, permissions, secrets, or hardening bug-fix PR fixes a bug or regression platform: k8s Affects Kubernetes deployments v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants