Skip to content

refactor(openshell-provider): inject a Services hook for cluster grants and profile sources - #13060

Closed
gaveezy wants to merge 7 commits into
v1from
split/5-openshell-services-hook
Closed

gaveezy wants to merge 7 commits into
v1from
split/5-openshell-services-hook

Conversation

@gaveezy

@gaveezy gaveezy commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Let callers of the OpenShell and Fabric providers inject a Services implementation that verifies cluster model Services, so a provider profile can carry a cluster source and a sandbox policy can grant that Service's verified addresses. The default keeps today's Docker credential behaviour and rejects every cluster source, so Docker and Podman deployments are unchanged.

Why

#12736 routes sandboxes to vLLM and Ollama Pods that the deployment runs in its cluster. The providers could not express that:

  • Provider credentials are parsed and resolved only through nemoclaw_docker::credentials; a caller cannot supply another source.
  • An inference profile grants only the literal IP in its endpoint URL. A cluster model is reached by a <name>.svc.cluster.local host, so a sandbox policy cannot grant its ClusterIP, and nothing checks which Service owns the address.
  • Without a bound field, a refresh that observes a different cluster_source would write it into state. On the base, profile_refresh_preserves_the_bound_cluster_source shows exactly that: state picks up substituted-service.
  • Two internal invariants, the profile metadata field set and the static search rule, were enforced with expect, so a violation would abort the provider process instead of returning an observation error.
  • N1b ([tracking] feat(kubernetes): manage vLLM and Ollama services (split) #12736 review, nit): only the ignored bundled lifecycle test constructed FabricProvider::with_services. A regression that dropped the injected callbacks passed cargo ci test. This PR includes the regular-step test that closes it.

This PR adds only the hook and the checks. #13063 supplies the cluster implementation (OpenShellServices) and switches the bundled providers to it; until then nothing produces a cluster source or cluster grants.

What changes

  • Services trait (openshell-provider): validate_credential_source, resolve_credential_source, validate_cluster_source and cluster_addresses. DockerServices implements the credential methods with nemoclaw_docker::credentials, as before, and returns BindingMismatch from both cluster methods.
  • Injection: GatewayClient::with_services, OpenShell::connect_with_services, OpenShellProvider::with_services and FabricProvider::with_services. Default and OpenShell::connect use DockerServices; the bundled openshell and fabric provider binaries still use the defaults.
  • Cluster profiles: openshell_provider_profile gains an optional, computed cluster_source.
    • It is a bound field (below), resets to empty when omitted on update, and any change replaces the profile.
    • nemoclaw_openshell::profile::cluster_definition builds the profile. It accepts only an http://<host>.svc.cluster.local:<port>/v1 endpoint without credentials, query or fragment, and grants only the addresses Services::cluster_addresses returns.
    • service_address_allowed rejects unspecified, loopback, multicast, link-local, broadcast and IPv4-mapped addresses.
    • The source and addresses are stored in new nemoclaw.nvidia.com/cluster-source and cluster-addresses annotations. Refresh re-reads the addresses and refuses a profile whose endpoints no longer match them.
  • Cluster grants: PolicyInput.cluster_grants names managed rules whose allowed_ips come from verified cluster profiles (ClusterGrants, RuntimeBinding::granted_policy: one or two unique /32 or /128 addresses per rule). Sandbox create (create_sandbox_request) and refresh (checked_sandbox_row_with) check each grant against the deployment's own profile: same owner, listed among the sandbox's providers, and the same endpoint apart from allowed_ips. The field is omitted from serialized policy when empty.
  • Bound fields (nemoclaw-tofu): Definition::bound_fields. Refresh returns BindingMismatch when an observed bound field differs from state, treating omission as the empty value.
  • No panics: annotations() returns Result, so unknown metadata returns Incomplete; an unparsable search rule returns Query (definition_with_rule).
  • SDK: image_runtime::policy_input sets cluster_grants: Default::default(). This is the only SDK change.

Breaking or user-visible changes

  • Provider schema: openshell_provider_profile gains cluster_source (optional, computed), and the openshell_sandbox policy block gains cluster_grants (optional list). The bundled providers use DockerServices, which accepts no cluster source, so a profile with cluster_source or a sandbox with cluster_grants fails when the provider creates or reads it. This is from reading the code; no test in this PR sets them against DockerServices.
  • State and annotations: no change for existing resources. cluster_grants is not serialized when empty, and a profile without a cluster source writes no new annotations.
  • Rust API: openshell_provider adds Services, DockerServices and the with_services constructors; nemoclaw_openshell::runtime::PolicyInput gains the public cluster_grants field, so struct literals need it (the SDK's one literal is updated); nemoclaw_tofu::Definition gains the public bound_fields field. The crates are publish = false.
  • No configuration, CLI or docs change.

Test proof

cargo ci (linux_arm64, this branch)

Run on the GB300 host (aarch64). The tree tested is the commit's tree.

ok tools in 0s
ok fmt in 1s
ok clippy in 36s
ok build in 74s
     Summary [  18.895s] 1393 tests run: 1393 passed, 174 skipped
ok test in 25s
ok schema in 0s
ok bundle in 170s
     Summary [ 394.734s] 127 tests run: 127 passed, 48 skipped
ok lifecycle in 401s
All selected CI steps passed in 709s

The test step's 4 doctests passed. The test step ran 1393 tests against #13056's 1387; cargo nextest list --profile ci lists all 6 new tests in this step.

The lifecycle timing report lists three local overruns of budgets that apply on the Linux CI runners: 394.7 s wall against 300 s, openshell-provider::contract 194.5 s summed against 190 s, and nemoclaw-provider::contract 111.0 s against 110 s. This PR does not cause them. The three provider contract binaries, run alternately on the base and on this branch with the same bundle on this host (two rounds each, --profile lifecycle):

Binary Base (round 1, 2) This branch (round 1, 2) Budget
openshell-provider::contract (44) 197.7 s, 194.9 s 196.0 s, 197.4 s 190 s
nemoclaw-provider::contract (29) 116.8 s, 118.2 s 116.4 s, 118.4 s 110 s
fabric-provider::contract (3) 26.9 s, 28.0 s 27.1 s, 27.6 s 40 s

Both trees exceed the same two budgets on this loaded host; the CI timing job on the Linux runners decides whether they hold there.

cargo run --locked -p nemoclaw-build -- docs --check passed after docs generated the untracked output; no tracked file changed.

New tests: red without the production change, green with it

Each red run edited only a separate worktree (wt-5-red) and restored the PR tree afterwards. Commands: cargo test --locked -p <crate> <target> -- <test names>.

On the base (split/1-openshell-fixes, de35958) with only the new tests added. The tests/support/mod.rs line that narrows bound_fields was left out there, because the field does not exist on the base.

Test Result on the base
nemoclaw-provider refresh::profile_refresh_preserves_the_bound_cluster_source FAILED: state becomes {"cluster_source": "substituted-service", …}, expected bound-service
refresh::changing_from_cluster_to_external_inference_replaces_the_owned_profile FAILED: planned cluster_source is "owned-cluster-storage", expected ""
nemoclaw-tofu resource::tests::refresh_preserves_declared_bound_fields does not compile: E0599, no method bound_fields on Definition
fabric-provider provider::tests::configured_provider_observes_cluster_grants_through_its_injected_services does not compile: E0405, no trait Services in openshell_provider
openshell-provider profile::tests::unsupported_profile_metadata_returns_an_error_instead_of_panicking does not compile: E0308, annotations returns a map, not a Result
profile::tests::unsupported_search_rules_return_an_observation_error does not compile: E0425, no function definition_with_rule

On this tree with one production mutant at a time:

Test Mutant Red result Green
resource::tests::refresh_preserves_declared_bound_fields M1: checked skips the bound_fields loop FAILED: adapter.checked(&prior, changed).is_err() ok
refresh::profile_refresh_preserves_the_bound_cluster_source M1 FAILED: state becomes substituted-service ok
same M2: the v1 provider_profile definition (no cluster_source) FAILED: state becomes substituted-service ok
refresh::changing_from_cluster_to_external_inference_replaces_the_owned_profile M2 FAILED: planned cluster_source is "owned-cluster-storage" ok
provider::tests::configured_provider_observes_cluster_grants_through_its_injected_services M3 (the N1b mutant): FabricProvider::with_services ignores services and uses GatewayClient::default() FAILED: read returned Err(BindingMismatch) ok
profile::tests::unsupported_profile_metadata_returns_an_error_instead_of_panicking M4: annotations uses v1's .expect("profile metadata field") FAILED: panicked, unsupported metadata must return an observation error ok
profile::tests::unsupported_search_rules_return_an_observation_error M5: definition_with_rule uses v1's .expect("static search policy") FAILED: panicked on unknown tls value 'unsupported-mode' ok

M1, M3, M4 and M5 ran together (each test depends on only one of them); M2 ran alone. Under M1, changing_from_cluster_to_external_inference_replaces_the_owned_profile still passed, as expected: it tests planning, not refresh.

Lifecycle tests

This PR adds no lifecycle-only tests. All 127 selected by the lifecycle profile passed (JUnit: ci-5-lifecycle.xml). The ones that drive the changed OpenShell and Fabric provider code through OpenTofu with the default DockerServices:

  • openshell-provider::contract: all 44 passed. They run this branch's openshell provider binary through OpenTofu against the fake gateway, so every profile, provider and sandbox create and refresh goes through DockerServices and the refactored profile and sandbox code. Examples: standalone::standalone_create_readback_rejects_substitution_and_retains_established_binding, standalone::standalone_hcl_rejects_missing_bound_resources_before_recreation, standalone::standalone_registrations_preserve_bindings_on_failed_or_foreign_observations, and the 22 example-configuration tests (explicit_policy, inline_inference, multiple_models, tavily_web_search, …).
  • fabric-provider::contract: all 3 passed: capabilities::capabilities_judge_the_image_for_the_configuration, readiness::readiness_reports_the_configured_agent_and_its_failed_health, pi_configuration_updates_without_replacing_the_sandbox.
  • nemoclaw-e2e::integration: all 49 passed. They run the bundle built from this branch, whose openshell and fabric providers use the default DockerServices. Those that create sandboxes include deployment::rejected_policy_fails_promptly_with_context_and_allows_recovery_or_destroy, deployment::separate_agent_sandboxes_cli_export_reapply_and_policy_drift, deployment::web_search_cli_export_reapply_and_destroy, multiple_providers::provider_union_export_reapply_drift_and_destroy_remain_scoped_to_each_sandbox and remote_service::managed_bearer_credentials_survive_recovery_reapply_and_replacement_outside_state.
All 127 lifecycle tests (passed)
  • fabric-provider::contract (3): capabilities::capabilities_judge_the_image_for_the_configuration, readiness::readiness_reports_the_configured_agent_and_its_failed_health, pi_configuration_updates_without_replacing_the_sandbox
  • nemoclaw-e2e::integration (49): deployment:: (24), export_observations:: (4), fabric_deployment:: (4), helm_recovery:: (5), inference_discovery::optional_catalog_failures_preserve_complete_unchanged_plans_and_typed_uncertainty, multiple_providers::provider_union_export_reapply_drift_and_destroy_remain_scoped_to_each_sandbox, remote_service:: (9), sandbox_readiness::standalone_sandbox_completion_rejects_unknown_health_and_retains_bindings
  • nemoclaw-provider::contract (29): discovery:: (3), gateway_readiness:: (1), gateway_storage:: (1), inference_capabilities:: (3), kubernetes_hcl:: (1), kubernetes_lifecycle:: (2), provider_protocol:: (4), runtime_image:: (1), service_capacity:: (1), service_readiness:: (2), service_storage:: (6), vllm_runtime:: (4)
  • openshell-provider::contract (44): capabilities:: (2), standalone:: (20), and the example configurations explicit_policy, fabric, fabric_claude, fabric_codex, fabric_hermes, fabric_mini_swe_agent, fabric_nooa, fabric_nooa_bench, fabric_openclaw, fabric_pi, fabric_remote_agent, hermes_auth, hermes_interfaces, inference_tuning, inline_inference, local, multiple_models, multiple_providers, multiple_sandboxes, openclaw_dashboard, openclaw_web_search, tavily_web_search
  • nemoclaw-fixture-provider::archive the_fixture_provider_is_found_beside_the_test_executables, nemoclaw-test-fixtures::ssh_relay the_relay_is_found_beside_the_test_executables

Live evidence (not qualification; #12732 stays open)

split/5-openshell-services-hook @ 086dac1e2, run in that worktree. It used the existing dist/linux_arm64 bundle (0.1.0-dev.91119d2dbc2426f1) from the branch's cargo ci run. 2026-10-12, GB300 host (ARM64), local Docker engine with the containerd image store. No GPU or inference.

cargo ci live-docker: ok live-docker in 359s, EXIT 0. The four nextest commands took 139.8 s, 59.3 s, 19.8 s and 15.1 s: 10 tests, 234.0 s wall, 275.6 s summed, within the 360 s budget.

Test (JUnit) Result
nemoclaw-e2e docker_provider_proxy::sdk_docker_proxy_lifecycle_preserves_readiness_and_storage_guards PASS, 82.1 s
nemoclaw-e2e managed_gateway::managed_gateway_plan_apply_noop_destroy_and_recovery_use_real_opentofu PASS, 59.2 s
nemoclaw-e2e cache_provider::standalone_hcl_recovers_cache_and_guards_credentials_without_sdk_orchestration PASS, 41.7 s
nemoclaw-build runtime::tests::retained_runtime_rebuilds_offline_without_protobuf_or_a_dependency_cache PASS, 41.7 s
nemoclaw-provider managed_gateway_live::pinned_docker_gateways_reach_ready_without_interfering_with_other_sandboxes PASS, 19.8 s
nemoclaw-provider managed_gateway_live::profile_revision::imported_profile_revisions_survive_repeated_reads_and_gateway_restart PASS, 15.1 s
nemoclaw-sdk kubernetes_auth::the_issuer_image_serves_both_documents_over_https PASS, 11.7 s
nemoclaw-runtime ollama_cache::pinned_ollama_reads_verified_cache_and_matches_declared_version PASS, 1.8 s
nemoclaw-build runtime::image::tests::runtime_archive_loads_with_its_exported_digest PASS, 1.5 s
nemoclaw-build fabric_cache::a_new_fabric_archive_cannot_reuse_an_older_compiled_core PASS, 1.0 s

10/10 passed. They include managed_gateway_live::profile_revision, the live test closest to the profile.rs code this PR refactors. No cluster services are involved: the hook's Kubernetes implementation arrives in #13063.

Docker inventory unchanged. Containers, networks, volumes and images were listed before and after the run, and the two lists were identical. The runner removed its nc-live-… Pi and proxy images and its labelled containers, volumes and networks. The pinned OpenShell and Ollama images were already present, so the run left nothing new.

The worktree had 0 tracked changes before and after; the run wrote only ignored paths (target/, .build/).

A kind-only run (PR-7) was running on the same host at the same time. It creates no host Docker objects.

Against v1 025b95a

Depends on / merge order

Split from #12736.

🤖 Generated with Claude Code

gaveezy and others added 2 commits October 12, 2026 15:43
…, and test fixtures

## Failure

Review of #12736 found six problems that do not depend on Kubernetes:

- OpenShell rejection text was discarded. `remote_error` maps every
  gateway status to a fixed category, so on kind a CreateSandbox
  rejection for conflicting `allowed_ips` endpoint metadata reached the
  user only as "observation query failed".
- Removing a ready sandbox still read its active-policy status, which
  teardown does not use; a failing status read blocked removal.
- The deployment lock is an `flock` on the open file description. A
  child spawned concurrently holds a copy of the descriptor until
  `exec`, so dropping `Store` could leave the deployment locked, and the
  next open failed with "another operation holds the deployment lock".
- Several tests wrote a script and executed it at once. A concurrent
  spawn that inherited the write descriptor made the exec fail with
  "Text file busy" (ETXTBSY).
- `cargo images build --platform linux/amd64 hermes` failed with Bake's
  "failed to find target hermes".
- The docs did not give the OpenClaw request format, how to recover when
  a malformed request leaves the runtime `unknown` (#12642), or that
  gateway profiles written before #12941 cannot be read.

## Decision

- `ObservationError` gains `Rejected { operation, code, detail }`.
  `remote_rejection` keeps the gateway's detail only for CreateWorkspace,
  CreateSandbox, DeleteProvider and DeleteProviderProfile, whose
  requests carry no credentials, and only for FailedPrecondition,
  InvalidArgument, AlreadyExists, OutOfRange and ResourceExhausted.
  `sanitized_detail` reduces the detail to printable ASCII of at most
  1024 characters and redacts bearer tokens, key/value credentials and
  token-like runs; `sanitized_resource_detail` also keeps one known
  resource name. Credential-bearing requests, reads and exec keep
  category-only errors.
- `Rejected` owns its text, so `ObservationError` is `Clone` but no
  longer `Copy`; workspace callers clone it.
- Teardown of a ready sandbox skips the active-policy status read. The
  owned identity checks still run.
- `Drop for Store` unlocks before the file closes, which releases the
  lock for every copy of the descriptor.
- Test fixtures execute an existing interpreter or binary and pass the
  written script as data. The provider staging test, which now runs the
  staged file through `/bin/sh`, asserts the executable bit that
  OpenTofu needs.
- `images::plan` lists each platform's harnesses with
  `buildx bake --print agents` and names the platforms that build a
  requested harness; other selections keep Bake's resolution.
- Docs: the headless OpenClaw request, the reported malformed-request
  failure and the whole-deployment replacement procedure, which
  rejections keep their detail, and the profile-format break.

API change: `ObservationError` (also `nemoclaw_sdk::ObservationError`)
is no longer `Copy` and has a new variant. Code that copies it must call
`.clone()`, and exhaustive matches need a `Rejected` arm. Every use in
this workspace is updated.

## Validation

- `cargo ci` on linux_arm64 passed in 690 s: fmt, clippy `-D warnings`,
  build, 1387 nextest tests (174 skipped) and 4 doctests, schema,
  bundle, and 127 lifecycle tests (48 skipped).
- Each new test failed with its production change reverted and passed
  with it: the two `remote_rejection` unit tests, the three redaction
  tests, the rejection-detail and ready-sandbox teardown fake-gateway
  tests, the lock test, and the harness-platform test. The
  credential-privacy test passes on v1 by design; it failed when
  CreateProvider was opted into rejection detail. The staging test
  failed when staging cleared the executable bit.
- Repeated `cargo test` runs on this host: the `nemoclaw-sdk` lib suite
  passed 22 of 22 runs (v1: 7 of 22, with tests that reopen the
  deployment lock failing), and the `nemoclaw-test-fixtures` lib suite
  50 of 50 (v1: 46 of 50; the kept failure logs show "Text file busy").
  The other touched suites passed 10 of 10 on both.
- `nemoclaw-build docs --check` passed.

Split from #12736.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts and profile sources

## Failure

#12736 routes sandboxes to model Pods that the deployment runs in its
cluster, and the OpenShell and Fabric providers could not express that:

- Provider credentials are parsed and resolved only through
  `nemoclaw_docker::credentials`; a caller cannot supply another source.
- An inference profile grants only the literal IP in its endpoint URL.
  A cluster model is reached by a `<name>.svc.cluster.local` host, so a
  sandbox policy cannot grant its ClusterIP, and nothing checks which
  Service owns the address.
- Two internal invariants, the profile metadata field set and the
  static search rule, were enforced with `expect`, so a violation would
  abort the provider instead of returning an observation error.

Review finding N1b on #12736: only the ignored bundled lifecycle test
constructed `FabricProvider::with_services`, so a regression that
dropped the injected callbacks passed the regular test step.

## Decision

- `openshell_provider::Services` validates and resolves credential
  sources, validates a cluster source, and returns a cluster Service's
  verified addresses. `DockerServices` keeps the Docker credential
  behaviour and returns `BindingMismatch` for every cluster source.
  `GatewayClient::with_services`, `OpenShell::connect_with_services`,
  `OpenShellProvider::with_services` and `FabricProvider::with_services`
  inject an implementation. `Default` and `OpenShell::connect` use
  `DockerServices`, and the bundled provider binaries still use the
  defaults.
- `openshell_provider_profile` gains an optional `cluster_source`. It is
  a bound field, resets when omitted on update, and any change replaces
  the profile. `nemoclaw_openshell::profile::cluster_definition` accepts
  only an `http://<host>.svc.cluster.local:<port>/v1` endpoint and grants
  only the addresses `Services::cluster_addresses` returns, after
  `service_address_allowed` rejects unspecified, loopback, multicast,
  link-local, broadcast and IPv4-mapped addresses. The source and
  addresses are kept in their own annotations; refresh re-reads the
  addresses and refuses a profile whose endpoints no longer match.
- `PolicyInput.cluster_grants` names managed rules whose `allowed_ips`
  come from verified cluster profiles (`RuntimeBinding::granted_policy`).
  Sandbox create and refresh check each grant against the deployment's
  own profile. The field is omitted from serialized policy when empty,
  so stored sandbox annotations do not change.
- `nemoclaw_tofu::Definition::bound_fields`: refresh returns
  `BindingMismatch` when an observed bound field differs from state,
  treating omission as the empty value. Without it, a refresh wrote a
  substituted `cluster_source` into state.
- `annotations()` returns `Result`, so unknown metadata returns
  `Incomplete`; an unparsable search rule returns `Query`.
- The SDK's `image_runtime::policy_input` sets an empty
  `cluster_grants`; nothing in the SDK produces grants yet.

Docker and Podman deployments are unchanged: the SDK emits no cluster
source or cluster grants. The provider schema gains
`openshell_provider_profile.cluster_source` and the `openshell_sandbox`
policy block's `cluster_grants`; with `DockerServices`, a resource that
sets either fails when the provider creates or reads it.

## Validation

- `cargo ci` on linux_arm64 passed in 709 s: fmt, clippy
  `-D warnings`, build, 1393 nextest tests (174 skipped) and 4
  doctests, schema, bundle, and 127 lifecycle tests (48
  skipped), including all 44 `openshell-provider::contract` and
  3 `fabric-provider::contract` tests.
- On the base, the two new `nemoclaw-provider` refresh tests fail and
  the other four new tests do not compile. On this tree, each new test
  failed under a mutant of the production code it covers and passed
  without it: dropping the `bound_fields` check, restoring the v1
  profile definition, making `FabricProvider::with_services` ignore its
  services (the N1b mutant), and restoring either `expect`.

Split from #12736.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown
Contributor

This repository limits you to 5 open pull requests. Please close or merge an existing PR before opening another one.

@github-actions github-actions Bot closed this Oct 13, 2026
@gaveezy gaveezy reopened this Oct 13, 2026
cv pushed a commit that referenced this pull request Oct 13, 2026
…, and test fixtures (#13056)

Report the gateway's reason when OpenShell rejects a credential-free
mutation, and fix sandbox teardown, deployment-lock release,
test-fixture flakes and the images plan message, with matching docs.
Nothing here depends on Kubernetes.

## Why

The review of #12736 found these problems; each predates or is
independent of the cluster model services.

- **F2** (#12736 review): OpenShell rejection text was discarded.
`remote_error` maps every gateway status to a fixed category, so on kind
a CreateSandbox rejection for conflicting `allowed_ips` endpoint
metadata reached the user only as `observation query failed`. Finding
the cause took a rebuilt bundle that logged `status.message()`.
- **`transport.rs:220`** (#12736 review: open at 59ad198, fixed at
c3496ea): removing a ready sandbox read its active-policy status,
which teardown does not use, so a failing status read blocked removal.
#12736 changed this without a test.
- **T1** (#12736 review): the deployment lock is an `flock` on the open
file description. A child spawned concurrently holds a copy of the
descriptor until `exec`, so dropping `Store` could leave the deployment
locked and the next open failed with `another operation holds the
deployment lock`. Besides the flaky SDK suite, an SDK process that runs
`tofu` can hit this.
- **T1-tail** (#12736 review) and **N1** (#12736 review, nit): several
tests wrote a script and executed it at once, which fails with `Text
file busy` (ETXTBSY) when a concurrent spawn holds the write descriptor.
Running the staged provider through `/bin/sh` stopped the staging test
from checking the executable bit OpenTofu needs.
- **HM-4** (#12736 review, nit): `cargo images build --platform
linux/amd64 hermes` failed with Bake's `failed to find target hermes`.
- **N2** (#12736 review) and
[#12642](#12642): no documented
OpenClaw request format, and no recovery path when a malformed request
leaves the runtime `unknown`. The gateway profile-format break from
#12941 had no operator note.

## What changes

- **Rejection text.** `ObservationError` gains `Rejected { operation,
code, detail }`. `nemoclaw_openshell::remote_rejection` keeps the
gateway's detail only for CreateWorkspace, CreateSandbox, DeleteProvider
and DeleteProviderProfile, whose requests carry no credentials, and only
for `FailedPrecondition`, `InvalidArgument`, `AlreadyExists`,
`OutOfRange` and `ResourceExhausted`. Other codes and operations return
the same category as before.
- **Redaction.** `ObservationError::sanitized_detail` reduces text to
printable ASCII of at most 1024 characters and redacts bearer tokens,
key/value credentials (`authorization`, `api_key`, `token`, `password`,
`secret`) and runs of 32 or more token characters.
`sanitized_resource_detail` additionally keeps one known resource name.
Credential-bearing provider creation and update, reads and exec keep
category-only errors.
- **Teardown.** `openshell-provider` skips the active-policy status read
when it reads a ready sandbox for removal (`if ready && !removing`). The
owned identity checks still run.
- **Lock.** `impl Drop for Store` unlocks before the file closes, which
releases the `flock` for every copy of the descriptor.
- **Test fixtures.** Tests execute an existing interpreter or binary
(`/bin/sh`, `/bin/cat`) and pass the written script as data. The
provider staging test asserts the executable bit.
- **Images plan.** `images::plan` lists each platform's harnesses with
`buildx bake --print agents` and names the platforms that build a
requested harness. Groups and other targets keep Bake's resolution.
- **Docs.** `agents.md`: the headless OpenClaw request and the reported
malformed-request failure. `usage.md`: "Replace Workloads After an
Unusable OpenClaw Runtime". `troubleshooting.md`: which rejections keep
their detail, and table rows for both failures. `provider.md`: "Gateway
Profile Format Upgrade".

## Breaking or user-visible changes

- **Rust API:** `ObservationError` (from `nemoclaw-backend`, re-exported
as `nemoclaw_sdk::ObservationError`) is `Clone` but no longer `Copy`,
and has the new `Rejected` variant. Code that copies it must call
`.clone()`, and exhaustive matches need a `Rejected` arm. The crates are
`publish = false`; every use in this workspace is updated. An
application using the SDK through a path dependency must make the same
edits.
- **Error text:** a rejected CreateWorkspace, CreateSandbox,
DeleteProvider or DeleteProviderProfile now reports `OpenShell
<operation> rejected (<code>): <detail>` instead of `observation query
failed`. This applies to Docker, Podman and Kubernetes gateways.
- **Images:** an unsupported harness now fails with, for example,
`hermes is built only for linux/arm64; linux/amd64 builds deepagents,
openclaw (docs/build.md#build-agent-images)`.
- No configuration, schema, bundle or state format change.

## Test proof

### `cargo ci` (linux_arm64, this branch)

Run on the GB300 host (aarch64). The tree tested is the commit's tree.

```
ok tools in 0s
ok fmt in 1s
ok clippy in 35s
ok build in 76s
     Summary [  19.032s] 1387 tests run: 1387 passed, 174 skipped
ok test in 25s
ok schema in 0s
ok bundle in 178s
     Summary [ 364.941s] 127 tests run: 127 passed, 48 skipped
ok lifecycle in 371s
All selected CI steps passed in 690s
```

The test step's 4 doctests passed. The lifecycle timing report lists one
local overrun: 364.9 s wall against the 300 s budget that applies on the
Linux CI runners. This PR adds no lifecycle tests; the per-test (90 s)
and per-binary budgets were met. `cargo run --locked -p nemoclaw-build
-- docs --check` passed after `docs` generated the untracked output; no
tracked file changed.

### New tests: red without the production change, green with it

Each red run edited only the working tree and restored the PR tree
afterwards. Commands: `cargo test --locked -p <crate> <target> -- <test
names>`.

| Test | Red change | Red result | Green |
|---|---|---|---|
| `nemoclaw-openshell`
`connection::tests::live_endpoint_ambiguity_keeps_its_conflict_kind` |
`remote_rejection` returns `remote_error` (v1 behaviour) | FAILED:
message lacks `conflicting metadata: allowed_ips=[]` | ok |
|
`connection::tests::definitive_rejections_keep_bounded_gateway_text_and_other_statuses_stay_fixed`
| same | FAILED: `missing operation rejection` | ok |
| `openshell-provider`
`fake_gateway_tests::gateway_validation_rejections_preserve_details_for_credential_free_mutations`
| `connected.rs` restored to v1 | FAILED: `missing CreateWorkspace
rejection detail: observation query failed` | ok |
|
`fake_gateway_tests::credential_requests_reads_and_exec_keep_backend_rejection_text_private`
| guard: passes on v1 by design; mutant opts CreateProvider into
`remote_rejection` | FAILED under the mutant: `Rejected { operation:
"CreateProvider", …, detail: "PRIVATE_SENTINEL" }` ≠ `Query` | ok |
|
`fake_gateway_tests::ready_sandbox_teardown_needs_owned_identity_but_not_active_policy_status`
| `transport.rs` restored to v1 (`if ready {`) | FAILED: removal read
returned `Err(Transport)` | ok |
| `nemoclaw-sdk`
`error::workload_details_redact_short_bearer_and_quoted_credentials` |
`sanitize_detail` returns its input | FAILED: secret kept | ok |
|
`error::workload_details_are_single_line_bounded_and_redact_token_like_runs`
| same | FAILED: `safe.len() <= 1024` | ok |
|
`error::resource_details_preserve_only_the_exact_known_name_outside_credentials`
| same | FAILED: name appears 5 times, expected 1 | ok |
| the three `error::` tests | `observation.rs` restored to v1 | does not
compile: no `sanitized_detail`, no `Rejected` (E0599) | ok |
| `nemoclaw-sdk`
`state::tests::dropping_store_releases_lock_while_a_duplicate_descriptor_remains_open`
| `state/mod.rs` restored to v1 (no `Drop for Store`) | FAILED:
`Conflict("another operation holds the deployment lock or locking
failed")` | ok |
| `nemoclaw-build`
`images::harnesses_missing_from_the_selected_platform_name_the_platforms_that_build_them`
(needs `docker buildx`; v0.37.1 here) | `images.rs` restored to v1 |
FAILED: got `docker failed to plan the image build` | ok |
| `nemoclaw-test-fixtures`
`tofu::tests::stages_only_the_selected_provider_and_cleans_only_its_workspace`
(changed test) | mutant: staging sets mode 0644 | FAILED: executable-bit
assertion | ok |

### Repeated runs of the touched suites

In-process `cargo test` runs on this host, which is where the descriptor
races occur (nextest isolates each test). Branch and v1 (29bb057) ran
under the same load.

| Suite | This branch | v1 |
|---|---|---|
| `cargo test -p nemoclaw-sdk --lib` | 22/22 runs passed (192 tests) |
7/22; failures in
`state::tests::lock_excludes_other_operations_and_atomic_intent_survives_reopen`
(`Conflict("another operation holds the deployment lock…")`),
`deployment::tests::changing_gateway_management_at_the_same_endpoint_preserves_saved_state`,
`deployment::export::tests::export_reports_recovery_for_each_saved_operation_state_without_changing_files`
|
| `cargo test -p nemoclaw-test-fixtures --lib` | 50/50 | 46/50; kept
logs show `Text file busy` in the staging test |
| `cargo test -p nemoclaw-runtime --lib vllm::runtime` | 10/10 | 10/10 |
| `cargo test -p nemoclaw-provider --lib hardware::ssh` | 10/10 | 10/10
|
| `cargo test -p nemoclaw-sdk --test integration kubernetes_connection`
| 10/10 | 10/10 |

### Lifecycle tests

This PR adds no lifecycle-only tests. All 127 selected by the
`lifecycle` profile passed. The ones that drive the changed OpenShell
code through OpenTofu:

- `openshell-provider::contract`: all 44 passed, including
`standalone::standalone_hcl_rejects_replacement_and_unauthorized_removal_during_plan`,
`standalone::standalone_hcl_recovers_lost_delete_response_without_repeating_the_mutation`,
`standalone::standalone_registrations_replace_and_remove_without_destroy_mode`
and the 22 example-configuration tests.
- `nemoclaw-e2e::integration` teardown paths, all passed:
`deployment::failed_first_apply_can_destroy_bound_resources_without_successful_reapply`,
`deployment::destroy_waits_for_graceful_sandbox_stop_without_retrying`,
`deployment::rejected_policy_fails_promptly_with_context_and_allows_recovery_or_destroy`,
`deployment::sandbox_startup_failure_names_reason_and_guidance_and_allows_destroy`,
`deployment::pi_start_failure_names_the_sandbox_in_cli_text_and_json_and_allows_destroy`,
`deployment::mixed_sandboxes_reorder_add_recover_export_and_destroy_independently`.

<details><summary>All 127 lifecycle tests (passed)</summary>

- `fabric-provider::contract` (3):
`capabilities::capabilities_judge_the_image_for_the_configuration`,
`pi_configuration_updates_without_replacing_the_sandbox`,
`readiness::readiness_reports_the_configured_agent_and_its_failed_health`
- `nemoclaw-e2e::integration` (49): `deployment::` (24),
`export_observations::` (4), `fabric_deployment::` (4),
`helm_recovery::` (5),
`inference_discovery::optional_catalog_failures_preserve_complete_unchanged_plans_and_typed_uncertainty`,
`multiple_providers::provider_union_export_reapply_drift_and_destroy_remain_scoped_to_each_sandbox`,
`remote_service::` (9),
`sandbox_readiness::standalone_sandbox_completion_rejects_unknown_health_and_retains_bindings`
- `nemoclaw-provider::contract` (29): `discovery::` (3),
`gateway_readiness::` (1), `gateway_storage::` (1),
`inference_capabilities::` (3), `kubernetes_hcl::` (1),
`kubernetes_lifecycle::` (2), `provider_protocol::` (4),
`runtime_image::` (1), `service_capacity::` (1), `service_readiness::`
(2), `service_storage::` (6), `vllm_runtime::` (4)
- `openshell-provider::contract` (44): `capabilities::` (2),
`standalone::` (20), and the example configurations `explicit_policy`,
`fabric`, `fabric_claude`, `fabric_codex`, `fabric_hermes`,
`fabric_mini_swe_agent`, `fabric_nooa`, `fabric_nooa_bench`,
`fabric_openclaw`, `fabric_pi`, `fabric_remote_agent`, `hermes_auth`,
`hermes_interfaces`, `inference_tuning`, `inline_inference`, `local`,
`multiple_models`, `multiple_providers`, `multiple_sandboxes`,
`openclaw_dashboard`, `openclaw_web_search`, `tavily_web_search`
- `nemoclaw-fixture-provider::archive`
`the_fixture_provider_is_found_beside_the_test_executables`,
`nemoclaw-test-fixtures::ssh_relay`
`the_relay_is_found_beside_the_test_executables`

</details>

### Live evidence (not qualification; #12732 stays open)

This branch merged with `v1` 025b95a (local merge ba8499b, GB300
host, aarch64, 2026-10-13):

- `cargo ci live-docker`: **11/11 passed** in 352 s, and the Docker
inventory was the same before and after.
- The suite includes `v1`'s new
`dummy_agent::the_dummy_agent_completes_a_managed_docker_lifecycle`
(48.1 s). It destroys a ready sandbox through the bundled OpenShell
provider and checks that no sandbox containers or volumes remain, which
is the live path of the teardown change (`if ready && !removing`).
- Full `cargo ci` on the merged tree: 1394 tests + 127 lifecycle, all
passed, 727 s. The branch needs no change for the new `v1`; "Update
branch" produces the tested tree.

No kind or GPU run: nothing in this PR depends on them.


## Depends on / merge order

- Base: `v1` at 29bb057. No dependencies; it merges in parallel with
#13057, #13058 and #13059, and the four branches merge into each other
without conflicts.
- #13060 is opened on this branch and retargets to `v1` when this branch
is deleted after merge.
- #13061 needs this PR and #13058 in `v1`.
- Lines of #12736 in these files that this PR leaves out, for the later
PRs to carry: the `ModelRuntimeStopped` doc comment in `observation.rs`
(#13061); in `provider.md`, the cluster `owner`/`generation` paragraph
and the "cluster resource identity refresh" clause of the profile-format
note (#13062); in `usage.md`, "including the cluster model and
credential PVCs" (#13062).

Split from #12736.

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from split/1-openshell-fixes to v1 October 13, 2026 16:24
cv pushed a commit that referenced this pull request Oct 13, 2026
…el services (#13058)

Docker-managed vLLM and Ollama services get CPU and memory limits, and a
service-level `updatePolicy` that stops plan and apply from replacing a
running model container unless the user opts in.

## Why

On `v1`, every managed model container on Docker runs with a fixed 104
GiB memory limit and no CPU cap.
An image, model, or serving change replaces the running container
without asking, so a routine re-apply, for example from automation that
bumps an image, can take a serving model down.

This PR also carries the fixes for the review findings on the limits
commit of #12736 (review at 487cfc8, items N1–N7):

| Finding | Problem | Fixed here by |
|---|---|---|
| CL-1 / N1 (medium) | Lowering `memoryLimitGiB` resized the running
model in place under `Preserve` and could OOM-kill it | A
`memory-limit-gib` label forces replacement, and
`preserve_docker_models` refuses an in-place memory decrease |
| CL-2 / N2 | The new default had no release note and no CLI hint |
Release-notes entry, and a `help` field on `DockerModelUpdateRefused`
naming `spec.services.<name>.updatePolicy` |
| CL-5 / N5 | A 1 s CFS period gave up to 1 s throttle stalls | 100 ms
period, `quota = millis × 100`, raised to the kernel's 1000 µs minimum |
| CL-6 / N6 | Docs said `Preserve` blocks limit changes when Docker
applied memory in place; no `/proc` watchdog caveat; no CFS period |
`inference.md`, `usage.md`, `provider.md` updated |
| CL-7 / N7 | Tests accepted the in-place memory update and never
checked provider refresh | Unit cases for memory decreases and Podman
with SSH placement; e2e steps for the stopped-container refresh and
memory refusal |

CL-3 and CL-4 concern the legacy `kubernetes.*` field migration, which
is not part of this split.

## What changes

- **Configuration.** `container.cpuLimitMillis` and
`container.memoryLimitGiB` on `kind: vllm` and `kind: ollama`, and a
per-service `updatePolicy` (`Preserve`, the default, or `Recreate`). The
new `ServiceUpdatePolicy` type lives in `services/update_policy.rs` and
is exported as `nemoclaw_sdk::services::ServiceUpdatePolicy`. The schema
default comes from `registry::constrain_schema`.
- **Validation.** An explicit memory limit must cover `sharedMemoryGiB`
under private IPC and the inline recipe's `preparationMemoryGiB`. A zero
CPU limit is refused before native container creation.
- **Docker compilation** (`docker_compute.rs`, `managed/spec.rs`).
- A CPU limit sets `cpu_period = 100000` and `cpu_quota = cpuLimitMillis
× 100` (at least 1000) in the OpenTofu resource and in the native
`HostConfig`.
  - A memory limit sets `memory` and `memory_swap`.
- Labels `nemoclaw.nvidia.com/cpu-limit-millis` (when a CPU limit is
set) and `nemoclaw.nvidia.com/memory-limit-gib` (when memory differs
from 104 GiB) force replacement. Without them, the pinned Docker
provider v4.6.0 would update limits in place, drop the CFS quota, and
could OOM-kill the model by lowering memory.
- Omitted limits add no CPU settings or labels and keep the 104 GiB
memory limit; `Process` omits `cpu_limit_millis` when unset, so existing
specifications serialize unchanged.
- **Update safety** (`deployment/runtime.rs`). `preserve_docker_models`
runs during runtime observation for plan and apply. Under `Preserve` it
refuses a plan that deletes a running or incompletely observed model
container, or lowers its `memory`/`memory_swap`, with the new
`Error::DockerModelUpdateRefused`. Missing containers, containers the
provider refreshes as stopped (`must_run = false`), deposed instances,
the gateway, and the Ollama proxy are not affected.
- **CLI.** The refusal carries a `help` line in text and JSON output
that names `spec.services.<name>.updatePolicy: Recreate` and links the
new docs section.
- **Docs.** New "Set Container Limits and Update Policy" section in
`docs/inference.md`; updates to `usage.md` (change table, Podman note),
`provider.md` (generated Docker attributes), `troubleshooting.md`, and a
release-notes entry. Schema and `docs/reference/configuration.md`
regenerated.

## Breaking or user-visible changes

- **Docker model updates default to `Preserve`.** Changing a managed
vLLM or Ollama service's image, model, serving settings,
`cpuLimitMillis`, or `memoryLimitGiB` now fails at plan and apply while
the container runs:

  ```
Docker model service 'qwen' is preserved by updatePolicy: Preserve;
replacing a running or incompletely observed container requires explicit
updatePolicy: Recreate, which permits downtime if the replacement cannot
start; resources retained
  ```

Set `spec.services.<name>.updatePolicy: Recreate` to allow the
replacement and its downtime. Changing only the policy does not restart
the container.
- Declaring `memoryLimitGiB: 104` (the default) does not replace an
existing container.
- Rust API: `managed::Process` gains `cpu_limit_millis: Option<u32>`,
and `Error` gains `DockerModelUpdateRefused { service }`.

## Test proof

`cargo ci` on linux_arm64 (aarch64, `CARGO_BUILD_JOBS=16`), tree
`b63292802` (commit `c8166f739`, on top of `642211537`, which merges
`v1` a5445c7):

```
ok tools in 0s
ok fmt in 1s
ok clippy in 21s
ok build in 37s
     Summary [  18.905s] 1392 tests run: 1392 passed, 177 skipped
ok test in 24s
ok schema in 0s
ok bundle in 64s
     Summary [ 424.928s] 129 tests run: 129 passed (1 slow), 49 skipped
ok lifecycle in 430s
All selected CI steps passed in 580s
```

The test step also ran 4 doctests, all passing.
`nemoclaw-build docs` (local link and heading check) also passes.
The slow test is `nemoclaw-provider::contract
service_readiness::standalone_proxy_readiness_rechecks_identity_and_credentials_without_sdk_or_gateway`
(10.3 s against its 10 s limit). This PR does not change that binary,
and `v1` runs the test in 9.9 s on this host.

### New tests: red on `v1`, green here

"v1 code" means every production file in this PR reset to `v1`
29bb057, with this PR's test files kept.
"Hunk removed" means the branch with one production hunk taken out or
disabled.
Each run was restored to the commit afterwards.

| Test | v1 code | Hunk removed (branch) | Branch |
|---|---|---|---|
|
`deployment::runtime::tests::docker_model_updates_preserve_running_containers_unless_recreation_is_explicit`
| FAIL: `updatePolicy` is an unknown field | FAIL without the
`preserve_docker_models` call; FAIL without the memory-decrease check
(CL-1) | PASS |
|
`managed::spec::tests::zero_cpu_limit_is_rejected_before_native_container_creation`
| FAIL: unknown field `cpu_limit_millis` | FAIL without the
`cpu_limit_millis != Some(0)` check | PASS |
|
`managed::spec::tests::legacy_service_process_keeps_its_fields_without_cpu_limit`
| does not compile (E0609, no field `cpu_limit_millis` on `Process`) |
FAIL without `skip_serializing_if` on `cpu_limit_millis` | PASS |
|
`runtime_compile::docker_model_limits_reach_opentofu_and_native_container_configuration`
| FAIL: `container.cpuLimitMillis` is an unknown field | FAIL without
the memory-limit label; FAIL without the CPU quota on the Docker
resource | PASS |
|
`runtime_compile::omitted_docker_model_limits_keep_independent_legacy_defaults`
| does not compile (E0609) | FAIL without the memory-limit label; FAIL
without `skip_serializing_if` | PASS |
|
`runtime_compile::docker_model_update_policy_does_not_change_runtime_resources`
| FAIL: `updatePolicy` is an unknown field | FAIL when the policy is
made to change the runtime process (a mutation; there is no hunk to
remove) | PASS |
|
`runtime_compile::portable_container_memory_limits_cover_shared_memory_and_recipe_preparation_on_docker`
| FAIL: `container.memoryLimitGiB` is an unknown field | FAIL without
`validate_memory` | PASS |
|
`formatting::tests::docker_model_refusal_names_the_service_update_policy_field`
(nemoclaw-cli) | does not compile (E0599, no variant
`DockerModelUpdateRefused`) | FAIL without the `help` arm | PASS |

Commands: `cargo nextest run --locked -p nemoclaw-sdk -p nemoclaw-cli
--profile ci -E 'test(=…)'` for the unit and integration tests.
Each "v1 code" run first compiled out the tests that cannot compile
there (`#[cfg(any())]`) so the rest of the binary could run.

### Lifecycle-only tests (`remote_service`, run with the bundle from
`cargo ci bundle`)

| Test | Branch | Time |
|---|---|---|
|
`remote_service::remote_model_reapply_and_drift_keep_bindings_and_stop_on_observation_failure`
| PASS | 85.6 s |
|
`remote_service::remote_ollama_recovers_reapplies_and_stops_on_observation_failure_keeping_data`
| PASS | 82.9 s |
|
`remote_service::managed_bearer_credentials_survive_recovery_reapply_and_replacement_outside_state`
| PASS | 73.4 s |
|
`remote_service::managed_bearer_cleanup_recovers_damage_keeps_bindings_and_teardown_accepts_both_identities`
| PASS | 73.0 s |
|
`remote_service::managed_pi_applies_without_generation_and_refused_sandbox_changes_keep_intent`
| PASS | 60.7 s |
|
`remote_service::remote_ollama_preserve_refuses_image_and_memory_changes_and_recreate_plans_replacement`
| PASS | 42.8 s |
|
`remote_service::remote_vllm_preserve_refuses_image_change_and_recreate_plans_replacement`
| PASS | 26.4 s |
|
`remote_service::partial_runtime_destroy_retains_storage_without_creating_network`
| PASS | 10.3 s |
|
`remote_service::partial_ollama_destroy_retains_storage_without_creating_network`
| PASS | 10.0 s |
|
`remote_service::unverified_ollama_images_are_checked_after_pull_before_storage`
| PASS | 9.2 s |
|
`remote_service::unverified_vllm_images_are_checked_after_pull_before_storage`
| PASS | 9.0 s |

Every scenario now deploys with `cpuLimitMillis` (1250 for vLLM, 10 for
Ollama) and `memoryLimitGiB: 64`.
What this PR adds to them:

- Each apply through the shared `Scenario::apply` helper checks
`CpuPeriod`, `CpuQuota`, `Memory` and `MemorySwap` in the container's
`HostConfig`, and its `memory-limit-gib` label, for vLLM and, in
`remote_ollama_preserve_…`, for Ollama.
- An image change (vLLM and Ollama) and a memory decrease (Ollama) are
refused at plan and apply, leaving the engine state, runtime state and
`intent.json` unchanged, then planned as a replacement under `Recreate`.
These steps run in their own scenarios, `remote_vllm_preserve_…` and
`remote_ollama_preserve_…`, each ending with the no-probe check, so
`remote_model_…` and `remote_ollama_recovers_…` keep close to `v1`'s
steps and time.
- A stopped vLLM container, which the provider refreshes as `must_run =
false`, is replaced under `Preserve`.
- The bearer key survives an image replacement under `Recreate`.

Reds: each run rebuilt the bundle with `cargo ci bundle` from the
modified tree, then ran `NEMOCLAW_TEST_BUNDLE=$PWD/dist/linux_arm64
cargo nextest run --locked --workspace --all-targets --profile lifecycle
--run-ignored only -E 'test(/^remote_service::/)'` on all 11
`remote_service` tests.

- **v1 code** (`v1` a5445c7 with its own bundle, and this branch's
`remote_service.rs`): all 11 fail at scenario setup, because `v1`
rejects `container.cpuLimitMillis` ("unknown fields are not allowed").
- **Without the `preserve_docker_models` call:**
`remote_vllm_preserve_…` and `remote_ollama_preserve_…` fail, because
the plan they expect to be refused succeeds. The other 9 pass:
`managed_bearer_credentials_…` uses `Recreate`, and `remote_model_…` and
`remote_ollama_recovers_…` no longer change the image or memory.
- **Without the memory-limit label:** the five scenarios that apply
through `Scenario::apply` (`remote_model_…`, both `…_preserve_…` tests,
`managed_bearer_cleanup_…` and `managed_pi_…`) fail the
`memory-limit-gib` label check after their first apply. In a diagnostic
run that applied `remote_ollama_preserve_…` without that check, it
failed because a memory decrease under `Recreate` plans an in-place
`["update"]`, not a replacement. That in-place update is the CL-1
failure.
- **With stopped containers also protected** (the `must_run != false`
clause removed): `remote_model_…` fails, because the plan for its
stopped container is refused with `DockerModelUpdateRefused`. The other
10 pass.

**Timing budget.**
On linux_amd64, this PR's first CI run took 91.3 s for
`remote_ollama_recovers_…`, over the 90 s per-test lifecycle limit in
`.config/test-budgets.yaml`, and 81.0 s for `remote_model_…`; `v1` runs
them there in 65.7–68.7 s and 67.5–68.7 s.
This PR had added an image change and a memory decrease to
`remote_ollama_recovers_…`, and `Preserve` refusals to
`remote_model_…`'s existing image-change step.
Those steps now run in `remote_vllm_preserve_…` and
`remote_ollama_preserve_…`, as #13042 split the deployment lifecycle
test into explicit scenarios; no limit changes.
In three runs of the `remote_service` tests on this host, interleaved
with `v1` a5445c7's:

| Test | This PR | `v1` | Estimate on linux_amd64 |
|---|---|---|---|
| `remote_model_…` | 85.0–85.3 s | 86.4–87.3 s | 67 s |
| `remote_ollama_recovers_…` | 86.0–87.0 s | 86.0–87.4 s | 67 s |
| `remote_ollama_preserve_…` | 42.7–43.1 s | — | 33–39 s |
| `remote_vllm_preserve_…` | 25.5–26.3 s | — | 20–24 s |

Each estimate multiplies this PR's time by `v1`'s linux_amd64 time over
its time here: 0.77–0.79 for the two existing tests, and 0.77–0.91 (the
range across `remote_service` tests) for the new ones.
CI runs the lifecycle suite in two slices with a 300 s budget each. Run
the same way here (`cargo ci lifecycle --partition slice:N/2`, twice
each), this branch's slices took 208.9–211.1 s and 218.0–226.6 s; `v1`'s
took 208.9–209.0 s and 198.7–201.7 s here and 201.6–206.0 s and
184.2–186.8 s on linux_amd64. Scaled the same way, this branch's slices
would take about 204 s and 206 s there.

## Depends on / merge order

- Base: `v1` (a5445c7 is merged into this branch). No dependencies;
merges in parallel with #13056, #13057 and #13059.
- It shares files with #13057 (`remote_service.rs`, `vllm/mod.rs`) and
#13059 (`formatting.rs`). `git merge-tree` of this branch with the
planning slices for #13056, #13057, #13059 and #13060 reports no
conflicts.
- #13061 needs this PR in `v1`, because its cluster settings use
`ServiceUpdatePolicy`. #13062 adds back the Kubernetes and OpenShift
wording removed from this PR's doc comments and docs, and the
`kubernetes.is_none()` guards in `preserve_docker_models`.

### Live evidence (not qualification; #12732 stays open)

`split/3-docker-container-limits` @ `fe97763b7`, this branch's
`dist/linux_arm64` bundle (`0.1.0-dev.2857ec70977bc92c`). 2026-10-12,
one GB300 (ARM64), local Docker engine, Docker managed gateway.

**Setup.** A copy of #12736's review deployment `docker-openclaw` with a
fresh UID and state directory, on 172.30.142.0/24 port 17842:
- managed Ollama `qwen3:0.6b`, profile `gb300`, image
`nc-prototype-ollama@sha256:dea377de…`;
- `container.cpuLimitMillis: 4000`, `container.memoryLimitGiB: 48`;
- an OpenClaw sandbox (image built from `split/8`; `image/` is identical
to `v1`).

| Check | Observed |
|---|---|
| Plan | `Plan incomplete · 6 known resource changes` |
| Apply | Ollama created in 1 s, agent runtime in 17 s. Apply ended
after 102 s with the known readiness message. |
| `docker inspect` of the model container | `CpuPeriod=100000`,
`CpuQuota=400000` (4000 millis × 100), `NanoCpus=0`,
`Memory=51539607552` (48 GiB), labels
`nemoclaw.nvidia.com/cpu-limit-millis=4000` and `memory-limit-gib=48`,
runtime `nvidia` |
| `memoryLimitGiB` 48 → 40 under the default `Preserve`: plan | EXIT 1:
`Docker model service 'qwen' is preserved by updatePolicy: Preserve;
replacing a running or incompletely observed container requires explicit
updatePolicy: Recreate, which permits downtime if the replacement cannot
start; resources retained`, plus the `DockerModelUpdateRefused` help
(below) |
| Same change: apply | EXIT 1: `No runtime resources changed.` plus the
same help |
| Container after the refused change | Same container ID; `Memory` still
48 GiB |
| Same change with `updatePolicy: Recreate` | 68 s. `ollama/qwen: delete
complete`, then `create complete`. New container ID with
`Memory=42949672960` (40 GiB), label `memory-limit-gib=40`,
`CpuQuota=400000` unchanged. The next plan: `No resource changes
planned.` |
| Destroy | `Destroy complete · 10s`; GPU back to 0 MiB |

The help printed at both plan and apply: `To replace the running model
container, set spec.services.qwen.updatePolicy: Recreate and apply
again; the model is unavailable until the replacement starts. See
docs/inference.md#set-container-limits-and-update-policy.`

Notes:
- Both applies ended with the known upstream "Fabric readiness could not
be established" (`fabric_health_unsupported`). This is not a failure of
this PR.
- Destroy retained the gateway-init container, the network and the
`gateway-data` and `ollama-qwen-data` volumes, as designed.

Split from #12736.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
gaveezy and others added 3 commits October 13, 2026 17:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

@wscurran wscurran added area: providers Inference provider integrations and provider behavior area: security Security controls, permissions, secrets, or hardening platform: k8s Affects Kubernetes deployments refactor PR restructures code without intended behavior change labels Oct 13, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cv added a commit that referenced this pull request Oct 14, 2026
…ofile metadata (#13125)

Unsupported OpenShell provider profile metadata and an unparsable static
search rule now return observation errors instead of aborting the
provider process.

## Why

`annotations()` looked up each profile metadata field with
`expect("profile metadata field")`, and the search profile definition
parsed its static rule with `expect("static search policy")`. A
violation of either invariant panicked the `openshell` provider.

## What changes

- `annotations()` returns `Result` and reports an unknown field as
`Incomplete`.
- `definition_with_rule` takes the search rule as an argument, so a test
can pass an invalid one; an unparsable rule returns `Query`.

No schema, state, or behavior change for valid profiles.

## Validation

- New tests
`unsupported_profile_metadata_returns_an_error_instead_of_panicking` and
`unsupported_search_rules_return_an_observation_error` fail to compile
on `v1` (E0308, E0425) and pass with this change.
- `cargo ci` passed on `v1` with the three split PRs combined (#13125,
#13126, #13127): 1452 tests, 136 lifecycle tests.

Split from #13060 (Hai Nguyen's work; co-authored).

Co-authored-by: Hai Nguyen <haingu@nvidia.com>
cv added a commit that referenced this pull request Oct 14, 2026
`nemoclaw_tofu::Definition` can now name bound fields. Refresh returns
`BindingMismatch` when an observed bound field differs from state,
treating omission as the empty value.

## Why

Refresh writes the observed row into state. For a field that records
which object a resource is bound to, such as the cluster source of an
inference profile, a substituted observation would silently rebind the
resource. A bound field makes that observation an error instead.

## What changes

- `Definition::bound_fields` (builder) and the public `bound_fields`
field.
- `ResourceAdapter::checked` compares each bound field between prior
state and the observation before the existing attribute checks.

No definition declares a bound field yet, so no provider behavior
changes. The OpenShell provider profile adopts it in the follow-up
cluster PR.

## Validation

- New test `resource::tests::refresh_preserves_declared_bound_fields`
fails to compile on `v1` (E0599, no method `bound_fields`) and passes
with this change.
- `cargo ci` passed on `v1` with the three split PRs combined: 1452
tests, 136 lifecycle tests.

Split from #13060 (Hai Nguyen's work; co-authored).

Co-authored-by: Hai Nguyen <haingu@nvidia.com>
cv added a commit that referenced this pull request Oct 14, 2026
…nShell and Fabric providers (#13127)

Callers of the OpenShell and Fabric providers can inject a `Services`
implementation for inference credential sources. The default,
`DockerServices`, keeps today's `nemoclaw_docker::credentials` behavior,
and the bundled provider binaries keep the default.

## Why

Provider credentials were parsed and resolved only through
`nemoclaw_docker::credentials`, so a caller could not supply another
source, such as credentials for cluster model Services.

## What changes

- `openshell_provider::Services` with `validate_credential_source` and
`resolve_credential_source`; `DockerServices` implements them with
`nemoclaw_docker::credentials`.
- `GatewayClient::with_services`, `OpenShell::connect_with_services`,
`OpenShellProvider::with_services`, and `FabricProvider::with_services`.
`Default` and `OpenShell::connect` use `DockerServices`.
- Provider registration observation and creation call the injected
services instead of `nemoclaw_docker::credentials` directly.

No schema, state, or behavior change. Rust API additions only; the
crates are `publish = false`.

## Validation

- New test `fabric-provider`
`provider::tests::configured_provider_observes_registrations_through_its_injected_services`
creates a registration with a credential source only the injected
services accept, then reads it through `FabricProvider::with_services`.
With a mutant where `with_services` ignores `services`, the read fails
with `Err(Incomplete)`; with this change it passes. It runs in the
regular test step, closing the gap where only an ignored lifecycle test
constructed `FabricProvider::with_services`.
- `cargo ci` passed on `v1` with the three split PRs combined: 1452
tests, 136 lifecycle tests.

The cluster methods (`validate_cluster_source`, `cluster_addresses`)
follow in a separate PR.

Split from #13060 (Hai Nguyen's work; co-authored).

Co-authored-by: Hai Nguyen <haingu@nvidia.com>
cv added a commit that referenced this pull request Oct 14, 2026
…dresses (#13128)

"An OpenShell provider profile can now carry a verified cluster source,
and a sandbox policy can grant that cluster Service's verified
addresses. The bundled providers use `DockerServices`, which rejects
every cluster source, so Docker and Podman deployments are unchanged
until a cluster `Services` implementation is injected (#13063).\n\n##
Why\n\n#12736 routes sandboxes to vLLM and Ollama Pods that the
deployment runs in its cluster. A cluster model is reached by a
`<name>.svc.cluster.local` host, so an inference profile, which grants
only the literal IP in its endpoint URL, could not grant the Service's
ClusterIP, and nothing checked which Service owned the address.\n\n##
What changes\n\n- **`Services` hook:** adds `validate_cluster_source`
and `cluster_addresses` to the trait from #13127. `DockerServices`
returns `BindingMismatch` from both.\n- **Cluster profiles:**
`openshell_provider_profile` gains an optional, computed
`cluster_source`.\n - It is a bound field (#13126) and resets to empty
when omitted on update, so any change replaces the profile.\n -
`nemoclaw_openshell::profile::cluster_definition` accepts only an
`http://<host>.svc.cluster.local:<port>/v1` endpoint without
credentials, query, or fragment, and grants only the addresses
`Services::cluster_addresses` returns.\n - `service_address_allowed`
rejects unspecified, loopback, multicast, link-local, broadcast, and
IPv4-mapped addresses.\n - The source and addresses are stored in new
`nemoclaw.nvidia.com/cluster-source` and `cluster-addresses`
annotations. Refresh re-reads the addresses and rejects a profile whose
endpoints no longer match them.\n- **Cluster grants:**
`PolicyInput.cluster_grants` names managed rules whose `allowed_ips`
come from verified cluster profiles (`RuntimeBinding::granted_policy`:
one or two unique `/32` or `/128` addresses per rule). Sandbox create
(`create_sandbox_request`) and refresh (`checked_sandbox_row_with`)
check each grant against the deployment's own profile: same owner,
listed among the sandbox's providers, and the same endpoint apart from
`allowed_ips`. Removal checks only the recorded policy, so it works when
the Service is gone. The field is omitted from serialized policy when
empty.\n- **SDK:** `image_runtime::policy_input` sets `cluster_grants:
Default::default()`.\n\n## Breaking or user-visible changes\n\n-
**Provider schema:** `openshell_provider_profile` gains
`cluster_source`, and the `openshell_sandbox` `policy` block gains
`cluster_grants`. With the bundled `DockerServices`, a profile with
`cluster_source` or a sandbox with `cluster_grants` fails on create and
read (`docker_services_reject_cluster_profiles`).\n- **State and
annotations:** no change for existing resources. `cluster_grants` is not
serialized when empty, and a profile without a cluster source writes no
new annotations.\n- **Rust API:**
`nemoclaw_openshell::runtime::PolicyInput` gains the public
`cluster_grants` field, so struct literals need it. The crates are
`publish = false`.\n\n## Validation\n\n`cargo ci` passed on this tree
(linux_amd64): 1462 tests and 136 lifecycle tests.\n\nNew tests:\n\n|
Test | Checks |\n|---|---|\n| `nemoclaw-provider`
`refresh::profile_refresh_preserves_the_bound_cluster_source` | Fails on
`v1` before this PR: state becomes `substituted-service`. |\n|
`refresh::changing_from_cluster_to_external_inference_replaces_the_owned_profile`
| Fails on `v1` before this PR: planned `cluster_source` stays
`owned-cluster-storage`. |\n| `nemoclaw-openshell`
`profile::tests::cluster_profiles_accept_only_plain_service_endpoints_and_unicast_addresses`
| Endpoint shape and address filter. |\n| `openshell-provider`
`profile::tests::docker_services_reject_cluster_profiles` | Bundled
default rejects cluster sources. |\n|
`owned_cluster_profiles_grant_exact_observed_addresses_and_reject_others`
| Exact `/32` and `/128` grants; no broader observed grant. |\n|
`cluster_grants_resolve_the_endpoint_ambiguity_with_the_provider_profile`
| Without the grant, OpenShell reports one endpoint ambiguity; with it,
none. |\n|
`profile_removal_validates_recorded_grants_when_the_service_is_absent` |
Refresh needs the Service; removal does not, but still rejects a
broadened grant. |\n|
`cluster_sandbox_grants_require_the_matching_owned_profile_and_exact_host_addresses`
| Grant count, prefix, uniqueness, owner, provider listing, endpoint.
|\n|
`sandbox_refresh_verifies_current_grants_but_removal_uses_recorded_policy`
| Moved or absent Service fails refresh; removal checks only recorded
policy. |\n| `fabric-provider`
`configured_provider_observes_cluster_grants_through_its_injected_services`
| `FabricProvider::with_services` keeps the cluster methods. |\n\nEach
production check was mutated once, and a new test failed each time: the
`granted_policy` address filter, `cluster_grant` endpoint equality, the
sandbox refresh grant comparison, the profile refresh endpoint
comparison, the `.svc.cluster.local` host check, and the
`validate_cluster_source` call.\n\nThe openshell-provider tests build
the cluster case from the `fabric-openclaw` contract fixture, so they
need no SDK types. #13063 can keep or replace them with its SDK-built
cases.\n\nSplit from #13060 (Hai Nguyen's work; co-authored). Follows
#13125, #13126, and #13127."

Co-authored-by: Hai Nguyen <haingu@nvidia.com>
@cv

cv commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of four smaller PRs carrying this work, now merged into v1:

Each commit credits you as co-author. The split/5-openshell-services-hook branch is untouched because #13061 targets it; rebasing #13061 onto v1 should leave only its own changes, since the four PRs cover this branch's diff.

@cv cv closed this Oct 14, 2026
gaveezy added a commit that referenced this pull request Oct 14, 2026
PR-6 and PR-7 merged v1 after #13060 was closed in favor of #13125,
#13126, #13127, and #13128. This merge brings v1's versions of that
code into PR-8; git merged it without conflicts.

#13128 added SDK-free cluster tests to the `tests` module of
`crates/openshell-provider/src/profile.rs`, next to PR-8's tests built
from the SDK. Four names are now defined twice there, so that module
does not compile at this commit. The next commit resolves them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gaveezy
gaveezy deleted the split/5-openshell-services-hook branch October 14, 2026 04:03
@wscurran wscurran added the v1 NemoClaw v1 branch label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: providers Inference provider integrations and provider behavior area: security Security controls, permissions, secrets, or hardening platform: k8s Affects Kubernetes deployments 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.

3 participants