Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ RUN NODE_OPTIONS=--max-old-space-size=4096 npm run build
RUN node scripts/deduplicate-runtime-artifacts.cjs

# Historical releases remain immutable in git and in the public R2 artifact
# CDN. Fly retains every compliance bundle, configured docs snapshot and required
# schema bundle. Versioned protocol tarball bodies are offloaded only after byte
# CDN. Fly retains every hosted compliance bundle, configured docs snapshot and
# required schema bundle. A superseded prerelease (its GA is published and no
# docs snapshot, schema alias or training bundle names it) leaves the image;
# hosted grading refuses it by name and points at the GA line and the CDN copy.
# Versioned protocol tarball bodies are offloaded only after byte
# verification against the CDN; a required release's archive that R2 does not
# list yet stays local, and every sidecar plus a discovery inventory stays local.
# Prune only the builder copy, never Git records.
Expand Down
2 changes: 1 addition & 1 deletion scripts/addie-tool-surface-budget.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schema_version": 4,
"profile_ids_sha256": "5c4b3378b3d01fbcf75aeb0a40a6b83f460060fbc3e7ec37dc8444647d804faa",
"profile_contract_sha256": "f5b6ce9565dc7bf027ee95d7fc2e962e2440d0bcf3a419a0aadae880dffcb1a4",
"profile_contract_sha256": "a3c7e11fc7c588c3ba0f1a1596a0e1a069a051a494034b9753ab6c8d1ecc42a0",
"baseline": {
"id": "2026-08-26-pre-domain-consolidation",
"metrics": {
Expand Down
124 changes: 109 additions & 15 deletions scripts/prune-runtime-artifacts.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ function retainedTrainingSchemaVersions(repoRoot) {
return versions;
}

// Other exact-version schema trees the runtime resolves through
// resolveRetainedSchemaRoot(): the frozen AdCP 3.3 creative sandbox and, when
// one is configured, the training agent's hosted preview. Imported from the
// same TypeScript constants the server reads.
function runtimeSandboxSchemaVersions(repoRoot) {
const { require: requireTypeScript } = require("tsx/cjs/api");
const agentRoot = join(repoRoot, "server", "src", "training-agent");
const catalogPath = join(agentRoot, "creative33", "catalog.ts");
const previewPath = join(agentRoot, "candidate-version.ts");
const { CREATIVE33_SCHEMA_VERSION: creative33 } = requireTypeScript(catalogPath, __filename);
const previewModule = requireTypeScript(previewPath, __filename);
if (!Object.hasOwn(previewModule, "TRAINING_AGENT_HOSTED_PREVIEW")) {
throw new Error(`${previewPath} must export TRAINING_AGENT_HOSTED_PREVIEW`);
}
const preview = previewModule.TRAINING_AGENT_HOSTED_PREVIEW;
const versions = new Set([assertVersion(creative33, catalogPath)]);
if (preview !== undefined) versions.add(assertVersion(preview?.bundle, previewPath));
return versions;
}

function publishedComplianceVersions(repoRoot) {
const manifestPath = join(
repoRoot,
Expand Down Expand Up @@ -247,23 +267,56 @@ function schemaDiscoveryAliasTargets(repoRoot) {
return targets;
}

// The GA release a prerelease leads to (3.3.0 for 3.3.0-rc.2), or undefined
// for a GA version.
function gaReleaseOf(version) {
const parsed = semver.parse(version);
if (!parsed || parsed.prerelease.length === 0) return undefined;
return `${parsed.major}.${parsed.minor}.${parsed.patch}`;
}

// A prerelease is superseded once its GA (same major.minor.patch) is in the
// hosted publication manifest. A prerelease line whose GA has not shipped yet
// (a future 4.0.0-beta.N before 4.0.0) is never superseded.
function isSupersededPrerelease(version, published) {
const ga = gaReleaseOf(version);
return ga !== undefined && published.has(ga);
}

// Superseded prereleases that no runtime anchor names. Their schema and
// compliance trees stay immutable in Git and published on the artifact CDN
// (R2); only the Fly image stops carrying them, and hosted grading refuses
// them by name (server/src/services/hosted-compliance-version.ts).
function supersededRuntimeVersions(candidates, published, anchors) {
return new Set([...candidates].filter((version) =>
isSupersededPrerelease(version, published) && !anchors.has(version)));
}

function runtimeArtifactManifest(repoRoot = resolve(__dirname, "..")) {
const published = publishedComplianceVersions(repoRoot);
const docs = docsSnapshotVersions(repoRoot);
const schemaAliases = schemaDiscoveryAliasTargets(repoRoot);
const trainingSchemas = retainedTrainingSchemaVersions(repoRoot);
const sandboxSchemas = runtimeSandboxSchemaVersions(repoRoot);
// Every tree the runtime reads by exact version, whatever its release
// state: docs snapshots, schema discovery alias targets, the training
// agent's retained bundles, the creative 3.3 sandbox and any hosted preview.
// A superseded prerelease named here keeps both its schema and its
// compliance tree and stays hosted.
const anchors = new Set([...docs, ...schemaAliases, ...trainingSchemas, ...sandboxSchemas]);
const superseded = supersededRuntimeVersions(published, published, anchors);
const hosted = new Set([...published].filter((version) => !superseded.has(version)));

return {
published,
hosted,
superseded,
docs,
schemaAliases,
trainingSchemas,
schemaVersions: new Set([
...published,
...docs,
...schemaAliases,
...trainingSchemas,
]),
sandboxSchemas,
anchors,
schemaVersions: new Set([...hosted, ...anchors]),
};
}

Expand All @@ -281,11 +334,24 @@ function verifyRequiredArtifacts(repoRoot, manifest = runtimeArtifactManifest(re
for (const version of manifest.schemaVersions) {
requireArtifact(schemaRoot, version, "index.json");
}
for (const version of manifest.published) {
for (const version of manifest.hosted) {
requireArtifact(complianceRoot, version, "index.json");
// hostedComplianceOptions() requires the same-version schema bundle.
requireArtifact(schemaRoot, version, "index.json");
}
// Only a prerelease whose own GA stays hosted may leave the image: every GA
// release and every prerelease line without a GA stays hosted.
for (const version of manifest.superseded) {
const ga = gaReleaseOf(version);
if (!ga || !manifest.hosted.has(ga) || manifest.anchors.has(version)) {
throw new Error(`Refusing to drop ${version}: it is not a superseded prerelease`);
}
}
for (const version of manifest.published) {
if (manifest.hosted.has(version) === manifest.superseded.has(version)) {
throw new Error(`Published release ${version} must be either hosted or superseded`);
}
}
for (const version of manifest.docs) {
if (!existsSync(join(docsRoot, version))) {
throw new Error(`Required runtime docs snapshot is missing: ${join(docsRoot, version)}`);
Expand Down Expand Up @@ -317,6 +383,22 @@ function pruneVersionDirectories(rootPath, keep) {
return removed;
}

// Compliance trees are otherwise retained wholesale. Remove only superseded
// prereleases that no runtime anchor names, published or not.
function pruneSupersededComplianceDirectories(rootPath, manifest) {
const removed = [...supersededRuntimeVersions(
versionDirectories(rootPath), manifest.published, manifest.anchors,
)].sort(semver.compare);
for (const version of removed) rmSync(join(rootPath, version), { recursive: true });
return removed;
}

function versionDirectories(rootPath) {
return readdirSync(rootPath, { withFileTypes: true })
.filter((entry) => entry.isDirectory() && semver.valid(entry.name) !== null)
.map((entry) => entry.name);
}

function rewriteSchemaDiscovery(repoRoot, keep) {
const indexPath = join(repoRoot, "dist", "schemas", "index.json");
const index = readJson(indexPath);
Expand All @@ -329,11 +411,7 @@ function rewriteSchemaDiscovery(repoRoot, keep) {

function verifyPrunedTree(repoRoot, manifest) {
verifyRequiredArtifacts(repoRoot, manifest);
const actual = new Set(
readdirSync(join(repoRoot, "dist", "schemas"), { withFileTypes: true })
.filter((entry) => entry.isDirectory() && semver.valid(entry.name) !== null)
.map((entry) => entry.name),
);
const actual = new Set(versionDirectories(join(repoRoot, "dist", "schemas")));
const unexpected = [...actual].filter((version) => !manifest.schemaVersions.has(version));
const missing = [...manifest.schemaVersions].filter((version) => !actual.has(version));
if (unexpected.length || missing.length) {
Expand All @@ -342,6 +420,13 @@ function verifyPrunedTree(repoRoot, manifest) {
);
}

const leftover = [...supersededRuntimeVersions(
versionDirectories(join(repoRoot, "dist", "compliance")), manifest.published, manifest.anchors,
)];
if (leftover.length) {
throw new Error(`Runtime compliance closure retains superseded prereleases: ${leftover.join(",")}`);
}

const schemaIndex = readJson(join(repoRoot, "dist", "schemas", "index.json"));
const indexed = new Set(schemaIndex.versions.map((entry) => entry.version));
const stale = [...indexed].filter((version) => !manifest.schemaVersions.has(version));
Expand Down Expand Up @@ -371,14 +456,18 @@ function pruneRuntimeArtifacts(repoRoot = resolve(__dirname, ".."), verifiedProt
join(repoRoot, "dist", "schemas"),
manifest.schemaVersions,
);
const complianceRemoved = pruneSupersededComplianceDirectories(
join(repoRoot, "dist", "compliance"),
manifest,
);
rewriteSchemaDiscovery(repoRoot, manifest.schemaVersions);
verifyPrunedTree(repoRoot, manifest);
if (protocolFiles.length) {
writeFileSync(join(repoRoot, "dist", "protocol", PROTOCOL_OFFLOAD_INDEX),
`${JSON.stringify({ schema_version: 1, files: protocolFiles }, null, 2)}\n`);
for (const name of verifiedProtocolFiles) rmSync(join(repoRoot, "dist", "protocol", name));
}
return { manifest, schemasRemoved, protocolFilesOffloaded: verifiedProtocolFiles };
return { manifest, schemasRemoved, complianceRemoved, protocolFilesOffloaded: verifiedProtocolFiles };
}

async function run() {
Expand All @@ -391,8 +480,11 @@ async function run() {
const result = pruneRuntimeArtifacts(repoRoot, verified);
console.log(
`Runtime artifact closure retained ${result.manifest.schemaVersions.size} schema releases; ` +
`pruned ${result.schemasRemoved.length}; offloaded ${verified.length} CDN-verified protocol archives. ` +
"Compliance, docs, latest.tgz, archives not yet in R2 and all sidecars were left intact.",
`pruned ${result.schemasRemoved.length}; dropped superseded prereleases ` +
`${[...result.manifest.superseded].sort(semver.compare).join(", ") || "none"} ` +
`(compliance trees removed: ${result.complianceRemoved.join(", ") || "none"}); ` +
`offloaded ${verified.length} CDN-verified protocol archives. ` +
"Other compliance trees, docs, latest.tgz, archives not yet in R2 and all sidecars were left intact.",
);
}

Expand All @@ -405,9 +497,11 @@ if (require.main === module) {

module.exports = {
docsSnapshotVersions,
isSupersededPrerelease,
pruneRuntimeArtifacts,
retainedTrainingSchemaVersions,
runtimeArtifactManifest,
runtimeSandboxSchemaVersions,
verifyPrunedTree,
verifyRequiredArtifacts,
protocolOffloadCandidates,
Expand Down
27 changes: 26 additions & 1 deletion scripts/smoke-hosted-compliance-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,36 @@ process.chdir(appRoot);
const {
hostedComplianceOptions,
hostedComplianceTarget,
isRetiredSupersededPrerelease,
resolveHostedComplianceVersion,
SupersededComplianceTargetError,
} = await import(servicePath);

const { loadComplianceIndex, listAllComplianceStoryboards } = await import('@adcp/sdk/testing');

// scripts/prune-runtime-artifacts.cjs leaves superseded prereleases out of the
// image. Each must be refused by name, pointing at its GA line and the CDN.
const retired = [];
for (const version of manifest.published_versions) {
if (isRetiredSupersededPrerelease(version)) {
const ga = version.replace(/-(?:beta|rc)\.\d+$/, '');
assert.ok(manifest.published_versions.includes(ga), `${version} left the image before its GA ${ga} was published`);
assert.throws(() => hostedComplianceTarget(version), (error) => {
assert.ok(error instanceof SupersededComplianceTargetError, `${version} must be refused as superseded`);
for (const text of [
version,
'superseded prerelease',
`"${ga.split('.').slice(0, 2).join('.')}"`,
`https://adcontextprotocol.org/schemas/${version}/`,
`https://adcontextprotocol.org/compliance/${version}/`,
]) {
assert.ok(error.message.includes(text), `${version} refusal must mention ${text}: ${error.message}`);
}
return true;
});
retired.push(version);
continue;
}
assert.equal(resolveHostedComplianceVersion(version), version);
const target = hostedComplianceTarget(version);
assert.equal(target.version, version);
Expand All @@ -51,5 +75,6 @@ for (const version of manifest.published_versions) {
}

console.log(
`Hosted compliance runtime smoke passed for ${manifest.published_versions.length} published versions.`,
`Hosted compliance runtime smoke passed: ${manifest.published_versions.length - retired.length} published versions graded; `
+ `${retired.length} superseded prereleases refused (${retired.join(', ') || 'none'}).`,
);
Loading
Loading