LearnNewsExamplesServices
Frontmatter
id19204
titleprepare runs its stages inside a git-dependency build
stateClosed
labels
bugaibuild
assigneesneo-fable-clio
createdAtSep 25, 2026, 12:17 PM
updatedAtSep 25, 2026, 12:51 PM
githubUrlhttps://github.com/neomjs/neo/issues/19204
authorneo-fable-clio
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 25, 2026, 12:51 PM

prepare runs its stages inside a git-dependency build

neo-fable-clio
neo-fable-clio commented on Sep 25, 2026, 12:17 PM

Context

The Fleet Manager's Electron packaging (neomjs/neo-agent-institution harness/pack.mjs) stages the organism and runs npm install on a generated manifest that pins the engine by commit: neo.mjs: github:neomjs/neo#d85060795d8abc99a7d6186968a35e9b8b77188b. On 2026-09-25 that install failed:

npm error code: 'EEXIST', syscall: 'symlink',
npm error path: '../../node_modules/neo-agent-skills/.agents/skills/architecture-pre-flight',
npm error dest: '/Users/Shared/…/neo-agent-institution/harness/.stage/organism/.claude/skills/architecture-pre-flight'

The stage root had gained .agents/skills and .claude/skills/* symlinks it never asked for, dangling (the stage's own node_modules/neo-agent-skills was not installed yet). Observation and inference are separated below.

The Problem

buildScripts/util/prepare.mjs is the engine's prepare lifecycle: husky, then neo-agent-skills-materialize. Its header says the materializer runs from prepare "never from postinstall: npm runs a dependency's postinstall inside every consumer's install … while a registry or tarball install never runs prepare" (prepare.mjs:28-31). That sentence is true for registry installs and false for git-dependency installs: npm builds a git dependency by cloning it to a cache directory and running its prepare there — with INIT_CWD set to the directory the top-level npm install was invoked from, i.e. the consumer's root.

The materializer resolves its target as args.root || consumerRoot(), and consumerRoot() returns INIT_CWD when set (neo-agent-skills/scripts/materialize-harness-skills.mjs, consumerRoot). So an engine pinned as github:neomjs/neo#<sha> materializes the engine's skills façade into whatever directory installed it. In the Institution's stage that root also receives the brain's postinstall materialization (the second git dependency, neo-agent-brain#8e09275, declares postinstall: neo-agent-skills-materialize); npm runs the two in parallel, and the loser of the rm→mkdir→symlink race exits with EEXIST. Every consumer that pins the engine by commit gets the façade written into its root on install; the race only makes it loud.

Falsifier run (2026-09-25, same tree): npm_config_ignore_scripts=true node pack.mjs — the stage completes, @electron/rebuild rebuilds the natives, organism staged … (rebuilt=true), exit 0. Nothing else in the install depends on the engine's prepare.

The Architectural Reality

  • buildScripts/util/prepare.mjs — runPrepare({root, env, spawnFn}) returns {skipped, stage, status}; the only guard today is npm_config_package_lock_only === 'true' → {skipped: 'package-lock-only'}. Both stages spawn with cwd: root.
  • The stages provision the engine's own checkout: husky writes the checkout's git hooks, the materializer projects the checkout's .agents/skills + .claude/skills. Neither has a meaning inside a consumer's node_modules or a cache clone.
  • npm sets INIT_CWD for every lifecycle script to the invoking directory; a prepare running in the engine's own checkout sees INIT_CWD === repoRoot (also under npm ci, npm install, npm run prepare from the root); a git-dependency build sees a foreign INIT_CWD. That is the discriminator — no npm flag or cwd heuristic is needed.
  • test/playwright/unit/buildScripts/prepare.spec.mjs pins the lock-only guard, stage order and failure propagation with an injected spawnFn; the new guard pins into the same spec.

The Fix

runPrepare gains a second guard beside the lock-only one: when env.INIT_CWD is set and does not resolve (realpath, falling back to lexical resolution) to root, return {skipped: 'dependency-build', stage: 'guard', status: 0} before any stage spawns. Header docs correct the "never runs prepare" sentence to name the git-dependency case. Nothing changes for a checkout install: husky and the materializer run exactly as today.

Contract Ledger Matrix

Target surface Source of authority Proposed behavior Fallback Docs Evidence
runPrepare (buildScripts/util/prepare.mjs) npm lifecycle contract (INIT_CWD); this ticket foreign INIT_CWD → skipped: 'dependency-build', status 0, no spawn; same or unset INIT_CWD → unchanged none — the guard is total the file header red-first spec arms below

Decision Record impact

none — no ADR governs the prepare lifecycle; ADR 0020 §3 (consumers install the engine as a dependency, no source-tree mixing) is the reason the guard is correct.

Acceptance Criteria

  • runPrepare({env: {INIT_CWD: '<other dir>'}, spawnFn}) returns {skipped: 'dependency-build', stage: 'guard', status: 0} and spawnFn is never called (red on dev).
  • runPrepare({env: {INIT_CWD: <root>}}) and runPrepare({env: {INIT_CWD: <symlink to root>}}) run both stages as today.
  • runPrepare({env: {}}) (no INIT_CWD) runs both stages as today.
  • The lock-only guard keeps precedence and its exact return shape.
  • Header comment names the git-dependency case; no other file changes.
  • Post-merge, in the Institution: harness/pack.mjs's stage install completes with the engine pinned at a commit that carries this guard (recorded on the Institution pin bump, not here).

Out of Scope

  • The materializer's INIT_CWD root resolution in neomjs/neo-agent-skills (correct for a consumer's own postinstall; the caller is what is wrong here).
  • neomjs/neo-agent-brain's postinstall: neo-agent-skills-materialize running inside its consumers (defect-noted separately; the Brain's call).
  • Making pack.mjs ignore lifecycle scripts — the probe used that to falsify the cause, not as the fix; the stage must keep running the natives' install scripts.

Related

neomjs/neo-agent-institution#7 (the Electron shell epic; the failing pack) · neomjs/neo-agent-skills scripts/materialize-harness-skills.mjs (consumerRoot) · #19198 (the engine's skills pin 0.1.16) · Ada's 2026-09-05 Institution-CI EEXIST diagnosis (same symptom class at the Institution root)

Live latest-open sweep: checked the latest 20 open issues at 2026-09-25 10:13Z; no equivalent. A2A claim sweep (last 60 min): no overlapping [lane-claim]. Memory Core sweep: the 2026-09-05 EEXIST diagnosis is the nearest prior art (Institution CI, root materialization), no prior decision on the engine's prepare. Own-assignment sweep: none on this surface.

Origin Session ID: 0fbfde3a-e817-4859-9351-2269eabdda9a Retrieval Hint: "prepare.mjs git-dependency INIT_CWD materializer EEXIST harness pack stage"

tobiu referenced in commit 87ac80a - "fix(build): prepare skips its stages inside a git-dependency build (#19204) (#19205) on Sep 25, 2026, 12:51 PM
tobiu closed this issue on Sep 25, 2026, 12:51 PM