Skip to content

MCP server: prevent nested npx version mismatch in sequant_run #389

Closed

Description

@admarble

Context

In #372, sequant_run calls spawnSync("npx", ["sequant", "run", ...]). When the MCP server itself was started via npx sequant serve, this creates a nested npx invocation that may resolve to a different cached version.

Goal

Ensure sequant_run invokes the same sequant binary that's running the MCP server.

Acceptance Criteria

  • sequant_run uses the current process's binary path instead of npx sequant
  • Works correctly when started via npx sequant serve, global install, and local node dist/bin/cli.js serve
  • Version consistency verified in tests

Approach

Use process.argv[0] + process.argv[1] or resolve the CLI path relative to __dirname instead of calling npx.

Activity

  1. added
    bug
    multi-agent
    on Mar 23, 2026
  2. added a commit that references this issue on Mar 23, 2026
  3. admarble commented on Mar 23, 2026

    @admarble
    ContributorAuthor

    Exec Phase — Progress Update

    AC Coverage

    AC Description Status
    AC-1 sequant_run uses current process binary instead of npx sequant ✅ Implemented
    AC-2 Works for npx, global install, and local node dist/bin/cli.js serve ✅ Implemented
    AC-3 Version consistency verified in tests ✅ Implemented

    Key Changes

    • src/mcp/tools/run.ts: Added resolveCliBinary() function that resolves the CLI binary path using process.argv[0] + process.argv[1], with fallback to __dirname-relative resolution and npx as last resort
    • src/mcp/server-extended.test.ts: Added 7 tests — 4 direct unit tests for resolveCliBinary() and 3 MCP integration tests verifying spawn behavior

    Quality Gates

    Check Status
    npm run build ✅ Passed
    npm run lint ✅ Passed
    npm test ✅ 1764 passed (75 files)

    PR

    PR #406: #406

    Quality Plan Alignment: N/A — No quality plan in issue

  4. admarble commented on Mar 23, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #389

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original sequant_run uses current process binary instead of npx sequant MET resolveCliBinary() returns [process.argv[0], [process.argv[1]]] — verified in code (run.ts:24-31) and 4 unit tests + 3 integration tests
    AC-2 Original Works for npx, global install, and local node dist/bin/cli.js serve MET Three resolution paths: (1) process.argv covers npx/global/local, (2) __dirname-relative for bundled, (3) npx fallback. __dirname path verified: dist/src/mcp/tools → dist/bin/cli.js
    AC-3 Original Version consistency verified in tests MET 7 new tests: 4 direct resolveCliBinary() unit tests + 3 MCP integration tests verifying spawn args. All 22 MCP tests pass

    Coverage: 3/3 AC items fully met


    Quality Plan Verification

    N/A — No quality plan found in issue comments


    CI Status

    No CI checks returned from gh pr checks — CI may not be configured or PR checks haven't started.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +185 -
    Lines deleted -2 -

    Cache Status

    N/A — No caching configured


    Build Verification

    N/A — Build passed (tsc clean)


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/mcp/tools/run.ts Standard ✅ Yes src/mcp/server-extended.test.ts
    CHANGELOG.md Optional N/A -

    Coverage: 1/1 changed source files have corresponding tests
    Critical paths without tests: None


    Code Review

    Strengths:

    • Clean separation of concerns: resolveCliBinary() is a pure, exported, testable function
    • Three-tier fallback strategy (process.argv → __dirname → npx) is robust
    • Good JSDoc explaining the resolution priority and return type
    • npx fallback preserves backward compatibility for edge cases
    • CHANGELOG entry is well-written and actionable

    Issues:

    • None found

    Suggestions:

    • None — implementation is minimal and focused

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on spawn args (observable behavior), not internals
    Coverage Depth ✅ OK All 3 resolution paths tested (argv exists, dirname exists, fallback)
    Mock Hygiene ✅ OK Only existsSync and spawnSync mocked (external I/O only)
    Test Reliability ✅ OK No timing deps, deterministic via mock control

    Anti-Pattern Detection

    Dependency Audit

    N/A — No dependency changes

    Code Patterns

    No anti-patterns detected in changed files. No hardcoded secrets, no await-in-loops, no empty catch blocks.


    Call-Site Review

    New exported functions detected: 1

    Function Call Sites Loop? Conditions AC Match
    resolveCliBinary() src/mcp/tools/run.ts:85 No Unconditional (called before every spawn) ✅ Correct — should always resolve before spawning

    Findings: Single call site, called exactly where needed, no guard required.


    Execution Evidence

    N/A — No scripts/CLI entrypoints modified (change is in library code)


    Skill Command Verification

    N/A — No skill files changed


    CLI Registration Verification

    N/A — No option interface changes


    Smoke Test

    Not Required — No workflow-affecting changes (library-internal binary resolution only)


    Self-Evaluation

    • Verified working: Yes — all 22 MCP tests pass, including 7 new tests specifically for MCP server: prevent nested npx version mismatch in sequant_run #389
    • Test efficacy: High — tests cover all 3 resolution paths and verify spawn args at the MCP integration level
    • Likely failure mode: If process.argv[1] is somehow empty/undefined in a novel runtime (e.g., compiled binary). Mitigated by the fallback chain.
    • Verdict confidence: High — small, focused change with thorough test coverage

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (bug fix)
    [Unreleased] entry ✅ Present under "Fixed"
    Entry format ✅ Valid (includes #389)

    Result: CHANGELOG requirements met


    Verdict: READY_FOR_MERGE

    Clean, focused fix with thorough test coverage. All 3 ACs met. The resolveCliBinary() function correctly resolves the CLI binary from process.argv with sensible fallbacks, eliminating the nested npx version mismatch.

    Documentation

    • CHANGELOG entry added
    • N/A — No new features/flags requiring README updates

    Next Steps

    1. Merge PR fix(#389): prevent nested npx version mismatch in MCP sequant_run #406 when CI passes
    2. Run /docs 389 if documentation is desired (optional for bug fix)
  5. added
    ready-for-review
    on Mar 23, 2026
  6. admarble commented on Mar 23, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #389

    Stale Branch Check

    Check Value
    Commits behind main 4
    Threshold 5
    Status ⚠️ Warning

    Branch is 4 commits behind main. Critical: #388 (async spawn refactor) landed on main and directly conflicts with this PR.


    AC Coverage

    AC Source Description Status Notes
    AC-1 Original sequant_run uses current process binary instead of npx sequant NOT_MET resolveCliBinary() is correct but patches spawnSync — main now uses spawnAsync (#388). Merge conflict confirmed.
    AC-2 Original Works for npx, global install, and local node dist/bin/cli.js serve NOT_MET Three-tier fallback (argv → __dirname → npx) is sound, but must be applied to spawnAsync() call, not spawnSync().
    AC-3 Original Version consistency verified in tests NOT_MET Tests mock spawnSync but main now mocks spawn. All 7 new tests will break after merge.

    Coverage: 0/3 AC items met


    Quality Plan Verification

    N/A — No quality plan found in issue comments


    CI Status

    No CI checks configured/running for PR #406.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +185 -
    Lines deleted -2 -

    Build Verification

    N/A — Build passes on feature branch (but against stale base)


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/mcp/tools/run.ts Standard ✅ Yes src/mcp/server-extended.test.ts
    CHANGELOG.md Optional N/A -

    Coverage: 1/1 changed source files have tests
    Critical paths without tests: None (but tests target wrong API after rebase)


    Code Review

    Strengths:

    • resolveCliBinary() is a clean, well-documented, pure function with good JSDoc
    • Three-tier fallback (process.argv → __dirname-relative → npx) is robust
    • __dirname path resolution verified: dist/src/mcp/tools/ → dist/bin/cli.js ✅
    • The function is exported and independently testable
    • CHANGELOG entry is well-structured

    Issues:

    Suggestions:


    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on spawn args (observable behavior)
    Coverage Depth ✅ OK All 3 resolution paths tested
    Mock Hygiene ✅ OK Only existsSync and spawnSync mocked
    Test Reliability ✅ OK Deterministic via mock control

    Note: Test quality is good, but mocks target spawnSync which no longer exists on main.


    Anti-Pattern Detection

    Dependency Audit

    N/A — No dependency changes

    Code Patterns

    No anti-patterns detected. No hardcoded secrets, no await-in-loops, no empty catch blocks.


    Call-Site Review

    New exported functions detected: 1

    Function Call Sites Loop? Conditions AC Match
    resolveCliBinary() run.ts:85 No Unconditional ✅ Correct — always resolve before spawning

    Execution Evidence

    N/A — No scripts/CLI entrypoints modified


    Skill Command Verification

    N/A — No skill files changed


    CLI Registration Verification

    N/A — No option interface changes


    Smoke Test

    Not Required — No workflow-affecting changes


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (bug fix)
    [Unreleased] entry ✅ Present under "Fixed"
    Entry format ✅ Valid (includes #389)
    Merge conflict ❌ Conflicts with #388 entry

    Self-Evaluation

    • Verified working: Yes — all 22 tests pass on the feature branch, build is clean, resolveCliBinary() logic verified manually
    • Test efficacy: High on feature branch, but zero after merge — tests mock spawnSync which no longer exists on main
    • Likely failure mode: Merge conflict. If somehow merged, spawnSync import would revert the async spawn refactor from MCP server: replace spawnSync with async spawn for sequant_run #388, breaking MCP server responsiveness.
    • Verdict confidence: High — the merge conflict is mechanically verifiable via git merge-tree

    Verdict: AC_NOT_MET

    The resolveCliBinary() implementation is well-designed and the approach is correct, but the PR is based on pre-#388 code that used spawnSync. Main has since been refactored to async spawn (PR #400). All three changed files have merge conflicts. The fix needs to be rebased and adapted to the async API.

    Next Steps

    1. Rebase onto main: git fetch origin && git rebase origin/main
    2. Resolve conflicts in src/mcp/tools/run.ts:
      • Keep resolveCliBinary() function (add resolve, dirname, existsSync imports)
      • Apply binary resolution to spawnAsync(command, args, ...) instead of spawnSync
      • Update args: [...prefixArgs, "run", ...issues.map(String)]
    3. Resolve conflicts in src/mcp/server-extended.test.ts:
    4. Resolve CHANGELOG.md: Combine both entries under [Unreleased]
    5. Re-run /qa 389 after rebase
  7. added
    needs-work
    and removed
    ready-for-review
    on Mar 23, 2026
  8. added a commit that references this issue on Mar 23, 2026
  9. admarble commented on Mar 23, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #389 (Re-run after rebase)

    Stale Branch Check

    Check Value
    Commits behind main 0
    Status ✅ OK

    Branch rebased cleanly onto main (includes #388 async spawn refactor).


    AC Coverage

    AC Source Description Status Notes
    AC-1 Original sequant_run uses current process binary instead of npx sequant MET resolveCliBinary() returns [process.argv[0], [process.argv[1]]] — verified in code (run.ts:27-31) and 4 unit tests + 3 MCP integration tests
    AC-2 Original Works for npx, global install, and local node dist/bin/cli.js serve MET Three resolution paths: (1) process.argv covers npx/global/local, (2) __dirname-relative for bundled (dist/src/mcp/tools → dist/bin/cli.js — verified), (3) npx fallback
    AC-3 Original Version consistency verified in tests MET 7 new tests total: 4 direct resolveCliBinary() unit tests + 3 MCP integration tests verifying spawn args. Uses async spawn mock pattern from #388. All 29 MCP-related tests pass (22 extended + 7 async integration)

    Coverage: 3/3 AC items fully met


    Quality Plan Verification

    N/A — No quality plan found in issue comments


    CI Status

    No CI checks configured for this repository.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +163 -
    Lines deleted -2 -

    Cache Status

    N/A — No caching configured


    Build Verification

    N/A — Build passed (tsc clean, eslint clean)


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/mcp/tools/run.ts Standard ✅ Yes src/mcp/server-extended.test.ts
    CHANGELOG.md Optional N/A -

    Coverage: 1/1 changed source files have corresponding tests
    Critical paths without tests: None


    Code Review

    Strengths:

    Issues:

    • None found

    Suggestions:

    • None — implementation is minimal and focused

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on spawn command/args (observable behavior)
    Coverage Depth ✅ OK All 3 resolution paths tested at both unit and integration level
    Mock Hygiene ✅ OK Only existsSync and spawn mocked (external I/O)
    Test Reliability ✅ OK Deterministic via mock control, no timing deps

    Anti-Pattern Detection

    Dependency Audit

    N/A — No dependency changes

    Code Patterns

    No anti-patterns detected. No hardcoded secrets, no await-in-loops, no empty catch blocks.


    Call-Site Review

    New exported functions detected: 1

    Function Call Sites Loop? Conditions AC Match
    resolveCliBinary() run.ts:103 No Unconditional (before every spawn) ✅ Correct — always resolve before spawning

    Execution Evidence

    N/A — No scripts/CLI entrypoints modified (library-internal binary resolution)


    Skill Command Verification

    N/A — No skill files changed


    CLI Registration Verification

    N/A — No option interface changes


    Smoke Test

    Not Required — No workflow-affecting changes


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (bug fix)
    [Unreleased] entry ✅ Present under "Fixed"
    Entry format ✅ Valid (includes #389)
    No merge conflicts ✅ Clean

    Self-Evaluation

    • Verified working: Yes — all 29 MCP tests pass (22 extended + 7 async integration), build clean, lint clean
    • Test efficacy: High — tests cover all 3 resolution paths and verify spawn args at both unit and MCP integration levels, using the correct async mock pattern from MCP server: replace spawnSync with async spawn for sequant_run #388
    • Likely failure mode: If process.argv[1] is empty/undefined in a novel runtime (e.g., compiled binary). Mitigated by the __dirname fallback and npx last-resort.
    • Verdict confidence: High — small, focused change with thorough test coverage, cleanly rebased onto current main

    Verdict: READY_FOR_MERGE

    Clean, focused fix rebased onto current main (#388 async spawn). All 3 ACs met. resolveCliBinary() correctly resolves the CLI binary from process.argv with sensible fallbacks, eliminating the nested npx version mismatch. No regressions — all existing #388 async tests pass unchanged.

    Documentation

    • CHANGELOG entry added
    • N/A — No new features/flags requiring README updates

    Next Steps

    1. Merge PR fix(#389): prevent nested npx version mismatch in MCP sequant_run #406
  10. added
    ready-for-review
    and removed
    needs-work
    on Mar 23, 2026
  11. added 2 commits that reference this issue on Mar 23, 2026
  12. admarble commented on Mar 23, 2026

    @admarble
    ContributorAuthor

    Documentation Updated

    File: docs/features/mcp-server.md (updated existing doc)

    Changes:

    Why update, not new file:

    This is a bug fix to the existing MCP server, not a new feature. The existing mcp-server.md is the canonical reference — adding a troubleshooting entry there is where users will look.


    Ready to merge!

  13. added 3 commits that reference this issue on Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmulti-agentready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions