Skip to content

fix(cli): a spawn whose version dir cannot be claimed runs the declaration, loudly (TASK-174) - #1970

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task174-claim-visible
Sep 27, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task174-claim-visible

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Follow-up to the merged #1965 (62d226c9), from Vera's second non-blocking note (74903). cli/src + tests, so cli goes 0.1.77 → 0.1.78.

The defect. claimInUse swallowed every failure and returned false. prepareMcpSpawn ignored the return, so a spawn whose claim could not be written exec'd from a version dir the pruner was free to rm -rf — the exact hazard the claim exists for — and said nothing. Vera's framing of the uncovered case: current and the grace window cover the pointed-at dir and the young one, so what is exposed is a no-pointer fallback onto a dir older than the window.

The fix: report it, and do not exec unprotected. I took the second of Vera's two options, and said why rather than picking silently. A claim failure means the directory under this seat is one a prune may take, so the spawn returns the declared command — what the guard approved, and what no pruner owns — instead of the home bin, and writes one line to stderr carrying the errno:

commonly: cannot claim <home>/<version> for pid <n> (EEXIST) — running the declared command instead,
because a prune could delete the directory this seat would run from
  • claimInUse now returns { claimed, reason }; reason is the errno (EEXIST, EACCES, ENOTDIR…), or not_claimable for a junk home / non-version / non-pid. A boolean could not tell "the home is a duplicate" from "nobody can write here", and only one of those is worth a sentence that names it.
  • prepareMcpSpawn gained an injectable warn (default: one line to process.stderr, itself failure-tolerant) so the arm can hold the text.
  • The warm still runs on the fallback path: with the seat off the version dir, a prune or a repair is safe — the fallback is why that is true.

Measured, not assumed (the failure mode the arm uses is a real one, reachable in the field): mkdirSync('<version>/.inuse', {recursive:true}) against an existing file throws EEXIST, and the file write under it throws ENOTDIR.

Tests. mcp-home.test.mjs 51/51; full five-suite baseline (home + pi ×2 + claude + codex) 170/170, 0 runtime errors. New arms:

  • a claim that cannot be written is LOUD: the spawn runs the declaration, not an unprotected dir — asserts the returned command is the npx declaration, the warn fired exactly once, and the line carries the version, the errno, and the consequence.
  • positive control: a usable marker dir takes the home path and warns about nothing — without it the loud arm would also pass if the spawn always fell back, which would undo TASK-174 entirely.
  • the junk-input arm now asserts not_claimable, and the success arm asserts {claimed: true}, so the shape is pinned in both directions.

Ledger — 15 mutations, no survivors (/tmp/kai-174d-ledger.py, whole 5-suite baseline asserted per run as a (suites, tests) pair, so a suite that fails to compile cannot read as a kill):

  • New: M27 drop the fallback → the loud arm; M28 keep the fallback, drop the warn → the loud arm; M29 report success on the failure path → the loud arm + the junk arm; M30 drop the errno (reason: 'claim_failed') → the same pair, because the line has to name the failure; M31 call a junk input claimable → the junk arm.
  • Re-run on this base, still killing their arms: M1, M2, M3, M9, M10, M11, M22, M24, M25, M26. M24's needle moved with the code (it now replaces the claim with a synthetic success).
  • Disclosed: the WARM-file mutations (M4–M8, M12, M13, M21, M23) were not re-run here — this diff does not touch mcp-warm-child.mjs, and they were all killed on the merged base. They remain valid only because that file is byte-identical to main in this PR.

Note on the line, for the gate: the message says "prune could delete the directory this seat would run from" rather than naming a code path, because the pruner that would do it is a different process — the warm child — and a log line claiming otherwise would be the kind of comment that drifts.

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 27, 2026
Merged via the queue into main with commit 8faa6e3 Sep 27, 2026
15 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