Skip to content

feat(mcpx): stage 3 (Prepare) — materialise the resolved dependency set into the cache (#1915) - #12992

Merged
dezren39 merged 1 commit into
mainfrom
lane-gx/1915-prepare-stage3
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
lane-gx/1915-prepare-stage3

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Stage 3 (Prepare) of #1915 — the last named stage of the import pipeline. Stages 1–2 (PRs #2575, #5637) compute the import graph and resolve it into a data-only dependency set; prepare mode then stopped at a report saying materialising the set "is stage 3 and is not part of this build". This PR is that materialisation.

What lands

  • prepare.go: PrepareSet writes the resolved set's exact pins as a package.json in a content-addressed cache entry (mcpx: one content-addressed cache for prepared dependencies, import graphs and flake resolutions #1908, kind imports) keyed by the canonical set (cache.KeyString over mcpx-prepare-v1 + sorted name@version pins), and an Installer populates node_modules. Production installer is npm with --ignore-scripts --no-audit --no-fund — a prepared environment is dependency code fetched because a script imports it; its install scripts never run. A warm cache is a hit and installs nothing again; the cache stores an entry only when its fill completes, so a failed install leaves nothing half-built behind.
  • canonicalPins fails closed: an unnamed, unpinned, or doubly-pinned package is refused rather than guessed at.
  • Wiring: CheckImportsResolved in prepare mode calls prepareResolved, which records the outcome on the report — structurally (Report.Prepared *PreparedSet, new) and as report lines. A materialisation failure is a fatal problem with a fix hint, not a late runtime module error. ResolveOptions gains the PrepareCache / PrepareInstall seams; the cache root otherwise derives the way the daemon's does (MCPX_CACHE_DIR → XDG_CACHE_HOME → home), mirrored in preflight because the daemon package is not importable from there.
  • The old stage-3 stub text is gone from prepare mode.

Deliberately not in this slice (named on #1915 and in the code): cross-project subsets are resolved and counted but not materialised — their design writes node_modules beside a foreign project's files, a write into a user's project that needs its own opt-in; no consumer points a run at the prepared environment yet (runner wiring is the next slice); the deno import-map form is likewise later.

Tests (oracle: the #1915 stage-3 design — same set ⇒ same cache entry; failure ⇒ no entry; scripts never run)

  • prepare_test.go: empty set is a no-op that installs nothing; unpinned / conflicting / no-cache-root refusals install nothing; subsets counted, only the entry project's set installed; end-to-end CheckImportsResolved prepare-mode test over a stubbed deno info graph asserting the package lands in the prepared environment, the stub text is gone, and the installer ran exactly once.
  • Verified on the laptop worktree: go build ./..., go vet ./internal/preflight/, go test -count=1 ./internal/preflight/ ./internal/cache/ pass; internal/runner and internal/settings pass. One unrelated failure in internal/cli (TestInlineDaemonCancelledWhileWaiting, a timing assertion) flaked under heavy parallel load from other lanes and passed twice on re-run — recorded on mcpx: resolve a script's import graph statically and prepare missing dependencies #1915.

Refs #1915 (does not close it: subset materialisation + runner wiring remain). Authored by Lane GX, who ended without a final report; reviewed, verified, and landed by Lane HT.


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…et into the cache (#1915)

Prepare mode no longer ends at "materialising it is stage 3 and is not
part of this build". prepareResolved now hands the resolved set to
PrepareSet, which writes the exact recorded pins as a package.json in a
content-addressed cache entry (#1908) keyed by the canonical set and
populates its node_modules with an installer that runs no scripts
(npm --ignore-scripts). The same set always keys the same entry — a
warm cache is a hit and installs nothing again — and a failed fill
leaves no entry behind, so the next prepare retries instead of serving
a half-built environment.

canonicalPins refuses a set that leaves a package unpinned or pins one
name two ways: preparing from it would key two environments alike or
install an unspecified version. Report gains Prepared *PreparedSet;
ResolveOptions gains the PrepareCache / PrepareInstall seams.

Deliberately not in this slice, and the report says so: cross-project
subsets are resolved and counted but not materialised (their design
writes node_modules beside a foreign project's files — a write into a
user's project that needs its own opt-in), no consumer points a run at
the prepared environment yet (runner wiring is the next slice), and the
deno import-map form is likewise later.

Tests: PrepareSet unit coverage (empty set no-op, unpinned/conflicting
refusals, no-cache-root refusal, subset counting) plus an end-to-end
CheckImportsResolved prepare-mode test over a stubbed deno graph.

Work authored by Lane GX (sandbox fix lane), who ended without a final
report; reviewed, verified, and landed by Lane HT.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f2a50f21-5d60-4c24-ac9e-619efd90bc12
Commits

Reviewing files that changed from the base of the PR and between 457a180 and d2e3e05.

Files selected for processing: 5

  • pkgs/mcpx/internal/preflight/imports.go
  • pkgs/mcpx/internal/preflight/preflight.go
  • pkgs/mcpx/internal/preflight/prepare.go
  • pkgs/mcpx/internal/preflight/prepare_test.go
  • pkgs/mcpx/internal/preflight/resolve.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 merged commit 6e3f9c3 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the lane-gx/1915-prepare-stage3 branch November 23, 2026 06:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T06:36:34.826838Z d2e3e05 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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