Skip to content

fix(base-image): make the Claude Code native binary land on arm64, and fail the build when it does not (Abilityai/lilu#9) - #2537

Merged
vybe merged 1 commit into
devfrom
promote/9-arm64-base-image
Sep 7, 2026
Merged

vybe merged 1 commit into
devfrom
promote/9-arm64-base-image

Conversation

@vybe

@vybe vybe commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

What changed

docker/base-image/Dockerfile — the Claude Code install layer. The arm64 base image was shipping a 500-byte placeholder instead of the native claude binary, so every agent created on it answered Error: claude native binary not installed. and was dead on arrival.

  • Re-install @anthropic-ai/claude-code-<platform> as a direct install target rather than relying on it being resolved as an optional dependency.
  • Fail the build loudly: an unconditional claude --version now terminates the install layer, so an image that cannot run Claude Code can no longer be produced at all.
  • 12 unit tests (tests/unit/test_lilu20_claude_install_layer.py, registered in tests/registry.json).

Root cause — the original hypothesis was wrong, and that matters

The lab's hypothesis was an npm flag (--ignore-scripts / --omit=optional). No flag was involved. npm exits 0 when an optional dependency fails to unpack, and install.cjs then returns 0 over the stub it finds — so the failure is silent by construction on any host where the 214 MB native package does not unpack cleanly. Reproduced byte-for-byte on x86 by starving the unpack, which is why the fix is not arm64-specific: the same silent-success path exists on every platform, arm64 just hits it.

Evidence from a live instance

Deployed and verified on the Lilu lab instance (NVIDIA DGX Spark, aarch64):

Check Result
GET /api/version 0.9.5-rc2+g04dc3ca3, git_commit 04dc3ca3a725a38913c09870e0f332a3d156c5db, build_date 2026-09-06T07:32:37Z, /health 200
Base image trinity-agent-base:0.9.5-rc2+g04dc3ca3
claude --version inside an agent built on the new base 2.1.263 (Claude Code)
claude.exe 215 211 432 bytes, ELF64 LSB, e_machine 0x00b7 (183 = AArch64) — the placeholder was 500 bytes
uname -m aarch64
Agent health runtime_available: true, claude_available: true, aggregate healthy, restart_count: 0
End-to-end agentic execution on the new base execution nI9Gv9cqYQj2Pehy61iUog — success in 8.9 s, $0.0917, 23 327 ctx; the agent authenticated, ran a task and returned a result

No rollback was needed; the rebuild survived its own health check. Both probe agents were torn down after the reads.

Not observed

The /update --force deploy log excerpt showing the new build-time verification step passing is lost — the ops execution was killed by a turn limit before it wrote one. The verification layer is inferred to have passed (an image carrying that tag cannot be produced otherwise), not observed. Recording it here rather than claiming it.

Adjacent upstream bugs found and deliberately NOT fixed here

Kept out of scope to keep this diff reviewable — each is real and reproducible:

  • docker/base-image/Dockerfile:42 hardcodes the Go tarball to linux-amd64, so every arm64 base image has been shipping an amd64 Go.
  • The same silent-optional-dependency exposure exists for @google/gemini-cli (line 81) and @openai/codex (line 88).

Provenance

Fork Abilityai/lilu-trinity:lilu @ 04dc3ca3 (authored by lilu-engineer), cherry-picked onto Abilityai/trinity:dev @ a5ac3cf3.

Refs Abilityai/lilu#9 · Abilityai/lilu#20 (closed on this evidence) · experiment ledger experiments/9-arm64-base-image.md

Product Quality Bar

  • sensible defaults — the build now fails closed instead of shipping a broken image
  • honest state — claude --version is the assertion, at build time
  • graceful degradation — n/a; this deliberately removes a silent-degradation path
  • named validation — the failing layer names what is missing

…d fail the build when it does not

Abilityai/lilu#20 (base-image half of #9; the create_agent runtime guard is #19
and is NOT in this commit).

