Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions docs/security/best-practices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,14 @@ Broader binary access would let unrelated sandbox processes send data to Tavily

## Operation Telemetry

NemoClaw collects anonymous telemetry to help improve the project.
NemoClaw collects operation telemetry to help improve the project.
The data shows usage of installation, sandbox, and configuration workflows.

Records include operation outcomes, timestamps, software versions, platform categories, environment and agent counts, and approved public model, provider, and configuration choices.
Records include operation outcomes, timestamps, software versions, platforms, environment and agent counts, and observed model, provider, and configuration choices.
Observed model IDs and configuration names can include private or custom values.
Observed names and versions are limited to 64 characters; longer values become `unknown` with a `collection_error` status.
An oversized value does not discard the rest of the record.
Production delivery is not enabled.

Telemetry payloads exclude user content, credentials, private endpoints, file paths, and persistent user, device, session, or sandbox identifiers.

Expand Down
22 changes: 20 additions & 2 deletions src/lib/actions/inference-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,20 @@ function observeInferenceRouteForSelection(input: {
return observeInferenceRouteBeforeMutation(input.deps, input.gatewayName);
}

function sharedInferenceRouteChanged(
nativeProvider: boolean,
previous: OpenShellInferenceRouteObservation,
provider: string,
model: string,
): boolean {
if (nativeProvider) return false;
return (
previous.state === "unconfigured" ||
previous.route.provider !== provider ||
previous.route.model !== model
);
}

function providerBackedRouteLacksRollbackTarget(input: {
nativeProvider: boolean;
directProviderBinding: boolean;
Expand Down Expand Up @@ -1590,6 +1604,7 @@ async function runInferenceSetWithoutHostLock(
selectingNative: selectingNative && !selectingNativeLocal,
provider,
expectedAttachment: nativeProviderAuthority,
previousAttachment: previousNativeAttachment,
gatewayName: preparedRoute.gatewayName,
sandboxName,
endpointUrl: registryMetadata.endpointUrl,
Expand Down Expand Up @@ -2087,12 +2102,15 @@ async function runInferenceSetWithoutHostLock(
patched.changed,
retryingOpenClawConfigSync,
appliedProvider,
rollbackRoute?.provider !== provider,
rollbackRoute?.model !== model,
Boolean(nativeSelection.providerChanged),
nativeAttachmentChanged,
nativeLocalAttachmentChanged,
sharedInferenceRouteChanged(selectingNative, preMutationRoute, provider, model),
previousProvider !== provider,
previousModel !== model,
previousInferenceApi !== preferredInferenceApi,
(entry.endpointUrl ?? null) !== (registryMetadata.endpointUrl ?? null),
(entry.credentialEnv ?? null) !== (registryMetadata.credentialEnv ?? null),
],
expectedGatewayName,
);
Expand Down
22 changes: 14 additions & 8 deletions src/lib/actions/inference-set/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export async function prepareNativeSelection(input: {
selectingNative: boolean;
provider: string;
expectedAttachment?: NativeProviderAttachment;
previousAttachment?: NativeProviderAttachment;
gatewayName: string;
sandboxName: string;
endpointUrl?: string | null;
Expand All @@ -198,6 +199,7 @@ export async function prepareNativeSelection(input: {
}): Promise<{
attachment?: NativeProviderAttachment;
attachmentChanged: boolean;
providerChanged?: boolean;
endpointUrl?: string;
}> {
if (!input.selectingNative) return { attachmentChanged: false };
Expand Down Expand Up @@ -251,17 +253,20 @@ export async function prepareNativeSelection(input: {
hostedNativeProvider(input.provider, definition.endpointUrl)?.endpoint,
);
const target = { kind: "named", gatewayName: input.gatewayName } as const;
// Repeated selections reuse the sandbox's attached NVIDIA credential.
// Hermes host credentials use NOUS_API_KEY; OPENAI_API_KEY is its injection slot.
const credentialValue =
input.expectedAttachment &&
(!isNativeNvidiaProvider(input.provider) ||
input.previousAttachment?.providerName === input.expectedAttachment.providerName)
? null
: input.deps.resolveCredentialValue(
input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv,
) || null;
const ensured = await lifecycle.ensureNativeProvider({
adapter: input.deps.providerAdapter,
target,
// Hosted model selection must not rotate a gateway-shared provider credential.
// Hermes host credentials use NOUS_API_KEY; OPENAI_API_KEY is its injection slot.
credentialValue:
input.expectedAttachment && !isNativeNvidiaProvider(input.provider)
? null
: input.deps.resolveCredentialValue(
input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv,
) || null,
credentialValue,
...(input.expectedAttachment ? { expected: input.expectedAttachment } : {}),
...(input.expectedAttachment && !authority.read(input.gatewayName)
? { recordedSandboxName: input.sandboxName }
Expand All @@ -285,6 +290,7 @@ export async function prepareNativeSelection(input: {
return {
attachment: attached.receipt,
attachmentChanged: attached.changed,
providerChanged: !input.expectedAttachment || credentialValue !== null,
endpointUrl: attached.receipt.endpointUrl,
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/actions/sandbox/agents/telemetry-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export async function readTelemetryAgentCommand<T>(
timeoutLimitMs = 1_000,
): Promise<T | null> {
return withTelemetryEvidence(async (remainingMs, signal) => {
const runtimeSelection = resolveSandboxConfigRuntimeSelection(sandboxName);
const runtimeSelection = resolveSandboxConfigRuntimeSelection(sandboxName, {
observationOnly: true,
});
if (target.kind === "named" && target.gatewayName !== runtimeSelection.gatewayName)
throw new Error("Native evidence target does not match the recorded sandbox gateway");
const reader = createSupervisedSandboxCommandReader(signal);
Expand Down
13 changes: 10 additions & 3 deletions src/lib/actions/sandbox/mcp-bridge-provider-inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { selectedOpenShellGateway } from "../../adapters/openshell/sandbox-obser
import { OPENSHELL_DEFAULT_WORKSPACE } from "../../adapters/openshell/sandbox-ssh-host";
import { getDockerDriverGatewayLocalTlsDir } from "../../onboard/docker-driver-gateway-local-tls";
import { resolveGatewayStateDirForPort } from "../../onboard/gateway/state-dir";
import { resolveGatewayCredentialMutationAuthority } from "../../onboard/gateway-teardown-authority";
import {
resolveGatewayCredentialMutationAuthority,
resolveGatewayObservationAuthority,
} from "../../onboard/gateway-teardown-authority";
import {
evaluateGatewayAttachmentConfiguration,
isExternallySupervised,
Expand Down Expand Up @@ -135,10 +138,13 @@ function providerRuntimeLocalTlsDir(

export function getMcpProviderInspectionRuntimeSelection(
sandbox: SandboxEntry,
options: { observationOnly?: boolean } = {},
): McpProviderInspectionRuntimeSelection {
const providerRuntimeGateway = getPersistedSandboxTargetGateway(sandbox);
const { gatewayName, gatewayPort } = providerRuntimeGateway;
const owner = resolveGatewayCredentialMutationAuthority({ gatewayName, gatewayPort });
const owner = options.observationOnly
? resolveGatewayObservationAuthority({ gatewayName, gatewayPort })
: resolveGatewayCredentialMutationAuthority({ gatewayName, gatewayPort });
const localTlsDir = providerRuntimeLocalTlsDir(owner, providerRuntimeGateway.selectedInProcess);
return {
gatewayName,
Expand All @@ -149,10 +155,11 @@ export function getMcpProviderInspectionRuntimeSelection(

export function resolveSandboxConfigRuntimeSelection(
sandboxName: string,
options: { observationOnly?: boolean } = {},
): OpenShellRuntimeSelection {
const sandbox = getKnownSandboxTarget(sandboxName);
if (!sandbox) throw new Error(`Sandbox '${sandboxName}' has no recorded runtime target.`);
return getMcpProviderInspectionRuntimeSelection(sandbox);
return getMcpProviderInspectionRuntimeSelection(sandbox, options);
}

export async function inspectMcpProvider(
Expand Down
45 changes: 36 additions & 9 deletions src/lib/actions/telemetry/native-reader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { spawn, type SpawnOptions } from "node:child_process";
import { spawn, type ChildProcess, type SpawnOptions } from "node:child_process";
import { captureOpenshellCommandAsyncResult } from "../../adapters/openshell/command-execution";
import {
buildSandboxCommandEnvironment,
Expand Down Expand Up @@ -32,21 +32,42 @@ export function createSupervisedSandboxCommandReader(
) => Promise<OpenShellInferenceRouteResult>;
dispose: () => void;
} {
const children = new Set<ChildProcess>();
// Cleanup must not depend on the caller returning to the event loop.
const killChildren = () => {
for (const child of children) {
try {
if (!foreground && process.platform !== "win32" && child.pid)
process.kill(-child.pid, "SIGKILL");
else child.kill("SIGKILL");
} catch {
try {
child.kill("SIGKILL");
} catch {}
}
}
};
const listeners = { SIGTERM: new Set<() => void>(), SIGINT: new Set<() => void>() };
const forwardTerm = () => {
for (const listener of listeners.SIGTERM) listener();
};
const forwardProcessTerm = () => {
forwardTerm();
killChildren();
process.removeListener("SIGTERM", forwardProcessTerm);
process.kill(process.pid, "SIGTERM");
};
const forwardInt = () => {
for (const listener of listeners.SIGINT) listener();
killChildren();
process.removeListener("SIGINT", forwardInt);
process.kill(process.pid, "SIGINT");
};
signal.addEventListener("abort", forwardTerm, { once: true });
const cancel = () => {
forwardTerm();
killChildren();
};
signal.addEventListener("abort", cancel, { once: true });
process.on("SIGTERM", forwardProcessTerm);
process.on("SIGINT", forwardInt);
const signalSource = {
Expand All @@ -67,12 +88,17 @@ export function createSupervisedSandboxCommandReader(
...request,
killGraceMs: 0,
signalSource,
...(foreground
? {
spawnImpl: ((binary: string, args: readonly string[] = [], options?: SpawnOptions) =>
spawn(binary, [...args], { ...options, detached: false })) as typeof spawn,
}
: {}),
spawnImpl: ((binary: string, args: readonly string[] = [], options?: SpawnOptions) => {
if (signal.aborted) throw new Error("Native evidence cancelled");
const child = spawn(binary, [...args], {
...options,
...(foreground ? { detached: false } : {}),
});
children.add(child);
child.once("close", () => children.delete(child));
if (signal.aborted) killChildren();
return child;
}) as typeof spawn,
});
const executor = createCliOpenShellSandboxCommandExecutor({
signalSource,
Expand Down Expand Up @@ -112,7 +138,8 @@ export function createSupervisedSandboxCommandReader(
).observeInferenceRoute(request);
},
dispose: () => {
signal.removeEventListener("abort", forwardTerm);
killChildren();
signal.removeEventListener("abort", cancel);
process.removeListener("SIGTERM", forwardProcessTerm);
process.removeListener("SIGINT", forwardInt);
},
Expand Down
11 changes: 7 additions & 4 deletions src/lib/actions/telemetry/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ export function setTelemetryOutcome(
export function recordTelemetryVersions(versions: {
previous?: string;
target?: string;
installed?: string;
installed?: string | null;
}): void {
appendReceipt({ kind: "versions", ...versions });
}

function readReceipts(current: Context): Record<string, unknown>[] {
return privateFile(current.directory, "receipts.ndjson", 1_048_576)
.split("\n")
Expand Down Expand Up @@ -238,7 +239,8 @@ export async function withTelemetryEvidence<T>(
const started = performance.now();
let remainingMs: number;
try {
remainingMs = TELEMETRY_DEADLINE_MS - usedEvidenceMs(current);
// Leave time for sender startup, terminal collection, delivery, and cleanup.
remainingMs = TELEMETRY_DEADLINE_MS - usedEvidenceMs(current) - 2_000;
} catch {
return null;
}
Expand Down Expand Up @@ -288,7 +290,8 @@ function terminalContext(current: Context, exitCode = 0): TelemetryOperationCont
else if (receipt.kind === "versions") {
if (typeof receipt.previous === "string") metadata.previousVersion = receipt.previous;
if (typeof receipt.target === "string") metadata.targetVersion = receipt.target;
if (typeof receipt.installed === "string") metadata.installedVersion = receipt.installed;
if (typeof receipt.installed === "string" || receipt.installed === null)
metadata.installedVersion = receipt.installed;
}
}
metadata.targets = [...targets.values()];
Expand Down Expand Up @@ -599,7 +602,7 @@ export async function finishInstallerTelemetry(
state: TelemetryState,
scope: TelemetryScope,
exitCode: number,
versions: { previous?: string; target?: string; installed?: string } = {},
versions: { previous?: string; target?: string; installed?: string | null } = {},
): Promise<void> {
const inherited = inheritedContext();
if (!inherited || inherited.directory !== directory) return;
Expand Down
35 changes: 17 additions & 18 deletions src/lib/actions/telemetry/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
ValueStatus,
} from "../../domain/telemetry/event";
import { readTelemetryTestLabel } from "../../domain/telemetry/event";
import { PUBLIC_VERSION_PATTERN } from "../../domain/telemetry/schema";
import { observedString } from "../../domain/telemetry/dimensions";
import { operationEnvelope } from "../../adapters/telemetry/gxt";
import {
allowedTelemetryCollection,
Expand All @@ -27,11 +27,8 @@ function publicVersion(
value: unknown,
missing: ValueStatus,
): { value: string; status: ValueStatus } {
return typeof value === "string" &&
value !== "unknown" &&
value.length <= 128 &&
new RegExp(PUBLIC_VERSION_PATTERN).test(value)
? { value, status: "reported" }
return typeof value === "string" && value.length > 0 && value !== "unknown"
? observedString(value)
: { value: "unknown", status: value == null || value === "unknown" ? missing : "unapproved" };
}
function installedVersion(): unknown {
Expand All @@ -54,6 +51,7 @@ function missingObservation(value: unknown): boolean {
return Object.entries(value).some(
([key, item]) =>
((key === "status" || key.endsWith("Status")) &&
!(key === "hostHardwarePlatformStatus" && item === "not_observed") &&
["collection_error", "not_observed", "not_persisted", "unavailable"].includes(item)) ||
missingObservation(item),
);
Expand Down Expand Up @@ -81,15 +79,10 @@ export async function collectOperationEvent(
? "not_observed"
: "not_applicable",
);
const hostPlatform = os.platform();
const hostOS =
process.platform === "darwin"
? "macos"
: process.platform === "win32"
? "windows"
: process.platform === "linux"
? "linux"
: "other";
const hostArch = ["x64", "arm64", "ia32", "arm"].includes(process.arch) ? process.arch : "other";
hostPlatform === "darwin" ? "macos" : hostPlatform === "win32" ? "windows" : hostPlatform;
const hostArch = os.arch();
const { targetPositions: _privatePositions, ...publicSnapshot } = snapshot;
const event: TelemetryOperationEvent = {
name: "nemoclaw_operation_finished",
Expand All @@ -115,11 +108,13 @@ export async function collectOperationEvent(
},
platform: {
hostOS,
hostOSStatus: hostOS === "other" ? "unapproved" : "reported",
hostOSStatus: "reported",
hostArch,
hostArchStatus: hostArch === "other" ? "unapproved" : "reported",
hostArchStatus: "reported",
hostContext: hostOS === "linux" && /microsoft/i.test(os.release()) ? "wsl" : "native",
hostContextStatus: "reported",
hostHardwarePlatform: "",
hostHardwarePlatformStatus: "not_observed",
},
location: {
countryCode: "",
Expand Down Expand Up @@ -171,7 +166,7 @@ export async function collectOperationEvent(
return event;
}

/** A single complete record, one attempt, and one collection/delivery deadline. */
/** One terminal record and one delivery attempt within the remaining operation budget. */
export async function sendOperationTelemetry(
context: TelemetryOperationContext,
budgetMs: number,
Expand All @@ -192,7 +187,11 @@ export async function sendOperationTelemetry(
controller.signal.addEventListener("abort", () => resolve(null), { once: true });
});
const event = await Promise.race([
collectOperationEvent(context, { signal: controller.signal, deadlineAt }),
// Reserve transport time even when an inventory observation stalls.
collectOperationEvent(context, {
signal: controller.signal,
deadlineAt: deadlineAt - Math.min(1_000, budgetMs / 2),
}),
deadline,
]);
if (event === null || controller.signal.aborted) return "failed";
Expand Down
Loading
Loading