🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(pricing): harden audit metadata validation (#15719)
Hassieb Pakzad5a6e1c9300e4
diff --git a/.github/workflows/model-price-audit.yml b/.github/workflows/model-price-audit.ymlindex eb016f1a05..5060ffd5c3 100644--- a/.github/workflows/model-price-audit.yml+++ b/.github/workflows/model-price-audit.yml@@ -227,7 +227,7 @@ jobs:- Use the allowed exact `date -u +%Y-%m-%dT00:00:00.000Z` command if you need the current timestamp.Final response:- - Always return one `modelsChecked` row for every distinct model price entry reviewed, including confirmed and unchanged entries.+ - Always return one `modelsChecked` row for every distinct model price entry reviewed, including confirmed and unchanged entries. Set `model` to the exact `modelName` from `default-model-prices.json` for existing entries; put aliases and match-pattern details in `comments`, never in `model`.- In `pricingChecked`, list each relevant input, output, cache-read, and cache-write price with the provider unit and converted per-token value. In `usageKeysChecked`, list every applicable semantic bucket and exact provider/Langfuse alias. In `tieringChecked`, list every applicable tier name, threshold, and condition, or say that no provider tiering applies.- Set `usageKeyCoverageConfirmed` to `yes` only after comparing the provider usage object, Langfuse ingestion normalization, and the provider usage-key matrix. Use `no` for a gap or unresolved capability and do not change that model entry.- Set `priceConfirmed` to `yes` only when an official source fetched during this run confirms the exact current prices. Otherwise set it to `no` and explain why in `comments`.@@ -585,16 +585,8 @@ jobs:CHANGED_PRICING_JSON=falseCHANGED_MODEL_TYPES=false- CHANGED_SKILL_REFERENCES=false- CHANGED_WORKFLOW=falsefor changed_file in "${changed_files[@]}"; docase "$changed_file" in- .agents/skills/add-model-price/references/*.md)- CHANGED_SKILL_REFERENCES=true- ;;- .github/workflows/model-price-audit.yml)- CHANGED_WORKFLOW=true- ;;worker/src/constants/default-model-prices.json)CHANGED_PRICING_JSON=true;;@@ -609,7 +601,7 @@ jobs:TYPES_DIFF_FILE="$RUNNER_TEMP/llm-types.diff"git show "HEAD:$CURRENT_PRICING_FILE" > "$BASE_PRICING_FILE"git diff --unified=0 -- "packages/shared/src/server/llm/types.ts" > "$TYPES_DIFF_FILE"- export BASE_PRICING_FILE CHANGED_MODEL_TYPES CHANGED_PRICING_JSON CHANGED_SKILL_REFERENCES CHANGED_WORKFLOW CURRENT_PRICING_FILE TYPES_DIFF_FILE+ export BASE_PRICING_FILE CHANGED_MODEL_TYPES CHANGED_PRICING_JSON CURRENT_PRICING_FILE TYPES_DIFF_FILEmapfile -t untracked_files < <(git ls-files --others --exclude-standard)if [ "${#untracked_files[@]}" -gt 0 ]; then@@ -628,152 +620,7 @@ jobs:STRUCTURED_OUTPUT_PATH="$RUNNER_TEMP/claude-model-price-audit.json"PR_TITLE_PATH="$RUNNER_TEMP/model-price-audit-pr-title.txt"export STRUCTURED_OUTPUT_PATH- node <<'NODE' > "$PR_TITLE_PATH"- const fs = require("node:fs");- const output = JSON.parse(fs.readFileSync(process.env.STRUCTURED_OUTPUT_PATH, "utf8"));- const title = output.pullRequestTitle.trim();- const normalize = (value) => value.trim().toLowerCase();-- if (!/^chore\(pricing\): [^\r\n]+$/.test(title) || title.length > 100) {- console.error("::error::pullRequestTitle must be a single-line Conventional Commit title starting with 'chore(pricing): ' and no longer than 100 characters");- process.exit(1);- }-- const description = title.slice("chore(pricing): ".length).trim().toLowerCase();- if (/^(audit|refresh|update)( default)? (model )?(prices?|pricing)( data)?$/.test(description)) {- console.error("::error::pullRequestTitle must identify the specific models or audit behavior changed");- process.exit(1);- }-- const basePrices = JSON.parse(fs.readFileSync(process.env.BASE_PRICING_FILE, "utf8"));- const currentPrices = JSON.parse(fs.readFileSync(process.env.CURRENT_PRICING_FILE, "utf8"));- const basePricesByName = new Map(basePrices.map((item) => [normalize(item.modelName), item]));- const currentPricesByName = new Map(- currentPrices.map((item) => [normalize(item.modelName), item]),- );- const pricingModelChanges = [];- for (const modelName of new Set([- ...basePricesByName.keys(),- ...currentPricesByName.keys(),- ])) {- const before = basePricesByName.get(modelName);- const after = currentPricesByName.get(modelName);- if (JSON.stringify(before) !== JSON.stringify(after)) {- pricingModelChanges.push({- modelName: after?.modelName ?? before.modelName,- expectedChange: before ? "updated" : "added",- });- }- }-- const typeModelChanges = new Set();- for (const line of fs.readFileSync(process.env.TYPES_DIFF_FILE, "utf8").split("\n")) {- const match = line.match(/^[+-]\s*"([^"]+)"(?:,|:)/);- if (match) typeModelChanges.add(match[1]);- }-- if (process.env.CHANGED_PRICING_JSON === "true" && pricingModelChanges.length === 0) {- console.error("::error::Pricing JSON changed without a concrete model-entry change");- process.exit(1);- }- if (process.env.CHANGED_MODEL_TYPES === "true" && typeModelChanges.size === 0) {- console.error("::error::Selectable-model types changed without a concrete model identifier change");- process.exit(1);- }-- const changedModelRows = output.modelsChecked.filter((item) =>- ["added", "updated"].includes(item.change),- );- const changedRowsByModel = new Map(- changedModelRows.map((item) => [normalize(item.model), item]),- );- for (const change of pricingModelChanges) {- const row = changedRowsByModel.get(normalize(change.modelName));- if (!row || row.change !== change.expectedChange) {- console.error(`::error::modelsChecked must report the actual ${change.expectedChange} pricing entry: ${change.modelName}`);- process.exit(1);- }- }-- const affectedModels = new Map();- for (const change of pricingModelChanges) {- affectedModels.set(normalize(change.modelName), change.modelName);- }- for (const modelName of typeModelChanges) {- affectedModels.set(normalize(modelName), modelName);- if (!changedRowsByModel.has(normalize(modelName))) {- console.error(`::error::modelsChecked must report the selectable-model change: ${modelName}`);- process.exit(1);- }- }- for (const row of changedModelRows) {- if (!affectedModels.has(normalize(row.model))) {- console.error(`::error::modelsChecked reports a model without a matching pricing or selectable-model diff: ${row.model}`);- process.exit(1);- }- }-- if (affectedModels.size > 0) {- const ignoredWords = new Set([- "default",- "flash",- "latest",- "lite",- "mini",- "model",- "models",- "nano",- "preview",- "price",- "prices",- "pricing",- "pro",- "turbo",- ]);- const descriptionWords = new Set(description.split(/[^a-z0-9]+/));- const unrepresentedModels = [...affectedModels.values()].filter((modelName) => {- const identifyingWords = normalize(modelName)- .split(/[^a-z0-9]+/)- .filter(- (word) =>- (word.length >= 3 || /[a-z][0-9]|[0-9][a-z]/.test(word)) &&- !ignoredWords.has(word),- );- return (- identifyingWords.length > 0 &&- !identifyingWords.some((word) => descriptionWords.has(word))- );- });-- if (unrepresentedModels.length > 0) {- console.error(`::error::pullRequestTitle does not represent these model families from the actual diff: ${unrepresentedModels.join(", ")}`);- process.exit(1);- }- } else if (- process.env.CHANGED_WORKFLOW === "true" ||- process.env.CHANGED_SKILL_REFERENCES === "true"- ) {- const auditChangeWords = [- "audit",- "guardrail",- "memory",- "prompt",- "reference",- "report",- "source",- "table",- "title",- "validation",- "workflow",- ];- if (!auditChangeWords.some((word) => description.includes(word))) {- console.error("::error::pullRequestTitle must identify the audit workflow or skill-reference behavior changed");- process.exit(1);- }- }-- process.stdout.write(title);- NODE+ node scripts/model-price-audit/prepare-metadata.mjs > "$PR_TITLE_PATH"PR_TITLE="$(cat "$PR_TITLE_PATH")"GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null git -c core.hooksPath=/dev/null add -- "${changed_files[@]}"diff --git a/scripts/model-price-audit/prepare-metadata.mjs b/scripts/model-price-audit/prepare-metadata.mjsnew file mode 100644index 0000000000..258ea7057f--- /dev/null+++ b/scripts/model-price-audit/prepare-metadata.mjs@@ -0,0 +1,129 @@+#!/usr/bin/env node++import fs from "node:fs";++process.on("uncaughtException", (error) => {+ console.error(`::error::${error.message}`);+ process.exit(1);+});++const requiredEnvironment = [+ "BASE_PRICING_FILE",+ "CURRENT_PRICING_FILE",+ "STRUCTURED_OUTPUT_PATH",+ "TYPES_DIFF_FILE",+];++for (const name of requiredEnvironment) {+ if (!process.env[name]) {+ throw new Error(`Missing required environment variable: ${name}`);+ }+}++const output = JSON.parse(+ fs.readFileSync(process.env.STRUCTURED_OUTPUT_PATH, "utf8"),+);+const title = output.pullRequestTitle.trim();+const normalize = (value) => value.trim().toLowerCase();+const normalizeReportedModel = (value) =>+ normalize(value).replace(/\s+\((?:also\s+)?matches\b[^)]*\)$/u, "");++if (!/^chore\(pricing\): [^\r\n]+$/.test(title) || title.length > 100) {+ throw new Error(+ "pullRequestTitle must be a single-line Conventional Commit title starting with 'chore(pricing): ' and no longer than 100 characters",+ );+}++const description = title.slice("chore(pricing): ".length).trim().toLowerCase();+if (+ /^(audit|refresh|update)( default)? (model )?(prices?|pricing)( data)?$/.test(+ description,+ )+) {+ throw new Error(+ "pullRequestTitle must identify the specific models or audit behavior changed",+ );+}++const basePrices = JSON.parse(+ fs.readFileSync(process.env.BASE_PRICING_FILE, "utf8"),+);+const currentPrices = JSON.parse(+ fs.readFileSync(process.env.CURRENT_PRICING_FILE, "utf8"),+);+const basePricesByName = new Map(+ basePrices.map((item) => [normalize(item.modelName), item]),+);+const currentPricesByName = new Map(+ currentPrices.map((item) => [normalize(item.modelName), item]),+);+const pricingModelChanges = [];+for (const modelName of new Set(+ Array.from(basePricesByName.keys()).concat(currentPricesByName.keys()),+)) {+ const before = basePricesByName.get(modelName);+ const after = currentPricesByName.get(modelName);+ if (JSON.stringify(before) !== JSON.stringify(after)) {+ pricingModelChanges.push({+ modelName: after?.modelName ?? before.modelName,+ expectedChange: before ? "updated" : "added",+ });+ }+}++const typeModelChanges = new Set();+for (const line of fs+ .readFileSync(process.env.TYPES_DIFF_FILE, "utf8")+ .split("\n")) {+ const match = line.match(/^[+-]\s*"([^"]+)"(?:,|:)/);+ if (match) typeModelChanges.add(match[1]);+}++if (+ process.env.CHANGED_PRICING_JSON === "true" &&+ pricingModelChanges.length === 0+) {+ throw new Error("Pricing JSON changed without a concrete model-entry change");+}+if (process.env.CHANGED_MODEL_TYPES === "true" && typeModelChanges.size === 0) {+ throw new Error(+ "Selectable-model types changed without a concrete model identifier change",+ );+}++const changedModelRows = output.modelsChecked.filter((item) =>+ ["added", "updated"].includes(item.change),+);+const changedRowsByModel = new Map(+ changedModelRows.map((item) => [normalizeReportedModel(item.model), item]),+);+for (const change of pricingModelChanges) {+ const row = changedRowsByModel.get(normalize(change.modelName));+ if (!row || row.change !== change.expectedChange) {+ throw new Error(+ `modelsChecked must report the actual ${change.expectedChange} pricing entry: ${change.modelName}`,+ );+ }+}++const affectedModels = new Map();+for (const change of pricingModelChanges) {+ affectedModels.set(normalize(change.modelName), change.modelName);+}+for (const modelName of typeModelChanges) {+ affectedModels.set(normalize(modelName), modelName);+ if (!changedRowsByModel.has(normalize(modelName))) {+ throw new Error(+ `modelsChecked must report the selectable-model change: ${modelName}`,+ );+ }+}+for (const row of changedModelRows) {+ if (!affectedModels.has(normalizeReportedModel(row.model))) {+ throw new Error(+ `modelsChecked reports a model without a matching pricing or selectable-model diff: ${row.model}`,+ );+ }+}++process.stdout.write(title);diff --git a/scripts/model-price-audit/prepare-metadata.test.mjs b/scripts/model-price-audit/prepare-metadata.test.mjsnew file mode 100644index 0000000000..c5591f9871--- /dev/null+++ b/scripts/model-price-audit/prepare-metadata.test.mjs@@ -0,0 +1,125 @@+import assert from "node:assert/strict";+import fs from "node:fs";+import os from "node:os";+import path from "node:path";+import { spawnSync } from "node:child_process";+import test from "node:test";++const scriptPath = path.join(import.meta.dirname, "prepare-metadata.mjs");++function runValidator({+ basePrices = [],+ currentPrices = basePrices,+ output,+ typesDiff = "",+ changedPricingJson = false,+ changedModelTypes = false,+}) {+ const fixtureDirectory = fs.mkdtempSync(+ path.join(os.tmpdir(), "model-price-audit-metadata-"),+ );+ const files = {+ base: path.join(fixtureDirectory, "base.json"),+ current: path.join(fixtureDirectory, "current.json"),+ output: path.join(fixtureDirectory, "output.json"),+ typesDiff: path.join(fixtureDirectory, "types.diff"),+ };+ fs.writeFileSync(files.base, JSON.stringify(basePrices));+ fs.writeFileSync(files.current, JSON.stringify(currentPrices));+ fs.writeFileSync(files.output, JSON.stringify(output));+ fs.writeFileSync(files.typesDiff, typesDiff);++ const result = spawnSync(process.execPath, [scriptPath], {+ encoding: "utf8",+ env: {+ ...process.env,+ BASE_PRICING_FILE: files.base,+ CHANGED_MODEL_TYPES: String(changedModelTypes),+ CHANGED_PRICING_JSON: String(changedPricingJson),+ CURRENT_PRICING_FILE: files.current,+ STRUCTURED_OUTPUT_PATH: files.output,+ TYPES_DIFF_FILE: files.typesDiff,+ },+ });+ fs.rmSync(fixtureDirectory, { force: true, recursive: true });+ return result;+}++const modelName = "gpt-5.5-2026-04-23";+const changedPrices = {+ before: [{ modelName, pricingTiers: [{ prices: { input: 5 } }] }],+ after: [{ modelName, pricingTiers: [{ prices: { input: 10 } }] }],+};++test("accepts a unique trailing match-alias annotation", () => {+ const result = runValidator({+ basePrices: changedPrices.before,+ currentPrices: changedPrices.after,+ changedPricingJson: true,+ output: {+ pullRequestTitle: "chore(pricing): update gpt-5.5 large-context tier",+ modelsChecked: [+ {+ model: `${modelName} (also matches gpt-5.5)`,+ change: "updated",+ },+ ],+ },+ });++ assert.equal(result.status, 0, result.stderr);+ assert.equal(+ result.stdout,+ "chore(pricing): update gpt-5.5 large-context tier",+ );+});++test("accepts a concrete title for a reference-only diff", () => {+ const result = runValidator({+ output: {+ pullRequestTitle:+ "chore(pricing): confirm gpt-5 alias and Opus 4.5 evidence",+ modelsChecked: [{ model: modelName, change: "none" }],+ },+ });++ assert.equal(result.status, 0, result.stderr);+});++test("rejects an unrelated decorated model row", () => {+ const result = runValidator({+ basePrices: changedPrices.before,+ currentPrices: changedPrices.after,+ changedPricingJson: true,+ output: {+ pullRequestTitle: "chore(pricing): update gpt-5.5 large-context tier",+ modelsChecked: [+ {+ model: "gpt-5.4 (also matches gpt-5.5)",+ change: "updated",+ },+ ],+ },+ });++ assert.notEqual(result.status, 0);+ assert.match(+ result.stderr,+ /modelsChecked must report the actual updated pricing entry/,+ );+});++test("rejects a generic pull request title", () => {+ const result = runValidator({+ output: {+ pullRequestTitle: "chore(pricing): update model prices",+ modelsChecked: [{ model: modelName, change: "none" }],+ },+ });++ assert.notEqual(result.status, 0);+ assert.match(+ result.stderr,+ /must identify the specific models or audit behavior changed/,+ );+});