On the arm64 DGX the claude-code install layer exited 0 while leaving
`bin/claude.exe` as the 500-byte, shebang-less placeholder instead of the
~214 MB native ELF. The image was tagged `latest`, and the damage only surfaced
at an agent's first turn: execve() on a shebang-less text file is ENOEXEC, and
`chat_with_agent` answers 503. Every agent created against that tag was born
unusable.

Root cause — it was NOT a flag
------------------------------
The stub's error text names `--ignore-scripts` / `--omit=optional`, which reads
like one of those was passed. It was not, and no inherited npm config was
involved either: at that point in the build nothing has been COPYed into the
image, no NPM_CONFIG_* ENV is set, and `docker build` does not inherit host
environment. Reading `install.cjs` shows it prints that same text on ANY
resolution failure — "This happens with --omit=optional *or when the download
failed*".

The suppression is npm's optional-dependency semantics itself. Two exit-0
swallows stack up: npm downgrades any failure to fetch or unpack an OPTIONAL
dependency to a warning, and `install.cjs` then `return`s (exit 0) when it
cannot resolve the native package, leaving the placeholder in place. The
native package is the largest single download in the whole build, so it is
also the likeliest one to fail — and the likeliest to hit ENOSPC unpacking.

How the optional dep is made to resolve
---------------------------------------
Three defences, all in the one RUN layer:

  a. `--include=optional --no-ignore-scripts` are now passed explicitly. Neither
     was being overridden on the DGX, but npm config precedence puts CLI flags
     above every npmrc and env source, so stating them makes that true for any
     future base image or build host as well. `--foreground-scripts` puts the
     postinstall's stderr in the build log instead of buffering it away.
  b. If `claude` still does not run, the platform-native package is re-installed
     as a DIRECT, non-optional target. This is the actual arm64 fix: npm only
     swallows the failure because the dependency is optional; asking for the
     same package by name makes the identical failure fatal. The platform key is
     computed with the same rule `install.cjs` uses (platform + arch + musl
     detection via process.report), so the layer stays arch-neutral — it works
     on arm64 and x64, glibc and musl, with no arch literal in the file — and
     `install.cjs` is re-run to place the binary.

What the verification step checks
---------------------------------
  c. A bare, unconditional `claude --version` is the layer's terminal command.
     The stub exits non-zero (ENOEXEC → 126); the real binary prints a version.
     It stays in THIS RUN because a separate layer would still cache and publish
     the broken install, and it is unconditional rather than `if arm64` because
     npm's silent-optional behaviour is not arch-specific — arm64 is only where
     it happened to bite.

Demonstration that a broken install now fails the build
-------------------------------------------------------
Reproduced on x86_64 with npm 10.8.2 by starving the unpack of disk (/tmp had
184 MB free; the native package needs 214 MB), i.e. with NO suppressing flag:

  $ npm install --prefix /tmp/p -g --include=optional --no-ignore-scripts \
        @anthropic-ai/[email protected]
  npm warn tar TAR_ENTRY_ERROR ENOSPC: no space left on device, write
  $ echo $?                              -> 0     # npm is happy
  $ stat -c %s .../bin/claude.exe        -> 500   # the stub, exactly as on the DGX
  $ /tmp/p/bin/claude --version; echo $? -> 126   # (c): `set -eu` aborts the layer
  $ npm install --prefix /tmp/p -g @anthropic-ai/[email protected]
  $ echo $?                              -> 1     # (b): direct target => fatal
  # and on a roomy disk the same recovery repairs an already-stubbed install:
  $ node .../install.cjs && /tmp/p/bin/claude --version
  2.1.252 (Claude Code)

Also measured, and the reason (a) names both flags rather than trusting either:
`--omit=optional` alone does NOT reproduce the stub (npm still installs the
optional dep of a directly-installed root), while `--ignore-scripts` does.

Tests
-----
tests/unit/test_lilu20_claude_install_layer.py — 12 static assertions over the
three defences, including executing the layer's own node platform-key
expression so a typo cannot make it silently empty. Mutation-checked: reverting
to the pre-fix one-liner fails 9, masking the check as `$(claude --version)`
fails 1, dropping the flags fails 1.

