Skip to content
Merged
2 changes: 1 addition & 1 deletion ci/test-file-size-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test/generate-openclaw-config.test.ts": 1907,
"test/install-preflight.test.ts": 3025,
"test/nemoclaw-start.test.ts": 4671,
"test/onboard-messaging.test.ts": 2033,
"test/onboard-messaging.test.ts": 2028,
"test/onboard-selection.test.ts": 4177
}
}
29 changes: 15 additions & 14 deletions src/lib/actions/sandbox/mcp-bridge-add-restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,28 +452,29 @@ async function addMcpBridgeUnlocked(
previousRevision: previousCredentialRevision,
}
: {}),
// A no-field provider update advances only the provider resource version.
// If the credential remains available, republish it after observing an
// absence; otherwise, a hostless recovery advances the provider revision.
// After an observed absence, republish an available host credential and
// then advance the provider resource version with a no-field update.
// Hostless recovery reuses the stored credential before the same refresh.
refreshAfterObservedAbsence: () => {
// invalidState: OpenShell 0.0.106 can coalesce a no-field provider
// refresh without publishing the credential into fresh sandbox execs.
// invalidState: OpenShell 0.0.106 can leave the credential absent from
// fresh sandbox execs after a credential-bearing provider update.
// sourceBoundary: OpenShell owns provider revision projection.
// whyNotSourceFix: NemoClaw can only observe absence after the bound
// policy is active, then republish when this process still has the host
// credential value. Hostless recovery retains the credential-free path.
// regressionTest: mcp-add-crash-consistency.test.ts covers republish
// and hostless recovery; mcp-provider-ownership.test.ts covers loss of
// the persisted provider identity before republish.
// removalCondition: remove the credential-bearing republish when the
// supported OpenShell version guarantees that a post-policy no-field
// refresh projects the bound credential into fresh sandbox execs.
const republished = upsertMcpProvider(entry.providerName ?? "", options.env, {
// credential value. One no-field update then publishes a new provider
// revision while preserving the exact provider ownership boundary.
// regressionTest: mcp-add-crash-consistency.test.ts covers the ordered
// republish and refresh plus hostless recovery; mcp-provider-ownership.test.ts
// covers loss of the persisted provider identity before either mutation.
// removalCondition: remove the ordered republish and refresh when the
// supported OpenShell version projects a credential-bearing update into
// fresh sandbox execs after policy binding.
upsertMcpProvider(entry.providerName ?? "", options.env, {
allowExisting: true,
expectedProviderId: entry.providerId,
requireExisting: true,
});
if (republished.action !== "updated") refreshMcpProviderEnvironment(entry);
refreshMcpProviderEnvironment(entry);
},
});
// The adapter was proven absent above, so cleanup is safe even when a
Expand Down
43 changes: 0 additions & 43 deletions src/lib/onboard/created-sandbox-finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import type { SandboxEntry } from "../state/registry";
import * as sandboxState from "../state/sandbox";
import {
completeOrdinaryOnboardSandboxCreation,
createCreatedSandboxCompletionActions,
createOnboardCreatedSandboxCompletion,
finalizeCreatedSandbox,
Expand All @@ -23,48 +22,6 @@ import type { CreatedSandboxRegistrationInput } from "./sandbox-registration";

const fixtures: string[] = [];

describe("ordinary sandbox completion", () => {
it("republishes attached provider state after Docker recreation without credential flags", () => {
const runOpenshell = vi.fn(
(_args: string[], _options: { ignoreError: true; suppressOutput: true }) => ({
status: 0,
stdout: "",
stderr: "",
}),
);
const setDefault = vi.fn();

expect(
completeOrdinaryOnboardSandboxCreation(
{
sandboxName: "alpha",
sandboxWasLiveDefault: false,
runtimeFields: { openshellDriver: "docker" } as SandboxEntry,
messagingProviders: ["alpha-slack", "alpha-slack"],
inferenceProvider: "compatible-endpoint",
liveExists: true,
},
{
setDefault,
runFile: vi.fn(),
scriptsDir: "/tmp/scripts",
gatewayName: "nemoclaw",
providerExistsInGateway: () => true,
runOpenshell,
armCancelRollback: vi.fn(),
dockerInfoFormat: vi.fn(() => "true"),
runCapture: vi.fn(() => ""),
},
),
).toBe("alpha");
expect(runOpenshell.mock.calls.map(([args]) => args)).toEqual([
["provider", "update", "-g", "nemoclaw", "compatible-endpoint"],
["provider", "update", "-g", "nemoclaw", "alpha-slack"],
]);
expect(runOpenshell.mock.calls.flat(2)).not.toContain("--credential");
});
});

afterEach(() => {
delete process.env.NEMOCLAW_OPENSHELL_BIN;
for (const fixture of fixtures.splice(0)) fs.rmSync(fixture, { recursive: true, force: true });
Expand Down
31 changes: 0 additions & 31 deletions src/lib/onboard/created-sandbox-finalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export function completeOrdinaryOnboardSandboxCreation(
readonly sandboxWasLiveDefault: boolean;
readonly runtimeFields: RegistrationSeed["runtimeFields"];
readonly messagingProviders: readonly string[];
readonly inferenceProvider: string | null;
readonly liveExists: boolean;
},
deps: {
Expand All @@ -230,14 +229,6 @@ export function completeOrdinaryOnboardSandboxCreation(
readonly scriptsDir: string;
readonly gatewayName: string;
readonly providerExistsInGateway: (providerName: string) => boolean;
readonly runOpenshell: (
args: string[],
options: { ignoreError: true; suppressOutput: true },
) => {
status: number | null;
stdout?: string | Buffer | null;
stderr?: string | Buffer | null;
};
readonly armCancelRollback: (sandboxName: string) => void;
readonly dockerInfoFormat: Parameters<typeof warnIfLandlockUnsupported>[0]["dockerInfoFormat"];
readonly runCapture: Parameters<typeof warnIfLandlockUnsupported>[0]["runCapture"];
Expand All @@ -253,28 +244,6 @@ export function completeOrdinaryOnboardSandboxCreation(
);
}
applyOnboardVmDnsMonkeypatch(input.sandboxName, input.runtimeFields);
if (input.runtimeFields.openshellDriver === "docker") {
const attachedProviders = new Set(
[input.inferenceProvider, ...input.messagingProviders].filter(
(provider): provider is string => Boolean(provider),
),
);
for (const provider of attachedProviders) {
if (!deps.providerExistsInGateway(provider)) continue;
const refreshed = deps.runOpenshell(
["provider", "update", "-g", deps.gatewayName, provider],
{
ignoreError: true,
suppressOutput: true,
},
);
if (refreshed.status !== 0) {
throw new Error(
`OpenShell did not republish attached provider '${provider}' after Docker sandbox recreation.`,
);
}
}
}
for (const provider of input.messagingProviders) {
if (!deps.providerExistsInGateway(provider)) printMessagingProviderMissing(provider);
}
Expand Down
64 changes: 62 additions & 2 deletions src/lib/onboard/sandbox-create/orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,51 @@ export async function completeHermesPortableSandboxRegistration(input: {
return registered;
}

function publishAttachedProvidersBeforeDockerSandboxCreation(
input: {
readonly openshellDriver: SandboxEntry["openshellDriver"];
readonly inferenceProvider: string | null;
readonly messagingProviders: readonly string[];
readonly extraProviders: readonly string[];
readonly gatewayName: string;
},
deps: Pick<SandboxCreateOrchestrationRuntime, "providerExistsInGateway" | "runOpenshell"> & {
readonly cleanupCreateSources: () => void;
},
): void {
if (input.openshellDriver === "docker") {
const providersRequiringExistenceProbe = new Set(
[input.inferenceProvider, ...input.messagingProviders].filter(
(provider): provider is string => Boolean(provider),
),
);
const attachedProviders = new Set([
...providersRequiringExistenceProbe,
...input.extraProviders,
]);
for (const attachedProvider of attachedProviders) {
if (
providersRequiringExistenceProbe.has(attachedProvider) &&
!deps.providerExistsInGateway(attachedProvider)
)
continue;
const refreshed = deps.runOpenshell(
["provider", "update", "-g", input.gatewayName, attachedProvider],
{
ignoreError: true,
suppressOutput: true,
},
);
if (refreshed.status !== 0) {
deps.cleanupCreateSources();
throw new Error(
`OpenShell did not publish attached provider '${attachedProvider}' before Docker sandbox creation.`,
);
}
}
}
}

type ApplyRecreatePolicyCarryForward = (
sandboxName: string,
nonInteractive: boolean,
Expand Down Expand Up @@ -1238,6 +1283,23 @@ export function createSandboxWithBaseImageResolution(runtime: SandboxCreateOrche
});
cleanupBuildContext();
} else {
publishAttachedProvidersBeforeDockerSandboxCreation(
{
openshellDriver: sandboxRuntimeFields.openshellDriver,
inferenceProvider: resolvedCreateIntent.inferenceProvider,
messagingProviders,
extraProviders: resolvedCreateIntent.extraProviders,
gatewayName: GATEWAY_NAME,
},
{
providerExistsInGateway,
runOpenshell,
cleanupCreateSources: () => {
cleanupInitialCreateSource();
cleanupBuildContext();
},
},
);
const created = await runCreateFlow(createArgv);
cleanupInitialCreateSource();
await completeCreatedSandboxRegistration(created, null);
Expand All @@ -1251,7 +1313,6 @@ export function createSandboxWithBaseImageResolution(runtime: SandboxCreateOrche
sandboxWasLiveDefault,
runtimeFields: sandboxRuntimeFields,
messagingProviders,
inferenceProvider: provider,
liveExists,
},
{
Expand All @@ -1260,7 +1321,6 @@ export function createSandboxWithBaseImageResolution(runtime: SandboxCreateOrche
scriptsDir: SCRIPTS,
gatewayName: GATEWAY_NAME,
providerExistsInGateway,
runOpenshell,
armCancelRollback: sandboxCancelRollback.arm,
dockerInfoFormat,
runCapture,
Expand Down
31 changes: 23 additions & 8 deletions test/mcp-add-crash-consistency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ providerCommands.runOpenshellProviderCommand = (args) => {
fs.appendFileSync(marker("republish-after-observed-absence"), "republish\n", { mode: 0o600 });
}
if (
crashAfter === "credential-projection-delayed-hostless" &&
(crashAfter === "credential-projection-coalesced" ||
crashAfter === "credential-projection-delayed-hostless") &&
isCredentialFreeRefresh &&
observedCredentialAbsentThisProcess
) {
Expand Down Expand Up @@ -223,13 +224,17 @@ processRecovery.executeSandboxExecCommand = (_sandbox, command) => {
!attachmentAttemptedThisProcess;
isPreupdateObservation && mark("observation");
if (crashAfter === "credential-projection-coalesced" && isObservation) {
if (credentialRepublishBeforeObservationCountThisProcess === 0) {
if (credentialFreeRefreshAfterAbsenceCountThisProcess === 0) {
observedCredentialAbsentThisProcess = true;
mark("credential-observed-absent");
}
return {
status: 0,
stdout: credentialRepublishBeforeObservationCountThisProcess > 0 ? "v" + providerVersion() : "absent",
stdout:
credentialRepublishAfterAbsenceCountThisProcess > 0 &&
credentialFreeRefreshAfterAbsenceCountThisProcess > 0
? "v" + providerVersion()
: "absent",
stderr: "",
};
}
Expand Down Expand Up @@ -571,7 +576,7 @@ function readBridge(home: string): Record<string, unknown> {
}

describe("MCP add crash consistency", () => {
it("commits one bridge and rejects one duplicate after delayed credential projection (#9764)", async () => {
it("commits one bridge after a credential-free refresh publishes the delayed credential revision (#9764)", async () => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-mcp-add-concurrent-projection-"));
try {
const script = buildAddProcessScript(home, "credential-projection-coalesced");
Expand All @@ -585,14 +590,24 @@ describe("MCP add crash consistency", () => {
expect(results.map((result) => result.status).sort(), combinedOutput).toEqual([0, 2]);
expect(results.find((result) => result.status === 2)?.stderr).toContain("already exists");
expect(combinedOutput).not.toContain("host-only-secret");
expect(fs.existsSync(path.join(home, "credential-observed-absent.marker"))).toBe(false);
expect(fs.existsSync(path.join(home, "credential-observed-absent.marker"))).toBe(true);
expect(fs.existsSync(path.join(home, "republish-before-observation.marker"))).toBe(true);
expect(fs.existsSync(path.join(home, "republish-after-observed-absence.marker"))).toBe(false);
const credentialRepublishCount = fs
expect(fs.existsSync(path.join(home, "republish-after-observed-absence.marker"))).toBe(true);
const credentialRepublishBeforeObservationCount = fs
.readFileSync(path.join(home, "republish-before-observation.marker"), "utf8")
.split("\n")
.filter(Boolean).length;
expect(credentialRepublishCount).toBe(1);
expect(credentialRepublishBeforeObservationCount).toBe(1);
const credentialRepublishAfterAbsenceCount = fs
.readFileSync(path.join(home, "republish-after-observed-absence.marker"), "utf8")
.split("\n")
.filter(Boolean).length;
expect(credentialRepublishAfterAbsenceCount).toBe(1);
const credentialFreeRefreshAfterAbsenceCount = fs
.readFileSync(path.join(home, "refresh-after-observed-absence.marker"), "utf8")
.split("\n")
.filter(Boolean).length;
expect(credentialFreeRefreshAfterAbsenceCount).toBe(1);
expect(fs.existsSync(path.join(home, "provider.marker"))).toBe(true);
expect(fs.existsSync(path.join(home, "attached.marker"))).toBe(true);
expect(fs.existsSync(path.join(home, "policy.marker"))).toBe(true);
Expand Down
Loading
Loading