Skip to content

fix(platform): fail the image build when its production install fails - #4004

Merged
yannickmonney merged 1 commit into
mainfrom
fix/platform-production-install-fail-closed
Sep 30, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/platform-production-install-fail-closed

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Root cause. The platform pruner stage ran HUSKY=0 bun install --production && rm -rf /app/node_modules && mv … && rm -rf <dev tools> 2>/dev/null || true && find … || true … as one sh AND-OR list. sh groups && and || left to right, so the first unbraced || true (and every later one) also caught a failed install. The install fails because of the manifests. Stage 1 copies tools/opengrep/package.json (since 121733e, 2026-06-17), and its unfrozen bun install writes a lockfile that includes that workspace. The pruner never copied that manifest, so --production, which freezes the lockfile, saw one workspace fewer and refused with lockfile had changes, but lockfile is frozen. The stage still passed. The swap and the explicit rm-list were skipped as well, so the runtime image shipped the builder's full dev node_modules (typescript, vitest, storybook, vite, rolldown, playwright-core, tsx, …).

Fix. Same Dockerfiles and pipeline, smallest change:

  • services/platform/Dockerfile, pruner: copy tools/opengrep/package.json as stage 1 does. Wrap only the optional cleanup in { …; }, so its || trues can no longer reach the install or the swap.

  • Same defect, two more sites:

    • In the runner stage, the unbraced groupadd … || true / useradd … || true also swallowed a failed apt-get install or SOPS download. Now braced.
    • In services/sandbox-runtime/Dockerfile, the trailing rm -f …docker.service 2>/dev/null || true swallowed a failed docker-ce install. Now braced.
    • Not affected: services/db/Dockerfile runs set -eux; cmd || true; one command at a time, and the || echo in services/web/Dockerfile sits in a RUN that holds only its best-effort command.
  • New guard, services/platform/tests/guards/dockerfile-fail-closed.guard.test.ts. It runs each of these RUNs' own text under /bin/sh, as BuildKit's shell form does, with recording doubles on a private PATH:

    • a failed install, swap, apt step or download must fail the RUN;
    • a failed cleanup, groupadd/useradd or unit strip must not;
    • the pruner's manifest list must match stage 1's.

    It reads services/sandbox-runtime/Dockerfile, so that file is added to the platform test turbo inputs and to the turbo-inputs guard's list.

Unchanged: the image's Bun pin (1.3.12), frozen-lockfile validation (--production still freezes the lockfile), workspace dependencies, the architecture matrix and the cleanup list itself.

How I verified it

Toolchain.

  • bun 1.3.12+700fc117a, extracted from oven/bun:1.3.12@sha256:8956c7667fa1… (the digest the hosted build resolved; binary sha256 1ac6637e4894…).
  • node v22.21.1, from node:22.21.1-bookworm-slim@sha256:25b3eb23a005….
  • Host: Debian 12 (dash 0.5.12, glibc 2.36).

This sandbox has no Docker daemon, so I replayed the stages outside BuildKit. The replay parses stage 1's COPY list and the pruner's COPY list and RUN text from the Dockerfile at each revision. It then runs the RUN verbatim through /bin/sh -c, with /app and /tmp remapped under a scratch root.

Replay at fc54249 (bun 1.3.12) Result
pruner, main's Dockerfile (4d14c55) error: lockfile had changes, but lockfile is frozen, RUN exit 0: the same output as hosted job 109868513524, step #73
pruner, grouping fix only same error, RUN exit 1 (fails closed)
pruner, this PR 1689 packages installed, RUN exit 0
lockfile probe against stage 1's lock, the pruner's manifest set drops exactly tools/opengrep, a manifest-only workspace; that is the whole divergence

