#18122·astro

Server manifest `assets` array order is nondeterministic (unsorted client glob), breaking byte-identical builds

Author: ianalitisCreated Sep 25, 2026Updated Sep 25, 2026
Labelspkg: astro- P2: nice to havetriage: fix pending

Astro Info

Astro                    v7.2.4
Vite                     v8.2.2
Node                     v24.21.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/cloudflare
Integrations             none

tinyglobby 0.2.17

Describe the Bug

Two consecutive astro build runs with the same inputs and the same fixed ASTRO_KEY produce a server chunk that differs only in the order of the serialized server manifest's "assets":[...] array. Because the array is serialized as JSON into the server chunks, identical inputs do not give byte-identical output, which breaks reproducible-build checks (and any deploy artifact hashing).

createManifest() in packages/astro/src/core/build/plugins/plugin-manifest.ts seeds internals.staticFiles from an unsorted glob:

typescript
const clientStatics = new Set(
  await glob('**/*', { cwd: fileURLToPath(buildOpts.settings.config.build.client) })
);
for (const file of clientStatics) {
  internals.staticFiles.add(file);
}

tinyglobby returns directory-walk entries in completion order, not a stable sorted order, so the order varies run to run. Measured directly on a built dist/client by calling the same glob 200 times in one process:

Client directory Files Distinct orders in 200 globs
Real project dist/client (5 routes, fonts, hashed _astro assets) 27 28-61
Small 6-file tree 6 2

Order carries no meaning: manifest.assets is only consumed for membership in core/routing/match-request.js (manifest.assets.has(url.pathname)). The array is serialized at packages/astro/src/core/build/plugins/plugin-manifest.ts (assets: staticFiles.map(prefixAssetPath)).

For context, this is not caused by the client/ssr/prerender builds running concurrently: buildApp() in core/build/static-build.js awaits the prerender build, then the SSR build, then the client build sequentially. The nondeterminism comes from the glob itself.

I checked before filing: main still builds the array from Array.from(staticFiles) without sorting, and npm latest is 7.3.5.

What's the expected result?

The server manifest's assets array should be serialized in a stable order, so that two builds with identical inputs produce byte-identical output.

Link to Minimal Reproducible Example

Paste this into an empty directory, then run npm install && node repro.mjs:

bash
mkdir -p src/pages/api

cat > package.json <<'EOF'
{
  "private": true,
  "type": "module",
  "dependencies": { "astro": "7.2.4", "@astrojs/cloudflare": "14.2.3" }
}
EOF

cat > astro.config.mjs <<'EOF'
import { defineConfig } from "astro/config";
import cloudflare from "@astrojs/cloudflare";
export default defineConfig({ output: "static", adapter: cloudflare() });
EOF

cat > src/pages/index.astro <<'EOF'
<html><body><h1>Home</h1></body></html>
EOF

# One on-demand route, so a server manifest is emitted.
cat > src/pages/api/ping.ts <<'EOF'
export const prerender = false;
export const GET = () => new Response("ok");
EOF

# Sibling public directories, so the client-directory glob has walks to race.
cat > seed.mjs <<'EOF'
import { mkdirSync, writeFileSync } from "node:fs";
const dirs = ["work", "shop", "visit", "quote", "fonts", "fonts/licenses", "media"];
for (const d of dirs) {
  mkdirSync(`public/${d}`, { recursive: true });
  for (let i = 1; i <= 4; i++) writeFileSync(`public/${d}/f${i}.txt`, `${d} ${i}\n`.repeat(i * 200));
}
EOF

# Builds repeatedly with one fixed ASTRO_KEY and compares every output file.
cat > repro.mjs <<'EOF'
import { spawnSync } from "node:child_process";
import { createHash, randomBytes } from "node:crypto";
import { readFileSync, readdirSync, rmSync } from "node:fs";
import { join, relative } from "node:path";
const env = { ...process.env, ASTRO_KEY: randomBytes(32).toString("base64"), ASTRO_TELEMETRY_DISABLED: "1" };
function build() {
  rmSync("dist", { recursive: true, force: true });
  const r = spawnSync(process.execPath, ["node_modules/astro/bin/astro.mjs", "build"], { env, encoding: "utf8" });
  if (r.status !== 0) throw new Error(r.stdout + r.stderr);
  const out = {};
  for (const e of readdirSync("dist", { recursive: true, withFileTypes: true })) {
    if (!e.isFile()) continue;
    const p = join(e.parentPath, e.name);
    out[relative("dist", p)] = createHash("sha256").update(readFileSync(p)).digest("hex");
  }
  return out;
}
const first = build();
for (let n = 2; n <= 21; n++) {
  const next = build();
  const changed = Object.keys(first).filter((k) => first[k] !== next[k]);
  if (changed.length) {
    console.log(`Reproduced on build ${n}: ${changed.join(", ")}`);
    process.exit(0);
  }
}
console.log("Not reproduced in 21 builds");
EOF

node seed.mjs

It reproduced on build 2 in my run (server/chunks/default-handler_*.mjs, differ only in the "assets" array order). The reproduction is intermittent and scales with the number and sibling layout of client files, so run the loop; the dist/client glob measurement above is the deterministic proof of the cause.

Participation

  • I am willing to submit a pull request for this issue.