Repository navigation
fix(apps): install npm deps where a node backend's package.json lives - #30460
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The change fixes the cause: the pre-start install assumed the npm project sits at the app root. Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: a Node app whose backend has its own
[FIRST-PRINCIPLES-REVIEWED] d8319ad Description read[DESCRIPTION-READ] e532548c1e93f3f7a8d7da5eafe407de25fda66e41c5d8df8bc67a9fc696e760 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change fixes the root cause. The pre-start install now finds every Notes
[DESIGN-REVIEWED] d8319ad Description read[DESCRIPTION-READ] 63af4e992cf59817d4b090672d3c33ac00dc07cef3d6b89ca15a79e9850dc183 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Approve. A Node app that keeps its backend as its own package (for example backend/dist/server.js with backend/package.json) now gets backend/node_modules before it starts. Before this change it failed every start with ERR_MODULE_NOT_FOUND. A failed npm run now also leaves a warning with the directory and exit code.
What I checked on d8319ad:
- Inside the app directory: the candidate directories are the resolved entry's parents, filtered to the resolved app root and the directories below it. The entry itself is already refused upstream by
file_entry_point_refusalif it resolves outside the root, so this is a second fence. Dropping the filter makestest_npm_never_runs_above_the_app_rootinstall in the directory above the root. - Same restrictions: each run uses the same
wrap_argv(..., mode="standard"), cgroup ceiling, env, flags and 120s timeout as before. Onlycwdchanges, and only to directories inside the app. - Root-level apps unchanged: for an entry at the root the walk is just the root, with the same skip-when-
node_modules-exists rule. The existing root-install, skip and failure tests pass unchanged.
Evidence: test_apps_backend_coverage_dispatch.py gives 49 passed. I ran three mutations, one at a time, and each reddened a named test:
- Containment filter removed:
test_npm_never_runs_above_the_app_rootfailed. - Root-only walk:
test_npm_installs_the_root_and_the_entry_points_own_package_directoryfailed. - Exit-code warning removed:
test_a_nonzero_npm_exit_is_logged_and_the_spawn_goes_aheadfailed.
CI is green: 77 success, 16 skipped, PR Readiness success. Merge-tree against main is clean. I did not run a real npm install or the full suite. Windows and macOS were checked against source only.
Non-blocking follow-up: each package directory has its own 120s budget, so an app with several on its entry path can wait a few minutes before its backend starts. Only that app is affected, because the wait sits under its own lifecycle lock. The manifest reference could say so.
Problem / Motivation
Goal: A Node app whose backend keeps its own
package.jsonin a subdirectory starts on the first enable, with its npm dependencies installed, instead of failing withERR_MODULE_NOT_FOUND.The app in the issue declares
backend/dist/server.jsas its entry point and lists its dependencies inbackend/package.json. An install never copiesnode_modules, and the gateway's ownnpm installbefore a Node backend start looked only at the app root'spackage.json. Sobackend/node_moduleswas never created, and the backend exited at once withERR_MODULE_NOT_FOUNDon every start. npm's exit status was not read either, so a failed install left nothing in the log.Why it matters
Every Node backend laid out as its own package in a subdirectory fails on every start until the user runs
npm installby hand inside the installed copy in the data home. Nothing in the gateway log points there, so the cause is hard to find.Not a goal
setup.onInstallon a local-path install. The docs say it is not run there; whether it should be, and behind which gate, is a maintainer decision that fix(apps): run setup.onInstall on local-dir installs and gate enable on it #10599 proposes an answer to. This PR does not change it.onEnablebefore the backend starts. That order is documented and stays.What changed (motivation → approach → change)
A Node backend with a
package.jsonbeside its entry point in a subdirectory gets its dependencies installed before it starts.The cause was that the gateway's pre-start install checked only
<app>/package.json. Node looks an entry's imports up in thenode_modulesof every directory above the entry, so before a Node backend starts the gateway takes those directories, from the app root down to the entry's own, and runs the same sandboxednpm install --productionin each one that has apackage.jsonand nonode_modules. The root keeps its install andbackend/gets one too. The directories come from the resolved entry path, so a candidate is never above the app root.A non-zero npm exit is logged as a warning that names the app, the directory and the exit code, and the backend still starts, as it does when npm cannot run at all. The manifest reference documents the install, including that it is how a local-path install gets its npm dependencies.
Backwards compatibility
Compatible: the app-root install runs as before; the only added work is an install in a directory on the entry point's path that has a
package.jsonand nonode_modules, which got none before.Removes nothing: no path, key, check or record is taken away; the start still goes ahead whatever npm does.
Tests
test_npm_installs_the_root_and_the_entry_points_own_package_directory: with apackage.jsonat the root and inbackend/, an entry atbackend/dist/server.jsruns npm twice, in the root first and then inbackend/.test_npm_never_runs_above_the_app_root: an entry point spelled through..back into the root still spawns, and thepackage.jsonin the directory above the root is never installed.test_a_nonzero_npm_exit_is_logged_and_the_spawn_goes_ahead: npm exiting 1 logs a warning naming the exit code, and node is still spawned.node_modules-exists and failed-install tests pass unchanged.Proof: PROVEN test/test_apps_backend_coverage_dispatch.py::TestNodeDispatch::test_npm_installs_the_root_and_the_entry_points_own_package_directory, test/test_apps_backend_coverage_dispatch.py::TestNodeDispatch::test_a_nonzero_npm_exit_is_logged_and_the_spawn_goes_ahead (head d8319ad)
Determinism: the three new tests passed 20 runs at
-n0and 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest_apps_backend_coverage_boot.pyandtest_apps_backend_coverage_stop.py; the whole file passed in a shuffled order (seed 21983).test_npm_never_runs_above_the_app_rootpasses onmaintoo: it pins that the new walk stays inside the app root.Manual verification
N/A — unit coverage sufficient: the change is which directories the existing sandboxed install runs in and a log line; the tests drive the real spawn body up to the process launch.
Screenshots / video
N/A — no user-visible frontend surface is touched.
Related Issues
Closes #10583
Sibling sweep
Swept: git grep -nE '"npm"|npm_bin|_find_npm_binary|package.json' -- 'src/kiro_crew/apps/.py' 'src/kiro_crew/apps/**/.py'
Sibling: src/kiro_crew/apps/registry.py:137 -- not affected -- the clone-time build step runs before the copy, which drops node_modules, so runtime dependencies come only from the pre-start install changed here
Pattern harvest
Not generalizable: the one runtime npm installer assumed the npm project sits at the app root; no second installer makes that assumption.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)