Skip to content

fix(cli): the cold spawn path pins the MCP spec to a published version, not @latest (TASK-174) - #1973

Merged
lilyshen0722 merged 2 commits into
mainfrom
kai/task174-spec-pin
Sep 27, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
kai/task174-spec-pin

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

TASK-174 second half, taken through Vera's HOLD (74938–74940). Head 588d64bb, cli 0.1.79, one bump as before. The cold spawn path still pins the declared spec to a published version instead of @latest; what changed is that the version it pins from can no longer be a string with a suffix in it.

The HOLD, reproduced

parseVersion is anchored at the start only (/^(\d+)\.(\d+)\.(\d+)/), so it is a prefix test being used as a validator. Measured on the previous head:

parseVersion('0.3.13/../../../../tmp/evil')      → [0, 3, 13]
join('/Users/x/.commonly/mcp', that string)      → '/Users/tmp/evil'

Vera's value, kept literal in the tests as a control. The version arrives from ~/.commonly/mcp/.registry.json, the current pointer, or npm view, and the previous head put it into an argv entry we execute (the npx spec) and into a directory name — where #1970's startsWith(pkgDir) confinement is computed from that dir, so it confined to the wrong place. Reachability is honest: it needs a writer to the operator's own home. But this is the commit that first carries such a value into an executed command, so it is the right moment.

The fix: producers normalise, builders refuse

One constructor, in mcp-server-version.js:

export const exactVersion = (spec) => { const t = parseVersion(spec); return t ? t.join('.') : null; };

Every place a version becomes a value: resolveRegistryLatest (all three returns — cache, registry, stale-cache — and what it writes back to the cache), readCurrentVersion, readRegistryCache, pinShippedSpec. Every place a version becomes a name: versionDirFor, and packageDirFor now routes through it, so the install destination, the temp prefix, the in-use marker, the pruner and the bin reader share one chokepoint.

Where I departed from the proposed fix, and why. Building the spec and the path from the parsed triple is right for pinShippedSpec and wrong for versionDirFor: that result is what the warm renames into, what the pruner removes, and what readBinPath reads, so silently rewriting 0.3.14-rc.1 → 0.3.14 aims all three at a different build that may be sitting on disk. Measured — the mutation that implements exactly that rebuild (M2 below) makes readBinPath(home, '0.3.14-rc.1') return 0.3.14's bin, and the new arm reddens. So the builder refuses instead: anything that is not exactly a triple lands on .unusable-version, a name no version can have, inside the home — every read misses and the spawn falls back to the declaration, which is already this module's fallback. Normalising stays at the producers, where the choice is deliberate and visible.

Anchoring the regex was rejected for the reason Vera gave — a real 0.3.13-rc.1 would fall back to @latest. The cost is disclosed and pinned by an arm: a prerelease pins as 0.3.13, the stable release of its triple.

(c): she was right, and it is now armed

Removing the index !== 2 bound passed all 112, because isShippedCommonlyMcpCommand already requires a 3-arg npx -y <package> with the package in slot 2 — so the bound is not reachable today and is redundant as an argument. It is now an arm rather than an argument: the same unpinned spec string placed in slot 0 and in slot 2 gets opposite answers.

The skip is named: cli/__tests__/adapters.claude.environment.test.mjs:314, (onLinux ? test : test.skip) — the sandbox.mode=bwrap arm, skipped on darwin because the binary is Linux-only. The 112 baseline is 59 + 30 + 23 across the three suites this touches.

Evidence

  • The three suites: 122 tests, 121 passed, 1 skipped (that bwrap arm), 0 failures.
  • Full cli suite: 50 suites / 971 tests, with the same two pre-existing failures that are present at base 8faa6e32 — verified in a clean worktree of the base (same two names, 1 suite / 3 tests), not assumed.
  • Lint as the gate runs it (eslint src --ext .js): exit 0. Explicitly linting the touched .js and .mjs files (the gate's --ext .js does not cover .mjs): exit 0.
  • Mutation ledger, 12 mutations, 10 killed, 2 disclosed survivors:
mutation killed by
M1 exactVersion returns the raw string (the HOLD itself) 8 arms
M2 versionDirFor rebuilds a prerelease onto its triple (the proposed shape) 2
M3 versionDirFor joins the raw string (pre-fix) 3
M4 pinShippedSpec puts the raw version in the argv spec 1
M5 the slot-2 bound dropped 1
M6 newestInstalledVersion counts a prefix match as a name survivor, see below
M6b M6 + M2 — loosen the name filter and the refusal 2
M7 the warm prune counts a prefix match as a name 1
M8 the registry answer reaches argv/paths unnormalised 2
M9 readRegistryCache hands the pin the raw cached string 1
M10 readCurrentVersion hands the pointer on raw 2
M11 the warm child's own readCurrent keeps the raw pointer survivor, hygiene

M6 is defence in depth, not a gap: loosening the name filter alone still yields nothing, because versionDirFor refuses the name — M6b shows both guards must be loosened, and the arm that reddens is the reader arm. Same shape as #1971's compound operator-pin mutation: a guarantee the ledger cannot kill with one edit is the shape of the guarantee. M11 is disclosed as a tripwire: the warm child's readCurrent only feeds parseVersion comparisons, so its consumers normalise again and no edit to that line changes an outcome; it is kept so a version is a triple wherever it is produced, and it is named here rather than dressed up as load-bearing.

Residuals

  1. Reachability needs a writer to this operator's own ~/.commonly/mcp/ files — hardening, not an open door (the pointer path already carried such a value before this PR). Disclosed because closing the class is the point of doing it here.
  2. A prerelease pins to its stable triple rather than being installed as a prerelease.
  3. The prune ignores a dir whose name is not an exact triple (leaves x.y.z-rc.1 alone) instead of deleting it — safer than removing a dir it would have to reinterpret, and a behaviour change from the previous head, which counted it.
  4. Consumers of .registry.json / current outside this cli are not covered by this PR; the fix is the cli path.

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 27, 2026
Merged via the queue into main with commit 52dbba1 Sep 27, 2026
17 of 22 checks passed
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