Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
27c72f5
fix(runtime): close prior review debt
ericksoa Jul 31, 2026
1c824cc
test(runtime): keep env cleanup branchless
ericksoa Jul 31, 2026
5c6b3f7
fix(runtime): preserve direct image execution
ericksoa Jul 31, 2026
611fdb6
fix(messaging): reject ambiguous channel identities
ericksoa Jul 31, 2026
76c54d4
fix(messaging): require canonical persisted channel ids
ericksoa Jul 31, 2026
7cf2a8d
chore(stack): refresh PR3.5b on current PR3.5a
ericksoa Jul 31, 2026
5f9d97d
test(e2e): add cross-runtime foundation
ericksoa Jul 31, 2026
abf45b3
test(e2e): keep runtime foundation branchless
ericksoa Jul 31, 2026
ed479ae
refactor(runtime): unify provider bundle registry
ericksoa Jul 31, 2026
005b3a7
fix(runtime): harden provider contract boundaries
ericksoa Jul 31, 2026
05cf2a5
fix(runtime): fail closed on managed image cleanup
ericksoa Jul 31, 2026
5c29046
fix(messaging): reject unresolved build hooks
ericksoa Jul 31, 2026
534773b
fix(runtime): close provider lifecycle authority gaps
ericksoa Jul 31, 2026
847e827
chore(stack): refresh PR3.5c on current PR3.5b
ericksoa Jul 31, 2026
77559f7
test(runtime): keep provider parity branchless
ericksoa Jul 31, 2026
a2afe77
fix(e2e): harden runtime foundation contracts
ericksoa Jul 31, 2026
004b060
test(e2e): verify fixture profiles stay unregistered
ericksoa Jul 31, 2026
771f48c
chore(stack): refresh PR3.5b on current PR3.5a
ericksoa Jul 31, 2026
c67afd3
chore(stack): refresh PR3.5c on current PR3.5b
ericksoa Jul 31, 2026
4788d28
test(e2e): expose runtime profile registration state
ericksoa Jul 31, 2026
64f562f
fix(runtime): preserve unproven cleanup authority
ericksoa Jul 31, 2026
15eef1b
chore(stack): refresh PR3.6 on repaired base
ericksoa Jul 31, 2026
d73f13a
test(runtime): cover unknown provider doctor result
ericksoa Jul 31, 2026
8f8bcd5
test(runtime): prove provider recovery boundaries
ericksoa Jul 31, 2026
f77bff8
fix(runtime): fail closed on retained cleanup ownership
ericksoa Jul 31, 2026
bf2fd19
test(rebuild): type cleanup ownership receipt
ericksoa Jul 31, 2026
4316a18
fix(runtime): prove cleanup authority before deletion
ericksoa Jul 31, 2026
062d66b
test(snapshot): mock destructive cleanup authority
ericksoa Jul 31, 2026
75730cf
test(runtime): prove cleanup planning is inert
ericksoa Jul 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/source-architecture-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"maxByFile": {
"src/lib/actions/sandbox/mcp-bridge-contracts.ts": 26,
"src/lib/actions/sandbox/process-recovery.ts": 26,
"src/lib/adapters/docker/index.ts": 45,
"src/lib/adapters/docker/index.ts": 43,
"src/lib/adapters/openshell/client.ts": 22,
"src/lib/adapters/openshell/resolve.ts": 28,
"src/lib/adapters/openshell/runtime.ts": 50,
"src/lib/adapters/openshell/timeouts.ts": 36,
"src/lib/agent/defs.ts": 32,
"src/lib/cli/branding.ts": 85,
"src/lib/cli/branding.ts": 84,
"src/lib/cli/nemoclaw-oclif-command.ts": 103,
"src/lib/cli/terminal-style.ts": 45,
"src/lib/core/json-types.ts": 37,
Expand Down
5 changes: 5 additions & 0 deletions ci/source-shape-test-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@
"test": "requires one advisor lane to publish the PR comment",
"category": "security"
},
{
"file": "test/runtime-provider-source-shape.test.ts",
"test": "keeps migrated provider identities and implementations behind the one bundle composition",
"category": "compatibility"
},
{
"file": "test/pr-limit-policy.test.ts",
"test": "keeps contributor guidance aligned with the enforced maintainer exemption",
Expand Down
44 changes: 43 additions & 1 deletion src/lib/actions/inference-set-failure-handling.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { InferenceSetError, runInferenceSet } from "./inference-set";
import { createDeps } from "./inference-set.test-support";

describe("runInferenceSet failure handling", () => {
it("fails before OpenShell or config mutation for an unknown durable runtime provider", async () => {
const deps = createDeps({
config: {},
entry: { name: "alpha", agent: "openclaw", openshellDriver: "unknown-runtime" },
});

await expect(
runInferenceSet({ provider: "nvidia-prod", model: "nvidia/model-a" }, deps),
).rejects.toThrow(/unknown-runtime.*not registered/u);
expect(deps.calls.prepareRunOpenshell).not.toHaveBeenCalled();
expect(deps.calls.captureOpenshell).not.toHaveBeenCalled();
expect(deps.calls.writeSandboxConfig).not.toHaveBeenCalled();
});

it("rechecks live runtime authority inside the sandbox mutation lock", async () => {
const initial = { name: "alpha", agent: "openclaw", openshellDriver: "docker" } as const;
const changed = {
name: "alpha",
agent: "openclaw",
openshellDriver: "unknown-runtime",
} as const;
const deps = createDeps({ config: {}, entry: initial });
deps.getSandbox = vi.fn().mockReturnValueOnce(initial).mockReturnValue(changed);

await expect(
runInferenceSet(
{
provider: "nvidia-prod",
model: "nvidia/model-a",
sandboxName: "alpha",
},
deps,
),
).rejects.toThrow(/unknown-runtime.*not registered/u);

expect(deps.calls.prepareRunOpenshell).toHaveBeenCalledOnce();
expect(deps.calls.withGatewayRouteMutationLock).not.toHaveBeenCalled();
expect(deps.calls.captureOpenshell).not.toHaveBeenCalled();
expect(deps.calls.writeSandboxConfig).not.toHaveBeenCalled();
expect(deps.calls.updateSandbox).not.toHaveBeenCalled();
});

it("resolves the OpenShell runner before entering the async mutation lock", async () => {
const deps = createDeps({
config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } },
Expand Down
17 changes: 17 additions & 0 deletions src/lib/actions/inference-set-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@ import {
matchesGatewayProviderBinding,
parseGatewayProviderMetadata,
} from "../onboard/gateway-provider-metadata";
import {
CURRENT_RUNTIME_PROVIDER_BUNDLES,
type RuntimeProviderBundleRegistry,
requireRuntimeProviderBundleForSandbox,
requireRuntimeProviderMutationAuthority,
} from "../onboard/runtime-provider/access";
import type { SandboxEntry } from "../state/registry";
import {
InferenceSetError,
OPEN_SHELL_FAILURE_CAPTURE_MAX_BUFFER,
openshellReportsProviderNotFound,
} from "./inference-set-error";
import type { InferenceSetProviderBinding } from "./inference-set-route-containment";

export type { RuntimeProviderBundleRegistry };

export function requireInferenceSetRuntimeAuthority(
entry: SandboxEntry,
providers: RuntimeProviderBundleRegistry = CURRENT_RUNTIME_PROVIDER_BUNDLES,
): void {
const runtimeProvider = requireRuntimeProviderBundleForSandbox(entry, providers);
requireRuntimeProviderMutationAuthority(runtimeProvider, "inference-set");
}

type CaptureProviderCommand = (
args: string[],
options: {
Expand Down
20 changes: 19 additions & 1 deletion src/lib/actions/inference-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ import {
type InferenceMutation,
readPreviousOpenClawInferenceApi,
} from "./inference-set-gateway-restart";
import { prepareInferenceSetProviderBinding } from "./inference-set-provider";
import {
prepareInferenceSetProviderBinding,
type RuntimeProviderBundleRegistry,
requireInferenceSetRuntimeAuthority,
} from "./inference-set-provider";
import { buildInferenceSetFailure } from "./inference-set-provider-diagnostics";
import {
applyOpenClawAnthropicReplyBudget,
Expand Down Expand Up @@ -134,6 +138,7 @@ export interface InferenceSetDeps extends InferenceGatewayRestartDeps {
target: AgentConfigTarget,
config: ConfigObject,
) => void;
runtimeProviders?: RuntimeProviderBundleRegistry;
recomputeSandboxConfigHash: (sandboxName: string, target: AgentConfigTarget) => void;
seedHermesDashboardConfig: (
sandboxName: string,
Expand Down Expand Up @@ -283,6 +288,17 @@ function assertSupportedProvider(provider: string, model: string): void {
);
}

function assertInferenceSetRuntimeAuthority(
entry: SandboxEntry,
providers: RuntimeProviderBundleRegistry | undefined,
): void {
try {
requireInferenceSetRuntimeAuthority(entry, providers);
} catch (error) {
throw new InferenceSetError(error instanceof Error ? error.message : String(error), 2);
}
}

function normalizeSandboxAgent(agentName: string | null | undefined): string {
const trimmed = typeof agentName === "string" ? agentName.trim() : "";
return (trimmed || "openclaw").toLowerCase();
Expand Down Expand Up @@ -1336,9 +1352,11 @@ export async function runInferenceSet(
// missing-binary path exits the process, which cannot be deferred safely by
// an async lock. The inner resolution still validates the live registry entry.
const selected = resolveTargetSandbox(options.sandboxName, deps);
assertInferenceSetRuntimeAuthority(selected.entry, deps.runtimeProviders);
deps.prepareRunOpenshell();
return withSandboxMutationLock(selected.sandboxName, async () => {
const lockedSelection = resolveTargetSandbox(selected.sandboxName, deps);
assertInferenceSetRuntimeAuthority(lockedSelection.entry, deps.runtimeProviders);
const gatewayName = resolveSandboxGatewayName(lockedSelection.entry);
const mutation = await deps.withGatewayRouteMutationLock(gatewayName, () =>
withTimerBoundShieldsMutationLockAsync(selected.sandboxName, "inference set", () =>
Expand Down
47 changes: 43 additions & 4 deletions src/lib/actions/sandbox/destroy-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

import { R, YW } from "../../cli/terminal-style";
import { getSandboxDeleteOutcome } from "../../domain/sandbox/destroy";
import {
CURRENT_RUNTIME_PROVIDER_BUNDLES,
type RuntimeProviderBundle,
type RuntimeProviderBundleRegistry,
requireRuntimeProviderDestructiveCleanupAuthority,
} from "../../onboard/runtime-provider/access";
import {
type DetachSandboxProvidersResult,
runSandboxProviderPreDeleteCleanup,
Expand All @@ -28,6 +34,11 @@ type SandboxDestroyExecutionInput = {
sandbox: SandboxEntry | null;
sandboxConfirmedAbsent: boolean;
sandboxName: string;
runtimeProviders?: RuntimeProviderBundleRegistry;
deps?: {
readTimerMarker?: typeof readTimerMarker;
wipeSandboxState?: typeof wipeSandboxState;
};
};

export type SandboxDestroyExecutionResult =
Expand Down Expand Up @@ -86,13 +97,14 @@ async function prepareMcpDestroy(
function wipeAndHardenLiveSandbox(
sandboxName: string,
sandboxConfirmedAbsent: boolean,
deps: NonNullable<SandboxDestroyExecutionInput["deps"]> = {},
): HardenedDeleteState {
if (sandboxConfirmedAbsent) return { hardenedForDelete: false };

// Wipe before delete while the retained volume is still mounted. The caller
// holds the timer-bound lock across this phase and all following teardown.
wipeSandboxState(sandboxName);
const timerMarker = readTimerMarker(sandboxName);
(deps.wipeSandboxState ?? wipeSandboxState)(sandboxName);
const timerMarker = (deps.readTimerMarker ?? readTimerMarker)(sandboxName);
if (!timerMarker) return { hardenedForDelete: false };

const timerProcessToken = /^[0-9a-f]{32}$/.test(timerMarker.processToken ?? "")
Expand Down Expand Up @@ -179,8 +191,31 @@ export async function executeSandboxDestroy({
sandbox,
sandboxConfirmedAbsent,
sandboxName,
runtimeProviders = CURRENT_RUNTIME_PROVIDER_BUNDLES,
deps = {},
}: SandboxDestroyExecutionInput): Promise<SandboxDestroyExecutionResult> {
return withTimerBoundShieldsMutationLockAsync(sandboxName, "destroy sandbox", async () => {
let runtimeProvider: RuntimeProviderBundle | null = null;
if (sandbox) {
try {
runtimeProvider = requireRuntimeProviderDestructiveCleanupAuthority(
sandboxName,
sandbox,
runtimeProviders,
).provider;
} catch (error) {
return {
ok: false as const,
deleteOutput:
error instanceof Error
? error.message
: `Runtime provider authority could not be proven: ${String(error)}`,
exitCode: 1,
gatewayUnreachable: false,
mcpOwnershipRequiresGateway: false,
};
}
}
const mcpPreparation = await prepareMcpDestroy(
sandboxName,
sandbox,
Expand All @@ -191,10 +226,14 @@ export async function executeSandboxDestroy({
// discarded during preparation. Remaining entries are the durable exact
// provider ownership manifest and must survive an unconfirmed delete.
const hasMcpOwnership = mcpPreparation.entries.length > 0;
const hardened = wipeAndHardenLiveSandbox(sandboxName, sandboxConfirmedAbsent);
const hardened = wipeAndHardenLiveSandbox(sandboxName, sandboxConfirmedAbsent, deps);
const detachProviders = (): DetachSandboxProvidersResult =>
runSandboxProviderPreDeleteCleanup(sandboxName, { runOpenshell, redact });
const detachOutcome: DetachSandboxProvidersResult = sandboxConfirmedAbsent
? { detached: [], failures: [] }
: runSandboxProviderPreDeleteCleanup(sandboxName, { runOpenshell, redact });
: runtimeProvider?.cleanup.supported === true && sandbox
? runtimeProvider.cleanup.prepareDestroy({ sandbox, sandboxName }, { detachProviders })
: detachProviders();
const deleteResult = runOpenshell(["sandbox", "delete", sandboxName], {
ignoreError: true,
stdio: ["ignore", "pipe", "pipe"],
Expand Down
65 changes: 65 additions & 0 deletions src/lib/actions/sandbox/destroy-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,71 @@ describe("destroySandbox flow", () => {
expectFailedDeletePreservesHostState(harness, exitSpy);
});

it("preserves provider and registry ownership when runtime authority is unknown", async () => {
const harness = createDestroyHarness({
openshellDriver: "unknown-runtime",
});

await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow("process.exit(1)");

const errorOutput = harness.errorSpy.mock.calls.map((call) => String(call[0])).join("\n");
expect(errorOutput).toContain("unknown-runtime");
expect(errorOutput).toContain("is not registered for this operation");
expect(
harness.runOpenshellSpy.mock.calls.some(
([args]) => Array.isArray(args) && args[0] === "sandbox" && args[1] === "delete",
),
).toBe(false);
expect(harness.removeSandboxSpy).not.toHaveBeenCalled();
});

it("blocks deletion and preserves ownership when image authority is unproven", async () => {
const harness = createDestroyHarness({
imageTag: "local/alpha:current",
workload: {
schemaVersion: 1,
kind: "legacy-dockerfile",
reference: "local/alpha:recorded",
shared: false,
},
});

await expect(harness.destroySandbox("alpha", { yes: true })).rejects.toThrow("process.exit(1)");

const errorOutput = harness.errorSpy.mock.calls.map((call) => String(call[0])).join("\n");
const logOutput = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n");
expect(errorOutput).toContain("Runtime provider 'docker'");
expect(errorOutput).toContain("recorded workload receipt");
expect(logOutput).not.toContain("Sandbox 'alpha' destroyed");
expect(harness.events).not.toContain("delete");
expect(harness.removeSandboxSpy).not.toHaveBeenCalled();
expect(harness.updateSessionSpy).not.toHaveBeenCalled();
});

it("retires registry and session ownership after the workload receipt is repaired", async () => {
const imageTag = "local/alpha:current";
const harness = createDestroyHarness({
imageTag,
workload: {
schemaVersion: 1,
kind: "legacy-dockerfile",
reference: imageTag,
shared: false,
},
});

await expect(harness.destroySandbox("alpha", { yes: true })).resolves.toBeUndefined();

expect(harness.dockerRunSpy).toHaveBeenCalledWith(["rmi", imageTag], {
ignoreError: true,
});
expect(harness.removeSandboxSpy).toHaveBeenCalledWith("alpha");
expect(harness.updateSessionSpy).toHaveBeenCalledOnce();
expect(harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n")).toContain(
"Sandbox 'alpha' destroyed",
);
});

it("refuses shields-up Hermes MCP destroy before stopping services or preparing MCP state", async () => {
const harness = createDestroyHarness({
agent: "hermes",
Expand Down
Loading
Loading