Noted, deliberately not changed (out of scope)
----------------------------------------------
`@google/gemini-cli` and `@openai/codex` resolve their binaries through the same
optional-dependency mechanism and carry the same silent-failure risk; the Go
tarball is hardcoded to linux-amd64. All three are recorded in the Dockerfile
comment. Verification on the DGX itself (`/redeploy`, `docker exec agent-lilu
claude --version`) is Lilu's — no Docker daemon is reachable from this
workspace, so the build was not run here.
@vybe
vybe enabled auto-merge (squash) September 6, 2026 10:43

@trinity-ability trinity-ability left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Validated via /validate-pr: targets dev, 3 files (base-image Dockerfile install layer, registry entry, 12 static unit tests). The Claude Code layer now passes --include=optional --no-ignore-scripts explicitly, re-installs the platform-native package as a direct target when the optional dep did not land, and ends the same RUN with a bare unconditional claude --version so a stub can never be tagged. Arch-neutral; verified live on the arm64 lab instance per the PR body. Tests pass locally (12 passed). Security greps clean; Dockerfile change is the fix itself. No closing keyword — the lilu#9 status needs a manual bump after merge.

@vybe
vybe merged commit 88056c3 into dev Sep 7, 2026
23 checks passed
@vybe
vybe deleted the promote/9-arm64-base-image branch September 7, 2026 09:22
trinity-ability pushed a commit that referenced this pull request Oct 22, 2026
…layer version assertion, pre-seed its provider packages, startup block + guardrail path deny; Go tarball per arch (#2981, checkpoint F)

Dockerfile
- OpenCode: ARG OPENCODE_VERSION=1.18.32; `uname -m` -> x64/arm64 (unmapped
  machine exits 1); `opencode-ai` and `opencode-linux-${ocarch}` named
  explicitly (optional-dep resolution picks the musl package on glibc and
  installs no binary); `opencode --version` compared to the pin in the SAME
  RUN, following the #2537 rule: the assertion is the layer's own command, so
  a silent no-binary install fails the build.
- Provider pre-seed under /opt/trinity/opencode, exact versions (--save-exact):
  @ai-sdk/[email protected], @ai-sdk/[email protected],
  @ai-sdk/[email protected], @openrouter/[email protected] — the versions
  OpenCode v1.18.32 itself declares (packages/opencode/package.json:60,70,71,96).
  Each is in BUNDLED_PROVIDERS (packages/opencode/src/provider/provider.ts:116,
  122,123,124), checked before the runtime Npm.add fallback (provider.ts:1831,
  1846). The set is NPM_ALLOWLIST plus the drivers of NATIVE_KEY_ENV's
  providers; openai/* resolves to @ai-sdk/openai via the models.dev npm field
  (provider.ts:1503; cloudflareGatewayNpm provider.ts:1260).
- Go: tarball resolved per `uname -m` (ruling T1), verified with `go version`
  grepping linux/${goarch} in the same RUN.

startup.sh
- OpenCode block (case-insensitive): seeds $AGENT_TMPDIR/opencode (0700) and
  $AGENT_TMPDIR/opencode/config/opencode — the dir _shared_config_dir() reads
  with XDG_CONFIG_HOME unset — writing opencode.json only if absent and linking
  the pre-seeded node_modules. Exports nothing: the harness already sets the
  four XDG vars and all three OPENCODE_DISABLE_* per turn (ruling T3), so no
  env file is needed.
- AGENTS.md -> CLAUDE.md is now a relative symlink for codex ONLY (ruling T8),
  adopting a byte-identical copy and leaving a differing authored file alone.

Guardrails: /home/developer/.tmp/opencode/* added to guardrails-baseline.json
and _GUARDRAIL_PATH_DENY; test_ent820_path_policy_parity requires the Files
policy to write-deny every hook entry, so .tmp/opencode joins
RUNTIME_CONFIG_PATTERNS / AGENT_SERVER_RUNTIME_CONFIG_RELPATHS in both
byte-identical file_path_policy.py mirrors, with the pinned sets in
test_files_protected_paths.py and test_ent819_files_read_tier.py.

Tests: tests/unit/test_2981_base_image_arch.py (27; executes the shipped
startup.sh blocks against a tmp home; reverting Dockerfile + startup.sh turns
25 red).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants