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
31 changes: 31 additions & 0 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,37 @@ Never overwrite a version, rebuild from another checkout, move a tag, or treat
an npm error as proof of absence. A conflict requires maintainer investigation
and a separately reviewed release decision.

npm accepts uploads before its
[publish-time malware scan](https://github.blog/changelog/2026-07-28-npm-publish-time-malware-scanning-and-dual-use-metadata/)
makes the version available. This normally takes about five minutes and can take

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Scan-delay figures cite a changelog post whose contents cannot be verified from the repository (nit)

The new paragraph asserts npm's scan "normally takes about five minutes and can take 15 minutes or longer", citing a github.blog changelog URL, and these figures calibrate the chosen 20-minute deadline and the recovery expectations. The link and the numbers entered the documentation from the untrusted PR description; if the cited post does not actually state those timings (or the delay is not attributable to malware scanning), the docs overclaim npm's documented behavior and operators calibrate waiting/recovery against unsupported figures.

Evidence and proof gap: I have no network access in this review, so I could not confirm the URL resolves or supports the quoted timings; I could only check internal consistency — the 2026-07-28 post date is chronologically plausible next to the repository's 2026-11-dated records (e.g., docs/BOOTSTRAP.md). This is a verify-manually nit, not a demonstrated factual error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official GitHub npm changelog documents typical five-minute scanning delays and possible delays of fifteen minutes or longer at peak load. The handbook now describes those as observations with no service-time guarantee. Official changelog

15 minutes or longer; these are typical timings, not service guarantees.
After one accepted upload, publication polls only exact
version reads, at most 41 times, normally 30 seconds apart, with a
20-minute monotonic elapsed-time budget. The final scheduled sleep is followed
by one bounded lookup, whose metadata and tarball verification can take up to
60 additional seconds.
Only this post-upload confirmation can wait through transport failures or HTTP
408, 429, 500, 502, 503 and 504. These remain unconfirmed states, never evidence
of absence or permission for another upload. A valid `Retry-After` can lengthen
the normal delay within the remaining budget; if it cannot fit, confirmation
stops without polling early or extending the deadline. Authentication failures,
malformed metadata and conflicting metadata or bytes still fail immediately.
Ordinary preflight, recovery, the last pre-write lookup and the separate final
byte verification remain strict. Success requires matching metadata and verified
tarball bytes; exhausting the confirmation budget is not success. The
30-minute job timeout remains the outer bound and can interrupt publication or
byte verification; it does not guarantee enough time for every worst-case step.
An unavailable version at the
deadline is not proof that the upload failed: check npm scanning or review status
and preserve the original artifact rather than uploading again blindly. Once
the exact version is visible, download the original immutable workflow artifact
by its artifact ID into a fresh prepared directory. Run the read-only `preflight`
command above with `--prepared-dir` pointing to those downloaded files and the
original independent manifest digest, tag, and commit. The artifact ID selects
the workflow download; it is not a `preflight` argument. If it matches, rerun
only the failed jobs in the original Publish run; publication skips the matching
existing version and the separate registry/provenance verification must pass.

## Registry verification and availability

After publication, the separate unprivileged job runs strict verification. The
Expand Down
139 changes: 113 additions & 26 deletions scripts/release-registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "node:fs/promises";
import { tmpdir } from "node:os";
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
import { performance } from "node:perf_hooks";
import { RELEASE_PACKAGES, RELEASE_REPOSITORY } from "./release-contract.mjs";
import {
validatePreparedManifest,
Expand All @@ -22,6 +23,14 @@ export const RELEASE_WORKFLOW = ".github/workflows/publish.yml";
const registry = "https://registry.npmjs.org/";
const provenanceType = "https://slsa.dev/provenance/v1";
const temporaryPrefix = "agent-access-registry-";
const confirmationBudgetMs = 20 * 60_000;

class RegistryConfirmationRetry extends Error {
constructor(retryAfterMs = 0) {
super("accepted upload registry confirmation is temporarily unavailable");
this.retryAfterMs = retryAfterMs;
}
}

function fail(message) {
// Never surface native command output, registry response bodies, or credentials.
Expand Down Expand Up @@ -55,63 +64,117 @@ function tarballUrl(record) {
return `${registry}${record.name}/-/${record.name.split("/")[1]}-${record.version}.tgz`;
}

async function responseBytes(response, maximum) {
function discardBody(body) {
try {
// Cleanup cannot replace a known status or hold the confirmation deadline.
void Promise.resolve(body?.cancel()).catch(() => {});
} catch {
// Preserve the verification result if cancellation throws synchronously.
}
}

async function responseBytes(response, maximum, confirmation = false) {
const length = response.headers?.get("content-length");
if (
length !== null &&
length !== undefined &&
(!/^\d+$/u.test(length) || Number(length) > maximum)
) {
await response.body?.cancel();
discardBody(response.body);
fail("registry response exceeded its release verification limit");
}
const chunks = [];
let size = 0;
if (response.body === null || response.body === undefined)
return Buffer.alloc(0);
for await (const chunk of response.body) {
size += chunk.length;
if (size > maximum) {
fail("registry response exceeded its release verification limit");
const reader = response.body.getReader();
try {
for (;;) {
let item;
try {
item = await reader.read();
} catch (error) {
if (confirmation) throw new RegistryConfirmationRetry();
throw error;
}
if (item.done) break;
size += item.value.length;
if (size > maximum) {
fail("registry response exceeded its release verification limit");
}
chunks.push(Buffer.from(item.value));
}
chunks.push(Buffer.from(chunk));
} finally {
discardBody(reader);
reader.releaseLock();
}
return Buffer.concat(chunks, size);
}

async function request(url, fetch) {
async function request(url, fetch, confirmation = false) {
try {
return await fetch(url, {
redirect: "error",
signal: AbortSignal.timeout(30_000),
headers: { accept: "application/json" },
});
} catch {
if (confirmation) throw new RegistryConfirmationRetry();
fail("registry lookup failed; package availability is unknown");
}
}

async function registryRecord(record, fetch) {
async function retryTransientConfirmation(response, confirmation) {
if (
!confirmation ||
![408, 429, 500, 502, 503, 504].includes(response.status)
)
return;
const value = response.headers?.get("retry-after");
let delay = 0;
if (value !== null && value !== undefined) {
if (/^\d+$/u.test(value)) {
delay = Number(value) * 1000;
} else {
const serverTime = Date.parse(response.headers?.get("date") ?? "");
delay =
Date.parse(value) -
(Number.isFinite(serverTime) ? serverTime : Date.now());
}
}
const retryAfterMs =
delay > 0 ? Math.min(delay, confirmationBudgetMs + 1) : 0;
discardBody(response.body);
throw new RegistryConfirmationRetry(retryAfterMs);
}

async function registryRecord(record, fetch, confirmation = false) {
const response = await request(
`${registry}${encodeURIComponent(record.name)}/${record.version}`,
fetch,
confirmation,
);
// Authentication errors, throttling, server errors, redirects, and malformed
// responses are unknown states. Only this exact response establishes absence.
// Only the accepted-upload confirmation caller may wait through transient
// unknown states. Ordinary preflight and pre-write checks remain strict.
await retryTransientConfirmation(response, confirmation);
// Only this exact response establishes absence, regardless of caller mode.
if (response.status === 404) {
await response.body?.cancel();
discardBody(response.body);
return null;
}
if (response.status !== 200) {
await response.body?.cancel();
discardBody(response.body);
fail("registry lookup failed; package availability is unknown");
}
let metadata;
try {
metadata = JSON.parse(
(await responseBytes(response, 2 * 1024 * 1024)).toString("utf8"),
(await responseBytes(response, 2 * 1024 * 1024, confirmation)).toString(
"utf8",
),
);
} catch {
} catch (error) {
if (error instanceof RegistryConfirmationRetry) throw error;
fail("registry package metadata verification failed");
}
if (
Expand All @@ -130,15 +193,17 @@ async function registryRecord(record, fetch) {
) {
fail("registry version conflicts with the prepared release");
}
const tarball = await request(metadata.dist.tarball, fetch);
const tarball = await request(metadata.dist.tarball, fetch, confirmation);
await retryTransientConfirmation(tarball, confirmation);
if (tarball.status !== 200) {
await tarball.body?.cancel();
discardBody(tarball.body);
fail("registry tarball verification failed");
}
let bytes;
try {
bytes = await responseBytes(tarball, record.size);
} catch {
bytes = await responseBytes(tarball, record.size, confirmation);
} catch (error) {
if (error instanceof RegistryConfirmationRetry) throw error;
fail("registry tarball verification failed");
}
if (
Expand Down Expand Up @@ -597,18 +662,40 @@ async function registryConsumer(verified, options, seams) {
}

async function confirmRegistry(record, seams) {
// npm accepts uploads before its publish-time malware scan makes them public.
// Bound both elapsed time and physical lookups; never publish again while waiting.
const now = seams.now ?? (() => performance.now());
const deadline = now() + confirmationBudgetMs;
const sleep =
seams.sleep ??
((milliseconds) =>
new Promise((resolve_) => setTimeout(resolve_, milliseconds)));
for (let attempt = 0; attempt < 6; attempt += 1) {
if (
(await registryRecord(record, seams.fetch ?? globalThis.fetch)) !== null
)
return;
if (attempt < 5) await sleep(2 ** attempt * 1000);
for (let attempt = 0; attempt < 41; attempt += 1) {
// A sleep scheduled within the budget still gets its final bounded lookup,
// including when the timer resumes at or just after the deadline.
let retryAfterMs = 0;
try {
if (
(await registryRecord(
record,
seams.fetch ?? globalThis.fetch,
true,
)) !== null
)
return;
} catch (error) {
if (!(error instanceof RegistryConfirmationRetry)) throw error;
retryAfterMs = error.retryAfterMs;
}
const remaining = deadline - now();
if (attempt === 40 || remaining <= 0) break;
// Never extend the deadline or retry before a server's requested delay.
if (retryAfterMs > remaining) break;
await sleep(Math.min(Math.max(30_000, retryAfterMs), remaining));
}
fail("published registry version was not visible after bounded verification");
fail(
"npm accepted the upload but the exact registry version could not be confirmed; preserve the artifact and check npm scanning or review status before retrying",
);
}

async function verifyPublishedBytes(verified, seams) {
Expand Down
Loading
Loading