Skip to content

fix(bundler): force-include every OTel devDep + CI smoke-test the packed tarball - #3683

Merged
tlgimenes merged 6 commits into
mainfrom
deco/iron-vale
Jun 4, 2026
Merged

tlgimenes merged 6 commits into
mainfrom
deco/iron-vale

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Production fix. decocms 2.393.0 published a dist/server/cli.js that does from "@opentelemetry/sdk-metrics" (and other OTel externals) without shipping the package in dist/server/node_modules/. Every consumer (npm install + Docker image) crashes at startup:
    Cannot find module '@opentelemetry/sdk-metrics' from
    /app/apps/mesh/node_modules/decocms/dist/server/cli.js
    
  • Root cause. bun build --target bun auto-externalizes every node_modules/ import. The bundler relies on @vercel/nft to trace + copy the package files. OTel v2 packages use conditional exports + lazy requires that nft can't follow — so it silently drops the package, and the bundle then crashes at runtime because the externalized from "..." resolves to nothing. The pre-existing ALWAYS_INCLUDE entry for @opentelemetry/resources was already the manual escape hatch for one instance of this; this PR extends it to every OTel package the runtime imports.
  • Static regression guard (fix(bundler): … commit). Adds verifyBundlesShipExternals() to bundle-server-script.ts. Fails the build if (a) any ALWAYS_INCLUDE entry didn't make it to disk, or (b) any external @opentelemetry/* import in cli.js / server.js / migrate.js has no shipped package. Scoped to @opentelemetry/* via STRICT_SHIPPING_PREFIXES so it doesn't false-positive on consumer-installed deps (pg, react, node-fetch, …) that the consumer's install resolves via decocms's runtime dependencies tree.
  • Publish-time backstop (ci(release-mesh): … commit). After npm pack, install the just-packed tarball in a scratch dir (bun add file://…/decocms-*.tgz) and run bun cli.js --version. Because bun emits ESM from "pkg" for externals, top-level external resolution is eager — a missing one crashes before --version prints. Runs before artifact upload, so publish-npm + build-docker never see a broken artifact. Also catches publish-time failure modes the static check can't (files-field filtering, prepublishOnly side-effects, signing weirdness).

Evidence the fix maps to the bug

Diffed published tarballs (npm pack [email protected] / 2.393.0):

OTel package 2.392.0 (worked) 2.393.0 (broken)
@opentelemetry/sdk-metrics shipped missing ← exact prod error
other OTel externals shipped shipped

Ran the new verifyBundlesShipExternals logic against the broken 2.393.0 cli.js: it flags @opentelemetry/sdk-metrics and only that — no false positives.

Out of scope (your hands)

  • 2.393.0 npm latest tag rollback + Docker image repoint require registry writes you'll want to do consciously:
    • npm dist-tag add [email protected] latest
    • Optional: npm deprecate [email protected] "Missing @opentelemetry/sdk-metrics — use 2.392.0 until 2.394.0 ships"
    • Repoint the deco-apps-cd / ArgoCD image tag away from mesh:2.393.0

Test plan

  • Pull this branch locally, run bun run --cwd=apps/mesh build:server
  • Verify the build prints ✅ Bundle externalization OK — ALWAYS_INCLUDE + every @opentelemetry/* import is shipped.
  • Verify apps/mesh/dist/server/node_modules/@opentelemetry/sdk-metrics/package.json exists after build
  • (Optional) cd apps/mesh && npm pack && SCRATCH=$(mktemp -d) && (cd "$SCRATCH" && printf '{"name":"smoke","version":"0.0.0","private":true}\n' > package.json && bun add "$OLDPWD"/decocms-*.tgz && bun ./node_modules/decocms/dist/server/cli.js --version) — should print a version, not "Cannot find module"
  • CI's new Smoke-test the packed tarball step passes
  • After merge: rollback latest npm tag to 2.392.0 and repoint the Docker GitOps tag

🤖 Generated with Claude Code

decocms 2.393.0 shipped with @opentelemetry/sdk-metrics missing from
dist/server/node_modules/, so every consumer crashed at startup with:

  Cannot find module '@opentelemetry/sdk-metrics' from
  /app/apps/mesh/node_modules/decocms/dist/server/cli.js

Root cause: `bun build --target bun` auto-externalizes every node_modules
import, and the bundler relies on @vercel/nft to trace + copy the package
files into dist/server/node_modules/. OTel v2 packages use conditional
exports + lazy requires that nft can't follow statically. When nft drops
one, the bundle still emits `from "@opentelemetry/..."` for it, and the
published cli.js can't resolve it at startup.

The existing ALWAYS_INCLUDE entry for @opentelemetry/resources was already
the manual escape hatch for one such failure. Extending it to every OTel
package the runtime imports closes the same hole for the rest.

Adds verifyBundlesShipExternals() that runs at the end of the build and
fails it if any ALWAYS_INCLUDE entry didn't make it to disk, or if any
external @opentelemetry/* import in the bundles has no shipped package.
Scoped to @opentelemetry/* via STRICT_SHIPPING_PREFIXES so it doesn't
false-positive on consumer-installed deps like pg / react / node-fetch
that resolve via decocms's runtime dependencies tree.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

Backstop for the decocms 2.393.0 incident — install the just-packed
tarball into a scratch dir exactly the way a consumer would
(`bun add decocms@<ver>`), then `bun cli.js --version`. Because bun emits
ESM `from "pkg"` for externals, loading cli.js eagerly resolves every
top-level external before --version ever prints — a missing one (e.g.
nft dropped an OTel package) crashes here with "Cannot find module …".

The static-side defense in apps/mesh/scripts/bundle-server-script.ts
(verifyBundlesShipExternals) catches the same failure at build time
without npm publish in the picture. This step is the publish-time
backstop that also catches failure modes the static check can't
(files-field stripping, prepublishOnly side-effects, signing weirdness).

Runs after `npm pack`, before `upload-artifact` — a failure stops the
mesh-package artifact from being produced, so publish-npm and
build-docker never see the bad bytes.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@tlgimenes tlgimenes changed the title fix(bundler): force-include every OTel devDep so nft doesn't drop them fix(bundler): force-include every OTel devDep + CI smoke-test the packed tarball Jun 4, 2026
tlgimenes and others added 4 commits June 3, 2026 21:17
…fier to direct-resolvable strict deps

The first pass at the OTel ship-everything fix listed transitive-only
packages (context-async-hooks, otlp-exporter-base, otlp-transformer,
semantic-conventions) in ALWAYS_INCLUDE. Bun's isolated install puts those
under node_modules/.bun/<pkg>@<ver>/... and only surfaces direct deps at
apps/mesh/node_modules/, so Bun.resolveSync() — which is how the bundler
turns ALWAYS_INCLUDE entries into nft entry points — couldn't find them
and failed the build:

  ❌ Failed to resolve @opentelemetry/context-async-hooks: error: Cannot
     find module '@opentelemetry/context-async-hooks' from '…/apps/mesh'

Direct deps only. Transitives get picked up by nft as it walks from the
direct entries — verified by inspecting the 2.393.0 tarball, which
shipped context-async-hooks and otlp-exporter-base despite neither being
direct deps. The runtime-resolution check (next paragraph) catches any
@opentelemetry/* package the bundle references but doesn't ship, so
demoting an entry from ALWAYS_INCLUDE to transitive isn't a silent
regression vector.

While here, narrow verifyBundlesShipExternals():

  - Drop the "every ALWAYS_INCLUDE entry must be shipped" invariant.
    React is in ALWAYS_INCLUDE as an nft entry point but it's also a
    runtime `dependency`, so the consumer install brings it in and the
    bundler never copies it. The invariant was false for the existing
    code, not just for the entries I added.

  - Exempt runtime `dependencies` from the strict @opentelemetry/* check.
    @opentelemetry/core is in the runtime dependencies list, so even if
    it's somehow absent from dist/server/node_modules/, the consumer's
    install resolves it.

Locally builds clean now: bun run --cwd=apps/mesh build:server prints
"✅ Bundle externalization OK — every @opentelemetry/* import resolves."
and dist/server/node_modules/@opentelemetry/ contains sdk-metrics,
sdk-node, exporter-prometheus, instrumentation-runtime-node, plus the
transitively-traced otlp-transformer and semantic-conventions.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Two follow-up fixes from the first CI run on this PR:

  1. release-mesh.yaml smoke test referenced cli.js by its raw bundle
     path (`bun ./node_modules/decocms/dist/server/cli.js --version`),
     which tripped knip's "unlisted binaries" check. Use the `deco` bin
     name (from decocms's `bin` field in package.json) so knip can
     resolve the reference: `./node_modules/.bin/deco --version`. The
     check still runs against the same compiled file — the bin is just
     a renamed entry point.

  2. apps/mesh/src/tools/eventbus/schema.ts had a stray double blank
     line introduced by an earlier commit on this branch
     (e6d6b4d "fix(event-bus): remove unused SubscriptionEntity
     export"). Local `bun run fmt` caught it; commit it so format:check
     in CI passes.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
…riendly)

The previous attempt invoked the deco bin straight from the workflow YAML
(`./node_modules/.bin/deco --version`), which knip's "unlisted binaries"
check flagged because knip scans workflow `run:` blocks for bare binary
names and doesn't know `deco` comes from the package we're publishing.

Per the repo's "never silence knip" policy, hide the bin behind a TS
shim — same pattern as the existing scripts/smoke-link.ts. The shim
still runs the bin, just via `bun run scripts/smoke-tarball.ts`, which
knip is happy with. Catches the #2.393.0 failure exactly the
same way: ESM bundle's top-level imports execute eagerly on load, so a
missing external still crashes before --version prints.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@tlgimenes
tlgimenes merged commit 6144b41 into main Jun 4, 2026
17 checks passed
@tlgimenes
tlgimenes deleted the deco/iron-vale branch June 4, 2026 00:41
decocms Bot pushed a commit that referenced this pull request Jun 4, 2026
PR: #3683 fix(bundler): force-include every OTel devDep + CI smoke-test the packed tarball
Bump type: patch

- decocms (apps/mesh/package.json): 2.393.4 -> 2.393.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant