Skip to content

mcpx: ResolvedScope plumbing + spawn cwd = resolved scope root (#958) - #3925

Merged
dezren39 merged 4 commits into
mainfrom
queue/4872-958-resolved-scope
Nov 2, 2026
Merged

dezren39 merged 4 commits into
mainfrom
queue/4872-958-resolved-scope

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Closes #958 — slice 1 of decision record 0004 (pkgs/mcpx/docs/decisions/0004-scope-resolved-roots.md), sections 1/2/3/6.

What changed

  • internal/config — ResolvedScope{Key, Root, Degraded} + Scope.Resolve(ctx); Scope.Key is now Resolve(ctx).Key (one resolution path). Root semantics per §1: worktree → checkout top-level; repo → parent of the common dir only when its base is .git, else none; cwd → canonical caller cwd; degraded repo/worktree → that cwd; global/session/psession/pid/call → none.
  • Plumbing (§2) — the registry resolves via Resolve (resolvedFor) and passes the ResolvedScope into Pool.Acquire/Call/ReadResource/GetPrompt/Request/Complete/Watch. The pool stores root on the Instance at creation; startLane/dial read it from the instance — restarts, era redials, exec-watch replacements and handoffs keep the creation root and never re-resolve.
  • Spawn cwd (§3) — pool.SpawnCwd, a pure function: config cwd → resolved root → unset (daemon cwd), applied to both stdio and supervised transports.
  • Observability (§6) — one server.spawn lifecycle line per spawn (server, key, root, cwd, cwd source: config/scope/daemon); key/root/cwdSource also on server.start; root in mcpx status instance JSON.

Tests

  • New: Resolve root semantics (worktree, repo from subdir, repo from a linked worktree roots at the main worktree, cwd, degraded-to-cwd root, rootless scopes, Key↔Resolve parity) — full internal/config package passes.
  • New: SpawnCwd decision table, and an end-to-end test that acquires an instance with a resolved root and verifies the root in status plus the child's actual cwd via /proc/<pid>/cwd.
  • Existing pool/daemon test call sites updated to the ResolvedScope signatures; go vet clean for config/pool/daemon. Full suite runs in CI.

Overlap

Refs #1989: its spawn-cwd acceptance criteria 1–4 are satisfied by this change; #1989 should close as covered once this lands (its gopls live-proof criterion belongs to slice 4, #961). Slices 2/3 (#959/#960) stay blocked on this slice.


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

Slice 1 of decision 0004 (pkgs/mcpx/docs/decisions/0004-scope-resolved-roots.md), sections 1/2/3/6:

- internal/config: ResolvedScope{Key, Root, Degraded} + Scope.Resolve; Scope.Key is Resolve().Key, one resolution path. Root semantics per spec: worktree -> checkout top-level; repo -> parent of the common dir only when its base is .git; cwd -> canonical caller cwd; degraded repo/worktree -> that cwd; global/session/psession/pid/call -> none.
- Registry resolves via Resolve and passes ResolvedScope into Pool.Acquire/Call/ReadResource/GetPrompt/Request/Complete/Watch; the pool stores root on the Instance at creation and startLane/dial read it from there (restarts, era redials and exec-watch replacements keep the creation root, never re-resolve).
- Spawn cwd (stdio, incl. supervised): pool.SpawnCwd pure function -- config cwd, else resolved root, else unset (daemon cwd).
- Observability: server.spawn lifecycle line (server, key, root, cwd, cwdSource), key/root/cwdSource on server.start, root in mcpx status instance JSON, root carried through instance handoff.

Tests: Resolve root semantics (worktree/repo/linked worktree/cwd/degraded/rootless/Key-parity), SpawnCwd decision table, end-to-end instance root in status + child cwd via /proc. Existing pool/daemon test call sites updated to the ResolvedScope signatures.

Refs #1989: its spawn-cwd acceptance criteria 1-4 are covered by this change; its gopls live-proof criterion belongs to slice 4 (#961).
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 18:40
@coderabbitai

coderabbitai Bot commented Nov 1, 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 20 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: 737ea50e-a0f4-4458-9944-028b5dfa45f7
Commits

Reviewing files that changed from the base of the PR and between a423735 and bdb04b5.

Files selected for processing: 30
  • pkgs/mcpx/internal/config/execid.go
  • pkgs/mcpx/internal/config/execid_test.go
  • pkgs/mcpx/internal/config/scope.go
  • pkgs/mcpx/internal/config/scope_resolve_test.go
  • pkgs/mcpx/internal/daemon/consumer.go
  • pkgs/mcpx/internal/daemon/consumer_scope_test.go
  • pkgs/mcpx/internal/daemon/exec_watch_test.go
  • pkgs/mcpx/internal/daemon/input_required.go
  • pkgs/mcpx/internal/daemon/ops.go
  • pkgs/mcpx/internal/daemon/registry.go
  • pkgs/mcpx/internal/daemon/registry_handoff_test.go
  • pkgs/mcpx/internal/daemon/reload_test.go
  • pkgs/mcpx/internal/daemon/routes_proto.go
  • pkgs/mcpx/internal/daemon/takeover_test.go
  • pkgs/mcpx/internal/pool/detach_test.go
  • pkgs/mcpx/internal/pool/era_test.go
  • pkgs/mcpx/internal/pool/execwatch.go
  • pkgs/mcpx/internal/pool/execwatch_test.go
  • pkgs/mcpx/internal/pool/follow_test.go
  • pkgs/mcpx/internal/pool/handoff.go
  • pkgs/mcpx/internal/pool/handoff_exec_test.go
  • pkgs/mcpx/internal/pool/pool.go
  • pkgs/mcpx/internal/pool/pool_test.go
  • pkgs/mcpx/internal/pool/request.go
  • pkgs/mcpx/internal/pool/self_connection_test.go
  • pkgs/mcpx/internal/pool/shutdown_drain_test.go
  • pkgs/mcpx/internal/pool/spawn_cwd_test.go
  • pkgs/mcpx/internal/pool/upstream_session_test.go
  • pkgs/mcpx/internal/pool/watch.go
  • pkgs/mcpx/internal/pool/watch_test.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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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-02T02:54:55.040451Z bdb04b5 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: ff15803fdd

ℹ️ 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 thread pkgs/mcpx/internal/daemon/registry.go Resolved
Comment thread pkgs/mcpx/internal/pool/pool.go Resolved
@dezren39

dezren39 commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

Addressed both Codex P2 findings in commit 84619fd80 (on top of current origin/main via merge commit 822d6c891):

  • Disambiguation now carries the selected instance's root into Acquire, so a new protocol lane or restart keeps the selected workspace root.
  • Scope-rooted relative executables are resolved and watched per instance using the effective spawn cwd; only the affected instance is replaced.

Verified: go test -count=1 ./internal/config ./internal/pool ./internal/daemon and git diff --check pass. Please re-review this head. @codex review

@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: 822d6c8912

ℹ️ 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 thread pkgs/mcpx/internal/pool/execwatch.go Resolved
InstanceHandoff now carries the instance execStamp and execIdentity
(resolved from its effective spawn cwd at creation), describe() records
them under execMu, and resumeInstance restores them on the adopted
instance. Without them a resumed instance read as zero-valued, so the
successor exec watch treated its unchanged executable as newly changed
and restarted adopted children after a daemon takeover (Codex review
finding on PR #3925).

Adds TestHandoffCarriesExecIdentityForRelativeCommand: a relative
./server under a scope root keeps its identity through detach, JSON
round trip, adopt and attach, and keeps serving afterwards.
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.

mcpx: ResolvedScope plumbing + spawn cwd = resolved scope root

1 participant