Skip to content

fix(mcp): treat an app on another Windows drive as outside the package - #20802

Merged
iamwhatever merged 1 commit into
mainfrom
fix/managed-tools-cross-drive
Oct 15, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/managed-tools-cross-drive

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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.py on GitHub-hosted runners.

serves_managed_tools answers "is this handler Kiro Crew's own code?" with os.path.commonpath([handler_file, package_dir]). On Windows, commonpath raises ValueError for 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 each tools/call is refused with identity_unattestable. #20530 fixed that bug, and it comes back here.

A GitHub-hosted Windows runner checks out on D: and keeps its temp dir on C:, so both tests in test/test_app_mcp_tool_policy_scope.py that load an app from tmp_path fail there (seen twice on #16847, Backend Tests (Windows) shard 7, job 116368074991). The self-hosted runner checks out on C:, 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

  • Changing what the managed tool policy names, or how a Kiro Crew server reads it.
  • Treating any other unreadable or unresolvable path as unmanaged. Those still fail closed.

What changed (motivation → approach → change)

The path test moves into _path_is_under(path, root, pathmod=os.path):

  1. If the drives differ (compared with 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.
  2. Otherwise commonpath runs as before. Its result and the root are compared with normcase, because commonpath keeps its input's casing and Windows paths compare caseless. Without this, a package path that differs from _PACKAGE_DIR only by drive-letter case read as unmanaged.
  3. Any other ValueError (absolute mixed with relative) still answers True.

pathmod defaults to os.path. The tests pass ntpath, 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 same commonpath check as before, and any other ValueError still fails closed. The ntpath tests 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, splitdrive returns no drive for either path and normcase changes 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.py and test/test_mcp_shared.py: 219 passed on Linux.
  • flake8, black --check, isort --check-only and mypy pass on both files. check_file_line_cap.py passes.

Manual verification

N/A: not run on a Windows host. The ntpath cases 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 other commonpath uses, and several already handle the cross-drive ValueError (for example apps/manager.py, artifact_source.py). Each one fails a different way, open or closed, so a sweep needs its own audit.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

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
@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 15, 2026 11:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision ad477e0b45b52adf5dd6591184e6df2cf48c11ac touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of ad477e0b45b52adf5dd6591184e6df2cf48c11ac — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ad477e0b45b52adf5dd6591184e6df2cf48c11ac — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check that Backend Tests (Windows) shard 7 goes green on a GitHub-hosted D: runner. The ntpath tests only simulate the drive pair.

Not justified as shipped

  • Item 2 — rides along: "commonpath keeps its input's casing… a package path that differs from _PACKAGE_DIR only by drive-letter case read as unmanaged". Base behaves this way too, and no report shows it. Both sides already go through os.path.realpath (_PACKAGE_DIR = os.path.dirname(os.path.realpath(__file__)), real = os.path.realpath(filename)). Its one effect is that more paths count as managed (fail-closed), so it carries no premise risk.

What this change ships

Inventory (3 items) — 2 justified

Intent: 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).

  1. A handler on a different Windows drive from the package is now unmanaged, so its tool calls run instead of being refused with identity_unattestable. — justified
  2. A package path that differs only in drive-letter case now counts as managed. — rides along
  3. Mixing an absolute and a relative path on one drive still applies the managed policy (fails closed), now pinned by tests that run on every OS. — justified

[FIRST-PRINCIPLES-REVIEWED] ad477e0

Description read

[DESCRIPTION-READ] 6ff83a324f7145c923532c6e22d94b22101c2cc4fad42038fa8678043562fffd

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed ad477e0b45b52adf5dd6591184e6df2cf48c11ac — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] ad477e0

Verdict parsed from the review's SHA-scoped output markers for commit ad477e0b45b52adf5dd6591184e6df2cf48c11ac.

False positive or not applicable? A repository writer can comment:
/ai-review override fable ad477e0b45b52adf5dd6591184e6df2cf48c11ac: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of ad477e0b45b52adf5dd6591184e6df2cf48c11ac and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ad477e0

False positive or not applicable? A repository writer can comment:
/ai-review override gpt ad477e0b45b52adf5dd6591184e6df2cf48c11ac: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 15, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 15, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_DIR is dirname(realpath(__file__)), and serves_managed_tools (:1508-1512) realpaths the handler file the same way before calling _path_is_under, so both sides are resolved identically. The OSError/ValueError from realpath still answers True (fail closed).
  • _path_is_under (:1515-1533): the drives are compared under normcase(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 through commonpath. The one ValueError left (absolute mixed with relative) still answers True.
  • The normcase on the final comparison fixes a real latent bug. ntpath.commonpath returns the casing of its first argument (the handler path), so d:\...\kiro_crew\x.py against D:\...\kiro_crew used 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 prefix kiro_crew_evil → False. All of these lean the right way.
  • docs/architecture/mcp.md:1510-1521 still 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_managed red.
  • Compare common == root without normcase → test_a_handler_under_the_package_is_managed_whatever_the_drive_case red.
  • Flip the remaining except ValueError: return True to False → test_a_pair_commonpath_refuses_on_one_drive_keeps_the_policy red.

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, commonpath raised and the answer was True. realpath only 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_filename is relative and the process changed directory after import, realpath resolves 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 mbriones98 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks green and readiness passed at ad477e0; no behavior change.

@iamwhatever
iamwhatever merged commit 9dafed1 into main Oct 15, 2026
121 of 127 checks passed
@iamwhatever
iamwhatever deleted the fix/managed-tools-cross-drive branch October 15, 2026 17:16
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 2026
jeeshofone added a commit to jeeshofone/KiroCrew that referenced this pull request Oct 15, 2026
…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
jeeshofone added a commit to jeeshofone/KiroCrew that referenced this pull request Oct 15, 2026
…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
jeeshofone added a commit to jeeshofone/KiroCrew that referenced this pull request Oct 16, 2026
…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
KiroCrewCaptain pushed a commit that referenced this pull request Oct 17, 2026
…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.
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.

Windows: app MCP tools refused when the app is on another drive than Kiro Crew

3 participants