Repository navigation
fix(mcp): treat an app on another Windows drive as outside the package - #20802
Conversation
serves_managed_tools used os.path.commonpath, which raises ValueError for paths on different Windows drives; the fail-closed branch then applied the managed tool policy to a user app, refusing its every call on the shared ACP runtime. Compare drives first, and compare the common path caselessly. Closes #20800
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] ad477e0 Description read[DESCRIPTION-READ] 93626d98b9ea841641d625b5703c1d9493059afec704accf44f8cbfedb55d355 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check that Backend Tests (Windows) shard 7 goes green on a GitHub-hosted Not justified as shipped
What this change shipsInventory (3 items) — 2 justifiedIntent: let an app MCP server on a different Windows drive from Kiro Crew serve its tools instead of having every call refused. This is a FIX (#20800, a regression of #20530).
[FIRST-PRINCIPLES-REVIEWED] ad477e0 Description read[DESCRIPTION-READ] 6ff83a324f7145c923532c6e22d94b22101c2cc4fad42038fa8678043562fffd That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
buluoray
left a comment
There was a problem hiding this comment.
An app MCP server installed on a different Windows drive from Kiro Crew now serves its own tools instead of having every tools/call refused with identity_unattestable, and the GitHub-hosted Windows shard stops going red on test_app_mcp_tool_policy_scope.py.
Verified against source
src/kiro_crew/mcp_shared.py:1478:_PACKAGE_DIRisdirname(realpath(__file__)), andserves_managed_tools(:1508-1512) realpaths the handler file the same way before calling_path_is_under, so both sides are resolved identically. TheOSError/ValueErrorfromrealpathstill answers True (fail closed)._path_is_under(:1515-1533): the drives are compared undernormcase(splitdrive(...))first. The only answer this changes is cross-drive, which goes from True to False. Code under the package always shares the package's drive, so a Kiro Crew server cannot take this branch. Same-drive paths still go throughcommonpath. The oneValueErrorleft (absolute mixed with relative) still answers True.- The
normcaseon the final comparison fixes a real latent bug.ntpath.commonpathreturns the casing of its first argument (the handler path), sod:\...\kiro_crew\x.pyagainstD:\...\kiro_crewused to compare unequal and read as unmanaged. - I probed more cases with
ntpath. UNC handler vs drive-letter package → False. UNC vs UNC that differ only in case → True.D:/a/kirocrew/SRC/kiro_crew/x.py(slashes and case) → True. Sibling prefixkiro_crew_evil→ False. All of these lean the right way. docs/architecture/mcp.md:1510-1521still describes the behaviour correctly ("a handler whose code location cannot be read keeps the policy"). No spec change was needed.
Tests: test/test_app_mcp_tool_policy_scope.py 10 passed; test/test_mcp_shared.py 209 passed (Linux, -n0).
Mutations (one at a time, restored between)
- Drop the drive-mismatch
return False→TestWindowsDrives::test_a_handler_on_another_drive_is_not_managedred. - Compare
common == rootwithoutnormcase→test_a_handler_under_the_package_is_managed_whatever_the_drive_casered. - Flip the remaining
except ValueError: return Trueto False →test_a_pair_commonpath_refuses_on_one_drive_keeps_the_policyred.
Blocking findings: none.
Non-blocking follow-ups
- If one side keeps an extended-length
\\?\prefix (\\?\D:\...) and the other does not, the drives compare unequal and the answer is False. Before this PR,commonpathraised and the answer was True.realpathonly keeps that prefix when the stripped path cannot be opened, and in that case the module could not have been imported anyway, so I don't think this can be reached. Stripping\\?\/\\?\UNC\before the drive comparison would close it for certain. - If a handler's
co_filenameis relative and the process changed directory after import,realpathresolves it against the new cwd. That cwd can sit on another drive and now reads as unmanaged. This is very unlikely for installed code, and the same-drive version of the problem already exists on main.
Not verified: nothing was run on a Windows host. The Windows behaviour was checked with ntpath and by reading source only.
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and readiness passed at ad477e0; no behavior change.
…r on another drive kirodotdev#20802 answers "not managed" for any drive mismatch, so the managed tool policy is skipped. That is right for an existing app file named by an absolute path, but it also fires for inputs that do not prove the handler is on another drive: a \\?\ long-path spelling on one side only (the same drive written another way), a relative co_filename (resolved against the cwd at call time) and a file that does not exist. serves_managed_tools now tells _path_is_under whether the handler is an existing file under an absolute name, and passes its own os.path so the module's path rules decide both checks. _path_is_under answers "not managed" on a drive mismatch only for such a file with no \\?\ prefix on either side; every other mismatch keeps the policy. Related: kirodotdev#20800, kirodotdev#20682
…r on another drive kirodotdev#20802 answers "not managed" for any drive mismatch, so the managed tool policy is skipped. That is right for an existing app file named by an absolute path, but it also fires for inputs that do not prove the handler is on another drive: a \\?\ long-path spelling on one side only (the same drive written another way), a relative co_filename (resolved against the cwd at call time) and a file that does not exist. serves_managed_tools now tells _path_is_under whether the handler is an existing file under an absolute name, and passes its own os.path so the module's path rules decide both checks. _path_is_under answers "not managed" on a drive mismatch only for such a file with no \\?\ prefix on either side; every other mismatch keeps the policy. Related: kirodotdev#20800, kirodotdev#20682
…r on another drive kirodotdev#20802 answers "not managed" for any drive mismatch, so the managed tool policy is skipped. That is right for an existing app file named by an absolute path, but it also fires for inputs that do not prove the handler is on another drive: a \\?\ long-path spelling on one side only (the same drive written another way), a relative co_filename (resolved against the cwd at call time) and a file that does not exist. serves_managed_tools now tells _path_is_under whether the handler is an existing file under an absolute name, and passes its own os.path so the module's path rules decide both checks. _path_is_under answers "not managed" on a drive mismatch only for such a file with no \\?\ prefix on either side; every other mismatch keeps the policy. Related: kirodotdev#20800, kirodotdev#20682
…r on another drive (#20746) * fix(mcp): keep the policy for a long-path, relative or missing handler on another drive #20802 answers "not managed" for any drive mismatch, so the managed tool policy is skipped. That is right for an existing app file named by an absolute path, but it also fires for inputs that do not prove the handler is on another drive: a \\?\ long-path spelling on one side only (the same drive written another way), a relative co_filename (resolved against the cwd at call time) and a file that does not exist. serves_managed_tools now tells _path_is_under whether the handler is an existing file under an absolute name, and passes its own os.path so the module's path rules decide both checks. _path_is_under answers "not managed" on a drive mismatch only for such a file with no \\?\ prefix on either side; every other mismatch keeps the policy. Related: #20800, #20682 * fix(mcp): compare drives without the long-path prefix Fold \\?\X:\ and \\?\UNC\server\share on both sides before the drive check with platform_compat.strip_extended_length_prefix, so a deep real app on another drive is not managed and a long-path spelling of Kiro Crew's own file still is. Drops the prefixed branch. The test fake resolves paths lexically so no case reaches a native realpath on a UNC host. A drive-relative name such as C:app\mcp_server.py has a drive but no root, so it resolves against that drive's cwd at call time and keeps the policy. A test pins the absolute-name check that decides it.
Problem / Motivation
Goal: An app MCP server on a different Windows drive than Kiro Crew serves its tools, and Backend Tests (Windows) stops failing
test_app_mcp_tool_policy_scope.pyon GitHub-hosted runners.serves_managed_toolsanswers "is this handler Kiro Crew's own code?" withos.path.commonpath([handler_file, package_dir]). On Windows,commonpathraisesValueErrorfor paths on two different drives, and the function treats that as managed. The app then gets the managed tool policy read, and on the shared ACP runtime eachtools/callis refused withidentity_unattestable. #20530 fixed that bug, and it comes back here.A GitHub-hosted Windows runner checks out on
D:and keeps its temp dir onC:, so both tests intest/test_app_mcp_tool_policy_scope.pythat load an app fromtmp_pathfail there (seen twice on #16847, Backend Tests (Windows) shard 7, job 116368074991). The self-hosted runner checks out onC:, so most runs pass.Why it matters
A real user app on another drive gets every tool call refused. And any PR whose Windows shard 7 lands on a GitHub-hosted runner is red for a reason outside its diff.
Not a goal
What changed (motivation → approach → change)
The path test moves into
_path_is_under(path, root, pathmod=os.path):normcase), the path cannot be under the package, so the answer is False. Kiro Crew's own servers always live under_PACKAGE_DIR, so this never lets one of them skip the policy.commonpathruns as before. Its result and the root are compared withnormcase, becausecommonpathkeeps its input's casing and Windows paths compare caseless. Without this, a package path that differs from_PACKAGE_DIRonly by drive-letter case read as unmanaged.ValueError(absolute mixed with relative) still answers True.pathmoddefaults toos.path. The tests passntpath, so the Windows cases run on every OS.This does not loosen the gate
A path on a different drive cannot be under the managed root, so it is exactly the not-managed case. Kiro Crew's own servers always load from
_PACKAGE_DIR, so none of them can land on that branch. Same-drive paths go through the samecommonpathcheck as before, and any otherValueErrorstill fails closed. Thentpathtests prove both: another drive answers False, and a same-drive package path (any drive-letter case) answers True, as do the fail-closed cases.Backwards compatibility
Compatible. On POSIX,
splitdrivereturns no drive for either path andnormcasechanges nothing, so the answer is unchanged. On Windows, one change: a handler on another drive is now unmanaged where it used to be managed. That case can only be third-party code.Removes nothing.
Tests
test/test_app_mcp_tool_policy_scope.py::TestWindowsDrives(new,ntpath): another drive → False; same package path with different drive-letter case → True; a sibling on the same drive → False; absolute mixed with relative on one drive → True (fail closed). Before the fix, the other-drive case raised and answered True, and the casing case answered False.test/test_app_mcp_tool_policy_scope.pyandtest/test_mcp_shared.py: 219 passed on Linux.flake8,black --check,isort --check-onlyandmypypass on both files.check_file_line_cap.pypasses.Manual verification
N/A: not run on a Windows host. The
ntpathcases cover the drive logic, and CI's Windows shards run the original two tests.Related Issues
Closes #20800
Pattern harvest
Not generalizable:
src/has 28 othercommonpathuses, and several already handle the cross-driveValueError(for exampleapps/manager.py,artifact_source.py). Each one fails a different way, open or closed, so a sweep needs its own audit.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)