From 2a82b91dd5ba94346868f368845f587f9ae16ca3 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 3 Aug 2026 11:02:07 -0700 Subject: [PATCH 1/6] feat(inference): add declarative serving catalog compiler --- managed-inference/schemas/catalog.schema.json | 53 +++ managed-inference/schemas/preset.schema.json | 96 +++++ managed-inference/schemas/recipe.schema.json | 151 ++++++++ package.json | 3 +- src/lib/inference/serving/catalog.test.ts | 245 ++++++++++++ src/lib/inference/serving/catalog.ts | 364 ++++++++++++++++++ src/lib/inference/serving/generate-catalog.ts | 80 ++++ src/lib/inference/serving/types.ts | 111 ++++++ .../managed-inference-catalog.test.ts | 44 +++ 9 files changed, 1146 insertions(+), 1 deletion(-) create mode 100644 managed-inference/schemas/catalog.schema.json create mode 100644 managed-inference/schemas/preset.schema.json create mode 100644 managed-inference/schemas/recipe.schema.json create mode 100644 src/lib/inference/serving/catalog.test.ts create mode 100644 src/lib/inference/serving/catalog.ts create mode 100644 src/lib/inference/serving/generate-catalog.ts create mode 100644 src/lib/inference/serving/types.ts create mode 100644 test/package-contract/managed-inference-catalog.test.ts diff --git a/managed-inference/schemas/catalog.schema.json b/managed-inference/schemas/catalog.schema.json new file mode 100644 index 00000000000..ba141726798 --- /dev/null +++ b/managed-inference/schemas/catalog.schema.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/NVIDIA/NemoClaw/managed-inference/schemas/catalog.schema.json", + "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0", + "title": "NemoClaw compiled managed inference serving catalog", + "type": "object", + "required": [ + "schemaVersion", + "compilerVersion", + "sourceRevision", + "readinessSchemaRef", + "recipes", + "presets", + "sources", + "catalogDigest" + ], + "properties": { + "schemaVersion": { "const": "1.0.0" }, + "compilerVersion": { "const": "1.0.0" }, + "sourceRevision": { "type": "string", "pattern": "^[0-9a-f]{40,64}$" }, + "readinessSchemaRef": { + "const": "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json" + }, + "recipes": { + "type": "array", + "items": { "$ref": "recipe.schema.json" } + }, + "presets": { + "type": "array", + "items": { "$ref": "preset.schema.json" } + }, + "sources": { + "type": "array", + "items": { + "type": "object", + "required": ["path", "kind", "id", "digest"], + "properties": { + "path": { + "type": "string", + "pattern": "^managed-inference/(?:recipes|presets)/.+\\.ya?ml$", + "maxLength": 512 + }, + "kind": { "enum": ["ServingRecipe", "ServingPreset"] }, + "id": { "type": "string", "minLength": 1, "maxLength": 160 }, + "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" } + }, + "additionalProperties": false + } + }, + "catalogDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" } + }, + "additionalProperties": false +} diff --git a/managed-inference/schemas/preset.schema.json b/managed-inference/schemas/preset.schema.json new file mode 100644 index 00000000000..6ce98de367d --- /dev/null +++ b/managed-inference/schemas/preset.schema.json @@ -0,0 +1,96 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/NVIDIA/NemoClaw/managed-inference/schemas/preset.schema.json", + "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0", + "title": "NemoClaw managed inference serving preset", + "type": "object", + "required": ["apiVersion", "kind", "metadata", "spec"], + "properties": { + "apiVersion": { "const": "nemoclaw.nvidia.com/managed-inference/v1" }, + "kind": { "const": "ServingPreset" }, + "metadata": { + "type": "object", + "required": ["id"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "displayName": { "type": "string", "minLength": 1, "maxLength": 256 } + }, + "additionalProperties": false + }, + "spec": { + "type": "object", + "required": ["selection", "priority", "plan"], + "properties": { + "selection": { "enum": ["automatic", "explicit-only", "disabled"] }, + "priority": { "type": "integer", "minimum": 0, "maximum": 10000 }, + "requirements": { + "type": "object", + "required": ["all"], + "properties": { + "all": { + "type": "array", + "maxItems": 64, + "items": { "$ref": "#/$defs/readinessRequirement" } + } + }, + "additionalProperties": false + }, + "plan": { + "type": "object", + "required": ["backend", "recipeRef"], + "properties": { + "backend": { "$ref": "#/$defs/backendId" }, + "recipeRef": { "$ref": "#/$defs/stableId" } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false, + "$defs": { + "stableId": { + "type": "string", + "pattern": "^[a-z][a-z0-9]*(?:[._/-][a-z0-9]+)+$", + "maxLength": 160 + }, + "backendId": { + "type": "string", + "pattern": "^[a-z][a-z0-9-]{0,63}$" + }, + "readinessRequirement": { + "type": "object", + "required": ["readiness"], + "properties": { + "readiness": { + "oneOf": [ + { + "type": "object", + "required": ["scope", "kind", "id", "state"], + "properties": { + "scope": { "enum": ["controller", "everyNode"] }, + "kind": { "enum": ["observation", "capability"] }, + "id": { "$ref": "#/$defs/stableId" }, + "state": { "enum": ["present", "absent"] } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["scope", "kind", "id", "status"], + "properties": { + "scope": { "enum": ["controller", "everyNode"] }, + "kind": { "const": "qualification" }, + "id": { "$ref": "#/$defs/stableId" }, + "status": { "enum": ["qualified", "unqualified"] } + }, + "additionalProperties": false + } + ] + } + }, + "additionalProperties": false + } + } +} diff --git a/managed-inference/schemas/recipe.schema.json b/managed-inference/schemas/recipe.schema.json new file mode 100644 index 00000000000..3a03e5f3d5c --- /dev/null +++ b/managed-inference/schemas/recipe.schema.json @@ -0,0 +1,151 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/NVIDIA/NemoClaw/managed-inference/schemas/recipe.schema.json", + "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0", + "title": "NemoClaw managed inference serving recipe", + "type": "object", + "required": ["apiVersion", "kind", "metadata", "spec"], + "properties": { + "apiVersion": { "const": "nemoclaw.nvidia.com/managed-inference/v1" }, + "kind": { "const": "ServingRecipe" }, + "metadata": { "$ref": "#/$defs/metadata" }, + "spec": { + "type": "object", + "required": ["backend", "model", "execution"], + "properties": { + "backend": { "$ref": "#/$defs/backendId" }, + "model": { + "type": "object", + "required": ["id", "revision"], + "properties": { + "id": { "type": "string", "minLength": 1, "maxLength": 256 }, + "revision": { + "type": "string", + "pattern": "^(?:[0-9a-f]{40,64}|sha256:[0-9a-f]{64})$" + }, + "servedName": { "$ref": "#/$defs/stableId" }, + "files": { + "type": "array", + "minItems": 1, + "maxItems": 32, + "items": { + "type": "object", + "required": ["path", "digest"], + "properties": { + "path": { + "type": "string", + "minLength": 1, + "maxLength": 512, + "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))[^\\u0000]+$" + }, + "digest": { "$ref": "#/$defs/sha256" } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false + }, + "runtime": { + "type": "object", + "properties": { + "image": { + "type": "string", + "pattern": "^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[0-9]+)?/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*@sha256:[0-9a-f]{64}$" + }, + "architecture": { "enum": ["amd64", "arm64"] }, + "components": { + "type": "object", + "maxProperties": 32, + "propertyNames": { "$ref": "#/$defs/stableId" }, + "additionalProperties": { + "type": "string", + "minLength": 1, + "maxLength": 128 + } + } + }, + "additionalProperties": false + }, + "execution": { + "type": "object", + "required": ["materializerRef", "lifecycleRef"], + "properties": { + "materializerRef": { "$ref": "#/$defs/adapterId" }, + "lifecycleRef": { "$ref": "#/$defs/adapterId" } + }, + "additionalProperties": false + }, + "serve": { + "type": "object", + "properties": { + "arguments": { + "type": "array", + "maxItems": 128, + "items": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "pattern": "^--[a-z0-9][a-z0-9-]*$", + "maxLength": 128 + }, + "value": { "$ref": "#/$defs/scalar" } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false + }, + "readiness": { + "type": "object", + "properties": { + "timeoutSeconds": { "type": "integer", "minimum": 1, "maximum": 86400 }, + "expectedModel": { "$ref": "#/$defs/stableId" } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false, + "$defs": { + "metadata": { + "type": "object", + "required": ["id"], + "properties": { + "id": { "$ref": "#/$defs/stableId" }, + "displayName": { "type": "string", "minLength": 1, "maxLength": 256 } + }, + "additionalProperties": false + }, + "stableId": { + "type": "string", + "pattern": "^[a-z][a-z0-9]*(?:[._/-][a-z0-9]+)+$", + "maxLength": 160 + }, + "backendId": { + "type": "string", + "pattern": "^[a-z][a-z0-9-]{0,63}$" + }, + "adapterId": { + "type": "string", + "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+/v[1-9][0-9]*$", + "maxLength": 160 + }, + "sha256": { + "type": "string", + "pattern": "^sha256:[0-9a-f]{64}$" + }, + "scalar": { + "oneOf": [ + { "type": "string", "maxLength": 1024 }, + { "type": "number" }, + { "type": "boolean" } + ] + } + } +} diff --git a/package.json b/package.json index 92b617dee5c..ae781a2548b 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "check:installer-hash": "bash scripts/check-installer-hash.sh", "typecheck": "tsc -p jsconfig.json", "build:policy-boundary": "tsc -p nemoclaw/tsconfig.shared.json", - "build:cli": "npm run build:policy-boundary && tsc -p tsconfig.src.json && node dist/lib/core/generate-build-identity.js && node dist/lib/cli/generate-oclif-metadata-manifest.js && if find nemoclaw-blueprint/scripts -name '*.ts' -print -quit | grep -q .; then tsc -p nemoclaw-blueprint/tsconfig.json; fi", + "build:cli": "npm run build:policy-boundary && tsc -p tsconfig.src.json && node dist/lib/core/generate-build-identity.js && node dist/lib/inference/serving/generate-catalog.js && node dist/lib/cli/generate-oclif-metadata-manifest.js && if find nemoclaw-blueprint/scripts -name '*.ts' -print -quit | grep -q .; then tsc -p nemoclaw-blueprint/tsconfig.json; fi", "clean:cli": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"", "typecheck:cli": "tsc -p tsconfig.cli.json", "validate:configs": "tsx scripts/validate-configs.mts", @@ -115,6 +115,7 @@ "nemoclaw/openclaw.plugin.json", "nemoclaw/package.json", "nemoclaw-blueprint/", + "managed-inference/", "schemas/network-policy.schema.json", "schemas/sandbox-policy.schema.json", "scripts/", diff --git a/src/lib/inference/serving/catalog.test.ts b/src/lib/inference/serving/catalog.test.ts new file mode 100644 index 00000000000..f1155267b01 --- /dev/null +++ b/src/lib/inference/serving/catalog.test.ts @@ -0,0 +1,245 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from "vitest"; +import catalogSchema from "../../../../managed-inference/schemas/catalog.schema.json" with { + type: "json", +}; +import presetSchema from "../../../../managed-inference/schemas/preset.schema.json" with { + type: "json", +}; +import recipeSchema from "../../../../managed-inference/schemas/recipe.schema.json" with { + type: "json", +}; +import { + compileTrustedServingCatalog, + parseCompiledServingCatalogJson, + serializeCompiledServingCatalog, +} from "./catalog"; +import type { + ServingCatalogRegistries, + ServingCatalogSchemas, + ServingCatalogSource, +} from "./types"; + +const SOURCE_REVISION = "a".repeat(40); +const IMAGE_DIGEST = "b".repeat(64); +const MODEL_REVISION = "c".repeat(40); +const SCHEMAS: ServingCatalogSchemas = { + catalog: catalogSchema, + preset: presetSchema, + recipe: recipeSchema, +}; +const REGISTRIES: ServingCatalogRegistries = { + materializers: new Set(["test.materializer/v1"]), + lifecycles: new Set(["test.lifecycle/v1"]), + readiness: new Map([ + ["test.runtime.present", "capability"], + ["test.runtime.other", "capability"], + ]), +}; + +function recipeSource( + id = "test.recipe.v1", + overrides: { image?: string; execution?: string } = {}, +): ServingCatalogSource { + return { + path: `managed-inference/recipes/test/${id}.yaml`, + contents: ` +apiVersion: nemoclaw.nvidia.com/managed-inference/v1 +kind: ServingRecipe +metadata: + id: ${id} +spec: + backend: test + model: + id: test/model + revision: ${MODEL_REVISION} + servedName: test-model + files: + - path: model.gguf + digest: sha256:${"d".repeat(64)} + runtime: + image: ${overrides.image ?? `registry.example/test/server@sha256:${IMAGE_DIGEST}`} + architecture: amd64 + execution: +${overrides.execution ?? " materializerRef: test.materializer/v1\n lifecycleRef: test.lifecycle/v1"} + serve: + arguments: + - name: --port + value: 8081 + readiness: + timeoutSeconds: 30 + expectedModel: test-model +`, + }; +} + +function presetSource( + id = "test.preset.auto", + options: { priority?: number; recipeRef?: string; readinessId?: string } = {}, +): ServingCatalogSource { + return { + path: `managed-inference/presets/test/${id}.yaml`, + contents: ` +apiVersion: nemoclaw.nvidia.com/managed-inference/v1 +kind: ServingPreset +metadata: + id: ${id} +spec: + selection: automatic + priority: ${options.priority ?? 100} + requirements: + all: + - readiness: + scope: everyNode + kind: capability + id: ${options.readinessId ?? "test.runtime.present"} + state: present + plan: + backend: test + recipeRef: ${options.recipeRef ?? "test.recipe.v1"} +`, + }; +} + +function compile(sources: readonly ServingCatalogSource[], registries = REGISTRIES) { + return compileTrustedServingCatalog({ + sources, + sourceRevision: SOURCE_REVISION, + schemas: SCHEMAS, + registries, + }); +} + +function requireValidationFailure(run: () => void, expectedMessage: string): void { + try { + run(); + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + + if (!message.includes(expectedMessage)) { + throw new Error( + `Expected validation error containing "${expectedMessage}", received "${message}".`, + ); + } + + return; + } + + throw new Error("Expected serving catalog validation to fail."); +} + +describe("managed inference serving catalog compiler", () => { + it("compiles managed-inference YAML to deterministic canonical JSON (#8144)", () => { + const recipe = recipeSource(); + const preset = presetSource(); + + const first = compile([recipe, preset]); + const second = compile([preset, recipe]); + + expect(serializeCompiledServingCatalog(first)).toBe(serializeCompiledServingCatalog(second)); + expect(first.readinessSchemaRef).toBe( + "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json", + ); + expect(first.recipes.map((definition) => definition.metadata.id)).toEqual(["test.recipe.v1"]); + expect(first.presets.map((definition) => definition.metadata.id)).toEqual(["test.preset.auto"]); + expect(first.sources.map((source) => source.path)).toEqual([ + "managed-inference/presets/test/test.preset.auto.yaml", + "managed-inference/recipes/test/test.recipe.v1.yaml", + ]); + }); + + it("rejects duplicate definition IDs and dangling recipe references (#8144)", () => { + const duplicate = { + ...recipeSource(), + path: "managed-inference/recipes/test/duplicate.yaml", + }; + expect(() => compile([recipeSource(), duplicate])).toThrow("ID test.recipe.v1 is duplicated"); + expect(() => + compile([ + recipeSource(), + presetSource("test.preset.missing", { + recipeRef: "test.recipe.missing", + }), + ]), + ).toThrow("references unknown recipe test.recipe.missing"); + }); + + it("rejects executable fields and mutable artifact references (#8144)", () => { + expect(() => + compile([ + recipeSource("test.recipe.shell", { + execution: + " materializerRef: test.materializer/v1\n lifecycleRef: test.lifecycle/v1\n command: sh -c server", + }), + ]), + ).toThrow("does not satisfy the ServingRecipe schema"); + expect(() => + compile([ + recipeSource("test.recipe.mutable", { + image: "registry.example/test/server:latest", + }), + ]), + ).toThrow("does not satisfy the ServingRecipe schema"); + }); + + it("rejects adapter and readiness IDs outside the injected registries (#8144)", () => { + expect(() => + compile([recipeSource()], { + ...REGISTRIES, + materializers: new Set(), + }), + ).toThrow("references unknown materializer test.materializer/v1"); + expect(() => + compile([ + recipeSource(), + presetSource("test.preset.unknown", { + readinessId: "test.readiness.unknown", + }), + ]), + ).toThrow("references unknown readiness entity test.readiness.unknown"); + }); + + it("rejects duplicate automatic selectors at one priority (#8144)", () => { + expect(() => + compile([ + recipeSource(), + presetSource(), + presetSource("test.preset.other", { priority: 100 }), + ]), + ).toThrow("have the same selector at priority 100 for backend test"); + }); + + it("accepts disjoint automatic selectors at one priority (#8144)", () => { + const catalog = compile([ + recipeSource(), + presetSource(), + presetSource("test.preset.other", { + priority: 100, + readinessId: "test.runtime.other", + }), + ]); + + expect(catalog.presets.map((preset) => preset.metadata.id)).toEqual([ + "test.preset.auto", + "test.preset.other", + ]); + }); + + it("accepts only compiled JSON whose digest matches its content (#8144)", () => { + const serialized = serializeCompiledServingCatalog(compile([recipeSource(), presetSource()])); + const parsed = parseCompiledServingCatalogJson(serialized, SCHEMAS); + const tampered = serialized.replace("test/model", "test/other-model"); + requireValidationFailure( + () => parseCompiledServingCatalogJson(tampered, SCHEMAS), + "digest mismatch", + ); + requireValidationFailure( + () => parseCompiledServingCatalogJson("apiVersion: v1", SCHEMAS), + "is not valid JSON", + ); + + expect(parsed.catalogDigest).toMatch(/^sha256:[0-9a-f]{64}$/); + }); +}); diff --git a/src/lib/inference/serving/catalog.ts b/src/lib/inference/serving/catalog.ts new file mode 100644 index 00000000000..8a6f0d33760 --- /dev/null +++ b/src/lib/inference/serving/catalog.ts @@ -0,0 +1,364 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { createHash } from "node:crypto"; + +import Ajv2020, { type AnySchema, type ValidateFunction } from "ajv/dist/2020.js"; +import { parseDocument } from "yaml"; + +import type { + CompiledServingCatalog, + CompiledServingCatalogPayload, + ServingCatalogRegistries, + ServingCatalogSchemas, + ServingCatalogSource, + ServingDefinitionKind, + ServingPreset, + ServingRecipe, +} from "./types"; + +const API_VERSION = "nemoclaw.nvidia.com/managed-inference/v1" as const; +const CATALOG_SCHEMA_VERSION = "1.0.0" as const; +const COMPILER_VERSION = "1.0.0" as const; +const READINESS_SCHEMA_REF = + "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json" as const; +const RECIPE_SCHEMA_ID = + "https://github.com/NVIDIA/NemoClaw/managed-inference/schemas/recipe.schema.json"; +const PRESET_SCHEMA_ID = + "https://github.com/NVIDIA/NemoClaw/managed-inference/schemas/preset.schema.json"; +const CATALOG_SOURCE_PATTERN = /^managed-inference\/(recipes|presets)\/.+\.ya?ml$/; + +interface CatalogValidators { + catalog: ValidateFunction; + preset: ValidateFunction; + recipe: ValidateFunction; +} + +interface CompileServingCatalogOptions { + sources: readonly ServingCatalogSource[]; + sourceRevision: string; + schemas: ServingCatalogSchemas; + registries: ServingCatalogRegistries; +} + +export class ServingCatalogValidationError extends Error { + constructor(message: string) { + super(message); + this.name = "ServingCatalogValidationError"; + } +} + +function compareCanonicalText(left: string, right: string): number { + return left < right ? -1 : left > right ? 1 : 0; +} + +function normalizeForCanonicalJson(value: unknown): unknown { + if (Array.isArray(value)) { + return value.map(normalizeForCanonicalJson); + } + if (value !== null && typeof value === "object") { + return Object.fromEntries( + Object.entries(value) + .sort(([left], [right]) => compareCanonicalText(left, right)) + .map(([key, nested]) => [key, normalizeForCanonicalJson(nested)]), + ); + } + return value; +} + +export function canonicalServingCatalogJson(value: unknown): string { + return JSON.stringify(normalizeForCanonicalJson(value)); +} + +function digest(value: unknown): string { + return `sha256:${createHash("sha256").update(canonicalServingCatalogJson(value)).digest("hex")}`; +} + +function createValidators(schemas: ServingCatalogSchemas): CatalogValidators { + const ajv = new Ajv2020({ allErrors: true, strict: true }); + ajv.addSchema(schemas.recipe as AnySchema); + ajv.addSchema(schemas.preset as AnySchema); + const recipe = ajv.getSchema(RECIPE_SCHEMA_ID); + const preset = ajv.getSchema(PRESET_SCHEMA_ID); + if (!recipe || !preset) { + throw new ServingCatalogValidationError("Serving catalog schemas have invalid identifiers."); + } + return { + recipe, + preset, + catalog: ajv.compile(schemas.catalog as AnySchema), + }; +} + +function validationDetails(validate: ValidateFunction): string { + return (validate.errors ?? []) + .map((error) => `${error.instancePath || "/"} ${error.message ?? "is invalid"}`) + .join("; "); +} + +function isRecord(value: unknown): value is Record { + return value !== null && typeof value === "object" && !Array.isArray(value); +} + +function parseTrustedYaml(source: ServingCatalogSource): Record { + let document; + try { + document = parseDocument(source.contents, { strict: true, uniqueKeys: true }); + } catch (error) { + throw new ServingCatalogValidationError( + `${source.path} is not valid YAML: ${error instanceof Error ? error.message : String(error)}`, + ); + } + if (document.errors.length > 0) { + throw new ServingCatalogValidationError( + `${source.path} is not valid YAML: ${document.errors.map((error) => error.message).join("; ")}`, + ); + } + let value: unknown; + try { + value = document.toJS({ maxAliasCount: 0 }); + } catch (error) { + throw new ServingCatalogValidationError( + `${source.path} cannot use YAML aliases: ${error instanceof Error ? error.message : String(error)}`, + ); + } + if (!isRecord(value)) { + throw new ServingCatalogValidationError(`${source.path} must contain one YAML mapping.`); + } + return value; +} + +function definitionIdentity( + source: ServingCatalogSource, + value: Record, +): { kind: ServingDefinitionKind; id: string } { + const kind = value.kind; + const metadata = value.metadata; + const id = isRecord(metadata) ? metadata.id : undefined; + if ((kind !== "ServingRecipe" && kind !== "ServingPreset") || typeof id !== "string") { + throw new ServingCatalogValidationError( + `${source.path} must declare a ServingRecipe or ServingPreset with metadata.id.`, + ); + } + return { kind, id }; +} + +function validateRecipeSemantics( + recipe: ServingRecipe, + registries: ServingCatalogRegistries, +): void { + const { materializerRef, lifecycleRef } = recipe.spec.execution; + if (!registries.materializers.has(materializerRef)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} references unknown materializer ${materializerRef}.`, + ); + } + if (!registries.lifecycles.has(lifecycleRef)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} references unknown lifecycle adapter ${lifecycleRef}.`, + ); + } + + const argumentNames = new Set(); + for (const argument of recipe.spec.serve?.arguments ?? []) { + if (argumentNames.has(argument.name)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} repeats structured argument ${argument.name}.`, + ); + } + argumentNames.add(argument.name); + } + + const modelFiles = new Set(); + for (const file of recipe.spec.model.files ?? []) { + if (modelFiles.has(file.path)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} repeats model file ${file.path}.`, + ); + } + modelFiles.add(file.path); + } +} + +function validatePresetReadiness( + preset: ServingPreset, + registries: ServingCatalogRegistries, +): void { + for (const requirement of preset.spec.requirements?.all ?? []) { + const registeredKind = registries.readiness.get(requirement.readiness.id); + if (registeredKind === undefined) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} references unknown readiness entity ${requirement.readiness.id}.`, + ); + } + if (registeredKind !== requirement.readiness.kind) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} uses ${requirement.readiness.id} as ${requirement.readiness.kind}, but the readiness registry declares ${registeredKind}.`, + ); + } + } +} + +function validateCatalogSemantics( + recipes: readonly ServingRecipe[], + presets: readonly ServingPreset[], +): void { + const recipesById = new Map(recipes.map((recipe) => [recipe.metadata.id, recipe])); + for (const preset of presets) { + const recipe = recipesById.get(preset.spec.plan.recipeRef); + if (!recipe) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} references unknown recipe ${preset.spec.plan.recipeRef}.`, + ); + } + if (recipe.spec.backend !== preset.spec.plan.backend) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} selects backend ${preset.spec.plan.backend}, but recipe ${recipe.metadata.id} uses ${recipe.spec.backend}.`, + ); + } + } + + const automaticSelectors = new Map(); + for (const preset of presets) { + if (preset.spec.selection !== "automatic") continue; + const requirements = (preset.spec.requirements?.all ?? []) + .map((requirement) => canonicalServingCatalogJson(requirement)) + .sort(); + const key = canonicalServingCatalogJson({ + backend: preset.spec.plan.backend, + priority: preset.spec.priority, + requirements, + }); + const previous = automaticSelectors.get(key); + if (previous) { + throw new ServingCatalogValidationError( + `Automatic presets ${previous} and ${preset.metadata.id} have the same selector at priority ${preset.spec.priority} for backend ${preset.spec.plan.backend}.`, + ); + } + automaticSelectors.set(key, preset.metadata.id); + } +} + +function catalogPayload(catalog: CompiledServingCatalog): CompiledServingCatalogPayload { + const { catalogDigest: _catalogDigest, ...payload } = catalog; + return payload; +} + +export function compileTrustedServingCatalog( + options: CompileServingCatalogOptions, +): CompiledServingCatalog { + const validators = createValidators(options.schemas); + const recipes: ServingRecipe[] = []; + const presets: ServingPreset[] = []; + const sources: CompiledServingCatalog["sources"] = []; + const definitionIds = new Set(); + const sourcePaths = new Set(); + + for (const source of [...options.sources].sort((left, right) => + compareCanonicalText(left.path, right.path), + )) { + const sourceMatch = CATALOG_SOURCE_PATTERN.exec(source.path); + const hasUnsafeSegment = source.path + .split("/") + .some((segment) => segment === "" || segment === "." || segment === ".."); + if (!sourceMatch || hasUnsafeSegment) { + throw new ServingCatalogValidationError( + `Catalog source ${source.path} is outside managed-inference/recipes or managed-inference/presets.`, + ); + } + if (sourcePaths.has(source.path)) { + throw new ServingCatalogValidationError(`Catalog source path ${source.path} is duplicated.`); + } + sourcePaths.add(source.path); + + const value = parseTrustedYaml(source); + const { kind, id } = definitionIdentity(source, value); + const expectedDirectory = kind === "ServingRecipe" ? "recipes" : "presets"; + if (sourceMatch[1] !== expectedDirectory) { + throw new ServingCatalogValidationError( + `${source.path} must place ${kind} definitions under managed-inference/${expectedDirectory}.`, + ); + } + const validate = kind === "ServingRecipe" ? validators.recipe : validators.preset; + if (!validate(value)) { + throw new ServingCatalogValidationError( + `${source.path} does not satisfy the ${kind} schema: ${validationDetails(validate)}`, + ); + } + if (definitionIds.has(id)) { + throw new ServingCatalogValidationError(`Serving definition ID ${id} is duplicated.`); + } + definitionIds.add(id); + + if (kind === "ServingRecipe") { + const recipe = value as unknown as ServingRecipe; + validateRecipeSemantics(recipe, options.registries); + recipes.push(recipe); + } else { + const preset = value as unknown as ServingPreset; + validatePresetReadiness(preset, options.registries); + presets.push(preset); + } + sources.push({ path: source.path, kind, id, digest: digest(value) }); + } + + recipes.sort((left, right) => compareCanonicalText(left.metadata.id, right.metadata.id)); + presets.sort((left, right) => compareCanonicalText(left.metadata.id, right.metadata.id)); + validateCatalogSemantics(recipes, presets); + + const payload: CompiledServingCatalogPayload = { + schemaVersion: CATALOG_SCHEMA_VERSION, + compilerVersion: COMPILER_VERSION, + sourceRevision: options.sourceRevision, + readinessSchemaRef: READINESS_SCHEMA_REF, + recipes, + presets, + sources, + }; + const catalog: CompiledServingCatalog = { ...payload, catalogDigest: digest(payload) }; + if (!validators.catalog(catalog)) { + throw new ServingCatalogValidationError( + `Compiled serving catalog is invalid: ${validationDetails(validators.catalog)}`, + ); + } + return catalog; +} + +export function parseCompiledServingCatalogJson( + source: string, + schemas: ServingCatalogSchemas, +): CompiledServingCatalog { + let value: unknown; + try { + value = JSON.parse(source); + } catch (error) { + throw new ServingCatalogValidationError( + `Compiled serving catalog is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, + ); + } + const validators = createValidators(schemas); + if (!validators.catalog(value)) { + throw new ServingCatalogValidationError( + `Compiled serving catalog is invalid: ${validationDetails(validators.catalog)}`, + ); + } + const catalog = value as CompiledServingCatalog; + const expectedDigest = digest(catalogPayload(catalog)); + if (catalog.catalogDigest !== expectedDigest) { + throw new ServingCatalogValidationError( + `Compiled serving catalog digest mismatch: expected ${expectedDigest}.`, + ); + } + return catalog; +} + +export function serializeCompiledServingCatalog(catalog: CompiledServingCatalog): string { + return `${canonicalServingCatalogJson(catalog)}\n`; +} + +export const servingCatalogContract = Object.freeze({ + apiVersion: API_VERSION, + catalogSchemaVersion: CATALOG_SCHEMA_VERSION, + compilerVersion: COMPILER_VERSION, + readinessSchemaRef: READINESS_SCHEMA_REF, +}); diff --git a/src/lib/inference/serving/generate-catalog.ts b/src/lib/inference/serving/generate-catalog.ts new file mode 100644 index 00000000000..a6a2a4f94cb --- /dev/null +++ b/src/lib/inference/serving/generate-catalog.ts @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; +import { dirname, join, relative } from "node:path"; + +import { resolveSourceBuildIdentity } from "../../core/version"; +import { compileTrustedServingCatalog, serializeCompiledServingCatalog } from "./catalog"; +import type { + ServingCatalogRegistries, + ServingCatalogSchemas, + ServingCatalogSource, +} from "./types"; + +const EMPTY_REGISTRIES: ServingCatalogRegistries = { + materializers: new Set(), + lifecycles: new Set(), + readiness: new Map(), +}; + +function readJson(path: string): object { + return JSON.parse(readFileSync(path, "utf8")) as object; +} + +function loadSchemas(rootDir: string): ServingCatalogSchemas { + const schemaRoot = join(rootDir, "managed-inference", "schemas"); + return { + catalog: readJson(join(schemaRoot, "catalog.schema.json")), + preset: readJson(join(schemaRoot, "preset.schema.json")), + recipe: readJson(join(schemaRoot, "recipe.schema.json")), + }; +} + +function discoverYamlFiles(directory: string): string[] { + if (!existsSync(directory)) return []; + return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { + const path = join(directory, entry.name); + if (entry.isDirectory()) return discoverYamlFiles(path); + return entry.isFile() && /\.ya?ml$/.test(entry.name) ? [path] : []; + }); +} + +function loadSources(rootDir: string): ServingCatalogSource[] { + const managedInferenceRoot = join(rootDir, "managed-inference"); + const files = [ + ...discoverYamlFiles(join(managedInferenceRoot, "recipes")), + ...discoverYamlFiles(join(managedInferenceRoot, "presets")), + ]; + return files + .sort((left, right) => (left < right ? -1 : left > right ? 1 : 0)) + .map((path) => ({ + path: relative(rootDir, path).replaceAll("\\", "/"), + contents: readFileSync(path, "utf8"), + })); +} + +export interface GenerateServingCatalogOptions { + rootDir: string; + outputPath?: string; + registries?: ServingCatalogRegistries; +} + +export function generateServingCatalog(options: GenerateServingCatalogOptions): string { + const outputPath = + options.outputPath ?? join(options.rootDir, "dist", "managed-inference", "catalog.json"); + const catalog = compileTrustedServingCatalog({ + sources: loadSources(options.rootDir), + sourceRevision: resolveSourceBuildIdentity({ rootDir: options.rootDir }).sourceRevision, + schemas: loadSchemas(options.rootDir), + registries: options.registries ?? EMPTY_REGISTRIES, + }); + mkdirSync(dirname(outputPath), { recursive: true }); + writeFileSync(outputPath, serializeCompiledServingCatalog(catalog)); + return outputPath; +} + +if (require.main === module) { + const rootDir = join(__dirname, "..", "..", "..", ".."); + generateServingCatalog({ rootDir }); +} diff --git a/src/lib/inference/serving/types.ts b/src/lib/inference/serving/types.ts new file mode 100644 index 00000000000..00f82e774d8 --- /dev/null +++ b/src/lib/inference/serving/types.ts @@ -0,0 +1,111 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +export type ServingDefinitionKind = "ServingRecipe" | "ServingPreset"; +export type ServingSelectionPolicy = "automatic" | "explicit-only" | "disabled"; +export type ReadinessEntityKind = "observation" | "capability" | "qualification"; + +export interface ServingMetadata { + id: string; + displayName?: string; +} + +export interface ServingRecipe { + apiVersion: "nemoclaw.nvidia.com/managed-inference/v1"; + kind: "ServingRecipe"; + metadata: ServingMetadata; + spec: { + backend: string; + model: { + id: string; + revision: string; + servedName?: string; + files?: Array<{ path: string; digest: string }>; + }; + runtime?: { + image?: string; + architecture?: "amd64" | "arm64"; + components?: Record; + }; + execution: { + materializerRef: string; + lifecycleRef: string; + }; + serve?: { + arguments?: Array<{ name: string; value?: string | number | boolean }>; + }; + readiness?: { + timeoutSeconds?: number; + expectedModel?: string; + }; + }; +} + +export interface ServingReadinessRequirement { + readiness: + | { + scope: "controller" | "everyNode"; + kind: "observation" | "capability"; + id: string; + state: "present" | "absent"; + } + | { + scope: "controller" | "everyNode"; + kind: "qualification"; + id: string; + status: "qualified" | "unqualified"; + }; +} + +export interface ServingPreset { + apiVersion: "nemoclaw.nvidia.com/managed-inference/v1"; + kind: "ServingPreset"; + metadata: ServingMetadata; + spec: { + selection: ServingSelectionPolicy; + priority: number; + requirements?: { all: ServingReadinessRequirement[] }; + plan: { + backend: string; + recipeRef: string; + }; + }; +} + +export interface ServingCatalogSourceProvenance { + path: string; + kind: ServingDefinitionKind; + id: string; + digest: string; +} + +export interface CompiledServingCatalogPayload { + schemaVersion: "1.0.0"; + compilerVersion: "1.0.0"; + sourceRevision: string; + readinessSchemaRef: "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json"; + recipes: ServingRecipe[]; + presets: ServingPreset[]; + sources: ServingCatalogSourceProvenance[]; +} + +export interface CompiledServingCatalog extends CompiledServingCatalogPayload { + catalogDigest: string; +} + +export interface ServingCatalogSource { + path: string; + contents: string; +} + +export interface ServingCatalogSchemas { + catalog: object; + preset: object; + recipe: object; +} + +export interface ServingCatalogRegistries { + materializers: ReadonlySet; + lifecycles: ReadonlySet; + readiness: ReadonlyMap; +} diff --git a/test/package-contract/managed-inference-catalog.test.ts b/test/package-contract/managed-inference-catalog.test.ts new file mode 100644 index 00000000000..551793405fb --- /dev/null +++ b/test/package-contract/managed-inference-catalog.test.ts @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import path from "node:path"; + +import { describe, expect, it } from "vitest"; +import catalogSchema from "../../managed-inference/schemas/catalog.schema.json" with { + type: "json", +}; +import presetSchema from "../../managed-inference/schemas/preset.schema.json" with { type: "json" }; +import recipeSchema from "../../managed-inference/schemas/recipe.schema.json" with { type: "json" }; + +import { parseCompiledServingCatalogJson } from "../../dist/lib/inference/serving/catalog"; + +const REPOSITORY_ROOT = path.join(import.meta.dirname, "..", ".."); + +describe("compiled managed inference serving catalog", () => { + it("build output contains a schema-valid catalog with a source revision and matching digest (#8144)", () => { + const source = readFileSync( + path.join(REPOSITORY_ROOT, "dist", "managed-inference", "catalog.json"), + "utf8", + ); + parseCompiledServingCatalogJson(source, { + catalog: catalogSchema, + preset: presetSchema, + recipe: recipeSchema, + }); + }); + + it("includes the compiled catalog in the npm package (#8144)", () => { + const result = JSON.parse( + execFileSync("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { + cwd: REPOSITORY_ROOT, + encoding: "utf8", + }), + ) as Array<{ files: Array<{ path: string }> }>; + const files = result[0]?.files.map((file) => file.path) ?? []; + + expect(files).toContain("dist/managed-inference/catalog.json"); + expect(files).toContain("managed-inference/schemas/catalog.schema.json"); + }, 120_000); +}); From 89194502682a22a03562c83b9428257128102107 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 3 Aug 2026 11:19:21 -0700 Subject: [PATCH 2/6] test(inference): keep catalog validation tests linear --- src/lib/inference/serving/catalog.test.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/lib/inference/serving/catalog.test.ts b/src/lib/inference/serving/catalog.test.ts index f1155267b01..7930849a3a0 100644 --- a/src/lib/inference/serving/catalog.test.ts +++ b/src/lib/inference/serving/catalog.test.ts @@ -113,21 +113,7 @@ function compile(sources: readonly ServingCatalogSource[], registries = REGISTRI } function requireValidationFailure(run: () => void, expectedMessage: string): void { - try { - run(); - } catch (error) { - const message = error instanceof Error ? error.message : String(error); - - if (!message.includes(expectedMessage)) { - throw new Error( - `Expected validation error containing "${expectedMessage}", received "${message}".`, - ); - } - - return; - } - - throw new Error("Expected serving catalog validation to fail."); + expect(run).toThrow(expectedMessage); } describe("managed inference serving catalog compiler", () => { From 89d93994a1fa4cd60745b445daee3a9f72be3177 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 3 Aug 2026 11:45:05 -0700 Subject: [PATCH 3/6] test(inference): harden catalog package contract --- src/lib/inference/serving/generate-catalog.ts | 4 +- .../managed-inference-catalog.test.ts | 68 +++++++++++++++---- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/lib/inference/serving/generate-catalog.ts b/src/lib/inference/serving/generate-catalog.ts index a6a2a4f94cb..b780ea59afd 100644 --- a/src/lib/inference/serving/generate-catalog.ts +++ b/src/lib/inference/serving/generate-catalog.ts @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, join, relative } from "node:path"; import { resolveSourceBuildIdentity } from "../../core/version"; @@ -12,6 +12,8 @@ import type { ServingCatalogSource, } from "./types"; +// Bootstrap only: valid while the catalog has no definitions. Production definitions must +// inject populated registries; tracked by https://github.com/NVIDIA/NemoClaw/issues/8144. const EMPTY_REGISTRIES: ServingCatalogRegistries = { materializers: new Set(), lifecycles: new Set(), diff --git a/test/package-contract/managed-inference-catalog.test.ts b/test/package-contract/managed-inference-catalog.test.ts index 551793405fb..23976654e7d 100644 --- a/test/package-contract/managed-inference-catalog.test.ts +++ b/test/package-contract/managed-inference-catalog.test.ts @@ -2,20 +2,55 @@ // SPDX-License-Identifier: Apache-2.0 import { execFileSync } from "node:child_process"; -import { readFileSync } from "node:fs"; +import { + copyFileSync, + cpSync, + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; +import { parseCompiledServingCatalogJson } from "../../dist/lib/inference/serving/catalog"; import catalogSchema from "../../managed-inference/schemas/catalog.schema.json" with { type: "json", }; import presetSchema from "../../managed-inference/schemas/preset.schema.json" with { type: "json" }; import recipeSchema from "../../managed-inference/schemas/recipe.schema.json" with { type: "json" }; -import { parseCompiledServingCatalogJson } from "../../dist/lib/inference/serving/catalog"; - const REPOSITORY_ROOT = path.join(import.meta.dirname, "..", ".."); +function createPackFixture(): string { + const fixtureRoot = mkdtempSync(path.join(tmpdir(), "nemoclaw-serving-catalog-pack-")); + const packageJson = JSON.parse( + readFileSync(path.join(REPOSITORY_ROOT, "package.json"), "utf8"), + ) as { scripts?: Record }; + // Local-directory packs always prepare first; keep this fixture scoped to packlist behavior. + packageJson.scripts = {}; + + writeFileSync( + path.join(fixtureRoot, "package.json"), + `${JSON.stringify(packageJson, null, 2)}\n`, + ); + copyFileSync(path.join(REPOSITORY_ROOT, ".gitignore"), path.join(fixtureRoot, ".gitignore")); + mkdirSync(path.join(fixtureRoot, "dist"), { recursive: true }); + cpSync( + path.join(REPOSITORY_ROOT, "dist", "managed-inference"), + path.join(fixtureRoot, "dist", "managed-inference"), + { recursive: true }, + ); + cpSync( + path.join(REPOSITORY_ROOT, "managed-inference"), + path.join(fixtureRoot, "managed-inference"), + { recursive: true }, + ); + return fixtureRoot; +} + describe("compiled managed inference serving catalog", () => { it("build output contains a schema-valid catalog with a source revision and matching digest (#8144)", () => { const source = readFileSync( @@ -30,15 +65,22 @@ describe("compiled managed inference serving catalog", () => { }); it("includes the compiled catalog in the npm package (#8144)", () => { - const result = JSON.parse( - execFileSync("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { - cwd: REPOSITORY_ROOT, - encoding: "utf8", - }), - ) as Array<{ files: Array<{ path: string }> }>; - const files = result[0]?.files.map((file) => file.path) ?? []; - - expect(files).toContain("dist/managed-inference/catalog.json"); - expect(files).toContain("managed-inference/schemas/catalog.schema.json"); + const fixtureRoot = createPackFixture(); + try { + const result = JSON.parse( + execFileSync("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { + cwd: fixtureRoot, + encoding: "utf8", + }), + ) as Array<{ files: Array<{ path: string }> }>; + const files = result[0]?.files.map((file) => file.path) ?? []; + + expect(files).toContain("dist/managed-inference/catalog.json"); + expect(files).toContain("managed-inference/schemas/catalog.schema.json"); + expect(files).toContain("managed-inference/schemas/recipe.schema.json"); + expect(files).toContain("managed-inference/schemas/preset.schema.json"); + } finally { + rmSync(fixtureRoot, { recursive: true, force: true }); + } }, 120_000); }); From a4559cec56267316321f418763e0361638f9979b Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 3 Aug 2026 17:26:57 -0700 Subject: [PATCH 4/6] feat(inference): type llama.cpp serving recipes Signed-off-by: Aaron Erickson --- managed-inference/schemas/catalog.schema.json | 2 +- managed-inference/schemas/preset.schema.json | 77 +++ managed-inference/schemas/recipe.schema.json | 402 +++++++++++++- src/lib/inference/serving/catalog.test.ts | 492 +++++++++++++++++- src/lib/inference/serving/catalog.ts | 222 +++++++- src/lib/inference/serving/generate-catalog.ts | 2 + src/lib/inference/serving/types.ts | 128 ++++- 7 files changed, 1300 insertions(+), 25 deletions(-) diff --git a/managed-inference/schemas/catalog.schema.json b/managed-inference/schemas/catalog.schema.json index ba141726798..ee2eeeae281 100644 --- a/managed-inference/schemas/catalog.schema.json +++ b/managed-inference/schemas/catalog.schema.json @@ -16,7 +16,7 @@ ], "properties": { "schemaVersion": { "const": "1.0.0" }, - "compilerVersion": { "const": "1.0.0" }, + "compilerVersion": { "const": "1.1.0" }, "sourceRevision": { "type": "string", "pattern": "^[0-9a-f]{40,64}$" }, "readinessSchemaRef": { "const": "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json" diff --git a/managed-inference/schemas/preset.schema.json b/managed-inference/schemas/preset.schema.json index 6ce98de367d..7bfc98587a2 100644 --- a/managed-inference/schemas/preset.schema.json +++ b/managed-inference/schemas/preset.schema.json @@ -76,6 +76,66 @@ }, "additionalProperties": false }, + { + "type": "object", + "required": ["scope", "kind", "id", "comparison"], + "properties": { + "scope": { "enum": ["controller", "everyNode"] }, + "kind": { "const": "observation" }, + "id": { "$ref": "#/$defs/stableId" }, + "comparison": { + "oneOf": [ + { + "type": "object", + "required": ["operator", "value"], + "properties": { + "operator": { "const": "equals" }, + "value": { "$ref": "#/$defs/comparisonScalar" } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["operator", "values"], + "properties": { + "operator": { "const": "one-of" }, + "values": { + "type": "array", + "minItems": 1, + "maxItems": 16, + "uniqueItems": true, + "items": { "$ref": "#/$defs/comparisonScalar" } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["operator", "value"], + "properties": { + "operator": { "const": "at-least" }, + "value": { + "type": "number", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["operator", "value"], + "properties": { + "operator": { "const": "version-at-least" }, + "value": { "$ref": "#/$defs/version" } + }, + "additionalProperties": false + } + ] + } + }, + "additionalProperties": false + }, { "type": "object", "required": ["scope", "kind", "id", "status"], @@ -91,6 +151,23 @@ } }, "additionalProperties": false + }, + "comparisonScalar": { + "oneOf": [ + { "$ref": "#/$defs/comparisonString" }, + { "type": "number", "minimum": 0, "maximum": 9007199254740991 }, + { "type": "boolean" } + ] + }, + "comparisonString": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9._+:-]{0,127}$", + "maxLength": 128 + }, + "version": { + "type": "string", + "pattern": "^[0-9]+(?:\\.[0-9]+){1,3}(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$", + "maxLength": 64 } } } diff --git a/managed-inference/schemas/recipe.schema.json b/managed-inference/schemas/recipe.schema.json index 3a03e5f3d5c..c268dfd1a61 100644 --- a/managed-inference/schemas/recipe.schema.json +++ b/managed-inference/schemas/recipe.schema.json @@ -14,6 +14,24 @@ "required": ["backend", "model", "execution"], "properties": { "backend": { "$ref": "#/$defs/backendId" }, + "providerId": { "$ref": "#/$defs/backendId" }, + "server": { + "type": "object", + "required": ["technology", "source"], + "properties": { + "technology": { "const": "llama.cpp" }, + "source": { + "type": "object", + "required": ["repository", "revision"], + "properties": { + "repository": { "$ref": "#/$defs/repositoryId" }, + "revision": { "$ref": "#/$defs/sourceRevision" } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, "model": { "type": "object", "required": ["id", "revision"], @@ -38,7 +56,15 @@ "maxLength": 512, "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))[^\\u0000]+$" }, - "digest": { "$ref": "#/$defs/sha256" } + "digest": { "$ref": "#/$defs/sha256" }, + "sizeBytes": { + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "format": { "const": "gguf" }, + "quantization": { "$ref": "#/$defs/artifactLabel" }, + "license": { "$ref": "#/$defs/artifactLabel" } }, "additionalProperties": false } @@ -54,6 +80,57 @@ "pattern": "^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[0-9]+)?/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*@sha256:[0-9a-f]{64}$" }, "architecture": { "enum": ["amd64", "arm64"] }, + "platforms": { + "type": "array", + "minItems": 2, + "maxItems": 2, + "uniqueItems": true, + "items": { "enum": ["linux/amd64", "linux/arm64"] }, + "allOf": [ + { "contains": { "const": "linux/amd64" } }, + { "contains": { "const": "linux/arm64" } } + ] + }, + "containerRuntime": { "const": "docker" }, + "hosts": { "const": 1 }, + "cuda": { + "type": "object", + "required": ["baseImage", "minimumDriverVersion"], + "properties": { + "baseImage": { "$ref": "#/$defs/imageDigest" }, + "minimumDriverVersion": { "$ref": "#/$defs/version" } + }, + "additionalProperties": false + }, + "gpu": { + "type": "object", + "required": ["vendor", "count", "offload", "cpuFallback"], + "properties": { + "vendor": { "const": "nvidia" }, + "count": { "const": 1 }, + "offload": { "const": "full" }, + "cpuFallback": { "const": "reject" } + }, + "additionalProperties": false + }, + "resources": { + "type": "object", + "required": ["memoryBytes", "writableStorageBytes", "pidsLimit"], + "properties": { + "memoryBytes": { + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "writableStorageBytes": { + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "pidsLimit": { "type": "integer", "minimum": 1, "maximum": 1048576 } + }, + "additionalProperties": false + }, "components": { "type": "object", "maxProperties": 32, @@ -71,6 +148,7 @@ "type": "object", "required": ["materializerRef", "lifecycleRef"], "properties": { + "receiptRef": { "$ref": "#/$defs/adapterId" }, "materializerRef": { "$ref": "#/$defs/adapterId" }, "lifecycleRef": { "$ref": "#/$defs/adapterId" } }, @@ -79,6 +157,28 @@ "serve": { "type": "object", "properties": { + "protocol": { "const": "openai-completions" }, + "port": { "type": "integer", "minimum": 1, "maximum": 65535 }, + "chatTemplate": { "$ref": "#/$defs/artifactLabel" }, + "contextSize": { "type": "integer", "minimum": 1, "maximum": 1048576 }, + "slots": { "type": "integer", "minimum": 1, "maximum": 1024 }, + "idleSleepSeconds": { "type": "integer", "minimum": -1, "maximum": 86400 }, + "limits": { + "type": "object", + "required": [ + "maxRequestBodyBytes", + "maxPromptTokens", + "maxCompletionTokens", + "requestTimeoutSeconds" + ], + "properties": { + "maxRequestBodyBytes": { "type": "integer", "minimum": 1, "maximum": 1073741824 }, + "maxPromptTokens": { "type": "integer", "minimum": 1, "maximum": 1048576 }, + "maxCompletionTokens": { "type": "integer", "minimum": 1, "maximum": 1048576 }, + "requestTimeoutSeconds": { "type": "integer", "minimum": 1, "maximum": 86400 } + }, + "additionalProperties": false + }, "arguments": { "type": "array", "maxItems": 128, @@ -102,13 +202,104 @@ "readiness": { "type": "object", "properties": { + "contractRef": { "$ref": "#/$defs/adapterId" }, "timeoutSeconds": { "type": "integer", "minimum": 1, "maximum": 86400 }, - "expectedModel": { "$ref": "#/$defs/stableId" } + "expectedModel": { "$ref": "#/$defs/stableId" }, + "probes": { + "type": "object", + "required": ["models", "health", "properties", "metrics"], + "properties": { + "models": { "const": true }, + "health": { "const": true }, + "properties": { "const": true }, + "metrics": { "const": true } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "policy": { + "type": "object", + "required": ["egress", "modelSource", "modelDownloads"], + "properties": { + "egress": { "const": "disabled" }, + "modelSource": { "const": "verified-local" }, + "modelDownloads": { "const": "disabled" } + }, + "additionalProperties": false + }, + "surfaces": { + "type": "object", + "required": [ + "ui", + "slotInspection", + "router", + "mcpProxy", + "serverTools", + "agentMode", + "multimodalProjection" + ], + "properties": { + "ui": { "const": "disabled" }, + "slotInspection": { "const": "disabled" }, + "router": { "const": "disabled" }, + "mcpProxy": { "const": "disabled" }, + "serverTools": { "const": "disabled" }, + "agentMode": { "const": "disabled" }, + "multimodalProjection": { "const": "disabled" } + }, + "additionalProperties": false + }, + "capabilities": { + "type": "object", + "required": [ + "agents", + "protocols", + "streaming", + "toolCalls", + "structuredOutputs", + "parallelToolCalls", + "responsesApi", + "embeddings", + "reranking", + "multimodal" + ], + "properties": { + "agents": { + "type": "array", + "maxItems": 16, + "uniqueItems": true, + "items": { + "type": "object", + "required": ["id", "qualificationRef"], + "properties": { + "id": { "$ref": "#/$defs/nonPathStableId" }, + "qualificationRef": { "$ref": "#/$defs/stableId" } + }, + "additionalProperties": false + } + }, + "protocols": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { "const": "openai-completions" } + }, + "streaming": { "type": "boolean" }, + "toolCalls": { "type": "boolean" }, + "structuredOutputs": { "type": "boolean" }, + "parallelToolCalls": { "const": false }, + "responsesApi": { "const": false }, + "embeddings": { "const": false }, + "reranking": { "const": false }, + "multimodal": { "const": false } }, "additionalProperties": false } }, - "additionalProperties": false + "additionalProperties": false, + "allOf": [{ "$ref": "#/$defs/llamaCppRecipeSpec" }] } }, "additionalProperties": false, @@ -127,10 +318,38 @@ "pattern": "^[a-z][a-z0-9]*(?:[._/-][a-z0-9]+)+$", "maxLength": 160 }, + "nonPathStableId": { + "type": "string", + "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+$", + "maxLength": 160 + }, "backendId": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" }, + "repositoryId": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}/[A-Za-z0-9][A-Za-z0-9._-]{0,127}$", + "maxLength": 192 + }, + "sourceRevision": { + "type": "string", + "pattern": "^[0-9a-f]{40,64}$" + }, + "artifactLabel": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$", + "maxLength": 128 + }, + "version": { + "type": "string", + "pattern": "^[0-9]+(?:\\.[0-9]+){1,3}(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$", + "maxLength": 64 + }, + "imageDigest": { + "type": "string", + "pattern": "^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[0-9]+)?/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*@sha256:[0-9a-f]{64}$" + }, "adapterId": { "type": "string", "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+/v[1-9][0-9]*$", @@ -146,6 +365,183 @@ { "type": "number" }, { "type": "boolean" } ] + }, + "llamaCppRecipeSpec": { + "if": { + "type": "object", + "anyOf": [ + { + "properties": { "backend": { "const": "install-llama-cpp" } }, + "required": ["backend"] + }, + { + "properties": { "providerId": { "const": "llama-cpp-local" } }, + "required": ["providerId"] + }, + { + "properties": { + "server": { + "type": "object", + "properties": { "technology": { "const": "llama.cpp" } }, + "required": ["technology"] + } + }, + "required": ["server"] + } + ] + }, + "then": { + "type": "object", + "required": [ + "providerId", + "server", + "model", + "runtime", + "execution", + "serve", + "readiness", + "policy", + "surfaces", + "capabilities" + ], + "properties": { + "backend": { "const": "install-llama-cpp" }, + "providerId": { "const": "llama-cpp-local" }, + "server": { + "type": "object", + "properties": { "technology": { "const": "llama.cpp" } }, + "required": ["technology"] + }, + "model": { + "type": "object", + "required": ["id", "revision", "servedName", "files"], + "properties": { + "id": { "$ref": "#/$defs/repositoryId" }, + "revision": { "$ref": "#/$defs/sourceRevision" }, + "servedName": { "$ref": "#/$defs/nonPathStableId" }, + "files": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": ["path", "digest", "sizeBytes", "format", "quantization", "license"], + "properties": { + "path": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*\\.gguf$", + "maxLength": 255 + }, + "digest": {}, + "sizeBytes": {}, + "format": {}, + "quantization": {}, + "license": {} + } + } + } + } + }, + "runtime": { + "type": "object", + "required": [ + "image", + "platforms", + "containerRuntime", + "hosts", + "cuda", + "gpu", + "resources" + ], + "properties": { + "image": {}, + "platforms": {}, + "containerRuntime": {}, + "hosts": {}, + "cuda": {}, + "gpu": {}, + "resources": {} + }, + "not": { + "anyOf": [ + { + "type": "object", + "properties": { "architecture": {} }, + "required": ["architecture"] + }, + { + "type": "object", + "properties": { "components": {} }, + "required": ["components"] + } + ] + } + }, + "execution": { + "type": "object", + "required": ["receiptRef", "materializerRef", "lifecycleRef"], + "properties": { "receiptRef": {}, "materializerRef": {}, "lifecycleRef": {} } + }, + "serve": { + "type": "object", + "required": [ + "protocol", + "port", + "chatTemplate", + "contextSize", + "slots", + "idleSleepSeconds", + "limits" + ], + "properties": { + "protocol": {}, + "port": { "const": 8081 }, + "chatTemplate": {}, + "contextSize": {}, + "slots": { "const": 1 }, + "idleSleepSeconds": { "const": -1 }, + "limits": {} + }, + "not": { + "type": "object", + "properties": { "arguments": {} }, + "required": ["arguments"] + } + }, + "readiness": { + "type": "object", + "required": ["contractRef", "timeoutSeconds", "expectedModel", "probes"], + "properties": { + "contractRef": {}, + "timeoutSeconds": {}, + "expectedModel": {}, + "probes": {} + } + }, + "policy": { "type": "object" }, + "surfaces": { "type": "object" }, + "capabilities": { "type": "object" } + } + }, + "else": { + "type": "object", + "not": { + "anyOf": [ + { + "type": "object", + "properties": { "providerId": {} }, + "required": ["providerId"] + }, + { "type": "object", "properties": { "policy": {} }, "required": ["policy"] }, + { "type": "object", "properties": { "surfaces": {} }, "required": ["surfaces"] }, + { + "type": "object", + "properties": { "capabilities": {} }, + "required": ["capabilities"] + } + ] + } + } } } } diff --git a/src/lib/inference/serving/catalog.test.ts b/src/lib/inference/serving/catalog.test.ts index 7930849a3a0..b3fb04eb779 100644 --- a/src/lib/inference/serving/catalog.test.ts +++ b/src/lib/inference/serving/catalog.test.ts @@ -31,11 +31,22 @@ const SCHEMAS: ServingCatalogSchemas = { recipe: recipeSchema, }; const REGISTRIES: ServingCatalogRegistries = { + receipts: new Set(["test.receipt/v1"]), materializers: new Set(["test.materializer/v1"]), lifecycles: new Set(["test.lifecycle/v1"]), + readinessContracts: new Set(["test.readiness/v1"]), readiness: new Map([ - ["test.runtime.present", "capability"], - ["test.runtime.other", "capability"], + ["test.runtime.present", { kind: "capability" }], + ["test.runtime.other", { kind: "capability" }], + ["test.os", { kind: "observation", valueType: "string", role: "operating-system" }], + ["test.architecture", { kind: "observation", valueType: "string", role: "architecture" }], + [ + "test.container-runtime", + { kind: "observation", valueType: "string", role: "container-runtime" }, + ], + ["test.gpu-count", { kind: "observation", valueType: "number", role: "gpu-count" }], + ["test.driver-version", { kind: "observation", valueType: "version", role: "driver-version" }], + ["test.agent.qualified", { kind: "qualification" }], ]), }; @@ -103,6 +114,177 @@ spec: }; } +function llamaCppRecipeSource(): ServingCatalogSource { + return { + path: "managed-inference/recipes/test/test.llama.recipe.yaml", + contents: ` +apiVersion: nemoclaw.nvidia.com/managed-inference/v1 +kind: ServingRecipe +metadata: + id: test.llama.recipe +spec: + backend: install-llama-cpp + providerId: llama-cpp-local + server: + technology: llama.cpp + source: + repository: test/llama.cpp + revision: ${"e".repeat(40)} + model: + id: test/model + revision: ${"f".repeat(40)} + servedName: test-model + files: + - path: test-model.Q4_K_M.gguf + digest: sha256:${"1".repeat(64)} + sizeBytes: 4294967296 + format: gguf + quantization: Q4_K_M + license: Apache-2.0 + runtime: + image: registry.example/test/llama-server@sha256:${"2".repeat(64)} + platforms: + - linux/amd64 + - linux/arm64 + containerRuntime: docker + hosts: 1 + cuda: + baseImage: registry.example/nvidia/cuda@sha256:${"3".repeat(64)} + minimumDriverVersion: 570.0.0 + gpu: + vendor: nvidia + count: 1 + offload: full + cpuFallback: reject + resources: + memoryBytes: 34359738368 + writableStorageBytes: 1073741824 + pidsLimit: 256 + execution: + receiptRef: test.receipt/v1 + materializerRef: test.materializer/v1 + lifecycleRef: test.lifecycle/v1 + serve: + protocol: openai-completions + port: 8081 + chatTemplate: test-chat + contextSize: 32768 + slots: 1 + idleSleepSeconds: -1 + limits: + maxRequestBodyBytes: 1048576 + maxPromptTokens: 24576 + maxCompletionTokens: 8192 + requestTimeoutSeconds: 120 + readiness: + contractRef: test.readiness/v1 + timeoutSeconds: 120 + expectedModel: test-model + probes: + models: true + health: true + properties: true + metrics: true + policy: + egress: disabled + modelSource: verified-local + modelDownloads: disabled + surfaces: + ui: disabled + slotInspection: disabled + router: disabled + mcpProxy: disabled + serverTools: disabled + agentMode: disabled + multimodalProjection: disabled + capabilities: + agents: [] + protocols: + - openai-completions + streaming: true + toolCalls: true + structuredOutputs: true + parallelToolCalls: false + responsesApi: false + embeddings: false + reranking: false + multimodal: false +`, + }; +} + +function llamaCppPresetSource(selection = "explicit-only"): ServingCatalogSource { + return { + path: "managed-inference/presets/test/test.llama.preset.yaml", + contents: ` +apiVersion: nemoclaw.nvidia.com/managed-inference/v1 +kind: ServingPreset +metadata: + id: test.llama.preset +spec: + selection: ${selection} + priority: 100 + requirements: + all: + - readiness: + scope: everyNode + kind: observation + id: test.os + comparison: + operator: equals + value: linux + - readiness: + scope: everyNode + kind: observation + id: test.architecture + comparison: + operator: one-of + values: + - amd64 + - arm64 + - readiness: + scope: everyNode + kind: observation + id: test.container-runtime + comparison: + operator: equals + value: docker + - readiness: + scope: everyNode + kind: observation + id: test.gpu-count + comparison: + operator: at-least + value: 1 + - readiness: + scope: everyNode + kind: observation + id: test.driver-version + comparison: + operator: version-at-least + value: 570.0.0 + plan: + backend: install-llama-cpp + recipeRef: test.llama.recipe +`, + }; +} + +function replaceSource( + source: ServingCatalogSource, + expected: string | RegExp, + replacement: string, +): ServingCatalogSource { + const found = + typeof expected === "string" + ? source.contents.includes(expected) + : expected.test(source.contents); + if (!found) { + throw new Error(`Synthetic serving source does not contain ${String(expected)}.`); + } + return { ...source, contents: source.contents.replace(expected, replacement) }; +} + function compile(sources: readonly ServingCatalogSource[], registries = REGISTRIES) { return compileTrustedServingCatalog({ sources, @@ -128,6 +310,7 @@ describe("managed inference serving catalog compiler", () => { expect(first.readinessSchemaRef).toBe( "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json", ); + expect(first.compilerVersion).toBe("1.1.0"); expect(first.recipes.map((definition) => definition.metadata.id)).toEqual(["test.recipe.v1"]); expect(first.presets.map((definition) => definition.metadata.id)).toEqual(["test.preset.auto"]); expect(first.sources.map((source) => source.path)).toEqual([ @@ -136,6 +319,311 @@ describe("managed inference serving catalog compiler", () => { ]); }); + it("compiles a complete synthetic llama.cpp recipe and explicit-only preset (#8181)", () => { + const recipe = llamaCppRecipeSource(); + const preset = llamaCppPresetSource(); + + const first = compile([recipe, preset]); + const second = compile([preset, recipe]); + + expect(serializeCompiledServingCatalog(first)).toBe(serializeCompiledServingCatalog(second)); + expect(first.recipes[0]?.spec).toMatchObject({ + providerId: "llama-cpp-local", + server: { technology: "llama.cpp" }, + runtime: { + platforms: ["linux/amd64", "linux/arm64"], + gpu: { count: 1, cpuFallback: "reject" }, + }, + serve: { protocol: "openai-completions", port: 8081, slots: 1 }, + capabilities: { agents: [], protocols: ["openai-completions"] }, + }); + expect(first.presets[0]?.spec.selection).toBe("explicit-only"); + expect(first.sources.every((source) => /^sha256:[0-9a-f]{64}$/.test(source.digest))).toBe(true); + expect(first.catalogDigest).toMatch(/^sha256:[0-9a-f]{64}$/); + }); + + it.each([ + ["a missing server source revision", ` revision: ${"e".repeat(40)}\n`, ""], + [ + "a mutable server source revision", + ` revision: ${"e".repeat(40)}`, + " revision: main", + ], + ["a mutable model revision", ` revision: ${"f".repeat(40)}`, " revision: latest"], + ["a missing GGUF byte size", " sizeBytes: 4294967296\n", ""], + [ + "a mutable server image", + ` image: registry.example/test/llama-server@sha256:${"2".repeat(64)}`, + " image: registry.example/test/llama-server:latest", + ], + [ + "a mutable CUDA base image", + ` baseImage: registry.example/nvidia/cuda@sha256:${"3".repeat(64)}`, + " baseImage: registry.example/nvidia/cuda:12.8", + ], + ["incomplete platform coverage", " - linux/arm64\n", ""], + ["missing process limits", " pidsLimit: 256\n", ""], + [ + "an embedded credential", + ` revision: ${"e".repeat(40)}`, + ` revision: ${"e".repeat(40)}\n credential: test-secret`, + ], + ["a host model path", " - path: test-model.Q4_K_M.gguf", " - path: /tmp/model.gguf"], + ["shell syntax", " chatTemplate: test-chat", " chatTemplate: $(id)"], + ["environment expansion", " chatTemplate: test-chat", " chatTemplate: \${HOME}"], + [ + "an unsupported protocol", + " protocol: openai-completions", + " protocol: openai-responses", + ], + ["CPU fallback", " cpuFallback: reject", " cpuFallback: allow"], + ["server egress", " egress: disabled", " egress: enabled"], + ["a remote model source", " modelSource: verified-local", " modelSource: remote"], + [ + "an arbitrary launch argument", + " protocol: openai-completions", + " protocol: openai-completions\n arguments:\n - name: --unsafe", + ], + ["an unsupported capability", " responsesApi: false", " responsesApi: true"], + ["a malformed agent qualification", " agents: []", " agents: [openclaw]"], + ["a path-based served model name", " servedName: test-model", " servedName: test/model"], + ])("rejects %s in a llama.cpp recipe (#8181)", (_case, expected, replacement) => { + const recipe = replaceSource(llamaCppRecipeSource(), expected, replacement); + + expect(() => compile([recipe])).toThrow("does not satisfy the ServingRecipe schema"); + }); + + it("rejects a llama.cpp readiness model that differs from the served name (#8181)", () => { + const wrongExpectedModel = replaceSource( + llamaCppRecipeSource(), + " expectedModel: test-model", + " expectedModel: other-model", + ); + + expect(() => compile([wrongExpectedModel])).toThrow( + "readiness expectedModel must match model servedName", + ); + }); + + it("rejects llama.cpp request token limits that exceed serve.contextSize (#8181)", () => { + const excessiveTokenLimits = replaceSource( + llamaCppRecipeSource(), + " maxCompletionTokens: 8192", + " maxCompletionTokens: 8193", + ); + + expect(() => compile([excessiveTokenLimits])).toThrow( + "request token limits exceed serve.contextSize", + ); + }); + + it.each([ + ["a backend that does not match llama.cpp", " backend: install-llama-cpp", " backend: vllm"], + [ + "a GGUF byte size above Number.MAX_SAFE_INTEGER", + " sizeBytes: 4294967296", + " sizeBytes: 9007199254740992", + ], + ])("rejects %s in the typed llama.cpp contract (#8181)", (_case, expected, replacement) => { + const recipe = replaceSource(llamaCppRecipeSource(), expected, replacement); + + expect(() => compile([recipe])).toThrow("does not satisfy the ServingRecipe schema"); + }); + + it("reserves the install-llama-cpp backend for typed llama.cpp recipes (#8181)", () => { + const escapedRecipe = replaceSource( + recipeSource(), + " backend: test", + " backend: install-llama-cpp", + ); + + expect(() => compile([escapedRecipe])).toThrow("does not satisfy the ServingRecipe schema"); + }); + + it.each([ + ["receipt contract", { receipts: new Set() }, "unknown receipt contract"], + ["materializer", { materializers: new Set() }, "unknown materializer"], + ["lifecycle adapter", { lifecycles: new Set() }, "unknown lifecycle adapter"], + ["readiness contract", { readinessContracts: new Set() }, "unknown readiness contract"], + ])("rejects a llama.cpp recipe with an unknown %s reference (#8181)", (_name, registry, message) => { + expect(() => compile([llamaCppRecipeSource()], { ...REGISTRIES, ...registry })).toThrow( + message, + ); + }); + + it("validates optional receipt and readiness contracts on generic recipes (#8181)", () => { + const receiptRecipe = recipeSource("test.recipe.receipt", { + execution: + " receiptRef: test.receipt/v1\n materializerRef: test.materializer/v1\n lifecycleRef: test.lifecycle/v1", + }); + const readinessRecipe = replaceSource( + recipeSource("test.recipe.readiness"), + " readiness:\n", + " readiness:\n contractRef: test.readiness/v1\n", + ); + + expect(() => compile([receiptRecipe], { ...REGISTRIES, receipts: new Set() })).toThrow( + "unknown receipt contract test.receipt/v1", + ); + expect(() => + compile([readinessRecipe], { ...REGISTRIES, readinessContracts: new Set() }), + ).toThrow("unknown readiness contract test.readiness/v1"); + }); + + it("rejects automatic selection for a llama.cpp recipe (#8181)", () => { + expect(() => compile([llamaCppRecipeSource(), llamaCppPresetSource("automatic")])).toThrow( + "must use explicit-only selection for llama.cpp recipe", + ); + }); + + it("requires readiness requirements for an explicit llama.cpp preset (#8181)", () => { + const presetWithoutReadiness = replaceSource( + llamaCppPresetSource(), + / requirements:[\s\S]*? plan:/u, + " plan:", + ); + + expect(() => compile([llamaCppRecipeSource(), presetWithoutReadiness])).toThrow( + "must declare readiness requirements for llama.cpp recipe", + ); + }); + + it.each([ + ["operating-system", " value: linux", " value: windows"], + ["architecture", " - arm64", " - riscv64"], + ["container-runtime", " value: docker", " value: podman"], + ["gpu-count", " value: 1", " value: 0"], + ["driver-version", " value: 570.0.0", " value: 1.0.0"], + ])("rejects a llama.cpp preset whose %s contradicts its recipe (#8181)", (role, expected, replacement) => { + const preset = replaceSource(llamaCppPresetSource(), expected, replacement); + + expect(() => compile([llamaCppRecipeSource(), preset])).toThrow( + `must require ${role} matching llama.cpp recipe`, + ); + }); + + it.each([ + ["shell syntax", "$(id)"], + ["environment expansion", "${HOME}"], + ["an absolute path", "/tmp/model.gguf"], + ])("rejects %s in a readiness comparison string (#8181)", (_case, value) => { + const preset = replaceSource( + llamaCppPresetSource(), + " value: linux", + ` value: ${value}`, + ); + + expect(() => compile([llamaCppRecipeSource(), preset])).toThrow( + "does not satisfy the ServingPreset schema", + ); + }); + + it("rejects a negative readiness threshold (#8181)", () => { + const preset = replaceSource( + llamaCppPresetSource(), + " value: 1", + " value: -1", + ); + + expect(() => compile([llamaCppRecipeSource(), preset])).toThrow( + "does not satisfy the ServingPreset schema", + ); + }); + + it("requires declared llama.cpp agents to reference a qualification entity (#8181)", () => { + const declaredAgent = replaceSource( + llamaCppRecipeSource(), + " agents: []", + " agents:\n - id: test.agent\n qualificationRef: test.agent.qualified", + ); + const unknownQualification = replaceSource( + declaredAgent, + " qualificationRef: test.agent.qualified", + " qualificationRef: test.agent.unknown", + ); + + expect(() => compile([declaredAgent])).not.toThrow(); + expect(() => compile([unknownQualification])).toThrow( + "references unknown agent qualification test.agent.unknown for test.agent", + ); + }); + + it("gates declared llama.cpp agents on preset qualification readiness (#8181)", () => { + const declaredAgent = replaceSource( + llamaCppRecipeSource(), + " agents: []", + " agents:\n - id: test.agent\n qualificationRef: test.agent.qualified", + ); + const preset = llamaCppPresetSource(); + const qualifiedPreset = replaceSource( + preset, + " plan:\n", + ` - readiness: + scope: everyNode + kind: qualification + id: test.agent.qualified + status: qualified + plan: +`, + ); + + expect(() => compile([declaredAgent, preset])).toThrow( + "must require qualified status for test.agent.qualified", + ); + expect(() => compile([declaredAgent, qualifiedPreset])).not.toThrow(); + }); + + it("rejects duplicate llama.cpp agent capability declarations (#8181)", () => { + const duplicateAgent = replaceSource( + llamaCppRecipeSource(), + " agents: []", + ` agents: + - id: test.agent + qualificationRef: test.agent.qualified + - id: test.agent + qualificationRef: test.other.qualified`, + ); + + expect(() => compile([duplicateAgent])).toThrow("repeats agent capability test.agent"); + }); + + it("rejects duplicate and contradictory readiness requirements (#8181)", () => { + const repeatedRequirement = ` - readiness: + scope: everyNode + kind: observation + id: test.os + comparison: + operator: equals + value: linux +`; + const duplicate = replaceSource( + llamaCppPresetSource(), + " plan:\n", + `${repeatedRequirement} plan:\n`, + ); + const contradiction = replaceSource( + duplicate, + " value: linux\n plan:", + " value: windows\n plan:", + ); + + expect(() => compile([llamaCppRecipeSource(), duplicate])).toThrow( + "repeats readiness requirement", + ); + expect(() => compile([llamaCppRecipeSource(), contradiction])).toThrow( + "has contradictory readiness requirements", + ); + }); + + it("rejects a readiness comparison whose value type conflicts with its registry entry (#8181)", () => { + const readiness = new Map(REGISTRIES.readiness); + readiness.set("test.gpu-count", { kind: "observation", valueType: "string" }); + + expect(() => + compile([llamaCppRecipeSource(), llamaCppPresetSource()], { ...REGISTRIES, readiness }), + ).toThrow("compares test.gpu-count as number, but the readiness registry declares string"); + }); + it("rejects duplicate definition IDs and dangling recipe references (#8144)", () => { const duplicate = { ...recipeSource(), diff --git a/src/lib/inference/serving/catalog.ts b/src/lib/inference/serving/catalog.ts index 8a6f0d33760..fe851cbd23a 100644 --- a/src/lib/inference/serving/catalog.ts +++ b/src/lib/inference/serving/catalog.ts @@ -14,12 +14,15 @@ import type { ServingCatalogSource, ServingDefinitionKind, ServingPreset, + ServingReadinessComparison, + ServingReadinessObservationRole, + ServingReadinessRequirement, ServingRecipe, } from "./types"; const API_VERSION = "nemoclaw.nvidia.com/managed-inference/v1" as const; const CATALOG_SCHEMA_VERSION = "1.0.0" as const; -const COMPILER_VERSION = "1.0.0" as const; +const COMPILER_VERSION = "1.1.0" as const; const READINESS_SCHEMA_REF = "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json" as const; const RECIPE_SCHEMA_ID = @@ -143,11 +146,22 @@ function definitionIdentity( return { kind, id }; } +type LlamaCppServingRecipe = Extract; + +function isLlamaCppServingRecipe(recipe: ServingRecipe): recipe is LlamaCppServingRecipe { + return recipe.spec.providerId === "llama-cpp-local"; +} + function validateRecipeSemantics( recipe: ServingRecipe, registries: ServingCatalogRegistries, ): void { - const { materializerRef, lifecycleRef } = recipe.spec.execution; + const { receiptRef, materializerRef, lifecycleRef } = recipe.spec.execution; + if (receiptRef && !registries.receipts.has(receiptRef)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} references unknown receipt contract ${receiptRef}.`, + ); + } if (!registries.materializers.has(materializerRef)) { throw new ServingCatalogValidationError( `Recipe ${recipe.metadata.id} references unknown materializer ${materializerRef}.`, @@ -158,15 +172,22 @@ function validateRecipeSemantics( `Recipe ${recipe.metadata.id} references unknown lifecycle adapter ${lifecycleRef}.`, ); } - - const argumentNames = new Set(); - for (const argument of recipe.spec.serve?.arguments ?? []) { - if (argumentNames.has(argument.name)) { - throw new ServingCatalogValidationError( - `Recipe ${recipe.metadata.id} repeats structured argument ${argument.name}.`, - ); + const readinessContractRef = recipe.spec.readiness?.contractRef; + if (readinessContractRef && !registries.readinessContracts.has(readinessContractRef)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} references unknown readiness contract ${readinessContractRef}.`, + ); + } + if (!isLlamaCppServingRecipe(recipe)) { + const argumentNames = new Set(); + for (const argument of recipe.spec.serve?.arguments ?? []) { + if (argumentNames.has(argument.name)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} repeats structured argument ${argument.name}.`, + ); + } + argumentNames.add(argument.name); } - argumentNames.add(argument.name); } const modelFiles = new Set(); @@ -178,22 +199,177 @@ function validateRecipeSemantics( } modelFiles.add(file.path); } + + if (isLlamaCppServingRecipe(recipe)) { + const servedName = recipe.spec.model.servedName; + if (recipe.spec.readiness.expectedModel !== servedName) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} readiness expectedModel must match model servedName.`, + ); + } + const { serve } = recipe.spec; + if (serve.limits.maxPromptTokens + serve.limits.maxCompletionTokens > serve.contextSize) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} request token limits exceed serve.contextSize.`, + ); + } + const agents = new Set(); + for (const agent of recipe.spec.capabilities.agents) { + if (agents.has(agent.id)) { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} repeats agent capability ${agent.id}.`, + ); + } + agents.add(agent.id); + const qualification = registries.readiness.get(agent.qualificationRef); + if (qualification?.kind !== "qualification") { + throw new ServingCatalogValidationError( + `Recipe ${recipe.metadata.id} references unknown agent qualification ${agent.qualificationRef} for ${agent.id}.`, + ); + } + } + } +} + +function comparisonValueType( + comparison: ServingReadinessComparison, +): "boolean" | "number" | "string" | "version" | "mixed" { + if (comparison.operator === "at-least") return "number"; + if (comparison.operator === "version-at-least") return "version"; + const values = comparison.operator === "one-of" ? comparison.values : [comparison.value]; + const types = new Set(values.map((value) => typeof value)); + if (types.size !== 1) return "mixed"; + const [type] = types; + return type === "boolean" || type === "number" || type === "string" ? type : "mixed"; +} + +function readinessRequirementKey(requirement: ServingReadinessRequirement): string { + const readiness = requirement.readiness; + return `${readiness.scope}:${readiness.kind}:${readiness.id}`; } function validatePresetReadiness( preset: ServingPreset, registries: ServingCatalogRegistries, ): void { + const requirementsByEntity = new Map(); for (const requirement of preset.spec.requirements?.all ?? []) { - const registeredKind = registries.readiness.get(requirement.readiness.id); - if (registeredKind === undefined) { + const readiness = requirement.readiness; + const registered = registries.readiness.get(readiness.id); + if (registered === undefined) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} references unknown readiness entity ${readiness.id}.`, + ); + } + if (registered.kind !== readiness.kind) { throw new ServingCatalogValidationError( - `Preset ${preset.metadata.id} references unknown readiness entity ${requirement.readiness.id}.`, + `Preset ${preset.metadata.id} uses ${readiness.id} as ${readiness.kind}, but the readiness registry declares ${registered.kind}.`, ); } - if (registeredKind !== requirement.readiness.kind) { + + if ("comparison" in readiness) { + if (registered.kind !== "observation") { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} cannot compare readiness entity ${readiness.id}.`, + ); + } + const comparisonType = comparisonValueType(readiness.comparison); + if (!registered.valueType || comparisonType !== registered.valueType) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} compares ${readiness.id} as ${comparisonType}, but the readiness registry declares ${registered.valueType ?? "no value type"}.`, + ); + } + } + + const key = readinessRequirementKey(requirement); + const canonicalRequirement = canonicalServingCatalogJson(requirement); + const previous = requirementsByEntity.get(key); + if (previous === canonicalRequirement) { throw new ServingCatalogValidationError( - `Preset ${preset.metadata.id} uses ${requirement.readiness.id} as ${requirement.readiness.kind}, but the readiness registry declares ${registeredKind}.`, + `Preset ${preset.metadata.id} repeats readiness requirement ${key}.`, + ); + } + if (previous !== undefined) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} has contradictory readiness requirements for ${key}.`, + ); + } + requirementsByEntity.set(key, canonicalRequirement); + } +} + +function canonicalReadinessComparison(comparison: ServingReadinessComparison): string { + if (comparison.operator !== "one-of") { + return canonicalServingCatalogJson(comparison); + } + return canonicalServingCatalogJson({ + ...comparison, + values: [...comparison.values].sort((left, right) => + compareCanonicalText(canonicalServingCatalogJson(left), canonicalServingCatalogJson(right)), + ), + }); +} + +function validateLlamaCppPreset( + recipe: LlamaCppServingRecipe, + preset: ServingPreset, + registries: ServingCatalogRegistries, +): void { + const expectedComparisons = new Map([ + ["operating-system", { operator: "equals", value: "linux" }], + [ + "architecture", + { + operator: "one-of", + values: recipe.spec.runtime.platforms.map((platform) => platform.slice("linux/".length)), + }, + ], + ["container-runtime", { operator: "equals", value: recipe.spec.runtime.containerRuntime }], + ["gpu-count", { operator: "at-least", value: recipe.spec.runtime.gpu.count }], + [ + "driver-version", + { operator: "version-at-least", value: recipe.spec.runtime.cuda.minimumDriverVersion }, + ], + ]); + const seenRoles = new Set(); + const qualified = new Set(); + + for (const requirement of preset.spec.requirements?.all ?? []) { + const readiness = requirement.readiness; + if (readiness.kind === "qualification" && readiness.status === "qualified") { + qualified.add(readiness.id); + } + const registered = registries.readiness.get(readiness.id); + if (registered?.kind !== "observation" || registered.role === undefined) continue; + const expected = expectedComparisons.get(registered.role); + if (!expected) continue; + if (seenRoles.has(registered.role)) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} repeats llama.cpp readiness role ${registered.role}.`, + ); + } + seenRoles.add(registered.role); + if ( + !("comparison" in readiness) || + canonicalReadinessComparison(readiness.comparison) !== canonicalReadinessComparison(expected) + ) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} must require ${registered.role} matching llama.cpp recipe ${recipe.metadata.id}.`, + ); + } + } + + for (const role of expectedComparisons.keys()) { + if (!seenRoles.has(role)) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} must require ${role} matching llama.cpp recipe ${recipe.metadata.id}.`, + ); + } + } + for (const agent of recipe.spec.capabilities.agents) { + if (!qualified.has(agent.qualificationRef)) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} must require qualified status for ${agent.qualificationRef} before selecting llama.cpp recipe ${recipe.metadata.id}.`, ); } } @@ -202,6 +378,7 @@ function validatePresetReadiness( function validateCatalogSemantics( recipes: readonly ServingRecipe[], presets: readonly ServingPreset[], + registries: ServingCatalogRegistries, ): void { const recipesById = new Map(recipes.map((recipe) => [recipe.metadata.id, recipe])); for (const preset of presets) { @@ -216,6 +393,19 @@ function validateCatalogSemantics( `Preset ${preset.metadata.id} selects backend ${preset.spec.plan.backend}, but recipe ${recipe.metadata.id} uses ${recipe.spec.backend}.`, ); } + if (isLlamaCppServingRecipe(recipe)) { + if (preset.spec.selection !== "explicit-only") { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} must use explicit-only selection for llama.cpp recipe ${recipe.metadata.id}.`, + ); + } + if ((preset.spec.requirements?.all.length ?? 0) === 0) { + throw new ServingCatalogValidationError( + `Preset ${preset.metadata.id} must declare readiness requirements for llama.cpp recipe ${recipe.metadata.id}.`, + ); + } + validateLlamaCppPreset(recipe, preset, registries); + } } const automaticSelectors = new Map(); @@ -304,7 +494,7 @@ export function compileTrustedServingCatalog( recipes.sort((left, right) => compareCanonicalText(left.metadata.id, right.metadata.id)); presets.sort((left, right) => compareCanonicalText(left.metadata.id, right.metadata.id)); - validateCatalogSemantics(recipes, presets); + validateCatalogSemantics(recipes, presets, options.registries); const payload: CompiledServingCatalogPayload = { schemaVersion: CATALOG_SCHEMA_VERSION, diff --git a/src/lib/inference/serving/generate-catalog.ts b/src/lib/inference/serving/generate-catalog.ts index b780ea59afd..fe3a56b900d 100644 --- a/src/lib/inference/serving/generate-catalog.ts +++ b/src/lib/inference/serving/generate-catalog.ts @@ -15,8 +15,10 @@ import type { // Bootstrap only: valid while the catalog has no definitions. Production definitions must // inject populated registries; tracked by https://github.com/NVIDIA/NemoClaw/issues/8144. const EMPTY_REGISTRIES: ServingCatalogRegistries = { + receipts: new Set(), materializers: new Set(), lifecycles: new Set(), + readinessContracts: new Set(), readiness: new Map(), }; diff --git a/src/lib/inference/serving/types.ts b/src/lib/inference/serving/types.ts index 00f82e774d8..c2d5af58e58 100644 --- a/src/lib/inference/serving/types.ts +++ b/src/lib/inference/serving/types.ts @@ -4,18 +4,30 @@ export type ServingDefinitionKind = "ServingRecipe" | "ServingPreset"; export type ServingSelectionPolicy = "automatic" | "explicit-only" | "disabled"; export type ReadinessEntityKind = "observation" | "capability" | "qualification"; +export type ReadinessValueType = "boolean" | "number" | "string" | "version"; +export type ServingReadinessObservationRole = + | "operating-system" + | "architecture" + | "container-runtime" + | "gpu-count" + | "driver-version"; export interface ServingMetadata { id: string; displayName?: string; } -export interface ServingRecipe { +interface ServingRecipeEnvelope { apiVersion: "nemoclaw.nvidia.com/managed-inference/v1"; kind: "ServingRecipe"; metadata: ServingMetadata; +} + +interface GenericServingRecipe extends ServingRecipeEnvelope { spec: { backend: string; + providerId?: never; + server?: never; model: { id: string; revision: string; @@ -28,6 +40,7 @@ export interface ServingRecipe { components?: Record; }; execution: { + receiptRef?: string; materializerRef: string; lifecycleRef: string; }; @@ -35,12 +48,105 @@ export interface ServingRecipe { arguments?: Array<{ name: string; value?: string | number | boolean }>; }; readiness?: { + contractRef?: string; timeoutSeconds?: number; expectedModel?: string; }; }; } +interface LlamaCppServingRecipe extends ServingRecipeEnvelope { + spec: { + backend: "install-llama-cpp"; + providerId: "llama-cpp-local"; + server: { + technology: "llama.cpp"; + source: { repository: string; revision: string }; + }; + model: { + id: string; + revision: string; + servedName: string; + files: Array<{ + path: string; + digest: string; + sizeBytes: number; + format: "gguf"; + quantization: string; + license: string; + }>; + }; + runtime: { + image: string; + platforms: Array<"linux/amd64" | "linux/arm64">; + containerRuntime: "docker"; + hosts: 1; + cuda: { baseImage: string; minimumDriverVersion: string }; + gpu: { vendor: "nvidia"; count: 1; offload: "full"; cpuFallback: "reject" }; + resources: { memoryBytes: number; writableStorageBytes: number; pidsLimit: number }; + }; + execution: { + receiptRef: string; + materializerRef: string; + lifecycleRef: string; + }; + serve: { + protocol: "openai-completions"; + port: 8081; + chatTemplate: string; + contextSize: number; + slots: 1; + idleSleepSeconds: -1; + limits: { + maxRequestBodyBytes: number; + maxPromptTokens: number; + maxCompletionTokens: number; + requestTimeoutSeconds: number; + }; + }; + readiness: { + contractRef: string; + timeoutSeconds: number; + expectedModel: string; + probes: { models: true; health: true; properties: true; metrics: true }; + }; + policy: { + egress: "disabled"; + modelSource: "verified-local"; + modelDownloads: "disabled"; + }; + surfaces: { + ui: "disabled"; + slotInspection: "disabled"; + router: "disabled"; + mcpProxy: "disabled"; + serverTools: "disabled"; + agentMode: "disabled"; + multimodalProjection: "disabled"; + }; + capabilities: { + agents: Array<{ id: string; qualificationRef: string }>; + protocols: ["openai-completions"]; + streaming: boolean; + toolCalls: boolean; + structuredOutputs: boolean; + parallelToolCalls: false; + responsesApi: false; + embeddings: false; + reranking: false; + multimodal: false; + }; + }; +} + +export type ServingRecipe = GenericServingRecipe | LlamaCppServingRecipe; + +export type ServingReadinessComparison = + | { operator: "equals"; value: string | number | boolean } + | { operator: "one-of"; values: Array } + | { operator: "at-least"; value: number } + | { operator: "version-at-least"; value: string }; + export interface ServingReadinessRequirement { readiness: | { @@ -49,6 +155,12 @@ export interface ServingReadinessRequirement { id: string; state: "present" | "absent"; } + | { + scope: "controller" | "everyNode"; + kind: "observation"; + id: string; + comparison: ServingReadinessComparison; + } | { scope: "controller" | "everyNode"; kind: "qualification"; @@ -81,7 +193,7 @@ export interface ServingCatalogSourceProvenance { export interface CompiledServingCatalogPayload { schemaVersion: "1.0.0"; - compilerVersion: "1.0.0"; + compilerVersion: "1.1.0"; sourceRevision: string; readinessSchemaRef: "https://github.com/NVIDIA/NemoClaw/schemas/system-readiness.schema.json"; recipes: ServingRecipe[]; @@ -105,7 +217,17 @@ export interface ServingCatalogSchemas { } export interface ServingCatalogRegistries { + receipts: ReadonlySet; materializers: ReadonlySet; lifecycles: ReadonlySet; - readiness: ReadonlyMap; + readinessContracts: ReadonlySet; + readiness: ReadonlyMap< + string, + | { + kind: "observation"; + valueType?: ReadinessValueType; + role?: ServingReadinessObservationRole; + } + | { kind: "capability" | "qualification" } + >; } From cc298cdfbcbe973ff7dc36bdd6e024a99a12e3b9 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 3 Aug 2026 17:53:32 -0700 Subject: [PATCH 5/6] test(inference): keep llama catalog fixtures linear Signed-off-by: Aaron Erickson --- src/lib/inference/serving/catalog.test.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/lib/inference/serving/catalog.test.ts b/src/lib/inference/serving/catalog.test.ts index b3fb04eb779..fb43ac65803 100644 --- a/src/lib/inference/serving/catalog.test.ts +++ b/src/lib/inference/serving/catalog.test.ts @@ -275,14 +275,9 @@ function replaceSource( expected: string | RegExp, replacement: string, ): ServingCatalogSource { - const found = - typeof expected === "string" - ? source.contents.includes(expected) - : expected.test(source.contents); - if (!found) { - throw new Error(`Synthetic serving source does not contain ${String(expected)}.`); - } - return { ...source, contents: source.contents.replace(expected, replacement) }; + const contents = source.contents.replace(expected, replacement); + expect(contents).not.toBe(source.contents); + return { ...source, contents }; } function compile(sources: readonly ServingCatalogSource[], registries = REGISTRIES) { From e358a67eca30117f9dadcf0833b5c1e181349762 Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 3 Aug 2026 22:22:19 -0700 Subject: [PATCH 6/6] fix(inference): format llama catalog tests --- src/lib/inference/serving/catalog.test.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/inference/serving/catalog.test.ts b/src/lib/inference/serving/catalog.test.ts index 0128858d960..1d3453894aa 100644 --- a/src/lib/inference/serving/catalog.test.ts +++ b/src/lib/inference/serving/catalog.test.ts @@ -701,10 +701,17 @@ describe("managed inference serving catalog compiler", () => { ); expect(() => compile([duplicateModelFile])).toThrow("repeats model file model.gguf"); - for (const path of ["./model.gguf", "models//model.gguf", "models/./model.gguf", "models/", "models\\model.gguf", "C:\\model.gguf"]) { - expect(() => compile([replaceSource(recipeSource(), "path: model.gguf", `path: ${path}`)])).toThrow( - "does not satisfy the ServingRecipe schema", - ); + for (const path of [ + "./model.gguf", + "models//model.gguf", + "models/./model.gguf", + "models/", + "models\\model.gguf", + "C:\\model.gguf", + ]) { + expect(() => + compile([replaceSource(recipeSource(), "path: model.gguf", `path: ${path}`)]), + ).toThrow("does not satisfy the ServingRecipe schema"); } }); @@ -733,7 +740,9 @@ describe("managed inference serving catalog compiler", () => { contents: mismatchedKind.contents.replace("kind: capability", "kind: observation"), }, ]), - ).toThrow("uses test.runtime.present as observation, but the readiness registry declares capability"); + ).toThrow( + "uses test.runtime.present as observation, but the readiness registry declares capability", + ); }); it("rejects duplicate automatic selectors at one priority (#8144)", () => {