Repository navigation
Conversation
… reason move_file of a directory to a destination inside that directory reported "Parent directory does not exist" (ENOENT) for a destination directory that did exist: the same-device move renames its source to a staging name first, which carries the destination's directory away with it. renameIntoDirectory now refuses that move before anything is renamed, with EINVAL and "Cannot move a directory into itself: <destination> is inside <source>". The check compares directories by identity from the destination's directory up to the root, so another spelling of the source (a different case on a case-insensitive volume) is still caught, and a symlink to a directory, which is not a directory move, is not. Closes #5555 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
🦋 Changeset detectedLatest commit: 37a1f2f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 16 | 0 | 0 | 1 |
| Head | 16 | 0 | 0 | 1 |
Updated by this run for 37a1f2f8dd72a6912969ac990f556422caa801fa.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the directory self-move error-handling change.
No open issues 🎉
What changed in this PR
Fixes #5555 by making the filesystem server report the real reason when move_file attempts to move a directory into its own subtree, rather than incorrectly reporting a missing parent directory.
Changes:
- Checks directory identity before staging the move and rejects self-containing moves with
EINVAL, leaving staging logic unchanged. - Adds regression tests for rejection, an untouched source tree, and valid moves.
- Documents the error and records a patch changeset.
| File | Description |
|---|---|
src/filesystem/README.md |
Documents the self-move refusal and error message. |
src/filesystem/pinned-directory.ts |
Adds an identity-based subtree check before renaming. |
src/filesystem/__tests__/move-into-own-subtree.test.ts |
Tests rejection behavior, tree preservation, and valid moves. |
.changeset/filesystem-move-into-own-subtree.md |
Records the filesystem package’s patch release note. |
Review effort: Balanced
|
Copilot round 1: clean (no findings, no suppressed comments). The review loop stops here on the clean-round exit; nothing was pushed in response. |
Closes #5555
Description
move_fileof a directory to a destination inside that same directory (sub→sub/inner/sub) failed withParent directory does not exist: …/sub/inner, although that directory exists. The same-device move (renameIntoDirectory()inpinned-directory.ts) renames its source to a staging name before it enters the destination's directory, so a destination directory inside the source is carried away with it, and the failedchdiris then worded as a missing parent.renameIntoDirectory()now refuses that move before anything is renamed, with codeEINVALand the messageCannot move a directory into itself: <destination> is inside <source>. The staging logic is unchanged.The check (a private
isInsideSource()besiderenameIntoDirectory()) compares directories by identity rather than by path string: itlstats the source and, when that is a directory,stats each directory from the destination's directory up to the root and compares it with the source using the module's existingisSameEntry(). So:sub→sub2) is not caught;lstatand nothing else;EXDEVcan arise, and a directory cannot be inside itself across devices.It is a refusal, not an anchor: it reads by path, and if it is wrong because a directory was swapped in between, the anchored steps of the move still hold as before.
Server Details
filesystemmove_filetool's error for one invalid request; the README'smove_fileentryMotivation and Context
#5555. The error named a condition that was false (an existing directory reported as missing), which sends a client, an LLM in particular, to "fix" it by creating the directory and retrying. Before the staged rename was introduced, the same call failed with the kernel's
EINVAL.The idea of refusing up front with
EINVALis the one the issue suggests, and @shivamm-gupta prototyped it in a comment on the issue (thank you). This change is written independently, and differs in comparing directories by identity instead of by path prefix.How Has This Been Tested?
Automated. New
src/filesystem/__tests__/move-into-own-subtree.test.ts:Clienton the in-memory transport):move_fileinto a directory below the source, directly inside the source, and with a trailing separator on the source all return the new message, neverParent directory does not exist, and leave the tree untouched with no staging name behind; a destination directory that really is missing still reportsParent directory does not exist;sub→sub2, a directory moved up out of its own subtree, and a file moved into a sibling directory still succeed;renameIntoDirectory()directly:EINVALwithfs.renameSyncnever called; a destination directory that does not exist below the source; another case of the source on a case-insensitive volume (skipped where the volume is case-sensitive); a symlink to a directory moved into that directory (succeeds); a missing source still reports the rename'sENOENT.npm run local:gateexits 0, which includes the per-file coverage gate.Inspector CLI 2.12.0, both eras, before and after. In a fresh directory
$Dholdingsub/inner/andsub/x.txt:isError: true, exit 5)v2/main(7f383a8e)legacy(2025-11-25)Parent directory does not exist: $D/sub/innerv2/main(7f383a8e)modern(2026-07-28)Parent directory does not exist: $D/sub/innerlegacy(2025-11-25)Cannot move a directory into itself: $D/sub/inner/sub is inside $D/submodern(2026-07-28)Cannot move a directory into itself: $D/sub/inner/sub is inside $D/subThe
modernresults carryio.modelcontextprotocol/serverInfoin_meta. After every run$Dstill held exactlysub,sub/innerandsub/x.txt.LLM client: Claude Code 2.1.327, headless (
claude -p --mcp-config … --strict-mcp-config --allowedTools mcp__filesystem__move_file). It has no era switch and does not print the protocol version it negotiated, so the era could not be selected. Prompt: "Use the filesystem server's move_file tool to move the directory$D/subto$D/sub/inner/sub. Then reply with exactly the text the tool returned, followed on a new line by one sentence saying what you would do next."v2/main: the tool returnedParent directory does not exist: $D/sub/inner.Cannot move a directory into itself: $D/sub/inner/sub is inside $D/sub, and the model said it would leave the directory where it is.Breaking Changes
None. A request that failed before still fails; only its error text changes (and the error's
code,ENOENT→EINVAL, inside the server).Types of changes
Checklist
npm run changeset) if this changes what a TypeScript server publishesAdditional context
The tool description and input schema are unchanged, so the interface diff is empty.
🤖 Generated with Claude Code