Skip to content

feat(mcpx): spawn-time ${mcpx.root}/${mcpx.cwd} substitution + load validation (#960) - #5135

Merged
dezren39 merged 2 commits into
mainfrom
queue/4874-960-mcpx-substitution
Nov 3, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/4874-960-mcpx-substitution

Conversation

@dezren39

@dezren39 dezren39 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Implements #960 (decision 0004 §4, slice 2) · queue task 4874 · prerequisite #958 (slice 1) is closed and ResolvedScope is on main, so the gate named in the issue is lifted.

What

  • Config-load validation (internal/config/placeholders.go, called from Config.Resolve): any ${mcpx.<name>} token with an unknown name, and any malformed ${mcpx. sequence (unterminated, empty, bad characters), in a server's args, env values or cwd is a config error naming the server and the field. Every other ${...} form passes through verbatim, as today.
  • Spawn-time substitution: Resolved.Effective(root, callerCwd) builds the per-instance spawn definition — ${mcpx.root} → the instance's resolved root, ${mcpx.cwd} → the creating caller's cwd — over Args, every Env value, and Cwd. The stored/merged config is never mutated; config output keeps showing placeholders. ResolvedScope now carries the canonicalized caller Cwd alongside Root (fixed at instance creation, never re-resolved, per §2).
  • Loud empty-value failure: a definition referencing ${mcpx.root} with an empty resolved root (or ${mcpx.cwd} with no caller cwd) fails the spawn in startLane before anything starts, naming server and field.
  • Era identity: startLane now hashes the effective (substituted) definition with pool.Identity, so two instances differing only by substituted root never share an era entry. dial takes the effective definition; HTTP session adoption passes the stored config (nothing spawns there).

Tests

  • internal/config/placeholders_test.go: validation matrix (unknown/malformed in each field, non-mcpx pass-through), substitution in Args/Env/Cwd including multi-placeholder values, stored config untouched, empty root/cwd failures.
  • internal/pool/placeholders_test.go: end-to-end spawn against the fake MCP server — the child process observes the substituted env values for both placeholders; Acquire with no root fails loudly naming server + placeholder; era identities differ across substituted roots and are stable for the same one.
  • Full internal/config, internal/pool, internal/daemon suites pass; go vet clean; darwin/arm64 build + test-compile clean for the touched packages.
  • Pre-existing failures unchanged: internal/conformance and internal/defaults link tests fail identically on a pristine worktree of current main (environmental — they need a bound mcpx binary / generated docs tree).

Cross-repo note

mcpx also lives in dezren39/nix. Per the one-change-one-issue rule this PR is the code side of the set; the nix port is owed and recorded as a SET-REMAINDER in the code backlog (hidden_files/backlog-code.md) so the next nix pass ports from issue #960 instead of rediscovering it.


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

@dezren39
dezren39 requested a review from a team as a code owner November 3, 2026 20:48
@coderabbitai

coderabbitai Bot commented Nov 3, 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 7 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: 80bcac80-ba09-45c2-886b-9fe1f878803a
Commits

Reviewing files that changed from the base of the PR and between d94b895 and 701a4d6.

Files selected for processing: 13
  • pkgs/mcpx/internal/config/config.go
  • pkgs/mcpx/internal/config/execid.go
  • pkgs/mcpx/internal/config/placeholders.go
  • pkgs/mcpx/internal/config/placeholders_test.go
  • pkgs/mcpx/internal/config/scope.go
  • pkgs/mcpx/internal/daemon/consumer.go
  • pkgs/mcpx/internal/daemon/registry.go
  • pkgs/mcpx/internal/pool/codex5135_test.go
  • pkgs/mcpx/internal/pool/execwatch.go
  • pkgs/mcpx/internal/pool/handoff.go
  • pkgs/mcpx/internal/pool/placeholders_test.go
  • pkgs/mcpx/internal/pool/pool.go
  • pkgs/mcpx/internal/pool/watch.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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T21:28:43.357569Z 701a4d6 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad5edcef9d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +621 to +624
eff, err := p.cfg.Effective(rs.Root, rs.Cwd)
if err != nil {
return nil, err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the creating caller's cwd across instance replacement

For any server using ${mcpx.cwd}, the initial caller-driven spawn succeeds, but a non-lazy restart stops the working child and fails to start its replacement. Instance retains only rs.Root, while Restart reconstructs ResolvedScope{Key, Root} and execwatch.replaceChild and the subscription monitor similarly omit Cwd. Consequently, this new Effective call rejects those replacements because the caller cwd is empty. Store the creating caller's cwd with the instance and propagate it through replacement paths, just as the root is preserved.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 701a4d6: Instance now stores the creating callers cwd alongside root(set at startLane creation), and every pool-driven replacement path propagates it —Restart(roots+cwds maps),execwatch.replaceChild, the subscription monitor (watchCwdcaptured withwatchRoot), and handoff adoption (InstanceHandoff.Cwd). Regression tests: TestRestartPreservesCallerCwdandTestExecWatchReplacesPlaceholderCwdChild` in pkgs/mcpx/internal/pool/codex5135_test.go (pool/config/daemon suites pass on the laptop).

spawnCwd, cwdSource = "", "daemon"
}
execStamp, execIdentity, _ := p.cfg.ExecStateAt(spawnCwd)
execStamp, execIdentity, _ := eff.ExecStateAt(spawnCwd)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use the effective definition for executable monitoring too

With a relative command such as ./server and cwd: "${mcpx.root}", startup now correctly resolves and runs the executable under the substituted directory, but executable monitoring still inspects the raw definition. In execwatch.go, checkExec takes the pool-wide branch because ExecUsesScopeRoot() requires an empty configured cwd, then p.cfg.ExecStamp() searches under the literal ${mcpx.root} directory. It therefore reports the executable missing and never detects updates to the running server. Preserve the effective definition or equivalent per-instance resolution inputs and use them for subsequent executable checks as well as this initial stamp.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 701a4d6: checkInstanceExec now stamps the instances effective (substituted) definition (p.cfg.Effective(in.root, in.cwd)+ExecStampAton the effective spawn cwd) instead of the raw stored definition, andExecUsesScopeRootalso returns true for a config cwd referencing ${mcpx.root}/${mcpx.cwd} so those pools route to the per-instance check rather than the pool-wide literal-placeholder stamp. Regression test:TestExecWatchReplacesPlaceholderCwdChild(a./server` under cwd "${mcpx.root}" is replaced when its executable changes).

Comment on lines +621 to +624
eff, err := p.cfg.Effective(rs.Root, rs.Cwd)
if err != nil {
return nil, err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Carry caller scope into schema discovery for placeholder servers

For a worktree-scoped server using ${mcpx.root} with no cached schemas, discovery always fails: refreshSchemas calls Acquire with only the synthetic schema key (pool.go:1137), so this substitution receives an empty root even when a foreground request has a valid caller workspace. Registry.Warm uses that path, leaving search and generated tool signatures empty; an ordinary caller-backed tool call does not populate the schema cache either. Foreground confirmation and annotation-dependent write-policy checks also invoke this rootless refresh despite having the caller context (consumer.go:448,638), preventing otherwise valid calls. Thread the caller's resolved scope into foreground schema discovery and defer caller-dependent background warming rather than manufacturing a root.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 701a4d6: schema refresh is now caller-scoped in the foreground — new Pool.RefreshSchemasFor(ctx, rs) acquires under the callers resolved scope, and the daemon consumers three foreground refresh sites (confirmDestructive, write-policy classification, ledger read-only check) pass r.resolvedFor(p, cc). The unscoped RefreshSchemas defers caller-scoped definitions (Pool.CallerScoped) with an explicit error instead of manufacturing a rootless start, and Registry.Warm skips caller-scoped pools so background warming no longer records a guaranteed failure. Regression test: TestRefreshSchemasForCallerScope.

…ma refresh (#960)

Codex review on PR #5135, three P2 findings: (1) Instance now stores the creating caller cwd alongside root and propagates it through Restart, exec-watch replacement, the subscription monitor, and handoff adoption; (2) exec monitoring resolves the effective (substituted) definition per instance and placeholder config cwds route to the per-instance check; (3) schema refresh gains RefreshSchemasFor on the caller resolved scope (consumer foreground paths threaded), unscoped refresh defers caller-scoped definitions instead of starting rootless, and registry Warm skips caller-scoped pools. Regression tests in codex5135_test.go.
@dezren39
dezren39 merged commit 5b0aeb5 into main Nov 3, 2026
3 checks passed
@dezren39
dezren39 deleted the queue/4874-960-mcpx-substitution branch November 3, 2026 21:29
@dezren39
dezren39 restored the queue/4874-960-mcpx-substitution branch November 8, 2026 04:10
@dezren39
dezren39 deleted the queue/4874-960-mcpx-substitution branch November 8, 2026 13:25
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