Skip to content

Detect wrong MCP binary in integration-test skill (#154)#155

Merged
obj-p merged 2 commits intomainfrom
fix/skill-detect-wrong-binary
May 1, 2026
Merged

Detect wrong MCP binary in integration-test skill (#154)#155
obj-p merged 2 commits intomainfrom
fix/skill-detect-wrong-binary

Conversation

@obj-p
Copy link
Copy Markdown
Owner

@obj-p obj-p commented May 1, 2026

Fixes #154.

Summary

When iterating in a git worktree nested under the main repo (e.g., .claude/worktrees/<name>/), Claude Code launches the stdio MCP server from the parent repo's .build/, not the worktree's. /resume makes it sticky — it preserves the original project root regardless of relaunch CWD. The integration-test skill's preview_build_info staleness check (#147 / #150) happily reports green in this state: the binary at the resolved path does match its running process; it just isn't the binary the developer is iterating on.

Hit live during PR #153 validation — a full integration-test run reported green against a parent-repo binary that didn't have any of the PR's changes.

Approach

Step 2 of the skill now runs two independent checks:

  • 2a. Wrong-binary check. Derive expected path from git rev-parse --show-toplevel of the skill's CWD, resolve symlinks the same way preview_build_info does, compare to its returned binaryPath. Mismatch aborts with a tailored relaunch message that explicitly names /resume as the trap.
  • 2b. Stale-binary check. Existing logic, unchanged.

Both checks must pass before proceeding. They cover independent failure modes — wrong binary entirely vs stale binary at the right path.

Why not change preview_build_info itself

The MCP server has no way to know what the developer's current worktree is. Users who installed PreviewsMCP via brew / mint / a binary copy have no <root>/.build/<arch>/debug/previewsmcp layout to compare against — a server-side check would falsely flag every end-user install as "wrong tree." The skill is the only programmatic caller of preview_build_info and the right place for developer-mode context (CWD, expected build layout).

Documentation

Adds a "worktree footgun" paragraph to AGENTS.md alongside the existing "Refresh stdio" guidance, with a pointer to the skill's automatic detection.

Out of scope

The upstream Claude Code behavior — ${workspaceFolder} not expanding in .mcp.json command (anthropics/claude-code#3239, #9427), and /resume preserving the original project root regardless of relaunch CWD. Tracked separately upstream.

Test plan

  • Skill change is markdown-only — verified the rendered Step 2 reads cleanly
  • AGENTS.md addition reads cleanly in context
  • Manual: simulated the abort message wording — it correctly names /resume as the cause
  • Next time /integration-test runs in a worktree, Step 2 will exercise the new check end-to-end

🤖 Generated with Claude Code

obj-p and others added 2 commits April 30, 2026 20:06
When iterating in a git worktree nested under the main repo, Claude
Code launches the stdio MCP server from the parent repo's `.build/`
rather than the worktree's. /resume makes it sticky. The skill's
existing `preview_build_info` staleness check happily reports green
in this state — the binary at the resolved path matches its running
process; it just isn't the binary the developer is iterating on.

Hit live during PR #153 validation: a full integration-test run
reported green against a parent-repo binary that didn't have any of
the PR's changes.

Step 2 of the skill now runs two independent checks:

  2a. Wrong-binary: derive expected path from `git rev-parse
      --show-toplevel` of the skill's CWD, resolve symlinks, compare
      to `preview_build_info`'s `binaryPath`. Mismatch aborts with a
      tailored relaunch message that names /resume as the trap.
  2b. Stale-binary: existing check, unchanged.

No change to `preview_build_info` itself — the MCP server has no way
to know what the developer's current worktree is, and end users who
installed via brew/mint don't have a `<root>/.build/...` layout to
compare against. The skill is the only programmatic caller and the
right place for the developer-mode check.

Also documents the footgun in AGENTS.md near the existing "Refresh
stdio" guidance, with a pointer to the skill's automatic detection.

Out of scope: the upstream Claude Code path-resolution / /resume
behavior. Tracked separately against anthropics/claude-code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Earlier wording framed worktree-based work as a footgun to detect.
The actual story is simpler: open Claude Code from inside the
worktree (don't /resume across them) and the relative .mcp.json
command path resolves to the worktree's binary on its own. The
skill's Step 2 detection is a safety net for accidental /resume,
not the primary mechanism.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@obj-p obj-p merged commit 2f6ab07 into main May 1, 2026
4 checks passed
@obj-p obj-p deleted the fix/skill-detect-wrong-binary branch May 1, 2026 00:51
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.

integration-test skill misses 'wrong binary' (worktree pointing at parent repo's binary)

1 participant