Skip to content

mcpx: point Node/Bun file runs at the prepared import environment (#1915) - #12998

Merged
dezren39 merged 1 commit into
mainfrom
lane-ie/1915-runner-prepared-env
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
lane-ie/1915-runner-prepared-env

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What

Remainder 1 of #1915: the runner now consumes Report.Prepared. Until this PR, a script.imports=prepare run materialised its resolved dependency set into the content-addressed cache (stage 3, PR #12992) and then ran without it — nothing pointed the run at the prepared environment.

How

In Run's imports block (file runs only; a text script resolves no graph and never prepares):

  • pointRunAtPreparedEnv links the prepared entry's node_modules beside the script — the placement linkDepsForFileRun already uses for the declared set — and holds it for the run's lifetime: the script directory's lock (reusing the deps block's lock when that block already took it; the single-capacity semaphore is never taken twice) plus a cache lease on the entry so pruning cannot delete it under a live exec (mcpx: one content-addressed cache for prepared dependencies, import graphs and flake resolutions #1908).
  • linkPreparedNodeModules mirrors linkNodeModules' rules: a real directory wins untouched; a link to an earlier prepared environment or to a workdir set refreshes; a dangling link is replaced only when a prepare run or this runner left it; any other link is the project's own.
  • A run that prepared none (report mode, empty set, no graph) removes a stale prepared link under the same lock, so it does not silently keep importing an earlier run's set.
  • A prepared entry whose node_modules is gone fails the run rather than falling back to an unprepared run — the failure shape prepare exists to replace.
  • Deno is not wired (its import-map form is a later slice), and parent-scope placement (the deps set's manifest-directory link) is likewise left for a follow-up; both are named on mcpx: resolve a script's import graph statically and prepare missing dependencies #1915.

preflight: the prepared manifest's name is now a named constant, and IsPreparedNodeModules recognises a prepared environment's node_modules by it — the runner can tell its own links from the project's without knowing the cache layout.

Verification

  • New runner tests: link rules (fresh / project-owned / user link / refresh from an earlier prepared env / refresh from a workdir set), stale-link removal, lock discipline (an already-held lock is not re-taken — proven against a held lock with a deadline), the deno skip, and the fail-closed missing-environment case.
  • New preflight test: IsPreparedNodeModules against a real PrepareSet entry, a foreign manifest, and a missing path.
  • go test -count=1 ./internal/runner/ ./internal/preflight/ — both suites pass in full; go build ./... and go vet clean; gofmt clean.

Refs #1915 (remainder 1 of the stage-3 follow-ups; the issue stays open for remainders 2 and 3).


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

)

Stage 3 (PR #12992) materialised a resolved dependency set into the
content-addressed cache, but nothing consumed Report.Prepared: a run
in script.imports=prepare mode paid for the environment and then ran
without it.

Runner wiring, in the imports block of Run (file runs only -- a text
script resolves no graph and never prepares):

- pointRunAtPreparedEnv links the prepared entry's node_modules
  beside the script, the placement linkDepsForFileRun already uses
  for the declared set, and holds it for the run's lifetime: the
  script directory's lock (the deps block's lock when that block
  already took it -- the single-capacity semaphore is never taken
  twice, tracked by depsFileLinkLocked) plus a cache lease on the
  entry so pruning cannot delete it under a live exec.
- linkPreparedNodeModules mirrors linkNodeModules' rules: a real
  directory wins untouched; a link to an earlier prepared
  environment or a workdir set refreshes; a dangling link is
  replaced only when a prepare run or this runner left it; any
  other link is the project's own.
- A run that prepared none (report mode, empty set, no graph)
  removes a stale prepared link under the same lock, so it does not
  silently keep importing an earlier run's set.
- A prepared entry with no node_modules fails the run instead of
  falling back to an unprepared run.
- Deno is not wired: its import-map form of the environment is a
  later slice, as is parent-scope linking (the deps set's
  manifest-directory placement).

preflight: the prepared manifest's name is now a named constant and
IsPreparedNodeModules recognises a prepared environment's
node_modules by it, so the runner can tell its own links from the
project's without knowing the cache layout.

Tests: new runner suite for the link rules, the stale-link removal,
the lock discipline (already-held lock is not re-taken), the deno
skip, and the fail-closed missing-environment case; a preflight test
for IsPreparedNodeModules. Full internal/runner and
internal/preflight suites pass; go build ./... clean.
@dezren39
dezren39 merged commit abea3b6 into main Nov 23, 2026
1 check passed
@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:48:16.420279Z e2253fd 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.

@dezren39
dezren39 deleted the lane-ie/1915-runner-prepared-env branch November 23, 2026 06:47
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

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