diff --git a/docs/security/best-practices.mdx b/docs/security/best-practices.mdx index ea9967ecfb2..96b3de6bcf5 100644 --- a/docs/security/best-practices.mdx +++ b/docs/security/best-practices.mdx @@ -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. diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index 9f5276c4e77..1334eb96244 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -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; @@ -1590,6 +1604,7 @@ async function runInferenceSetWithoutHostLock( selectingNative: selectingNative && !selectingNativeLocal, provider, expectedAttachment: nativeProviderAuthority, + previousAttachment: previousNativeAttachment, gatewayName: preparedRoute.gatewayName, sandboxName, endpointUrl: registryMetadata.endpointUrl, @@ -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, ); diff --git a/src/lib/actions/inference-set/native.ts b/src/lib/actions/inference-set/native.ts index 84d963d65df..9591f961aff 100644 --- a/src/lib/actions/inference-set/native.ts +++ b/src/lib/actions/inference-set/native.ts @@ -188,6 +188,7 @@ export async function prepareNativeSelection(input: { selectingNative: boolean; provider: string; expectedAttachment?: NativeProviderAttachment; + previousAttachment?: NativeProviderAttachment; gatewayName: string; sandboxName: string; endpointUrl?: string | null; @@ -198,6 +199,7 @@ export async function prepareNativeSelection(input: { }): Promise<{ attachment?: NativeProviderAttachment; attachmentChanged: boolean; + providerChanged?: boolean; endpointUrl?: string; }> { if (!input.selectingNative) return { attachmentChanged: false }; @@ -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 } @@ -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, }; } diff --git a/src/lib/actions/sandbox/agents/telemetry-verification.ts b/src/lib/actions/sandbox/agents/telemetry-verification.ts index 10eb0c03fe6..8c3331a1c78 100644 --- a/src/lib/actions/sandbox/agents/telemetry-verification.ts +++ b/src/lib/actions/sandbox/agents/telemetry-verification.ts @@ -42,7 +42,9 @@ export async function readTelemetryAgentCommand( timeoutLimitMs = 1_000, ): Promise { 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); diff --git a/src/lib/actions/sandbox/mcp-bridge-provider-inspection.ts b/src/lib/actions/sandbox/mcp-bridge-provider-inspection.ts index 86909987f4a..1bc8c24de0d 100644 --- a/src/lib/actions/sandbox/mcp-bridge-provider-inspection.ts +++ b/src/lib/actions/sandbox/mcp-bridge-provider-inspection.ts @@ -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, @@ -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, @@ -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( diff --git a/src/lib/actions/telemetry/native-reader.ts b/src/lib/actions/telemetry/native-reader.ts index 9ffe517dab1..e020541561d 100644 --- a/src/lib/actions/telemetry/native-reader.ts +++ b/src/lib/actions/telemetry/native-reader.ts @@ -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, @@ -32,21 +32,42 @@ export function createSupervisedSandboxCommandReader( ) => Promise; dispose: () => void; } { + const children = new Set(); + // 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 = { @@ -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, @@ -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); }, diff --git a/src/lib/actions/telemetry/operation.ts b/src/lib/actions/telemetry/operation.ts index e4858c482cf..92e7f21fcc9 100644 --- a/src/lib/actions/telemetry/operation.ts +++ b/src/lib/actions/telemetry/operation.ts @@ -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[] { return privateFile(current.directory, "receipts.ndjson", 1_048_576) .split("\n") @@ -238,7 +239,8 @@ export async function withTelemetryEvidence( 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; } @@ -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()]; @@ -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 { const inherited = inheritedContext(); if (!inherited || inherited.directory !== directory) return; diff --git a/src/lib/actions/telemetry/send.ts b/src/lib/actions/telemetry/send.ts index d680182f348..8b8282fe5ae 100644 --- a/src/lib/actions/telemetry/send.ts +++ b/src/lib/actions/telemetry/send.ts @@ -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, @@ -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 { @@ -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), ); @@ -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", @@ -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: "", @@ -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, @@ -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"; diff --git a/src/lib/actions/telemetry/snapshot.test.ts b/src/lib/actions/telemetry/snapshot.test.ts index f96b20a6409..69255b66d62 100644 --- a/src/lib/actions/telemetry/snapshot.test.ts +++ b/src/lib/actions/telemetry/snapshot.test.ts @@ -248,7 +248,7 @@ it("joins a published OpenClaw configuration to its operation target (#12859)", }, ], }); - expect(event.parameters.configurations[0].agents[0].models[0].modelId).toBe("other"); + expect(event.parameters.configurations[0].agents[0].models[0].modelId).toBe("gpt-4o"); expect(event.parameters.configurations[1].agents).toHaveLength(1); expect(event.parameters.configurations[1].agents[0].models[0]).toMatchObject({ modelId: "nvidia/nemotron-3-ultra-550b-a55b", @@ -346,7 +346,7 @@ async function collectNativeConfiguration( it.each([ ["0.1.71", "0.1.71", "reported"], - ["private-build", "other", "unapproved"], + ["private-build", "private-build", "reported"], ])( "reports managed Deep Agents version %s as %s (#12376)", async (agentVersion, managedAgentVersion, managedAgentVersionStatus) => { diff --git a/src/lib/actions/telemetry/snapshot.ts b/src/lib/actions/telemetry/snapshot.ts index 60638678164..70c9305a6b8 100644 --- a/src/lib/actions/telemetry/snapshot.ts +++ b/src/lib/actions/telemetry/snapshot.ts @@ -5,12 +5,12 @@ import path from "node:path"; import { createSupervisedSandboxCommandReader } from "./native-reader"; import type { OpenShellInferenceRouteResult } from "../../adapters/openshell/inference-route"; import { - approvedCategory, + observedString, classifyTelemetryAgent, classifyTelemetrySandboxOS, - COMPUTE_DRIVERS, + hasNativeTelemetryParser, + hasTelemetryCollectionError, dataRecord, - MANAGED_AGENT_VERSIONS, MESSAGING_CHANNELS, parseRuntimeRoster, projectRuntimeAgents, @@ -83,10 +83,7 @@ function projectConfiguration( sandboxOSStatus = "reported"; imageOwnership = "managed"; imageOwnershipStatus = "reported"; - const version = approvedCategory( - entry.agentVersion, - MANAGED_AGENT_VERSIONS[harness.agentHarnessId] ?? [], - ); + const version = observedString(entry.agentVersion); managedAgentVersion = version.value; managedAgentVersionStatus = version.status; } else if (workload?.kind === "external-image") { @@ -120,11 +117,11 @@ function projectConfiguration( } catch { sandboxOSStatus = imageOwnershipStatus = managedAgentVersionStatus = "collection_error"; } - const driver = approvedCategory(entry.openshellDriver, COMPUTE_DRIVERS); + const driver = observedString(entry.openshellDriver); const webSearch = booleanSetting(entry.webSearchEnabled); const observability = booleanSetting(entry.observabilityEnabled); if ( - harness.agentHarnessStatus === "reported" && + hasNativeTelemetryParser(harness.agentHarnessId) && !DCODE_OBSERVABILITY_FEATURE.supportsAgent(entry.agent) ) { observability.status = @@ -154,6 +151,10 @@ function projectConfiguration( : "reported"; } else if (entry.sandboxGpuEnabled !== undefined) gpuStatus = "collection_error"; const policy = readAppliedPolicySelection(entry.appliedPolicySelection); + const policyTier = observedString( + policy?.tier, + entry.appliedPolicySelection === undefined ? "not_persisted" : "collection_error", + ); const policyWriteFailed = metadataErrors.some((error) => error.category === "policy_tier"); const settings: TelemetrySettings = { computeDriver: driver.value, @@ -166,14 +167,8 @@ function projectConfiguration( observabilityStatus: observability.status, imageOwnership, imageOwnershipStatus, - policyTier: policyWriteFailed ? "unknown" : (policy?.tier ?? "unknown"), - policyTierStatus: policyWriteFailed - ? "collection_error" - : policy - ? "reported" - : entry.appliedPolicySelection === undefined - ? "not_persisted" - : "collection_error", + policyTier: policyWriteFailed ? "unknown" : policyTier.value, + policyTierStatus: policyWriteFailed ? "collection_error" : policyTier.status, }; let configuredMessagingChannels: string[] = []; let messagingStatus: ValueStatus = @@ -243,10 +238,24 @@ async function collectRuntime( row.currentInferenceRouteStatus = "not_observed"; return; } + // Only settled observations may update the row after cancellation. + let cancel: () => void = () => {}; + const cancelled = new Promise<{ cancelled: true }>((resolve) => { + cancel = () => resolve({ cancelled: true }); + options.signal.addEventListener("abort", cancel, { once: true }); + if (options.signal.aborted) cancel(); + }); + const observe = async (observation: Promise): Promise => { + const result = await Promise.race([observation.then((value) => ({ value })), cancelled]); + if ("cancelled" in result) throw new Error("Telemetry observation cancelled"); + return result.value; + }; let osObservation: Promise | undefined; let routeObservation: Promise | undefined; try { - const runtimeSelection = getMcpProviderInspectionRuntimeSelection(entry); + const runtimeSelection = getMcpProviderInspectionRuntimeSelection(entry, { + observationOnly: true, + }); const gatewayName = resolveSandboxGatewayName(entry); const routeKey = JSON.stringify([gatewayName, runtimeSelection]); let route = options.routes.get(routeKey); @@ -254,9 +263,11 @@ async function collectRuntime( const remaining = options.deadlineAt - Date.now(); if (options.signal.aborted || remaining <= 0) throw new Error("Telemetry observation deadline reached"); - route = reader.observeInferenceRoute( - { target: { kind: "named", gatewayName }, timeoutMs: remaining }, - runtimeSelection, + route = observe( + reader.observeInferenceRoute( + { target: { kind: "named", gatewayName }, timeoutMs: remaining }, + runtimeSelection, + ), ); options.routes.set(routeKey, route); } @@ -275,16 +286,18 @@ async function collectRuntime( const remaining = options.deadlineAt - Date.now(); if (options.signal.aborted || remaining <= 0) throw new Error("Telemetry observation deadline reached"); - return reader.read( - { - sandboxName: entry.name, - target: { kind: "named", gatewayName }, - command, - timeoutMilliseconds: remaining, - timeoutKillSignal: "SIGKILL", - outputLimitBytes: 16 * 1024 * 1024, - }, - runtimeSelection, + return observe( + reader.read( + { + sandboxName: entry.name, + target: { kind: "named", gatewayName }, + command, + timeoutMilliseconds: remaining, + timeoutKillSignal: "SIGKILL", + outputLimitBytes: 16 * 1024 * 1024, + }, + runtimeSelection, + ), ); }; if (row.sandboxOSStatus !== "reported") { @@ -298,8 +311,8 @@ async function collectRuntime( row.sandboxOSStatus = "collection_error"; }); } - if (row.agentHarnessId === "other" || row.agentHarnessId === "unknown") { - row.agentsStatus = row.defaultAgentModel.status = row.agentHarnessStatus; + if (!hasNativeTelemetryParser(row.agentHarnessId)) { + row.agentsStatus = row.defaultAgentModel.status = "not_observed"; return; } const config = resolveAgentConfig(entry.name, { @@ -341,6 +354,7 @@ async function collectRuntime( row.sandboxOSStatus = "collection_error"; } finally { await Promise.all([osObservation, routeObservation]); + options.signal.removeEventListener("abort", cancel); } } @@ -436,7 +450,15 @@ export async function collectOperationSnapshot(options: { snapshot.configurations = entries.map((entry, index) => projectConfiguration(entry, metadataErrors[index]), ); - const reader = createSupervisedSandboxCommandReader(options.signal, true); + const controller = new AbortController(); + const parentSignal = options.signal; + const cancel = () => controller.abort(); + parentSignal.addEventListener("abort", cancel, { once: true }); + const remaining = options.deadlineAt - Date.now(); + const timer = setTimeout(cancel, Math.max(0, remaining)); + if (parentSignal.aborted || remaining <= 0) cancel(); + options = { ...options, signal: controller.signal }; + const reader = createSupervisedSandboxCommandReader(options.signal); const routes = new Map>(); let nextIndex = 0; let observationIncomplete = false; @@ -463,11 +485,14 @@ export async function collectOperationSnapshot(options: { ), ); } finally { + controller.abort(); + clearTimeout(timer); + parentSignal.removeEventListener("abort", cancel); reader.dispose(); } snapshot.publishedEnvironmentCount = entries.length; snapshot.configuredRuntimeCount = snapshot.configurations.filter( - (row) => row.agentHarnessId !== "unknown", + (row) => row.agentHarnessStatus === "reported", ).length; snapshot.configuredAgentCount = snapshot.configurations.reduce( (count, row) => count + row.agents.length, @@ -476,7 +501,7 @@ export async function collectOperationSnapshot(options: { const collectionError = inventoryError || observationIncomplete || - snapshot.configurations.some((row) => JSON.stringify(row).includes('"collection_error"')); + snapshot.configurations.some(hasTelemetryCollectionError); if (collectionError) { snapshot.collectionStatus = snapshot.configurations.length > 0 ? "partial" : "collection_error"; } @@ -488,7 +513,7 @@ export async function collectOperationSnapshot(options: { ) ) snapshot.countsStatus = "collection_error"; - else if (snapshot.configurations.some((row) => row.agentHarnessId === "unknown")) + else if (snapshot.configurations.some((row) => row.agentHarnessStatus === "not_persisted")) snapshot.countsStatus = "not_persisted"; else { const unknownRoster = snapshot.configurations.find((row) => row.agentsStatus !== "reported"); diff --git a/src/lib/adapters/telemetry/gxt.ts b/src/lib/adapters/telemetry/gxt.ts index ba4bc250014..bb6bf41d63b 100644 --- a/src/lib/adapters/telemetry/gxt.ts +++ b/src/lib/adapters/telemetry/gxt.ts @@ -51,7 +51,7 @@ export function operationEnvelope( deviceType: "undefined", eventProtocol: "1.6", eventSchemaVer: TELEMETRY_SCHEMA_VERSION, - eventSysVer: "nemoclaw-telemetry/3.0", + eventSysVer: `nemoclaw-telemetry/${TELEMETRY_SCHEMA_VERSION}`, externalUserId: "undefined", gdprBehOptIn: "None", gdprFuncOptIn: "None", diff --git a/src/lib/cli/installer-telemetry-entry.ts b/src/lib/cli/installer-telemetry-entry.ts index e88b2d354b8..98557f22b86 100644 --- a/src/lib/cli/installer-telemetry-entry.ts +++ b/src/lib/cli/installer-telemetry-entry.ts @@ -15,7 +15,6 @@ import { TELEMETRY_CONTEXT_ENV, } from "../actions/telemetry/operation"; -const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/; const OUTCOMES: readonly TelemetryOutcome[] = [ "completed", "checked", @@ -35,7 +34,7 @@ const STATES: readonly TelemetryState[] = [ function installedVersion(): string | undefined { const value = process.env.NEMOCLAW_TELEMETRY_INSTALLED_VERSION; - return value && VERSION_PATTERN.test(value) ? value : undefined; + return value || undefined; } function readBuildVersion(identityPath: string): string | undefined { @@ -48,8 +47,7 @@ function readBuildVersion(identityPath: string): string | undefined { file.close(); } const identity = JSON.parse(raw) as { nemoclawVersion?: unknown }; - return typeof identity.nemoclawVersion === "string" && - VERSION_PATTERN.test(identity.nemoclawVersion) + return typeof identity.nemoclawVersion === "string" && identity.nemoclawVersion.length > 0 ? identity.nemoclawVersion : undefined; } catch { @@ -73,7 +71,7 @@ async function main(): Promise { } if (process.env.NEMOCLAW_TELEMETRY_INSTALLER_PHASE === "installed") { const version = installedVersion(); - recordTelemetryVersions({ installed: version ?? "unknown" }); + recordTelemetryVersions({ installed: version ?? null }); recordTelemetryTarget({ scope: "cli", outcome: version ? "completed" : "unverified", @@ -121,7 +119,7 @@ async function main(): Promise { state, args[2] as TelemetryScope, Number(args[1]), - { installed: actual ?? "unknown" }, + { installed: actual ?? null }, ); } diff --git a/src/lib/domain/telemetry/dimensions.ts b/src/lib/domain/telemetry/dimensions.ts index e9775161265..9386234d8d2 100644 --- a/src/lib/domain/telemetry/dimensions.ts +++ b/src/lib/domain/telemetry/dimensions.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { isManagedInferenceBaseUrl } from "../../onboard/workload/authority"; +import { matchesRecordedNativeProviderEndpoint } from "../../inference/native-provider/recorded-selection"; import type { TelemetryAgent, TelemetryConfiguration, @@ -17,27 +18,12 @@ import { type ModelSelectionProvenance, } from "./provenance"; -import { - AGENT_HARNESS_IDS, - TELEMETRY_MODEL_IDS, - TELEMETRY_API_FAMILIES, - TELEMETRY_MODEL_KEYS, - dataRecord, - classifyTelemetryProvider, -} from "./values"; +import { dataRecord, classifyTelemetryProvider } from "./values"; export { - AGENT_HARNESS_IDS, - TELEMETRY_MODEL_IDS, TELEMETRY_PROVIDER_PROFILES, - TELEMETRY_API_FAMILIES, MODEL_SELECTION_SOURCES, - COMPUTE_DRIVERS, GPU_STATES, MESSAGING_CHANNELS, - POLICY_TIER_CATEGORIES, - SANDBOX_OPERATING_SYSTEMS, - MANAGED_AGENT_VERSIONS, - TELEMETRY_MODEL_KEYS, dataRecord, classifyTelemetryProvider, } from "./values"; @@ -55,39 +41,51 @@ const NATIVE_PROVIDERS: Readonly> = { custom: "custom", }; -export function approvedCategory( +export function hasTelemetryCollectionError(value: unknown): boolean { + if (Array.isArray(value)) return value.some(hasTelemetryCollectionError); + const record = dataRecord(value); + return ( + record !== null && + Object.entries(record).some( + ([key, item]) => + ((key === "status" || key.endsWith("Status")) && item === "collection_error") || + hasTelemetryCollectionError(item), + ) + ); +} + +export function observedString( value: unknown, - allowed: readonly string[], + missingStatus: ValueStatus = "not_persisted", ): { value: string; status: ValueStatus } { - if (value === undefined || value === null || value === "") - return { value: "unknown", status: "not_persisted" }; - if (typeof value !== "string") return { value: "unknown", status: "collection_error" }; - return allowed.includes(value) && value !== "unknown" && value !== "other" + if (value === undefined || value === null || value === "" || value === "unknown") + return { value: "unknown", status: missingStatus }; + return typeof value === "string" && value.length <= 64 ? { value, status: "reported" } - : { value: "other", status: "unapproved" }; + : { value: "unknown", status: "collection_error" }; } export function classifyTelemetryAgent( value: unknown, ): Pick { - const category = approvedCategory(value, AGENT_HARNESS_IDS); + const category = observedString(value); return { agentHarnessId: category.value, agentHarnessStatus: category.status }; } -export function classifyTelemetryApi(value: unknown): string { - return typeof value === "string" && TELEMETRY_API_FAMILIES.some((item) => item === value) - ? value - : "unknown"; +export function hasNativeTelemetryParser(agentHarnessId: string): boolean { + return ( + agentHarnessId === "openclaw" || + agentHarnessId === "hermes" || + agentHarnessId === "langchain-deepagents-code" + ); } export function classifyTelemetrySandboxOS(raw: string): { value: string; status: ValueStatus } { - const name = raw.trim(); + const name = raw.replace(/[\r\n]+$/, ""); if (name === "Linux") return { value: "linux", status: "reported" }; if (/^(?:Windows_NT|MINGW(?:32|64)_NT|MSYS_NT|CYGWIN_NT)(?:-[0-9]+(?:[.-][0-9]+)*)?$/.test(name)) return { value: "windows", status: "reported" }; - if (["Darwin", "FreeBSD", "OpenBSD", "NetBSD", "SunOS", "AIX"].includes(name)) - return { value: "other", status: "unapproved" }; - return { value: "unknown", status: "collection_error" }; + return observedString(name, "collection_error"); } export interface RuntimeRouteAuthority { @@ -95,6 +93,8 @@ export interface RuntimeRouteAuthority { provider?: string | null; modelSelectionProvenance?: unknown; nativeModelSelectionProvenance?: unknown; + nativeNvidiaProviderAttachment?: unknown; + nativeHostedProviderAttachment?: unknown; modelAssignmentSelections?: unknown; metadataErrors?: readonly TelemetryMetadataError[]; /** Sandbox-facing route recorded in the managed startup profile; hosted native routes are upstream URLs. */ @@ -217,7 +217,7 @@ function projectModel( authority: RuntimeRouteAuthority, slot?: { agentId: string; reference: string; inherited: boolean; sources: AssignmentSources }, ): TelemetryModel { - const model = approvedCategory(reference.model, TELEMETRY_MODEL_IDS); + const model = observedString(reference.model); const nativeChoice = reference.nativeConfiguration !== undefined && authority.nativeModelSelectionProvenance !== undefined; @@ -244,18 +244,24 @@ function projectModel( gatewayReceipt.provider === authority.provider ? gatewayReceipt.providerProfile : undefined; + const nativeProvider = + bound && + bound.provider === authority.provider && + matchesRecordedNativeProviderEndpoint( + authority, + dataRecord(dataRecord(reference.nativeConfiguration)?.model)?.base_url, + ) + ? bound.providerProfile + : undefined; const provider = reference.managed ? (bound?.providerProfile ?? gatewayProvider ?? classifyTelemetryProvider(authority.provider)) - : reference.providerKey - ? (NATIVE_PROVIDERS[reference.providerKey] ?? "custom") - : "unknown"; - const api = classifyTelemetryApi(reference.api); + : (nativeProvider ?? + (reference.providerKey ? (NATIVE_PROVIDERS[reference.providerKey] ?? "custom") : "unknown")); + const api = observedString(reference.api, "unavailable"); return { assignment, modelId: model.value, modelStatus: model.status, - knownModelKey: TELEMETRY_MODEL_KEYS[model.value] ?? model.value, - knownModelKeyStatus: model.status, modelSource: source.value, modelSourceStatus: source.status, providerProfile: provider, @@ -265,9 +271,8 @@ function projectModel( : reference.managed && authority.provider == null ? "not_persisted" : "collection_error", - apiFamily: api, - apiStatus: - api !== "unknown" ? "reported" : reference.api === undefined ? "unavailable" : "unapproved", + apiFamily: api.value, + apiStatus: api.status, }; } @@ -279,8 +284,6 @@ export function unknownModel( assignment, modelId: "unknown", modelStatus: status, - knownModelKey: "unknown", - knownModelKeyStatus: status, modelSource: "unknown", modelSourceStatus: status, providerProfile: "unknown", @@ -415,6 +418,12 @@ export function projectRuntimeAgents( roster: readonly Record[] | undefined, authority: RuntimeRouteAuthority, ): RuntimeAgentProjection { + if (!hasNativeTelemetryParser(runtime.agentHarnessId)) + return { + agents: [], + agentsStatus: "not_observed", + defaultAgentModel: { agentPosition: -1, modelPosition: -1, status: "not_observed" }, + }; if (runtime.agentHarnessId === "openclaw" && roster?.length === 0) return { agents: [], @@ -497,7 +506,7 @@ export function projectRuntimeAgents( if (invalidSubagent || subagent !== undefined) models.push(readModel(invalidSubagent ? undefined : subagent, "subagent")); const modelsStatus: ValueStatus = - sources.invalid || models.some((model) => Object.values(model).includes("collection_error")) + sources.invalid || models.some(hasTelemetryCollectionError) ? "collection_error" : "reported"; return { @@ -580,17 +589,15 @@ export function projectRuntimeAgents( } else return { agents: [], - agentsStatus: "unapproved", - defaultAgentModel: { agentPosition: -1, modelPosition: -1, status: "unapproved" }, + agentsStatus: "not_observed", + defaultAgentModel: { agentPosition: -1, modelPosition: -1, status: "not_observed" }, }; const model = projectModel(reference, "primary", authority); return { agents: [ { ...runtime, - modelsStatus: Object.values(model).includes("collection_error") - ? "collection_error" - : "reported", + modelsStatus: hasTelemetryCollectionError(model) ? "collection_error" : "reported", models: [model], }, ], diff --git a/src/lib/domain/telemetry/event.ts b/src/lib/domain/telemetry/event.ts index 68c62e9709d..e88e3a13be0 100644 --- a/src/lib/domain/telemetry/event.ts +++ b/src/lib/domain/telemetry/event.ts @@ -79,8 +79,6 @@ export interface TelemetryModel { assignment: TelemetryModelAssignment; modelId: string; modelStatus: ValueStatus; - knownModelKey: string; - knownModelKeyStatus: ValueStatus; modelSource: string; modelSourceStatus: ValueStatus; providerProfile: string; @@ -166,7 +164,7 @@ export interface TelemetryOperationContext { scope: TelemetryScope; previousVersion?: string; targetVersion?: string; - installedVersion?: string; + installedVersion?: string | null; targets: TelemetryTargetReceipt[]; } @@ -195,6 +193,8 @@ export interface OperationEventParameters extends Omit 0 && - record.reference.length <= 1024 && typeof record.assignment === "string" && ["primary", "override", "fallback", "subagent"].includes(record.assignment) && MODEL_SELECTION_SOURCES.some((source) => source === record.modelSource) @@ -66,9 +63,11 @@ export function readModelAssignmentSelection(value: unknown): ModelAssignmentSel } export function readAppliedPolicySelection(value: unknown): AppliedPolicySelection | null { const record = closed(value, ["schemaVersion", "source", "tier"]); - const tier = POLICY_TIER_CATEGORIES.find((item) => item === record?.tier); - return record?.schemaVersion === 1 && record.source === "verified_selection" && tier - ? { schemaVersion: 1, source: "verified_selection", tier } + return record?.schemaVersion === 1 && + record.source === "verified_selection" && + typeof record.tier === "string" && + record.tier.length > 0 + ? { schemaVersion: 1, source: "verified_selection", tier: record.tier } : null; } export function readModelSelectionProvenance(value: unknown): ModelSelectionProvenance | null { @@ -84,24 +83,23 @@ export function readModelSelectionProvenance(value: unknown): ModelSelectionProv (item) => item === record?.providerProfile, ); const modelSource = MODEL_SELECTION_SOURCES.find((item) => item === record?.modelSource); - const apiFamily = TELEMETRY_API_FAMILIES.find((item) => item === record?.apiFamily); return record?.schemaVersion === 1 && typeof record.model === "string" && record.model.length > 0 && - record.model.length <= 1024 && typeof record.provider === "string" && record.provider.length > 0 && record.provider.length <= 1024 && providerProfile && modelSource && - apiFamily + typeof record.apiFamily === "string" && + record.apiFamily.length > 0 ? { schemaVersion: 1, model: record.model, provider: record.provider, providerProfile, modelSource, - apiFamily, + apiFamily: record.apiFamily, } : null; } @@ -123,15 +121,14 @@ export function readHermesModelSelectionTuple( : mode === "codex_responses" ? "openai-responses" : mode; - const apiFamily = TELEMETRY_API_FAMILIES.find((item) => item !== "unknown" && item === api); return typeof model?.default === "string" && model.default.length > 0 && - model.default.length <= 1024 && typeof provider === "string" && provider.length > 0 && provider.length <= 1024 && - apiFamily - ? { model: model.default, provider, apiFamily } + typeof api === "string" && + api.length > 0 + ? { model: model.default, provider, apiFamily: api } : null; } @@ -187,6 +184,8 @@ export function selectedModelProvenance(input: { providerProfile, modelSource: input.modelSource ?? "unknown", apiFamily: - TELEMETRY_API_FAMILIES.find((item) => item === input.preferredInferenceApi) ?? "unknown", + typeof input.preferredInferenceApi === "string" && input.preferredInferenceApi.length > 0 + ? input.preferredInferenceApi + : "unknown", }; } diff --git a/src/lib/domain/telemetry/schema.ts b/src/lib/domain/telemetry/schema.ts index 156e0e2b401..2a3ed8ec477 100644 --- a/src/lib/domain/telemetry/schema.ts +++ b/src/lib/domain/telemetry/schema.ts @@ -4,22 +4,14 @@ import Ajv from "ajv"; import { assertSafeConfigStructure } from "../../security/config-structure"; import { - AGENT_HARNESS_IDS, - COMPUTE_DRIVERS, GPU_STATES, - MANAGED_AGENT_VERSIONS, MESSAGING_CHANNELS, MODEL_SELECTION_SOURCES, - POLICY_TIER_CATEGORIES, - SANDBOX_OPERATING_SYSTEMS, - TELEMETRY_API_FAMILIES, - TELEMETRY_MODEL_IDS, - TELEMETRY_MODEL_KEYS, TELEMETRY_PROVIDER_PROFILES, } from "./dimensions"; import { TELEMETRY_OPERATIONS, type TelemetryOperationEvent } from "./event"; -export const TELEMETRY_SCHEMA_VERSION = "3.0"; +export const TELEMETRY_SCHEMA_VERSION = "4.0"; export const TELEMETRY_CLIENT_ID = "2247027956751513"; export const VALUE_STATUSES = [ "reported", @@ -42,12 +34,11 @@ export const OUTCOMES = [ ]; export const STATES = ["applied", "pending", "partial", "unchanged", "unavailable"]; export const SCOPES = ["cli", "sandbox", "configuration"]; -export const PUBLIC_VERSION_PATTERN = - "^(?:unknown|[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?(?:\\+[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?)$"; -const string = (values?: readonly string[]) => ({ +const string = (values: readonly string[]) => ({ type: "string", - ...(values ? { enum: [...values] } : {}), + enum: [...values], }); +const boundedString = (maxLength: number) => ({ type: "string", maxLength }); const object = (properties: Record) => ({ type: "object", additionalProperties: false, @@ -62,41 +53,35 @@ const timestamp = { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$", }; -const version = { type: "string", maxLength: 128, pattern: PUBLIC_VERSION_PATTERN }; +const version = boundedString(128); const model = object({ assignment: string(["primary", "override", "fallback", "subagent"]), - modelId: string(TELEMETRY_MODEL_IDS), + modelId: boundedString(512), modelStatus: status, - knownModelKey: string([...new Set(Object.values(TELEMETRY_MODEL_KEYS)), "other", "unknown"]), - knownModelKeyStatus: status, modelSource: string(MODEL_SELECTION_SOURCES), modelSourceStatus: status, providerProfile: string(TELEMETRY_PROVIDER_PROFILES), providerStatus: status, - apiFamily: string(TELEMETRY_API_FAMILIES), + apiFamily: boundedString(64), apiStatus: status, }); const harnessFields = { - agentHarnessId: string(AGENT_HARNESS_IDS), + agentHarnessId: boundedString(64), agentHarnessStatus: status, - managedAgentVersion: string([ - ...new Set(Object.values(MANAGED_AGENT_VERSIONS).flat()), - "other", - "unknown", - ]), + managedAgentVersion: version, managedAgentVersionStatus: status, }; const configuration = object({ state: string(STATES), status, ...harnessFields, - sandboxOS: string(SANDBOX_OPERATING_SYSTEMS), + sandboxOS: boundedString(64), sandboxOSStatus: status, defaultAgentModel: object({ agentPosition: position, modelPosition: position, status }), currentInferenceRoute: model, currentInferenceRouteStatus: status, settings: object({ - computeDriver: string(COMPUTE_DRIVERS), + computeDriver: boundedString(64), computeDriverStatus: status, gpuState: string(GPU_STATES), gpuStatus: status, @@ -106,7 +91,7 @@ const configuration = object({ observabilityStatus: status, imageOwnership: string(["managed", "custom", "unknown"]), imageOwnershipStatus: status, - policyTier: string([...POLICY_TIER_CATEGORIES, "unknown"]), + policyTier: boundedString(64), policyTierStatus: status, }), messaging: object({ @@ -139,12 +124,14 @@ export const operationParametersSchema = object({ targetStatus: status, }), platform: object({ - hostOS: string(["linux", "macos", "windows", "other", "unknown"]), + hostOS: boundedString(64), hostOSStatus: status, - hostArch: string(["x64", "arm64", "ia32", "arm", "other", "unknown"]), + hostArch: boundedString(64), hostArchStatus: status, hostContext: string(["native", "wsl", "unknown"]), hostContextStatus: status, + hostHardwarePlatform: boundedString(64), + hostHardwarePlatformStatus: status, }), location: object({ countryCode: { type: "string", maxLength: 2, pattern: "^(?:|[A-Z]{2})$" }, @@ -235,7 +222,7 @@ export function proposedSmsSchema(): Record { personalization: "anonymous", }, description: - "One complete terminal NemoClaw operation record with approved categories and explicit collection status. Production disabled.", + "One terminal NemoClaw operation with observed values, reporting categories, and explicit collection status. Production disabled.", oneOf: [{ $ref: "#/definitions/events/nemoclaw_operation_finished" }], definitions: { types: {}, @@ -243,7 +230,7 @@ export function proposedSmsSchema(): Record { nemoclaw_operation_finished: { ...operationParametersSchema, description: - "One complete terminal NemoClaw operation record containing all approved anonymous versions, platform, agent/model/provider associations, settings, messaging, coarse-location status and QA label.", + "One terminal NemoClaw operation containing versions, host hardware and OS, agent/model/provider associations, settings, messaging, location status, and QA label.", eventMeta: { service: "telemetry", gdpr: { diff --git a/src/lib/domain/telemetry/values.ts b/src/lib/domain/telemetry/values.ts index 31c1af1a17a..f7a237d61cd 100644 --- a/src/lib/domain/telemetry/values.ts +++ b/src/lib/domain/telemetry/values.ts @@ -1,23 +1,6 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -export const AGENT_HARNESS_IDS = [ - "openclaw", - "hermes", - "langchain-deepagents-code", - "other", - "unknown", -] as const; -export const TELEMETRY_MODEL_IDS = [ - "Qwen/Qwen3.6-27B-FP8", - "nvidia/nemotron-3-ultra-550b-a55b", - "nvidia/nvidia/nemotron-3-ultra", - "deepseek-ai/DeepSeek-V4-Flash", - "nvidia/qwen/qwen3.6-27b", - "nvidia/deepseek-ai/deepseek-v4-flash", - "other", - "unknown", -] as const; export const TELEMETRY_PROVIDER_PROFILES = [ "nvidia", "openai", @@ -32,12 +15,6 @@ export const TELEMETRY_PROVIDER_PROFILES = [ "custom", "unknown", ] as const; -export const TELEMETRY_API_FAMILIES = [ - "openai-completions", - "openai-responses", - "anthropic-messages", - "unknown", -] as const; export const MODEL_SELECTION_SOURCES = [ "product_catalog", "provider_catalog", @@ -45,7 +22,6 @@ export const MODEL_SELECTION_SOURCES = [ "local", "unknown", ] as const; -export const COMPUTE_DRIVERS = ["docker", "podman", "kubernetes", "other", "unknown"] as const; export const GPU_STATES = [ "not_configured", "configured_unverified", @@ -63,21 +39,6 @@ export const MESSAGING_CHANNELS = [ "googlechat", "other", ] as const; -export const POLICY_TIER_CATEGORIES = ["restricted", "balanced", "open", "personal"] as const; -export const SANDBOX_OPERATING_SYSTEMS = ["linux", "windows", "other", "unknown"] as const; -export const MANAGED_AGENT_VERSIONS: Readonly> = { - openclaw: ["2026.9.2"], - hermes: ["0.21.3"], - "langchain-deepagents-code": ["0.1.71"], -}; -export const TELEMETRY_MODEL_KEYS: Readonly> = { - "Qwen/Qwen3.6-27B-FP8": "qwen3_6_27b_fp8", - "nvidia/nemotron-3-ultra-550b-a55b": "nemotron3_ultra_550b_a55b", - "nvidia/nvidia/nemotron-3-ultra": "nemotron3_ultra", - "deepseek-ai/DeepSeek-V4-Flash": "deepseek_v4_flash", - "nvidia/qwen/qwen3.6-27b": "qwen3_6_27b", - "nvidia/deepseek-ai/deepseek-v4-flash": "deepseek_v4_flash", -}; const PROVIDERS: Readonly> = { "nvidia-prod": "nvidia", "nvidia-nim": "nvidia", diff --git a/src/lib/inference/native-provider/recorded-selection.ts b/src/lib/inference/native-provider/recorded-selection.ts index d5c48e9d5d9..2d6c667dea5 100644 --- a/src/lib/inference/native-provider/recorded-selection.ts +++ b/src/lib/inference/native-provider/recorded-selection.ts @@ -3,9 +3,13 @@ import { NVIDIA_HOSTED_LOGICAL_PROVIDER, + NVIDIA_HOSTED_NATIVE_ENDPOINT, normalizeNativeNvidiaProviderAttachment, } from "../native-nvidia/contract"; -import { requireHostedProviderAttachment } from "./hosted-attachment"; +import { + requireHostedProviderAttachment, + hostedNativeProviderForAttachment, +} from "./hosted-attachment"; import { normalizeProviderBaseUrl } from "../../core/provider-endpoint"; import type { NativeProviderAttachment } from "./contract"; @@ -52,3 +56,24 @@ export function recordedNativeProviderAttachment(selection: { } return hosted; } + +export function matchesRecordedNativeProviderEndpoint( + selection: Parameters[0], + endpoint: unknown, +): boolean { + try { + const attachment = recordedNativeProviderAttachment(selection); + const expected = + selection.provider === NVIDIA_HOSTED_LOGICAL_PROVIDER + ? NVIDIA_HOSTED_NATIVE_ENDPOINT + : hostedNativeProviderForAttachment(attachment)?.endpoint; + return Boolean( + attachment && + typeof endpoint === "string" && + expected && + new URL(endpoint).href.replace(/\/$/u, "") === new URL(expected).href.replace(/\/$/u, ""), + ); + } catch { + return false; + } +} diff --git a/src/lib/onboard/gateway-teardown-authority.ts b/src/lib/onboard/gateway-teardown-authority.ts index a3a12ac6f3c..b4bc1eb3d75 100644 --- a/src/lib/onboard/gateway-teardown-authority.ts +++ b/src/lib/onboard/gateway-teardown-authority.ts @@ -57,7 +57,12 @@ export type GatewayTeardownAuthorityResolver = ( deps?: GatewayTeardownAuthorityDeps, ) => GatewayOwner; -type GatewayAuthorityEffect = "credential mutation" | "forward recovery" | "rebuild" | "teardown"; +type GatewayAuthorityEffect = + | "credential mutation" + | "forward recovery" + | "rebuild" + | "teardown" + | "observation"; const FRESH_ONBOARDING_CHECKPOINT_RECOVERY = " Start a fresh onboarding run to replace the invalid checkpoint before retrying."; @@ -168,7 +173,9 @@ function resolveGatewayEffectAuthority( ? "sandbox rebuild" : effect === "forward recovery" ? "sandbox forward recovery" - : "provider credential mutation"; + : effect === "observation" + ? "gateway observation" + : "provider credential mutation"; if (resolveGatewayName(target.gatewayPort) !== target.gatewayName) { throw new GatewayAuthorityError( `Refusing ${operation} for noncanonical target '${target.gatewayName}@${String(target.gatewayPort)}'.`, @@ -303,6 +310,17 @@ export function resolveGatewayForwardAuthority( return resolveGatewayEffectAuthority(target, "forward recovery", deps); } +/** Read-only inspection reuses recorded service ownership without service discovery. */ +export function resolveGatewayObservationAuthority(target: GatewayTeardownTarget): GatewayOwner { + const session = loadTargetSession(target, process.env); + const authority = session?.checkpoint?.gatewayAuthority; + return resolveGatewayEffectAuthority(target, "observation", { + loadSession: () => session, + hasPackagedService: () => + authority?.kind === "selected" && authority.value.source === "packaged-service", + }); +} + /** Revalidate the exact checkpointed authority before a provider credential mutation. */ export function resolveGatewayCredentialMutationAuthority( target: GatewayTeardownTarget, diff --git a/src/lib/sandbox/config-telemetry.ts b/src/lib/sandbox/config-telemetry.ts index dbf136aefe0..c2c2fcef3b1 100644 --- a/src/lib/sandbox/config-telemetry.ts +++ b/src/lib/sandbox/config-telemetry.ts @@ -9,6 +9,7 @@ import { import { isTelemetryConfigurationKey } from "../domain/telemetry/event"; import { readModelSelectionProvenance, + readHermesModelSelectionTuple, selectedModelProvenance, } from "../domain/telemetry/provenance"; import { CLI_NAME } from "../cli/branding"; @@ -37,40 +38,31 @@ export function persistConfigurationTelemetry( pending === undefined ? {} : { configurationApplyPending: pending ? true : undefined }; if (config) { const modelConfig = isConfigObject(config.model) ? config.model : {}; - const model = modelConfig.default; const nativeProvider = modelConfig.provider; const upstream = isConfigObject(config._nemoclaw_upstream) ? config._nemoclaw_upstream.provider : undefined; - const provider = nativeProvider === "custom" ? upstream : nativeProvider; - const apiMode = modelConfig.api_mode; - const api = - apiMode === undefined || apiMode === "" - ? "openai-completions" - : apiMode === "anthropic_messages" - ? "anthropic-messages" - : apiMode === "codex_responses" - ? "openai-responses" - : typeof apiMode === "string" - ? apiMode - : null; + const tuple = readHermesModelSelectionTuple(config); const previous = readModelSelectionProvenance(entry.nativeModelSelectionProvenance); const source = key === "model.default" && newModelSelection ? "custom" - : previous && previous.model === model && previous.provider === provider + : previous && + previous.model === tuple?.model && + previous.provider === tuple.provider && + previous.apiFamily === tuple.apiFamily ? previous.modelSource : undefined; updates.nativeModelSelectionProvenance = - typeof model === "string" && typeof provider === "string" && source + tuple && source ? selectedModelProvenance({ - model, - provider, + model: tuple.model, + provider: tuple.provider, endpointUrl: nativeProvider === "custom" && upstream === entry.provider ? entry.endpointUrl : undefined, - preferredInferenceApi: api, + preferredInferenceApi: tuple.apiFamily, modelSource: source, }) : undefined;