Runtime contents.

  • The production tree is a strict subset of what ships today: 0 packages added and 378 dev-only name@version removed (2063 → 1607 entries, 1008 → 707 MB).
  • The api/worker import closure resolves with 0 unresolved imports: Node 22.21.1 with backend/node-loader.mjs walks 957 first-party files and reaches 41 packages.
  • So does the web closure: Bun 1.3.12 from server.ts walks 72 files and reaches 12 packages.
  • A negative control that hides hono reports 88 unresolved imports on the Node side and 4 on the Bun side.
  • Across the transitive runtime graph, every dependent loads the same name@version as today. The only exceptions are type-only @types/* packages, which the rm-list deletes by design.

Tests and checks.

  • The new guard passes 15/15 on this head. On main's Dockerfiles 9 cases fail: every "fails the build when…" case and the manifest pin. On the grouping-only variant only the manifest pin fails.
  • The dockerfile-env-parity, turbo-inputs, privilege-drop and new guard files together pass 57/57.
  • The tools/cli compose-parity, deployment-ci and platform-docs suites pass 125/125.
  • oxfmt, oxlint --type-aware on the changed files and a scoped tsc are clean. The workspace-wide gates are left to CI.

Hosted proof from this PR's run. CI builds merge commit 5ec0d41b, whose tree fc2d5c01… is identical to head fc54249a9.

  • Build platform, pruner step #79: bun install v1.3.12 (700fc117) → 1689 packages installed [7.43s] → DONE, with no error:. Image receipt: sha256:2bdc2d52eecb1b99499f2f3213c457573bf219a1d631f5faafe6ab27397f57cc ↔ 5ec0d41b.
  • Validate images (pulled by that digest): all passed. The platform image is 1599 MB; the PR fix(platform): preserve newer cloud import picker selections #3995 image, which carried the dev tree, was 1859 MB.
  • Smoke test (same digest): 29/29. Scan platform and Scan sandbox-runtime: pass.
  • Build sandbox-runtime: the braced engine-install RUN executed (Setting up docker-ce … DONE 15.6s).
  • Published images compared, layers streamed and digest-verified:
    • the before image (tale-platform:sha-4d14c55d5) has a node_modules inventory identical to the local base replay: 2063 entries;
    • this PR's image has one identical to the local fixed replay: 1607 entries, including typescript, vitest, storybook, playwright-core, tsx and @types gone.
  • Runtime import resolution against this PR's shipped /app: 0 unresolved imports on the Node side (957 files) and on the Bun side (72 files).

Open items

  • The production install runs the root prepare script, which uses bunx to fetch husky@latest: husky is not installed in production, and HUSKY=0 makes the call a no-op. This is pre-existing and was hidden while the install failed. A follow-up could pin husky there or skip lifecycle scripts.
  • Stage 1's bun install stays unfrozen by design. It installs 14 of the 23 workspaces and re-resolves the committed lock for that subset, dropping 9 workspaces and re-hoisting entities. The committed lock itself is checked by CI's bun install --frozen-lockfile under Bun 1.4.2.

Closes #3996

The pruner's RUN chained the production install, the swap into
/app/node_modules and the optional cleanup into one sh AND-OR list.
sh groups && and || left to right, so the cleanup's first unbraced
`|| true` also caught a failed install: Bun 1.3.12 refused the
lockfile ("lockfile had changes, but lockfile is frozen"), the stage
still succeeded, and the image shipped the builder's full dev
node_modules (typescript, vitest, storybook, vite and the rest).

The refusal came from the manifests. Stage 1 installs from
tools/opengrep's manifest and writes its lockfile with that workspace,
but the pruner never copied it, so the frozen production install saw
one workspace fewer. The pruner now copies it, the cleanup keeps its
`|| true`s inside braces, and a guard runs the RUN's own text under
/bin/sh with recording doubles (a failed install or swap fails the
RUN, a failed cleanup does not) and pins the pruner's manifests to
stage 1's.

The same unbraced `|| true` also swallowed a failed package install
or SOPS download in the runner stage and a failed engine install in
the sandbox-runtime image; both are braced and guarded the same way.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent/root review accepts the five-file correction at fc54249a97868b23778500c626a1e0cabce34db7. Root read the full patch and the final source-bound review. The missing tools/opengrep manifest is restored; optional cleanup/user creation/unit removal can no longer swallow required install or swap failures. Independent actual /bin/sh controls pass 34/34, including ten required-failure cases that the old source incorrectly masked.

All six normal workflows are terminal-success at this head. The actual hosted merge 5ec0d41b has the same complete tree. Platform Unit, Typecheck and Browser executed as cache misses; the two pre-test APT/Chromium timeouts remain preserved and each received exactly one targeted normal retry. Final rollup: 54 success, 12 event/scope skips, Trivy neutral. No failed/cancelled check is being waived.

The normal shipping platform pruner actually executed Bun 1.3.12, installed 1,689 packages and completed without an install error; required platform-runner and sandbox engine stages also executed. The platform digest sha256:2bdc2d52eecb1b99499f2f3213c457573bf219a1d631f5faafe6ab27397f57cc and sandbox digest sha256:fda183ec70c846fe78e71daea2b5b4f1fb9a4d16a4f1463916e39b4cb526d4ce bind to that checkout and downstream pulls: smoke 29/29, image validation 40/40 and sandbox runtime 89/89. Selected cleanup targets are absent from the actual platform SBOM.

Limits remain explicit: workspace-deps was cached, shared UI browser results were replayed, scans completed/SARIF uploaded but their informational configuration is not a zero-vulnerability gate, and the existing unfrozen builder/prepare lifecycle is not a hermetic-install claim. The author's complete import-closure/package-delta claims are separate from this independently observed proof. Root also checked the two already accepted subsequent main commits; none touches this PR's five files. A fresh candidate/publication/deployment is still required.

Final independent report SHA256: 538fd86925515b53740c9351237482f74bea503265d3e32ee9554187c103579f; evidence index: acf3d24fc51de3f014daac7156d395b5e0913df87ab57d9aba9c657a68204b0e (731 retained files). Proceeding only through normal expected-head squash merge.

@yannickmonney
yannickmonney merged commit 778fce6 into main Sep 30, 2026
98 of 100 checks passed
@yannickmonney
yannickmonney deleted the fix/platform-production-install-fail-closed branch September 30, 2026 15:07
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.

Bug: platform image succeeds after production dependency install fails

1 participant