Skip to content

mcpx: key scopes by directory identity so a wrong-case cwd shares one instance (#1912) - #2563

Merged
dezren39 merged 1 commit into
mainfrom
queue/3190-1912-mcpx-scope-identity
Oct 30, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/3190-1912-mcpx-scope-identity

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #1912. Queue task 3190 (triage task 2807 confirmed the bug live on main). Design decision (Approach C, side-table variant) recorded on #1912 before implementation.

What changed

  • Scope.Key (cwd, repo, worktree scopes) now routes its path through a new keyPath() in pkgs/mcpx/internal/config/scope.go: canonicalize as before, os.Stat the result, and look its (dev, inode) up in a process-wide side table that remembers the first canonical spelling seen for that identity. Every spelling of one directory keys to the first spelling — one key, one instance, on all three scopes.
  • dirIdentity added beside gitDevice in gitsys_unix.go (syscall.Stat_t, no new dependency) / gitsys_other.go (no identity available → fallback).
  • Fallbacks keep today's behaviour exactly: Stat failure (deleted/unreadable cwd) or no platform identity → canonical path alone. That is the safe over-isolation direction; two genuinely different directories differing only by case have different inodes, so accidental sharing is impossible.
  • The key stays a plain readable path (existing exact-key tests and mcpx daemons output unaffected).

Found during development

The first version of the side table failed an existing test: a temp directory's inode was recycled after deletion and the table resurrected the dead directory's spelling as a live directory's key. keyPath now re-validates a remembered spelling against the identity before reusing it and replaces stale entries; TestKeyPathRecycledIdentityDoesNotResurrectADeadSpelling pins this.

Tests

  • TestGitCaseOfAWrongCaseCwdIsKept inverted, not deleted: discovery still keeps the caller's spelling; the test now asserts cwd/repo/worktree keys for both spellings coincide (darwin-gated, as before; cross-checked here with GOOS=darwin go vet).
  • New portable internal tests stub dirIdentity (the gitDevice pattern) to cover both volume kinds on any OS: two spellings/one identity key together; case-differing distinct directories stay separate; unstattable path falls back to itself; recycled identity does not resurrect a dead spelling.
  • New real-filesystem test in scope_test.go: case-differing directories stay separate on case-sensitive volumes and key together where the volume resolves them to one directory.
  • Fail-before shown on the laptop: with keyPath neutered to ignore identity, TestKeyPathTwoSpellingsOfOneDirectoryKeyTogether fails ("/Users/x/Repo" vs "/users/x/repo"); restored, it passes.
  • Laptop: go test ./internal/config/ -count=1 PASS; daemon degraded-scope tests PASS. Note: the full internal/daemon package test binary gets signal: terminated on the laptop — reproduced identically on a clean origin/main worktree, so it is a pre-existing laptop environment issue, not this change; CI is authoritative.

Open questions from #1912 (key persistence across restarts, container bind mounts, #88 interaction) are answered in the design-decision comment on the issue.


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

… instance (#1912)

canonical() keeps the caller's spelling, so on a case-insensitive volume two spellings of one directory produced two scope keys and two server instances across the cwd, repo and worktree scopes. Scope.Key now routes through keyPath(): stat the canonical path, look its (dev, inode) up in a side table remembering the first spelling seen for that identity, and key every spelling to the first. The key stays a plain readable path. Stat failure or a platform without identity falls back to the path alone (today's behaviour, the safe over-isolation direction); distinct directories differing only by case have distinct inodes, so accidental sharing is impossible. Cached spellings are re-validated against the identity before reuse, so a recycled inode cannot resurrect a deleted directory's spelling (caught by the existing suite during development; regression test included). TestGitCaseOfAWrongCaseCwdIsKept is inverted, not deleted: discovery still keeps the spelling, but the cwd/repo/worktree keys for both spellings must now coincide. Portable internal tests stub dirIdentity (the gitDevice pattern) for both volume kinds; fail-before verified by neutering keyPath (new test fails), pass after restore.
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 04:53
@coderabbitai

coderabbitai Bot commented Oct 30, 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 49 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: d396fcb2-acc1-4654-bda1-efc1a0f4c748
Commits

Reviewing files that changed from the base of the PR and between 86b7d01 and 7caf972.

Files selected for processing: 6
  • pkgs/mcpx/internal/config/gitdiscover_darwin_test.go
  • pkgs/mcpx/internal/config/gitsys_other.go
  • pkgs/mcpx/internal/config/gitsys_unix.go
  • pkgs/mcpx/internal/config/scope.go
  • pkgs/mcpx/internal/config/scope_identity_internal_test.go
  • pkgs/mcpx/internal/config/scope_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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-10-30T04:54:57.247404Z 7caf972 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 merged commit fbedd80 into main Oct 30, 2026
7 of 8 checks passed
@dezren39
dezren39 deleted the queue/3190-1912-mcpx-scope-identity branch October 30, 2026 06:59
@dezren39
dezren39 restored the queue/3190-1912-mcpx-scope-identity branch November 1, 2026 09:04
@dezren39
dezren39 deleted the queue/3190-1912-mcpx-scope-identity branch November 1, 2026 16:45
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: a wrong-case cwd on a case-insensitive volume keys separately from the on-disk spelling

1 participant