Repository navigation
fix(mcp): repair Windows command casing at every resolver, not only the rewriter - #15071
Conversation
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the Windows CI shard runs the new test file green — the launcher-shim acceptance itself is still only encoded, not reproduced, in this PR. [DESIGN-REVIEWED] d1b78da Description read[DESCRIPTION-READ] 1939f1e784d31e86fe8cc0affbdb93dcabfdc87f164591507f9e443394696fea 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 (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Description admits "Not run on a Windows host with a launcher shim" — confirm the Windows CI shard greens this file on a real NTFS PATHEXT host before merge. What this change shipsInventory (5 items) — 5 justifiedIntent: On Windows, make every MCP server declared by bare name start even behind a case-sensitive launcher shim, by repairing
Counts run: [FIRST-PRINCIPLES-REVIEWED] d1b78da Description read[DESCRIPTION-READ] 411fcdc5d7b146504b33ca3832c6f5bec6baff065a1e88899dff7ccc483bea78 That sha256 names the PR description this verdict read. Recompute it with |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed |
buluoray
left a comment
There was a problem hiding this comment.
Requesting changes at 457210d. resolved_command_casing itself reads correctly. Two things are in the way.
1. test_an_ambiguous_directory_keeps_the_which_result fails on real Windows because of how the test is built. This is the Backend Tests (Windows) (4) red.
The test writes bin/demo-mcp.exe and then bin/Demo-Mcp.exe and expects two directory entries. NTFS on a stock Windows runner is case-insensitive, so the second write_text overwrites the first file and no second entry exists (sibling.exists() still passes because the lookup is case-insensitive). scandir returns one entry, the helper correctly finds a single match and repairs .EXE to .exe, and the == raw assertion fails:
assert 'C:\\Users\\r...\\demo-mcp.exe' == 'C:\\Users\\r...\\demo-mcp.EXE'
The helper is right. The test's premise ("this host's filesystem stands in for it") only holds on a case-sensitive filesystem. Two ways to fix it: probe for case sensitivity (write a, check whether A exists) and pytest.skip the test where it isn't, or build the ambiguous directory without touching the disk by monkeypatching os.scandir to yield two entries. The second also keeps the assertion running on Windows, which is where this test matters.
2. src/kiro_crew/agent.py conflicts with main. git merge-tree against origin/main shows CONFLICT (content) there, and the branch is 120 commits behind. It needs a rebase before CI can mean anything.
Not this PR: the Backend Tests (3.12, 2) red is test_remote_crew_chaining.py (hop port ownership), which this diff doesn't touch. Coverage Gate fails because the shards failed.
|
Heads-up: I'm force-pushing this branch ( |
457210d to
aa7c0bd
Compare
|
self-added: yes
|
|
self-added: yes
|
|
@buluoray thanks, both points are addressed in 1.
It now runs, and means the same thing, on Windows, macOS and Linux. Mutation check: weakening the helper's 2. Also folded in: the Opus lane's advisory that the helper's docstring over-claimed "every consumer of a Negative control on the rebased head: reverting the two call sites (helper kept) fails the three call-site tests and passes the ten helper tests; reverting all of I'll ping again once CI is green. |
|
Pushed |
aa7c0bd to
ba68853
Compare
…he rewriter On Windows `shutil.which` spells the extension it appends exactly as PATHEXT spells it, so a bare `demo-mcp` resolves to `demo-mcp.EXE` while the file on disk is `demo-mcp.exe`. A launcher that dispatches on its own argv[0] basename case-sensitively (a tool manager's multiplexer shim) refuses to run under that spelling and the MCP server never starts. The rewriter already restored the on-disk basename, but the agent-config resolver (`agent._resolve_command`) and the dashboard probe (`mcp_discovery`) consumed raw `which` output, and the resolver's result is PERSISTED as the spec's absolute `command`. An absolute command is accepted verbatim on every later pass, so the uppercase spelling written once looked operator-authored to the rewriter from then on and its repair never ran. Move the helper to `kiro_crew.env.resolved_command_casing`, beside the `mcp_search_path` the three resolvers already share, and apply it on both return paths of `_resolve_command` and in the probe. Repairing at the resolver also keeps the provenance record's `emitted` value repaired, so `command_is_ours` still recognises the entry and re-derivation stays on. Fixes #11627 (cherry picked from commit aa7c0bd, #15071; applied as its pre-#14919 revision 457210d plus the round-2 test and docstring delta, since release/0.8.0 predates the agent.py split)
|
|
self-added: yes
|
ba68853 to
b1a11b3
Compare
…he rewriter On Windows `shutil.which` spells the extension it appends exactly as PATHEXT spells it, so a bare `demo-mcp` resolves to `demo-mcp.EXE` while the file on disk is `demo-mcp.exe`. A launcher that dispatches on its own argv[0] basename case-sensitively (a tool manager's multiplexer shim) refuses to run under that spelling and the MCP server never starts. The rewriter already restored the on-disk basename, but the agent-config resolver (`agent._resolve_command`) and the dashboard probe (`mcp_discovery`) consumed raw `which` output, and the resolver's result is PERSISTED as the spec's absolute `command`. An absolute command is accepted verbatim on every later pass, so the uppercase spelling written once looked operator-authored to the rewriter from then on and its repair never ran. Move the helper to `kiro_crew.env.resolved_command_casing`, beside the `mcp_search_path` the three resolvers already share, and apply it on both return paths of `_resolve_command` and in the probe. Repairing at the resolver also keeps the provenance record's `emitted` value repaired, so `command_is_ours` still recognises the entry and re-derivation stays on. Fixes #11627 (cherry picked from commit aa7c0bd, #15071; applied as its pre-#14919 revision 457210d plus the round-2 test and docstring delta, since release/0.8.0 predates the agent.py split)
…he rewriter On Windows `shutil.which` spells the extension it appends exactly as PATHEXT spells it, so a bare `demo-mcp` resolves to `demo-mcp.EXE` while the file on disk is `demo-mcp.exe`. A launcher that dispatches on its own argv[0] basename case-sensitively (a tool manager's multiplexer shim) refuses to run under that spelling and the MCP server never starts. The rewriter already restored the on-disk basename, but the agent-config resolver (`agent._resolve_command`) and the dashboard probe (`mcp_discovery`) consumed raw `which` output, and the resolver's result is PERSISTED as the spec's absolute `command`. An absolute command is accepted verbatim on every later pass, so the uppercase spelling written once looked operator-authored to the rewriter from then on and its repair never ran. Move the helper to `kiro_crew.env.resolved_command_casing`, beside the `mcp_search_path` the three resolvers already share, and apply it on both return paths of `_resolve_command` and in the probe. Repairing at the resolver also keeps the provenance record's `emitted` value repaired, so `command_is_ours` still recognises the entry and re-derivation stays on. Fixes kirodotdev#11627
|
Rebased: main moved in src/kiro_crew/acp/skill_projection.py, src/kiro_crew/platform_compat.py since this head went green (321fd99 -> 7460284); CI re-running. That range includes #15633, the fix for the main-wide |
b1a11b3 to
d1b78da
Compare
…he rewriter On Windows `shutil.which` spells the extension it appends exactly as PATHEXT spells it, so a bare `demo-mcp` resolves to `demo-mcp.EXE` while the file on disk is `demo-mcp.exe`. A launcher that dispatches on its own argv[0] basename case-sensitively (a tool manager's multiplexer shim) refuses to run under that spelling and the MCP server never starts. The rewriter already restored the on-disk basename, but the agent-config resolver (`agent._resolve_command`) and the dashboard probe (`mcp_discovery`) consumed raw `which` output, and the resolver's result is PERSISTED as the spec's absolute `command`. An absolute command is accepted verbatim on every later pass, so the uppercase spelling written once looked operator-authored to the rewriter from then on and its repair never ran. Move the helper to `kiro_crew.env.resolved_command_casing`, beside the `mcp_search_path` the three resolvers already share, and apply it on both return paths of `_resolve_command` and in the probe. Repairing at the resolver also keeps the provenance record's `emitted` value repaired, so `command_is_ours` still recognises the entry and re-derivation stays on. Fixes #11627 (cherry picked from commit aa7c0bd, #15071; applied as its pre-#14919 revision 457210d plus the round-2 test and docstring delta, since release/0.8.0 predates the agent.py split)
|
@buluoray could you re-review? Both of your points are addressed (replies above). The current head |
… release/0.8.0 (#15619) * fix(windows): backport the directory-junction hardening to release/0.8.0 (#15666) Backport of #14327, #14962, #15310 to release/0.8.0, cherry-picked in main's merge order. * fix(windows): anchor six directory-link fences to pinned descriptors (#14327) (cherry picked from commit 6b0a6d5) * fix(config): refuse a link or junction at the workspace dir name (#14962) (cherry picked from commit 4bb50ef) * fix(windows): make four is_symlink guards see a junction (#12379, #10492) (#15310) (cherry picked from commit 6d54165) * style(test): black-format the failed-start reap test and drop its history wording on release/0.8.0 (#15665) test/test_acp_runtime_failed_start_reap.py arrived with #15625 not black-formatted (fails scripts/check_black_formatting.py on the release tip), and the _gone docstring said "no longer runs", which scripts/check_comment_history.py flags as history narration. Black 26.3.1 (--target-version py310) reflow, and the docstring now reads "has stopped running", the wording the #15664 forward-port uses. Test file only. * fix(adaptive): keep a same-window gate step from eating idle recovery (#15595) Idle recovery (#15541) took its exec step only when nothing else had changed on the sample. A spawn-gate increase earned on the same sample set that shared flag, so the idle exec step due on it was skipped, and the gate step also restarted the one-increase-per-window clock: the exec cap then waited a further window for a step it had already been due. Judge the idle step on the exec track alone. Both tracks keep sharing one increase-per-window clock across samples, as the earn rules do. An increase's reason now names each track it moved: the exec note only when the exec cap moved, and every gate step as "spawn gate target X -> Y" (the policy's target; the daemon confirms or clamps it). A gate-only step used to read "clean window earned +1", and a gate step beside an exec step was not mentioned at all. (cherry picked from commit f23a39f) * fix(acp): treat only JSON whitespace as an empty mcp.json (#15673) #15627 read an empty or whitespace-only MCP settings file as absent, using bytes.strip() with no argument. That also strips \x0b and \x0c, which JSON does not allow, so a file holding only those bytes read as "no restrictions" instead of failing closed like any other malformed document. The emptiness check now strips only space, tab, CR and LF (RFC 8259); anything else goes to the parser and fails closed as before #15627. Refs #15616 (cherry picked from commit 157fd51) * fix(sandbox): backport the scope probe PATH and bus-path fixes to release/0.8.0 (#15638) * fix(sandbox): keep the scope probe refresh off PATH, decode bus paths Two defects the post-logout probe fix (#15622) introduced, from its review: - The probe now refreshes on a TTL, and every refresh resolved systemd-run with shutil.which on the event loop. A PATH entry on a stalled mount would hang the gateway's loop. The probe now uses platform_compat.trusted_system_bin, the same fixed-directory lookup cgroup_scope_argv already pins its wrapper with. - DBUS_SESSION_BUS_ADDRESS unix:path= values may percent-escape any byte. Probing the escaped spelling literally misses a live bus that lives outside XDG_RUNTIME_DIR and drops the cgroup ceiling. The value is now decoded before it is dialed. (cherry picked from commit e5a68df) (cherry picked from commit 623f2b4) * fix(sandbox): resolve the probe's systemd-run without any PATH walk Second-round review of this PR: trusted_system_bin's miss diagnostic still calls shutil.which, so a host with no trusted systemd-run walked PATH on the event loop at the first probe refresh. The probe now uses platform_compat.trusted_system_bin_quiet, the same fixed-directory lookup without the diagnostic, and reports the miss in its reason. A D-Bus unix:path= value that decodes to an empty path or one holding a NUL cannot name a socket and made os.stat raise ValueError on the spawn path; such values are now skipped. (cherry picked from commit 5843231) * fix(chat): restore the interrupted turn when Resume lands on a natively loaded session (#15643) (#15644) * fix(chat): restore the interrupted turn when Resume lands on a natively loaded session (#15643) kiro-cli appends a prompt to <sid>.jsonl only once the model has answered it. When the process serving a turn dies mid-answer (a gateway restart, a crash, a recycled runtime) that request is never written, so session/load brings the conversation back without it. A natively resumed session gets no Kiro Crew replay, so the Resume press on that turn sent a bare "finish the user's most recent request" with the request missing: the model answered the turn before it, or said there was nothing to continue. Reproduced against kiro-cli 2.26.1: after a completed turn and a second turn killed mid-stream, session/load restores only the first. The path is any native resume: a dashboard chat with agent.tool_search off, a dashboard chat linked to a channel, and the automatic connection-lost recovery on a respawned runtime. When the Resume message or the connection-lost recovery runs on a session that this turn natively resumed, _run_chat now prepends the interrupted turn from the slot's own transcript (the opener the turn-in-flight marker restores, plus the partial answer), bracketed [INTERRUPTED TURN] so the context scanner attributes it. A cold start that replays already carries the turn and is unchanged. A session whose only turn was interrupted was already covered: SessionMap.get prunes a sid whose log holds no turn. Backport of #15643 to release/0.8.0. Conflict: context.py still carries compress_thread_history here (removed on main by #14952); the new helper is placed after it. * fix(chat): open the interrupted-turn restore at the right row, and mint it after the scrub (#15643) A cron, app or synthesis delivery opens its turn as an inject row. The interrupted-turn walk only stopped at user, nudge and sub-agent rows, so for such a turn it reached the already-answered request before it and restored that as the user's most recent request. Openers now include the inject kinds dashboard.state.TURN_OPENING_INJECT_KINDS names (the dispatching kinds minus recovery and user_replay, which continue a turn). The session-busy recovery (_BUSY_RECOVER_MSG) also resets the session and session/loads the same native conversation, so it gets the restore too. The frame tells the model the request inside it is the one to carry on with, so its markers join _STRUCTURAL_MARKER_RES and the runner prepends it after the egress scrub, like the task checklist; the builder scrubs the restored payload itself. The turn-in-flight marker now copies a sub-agent completion opener too (_LOCAL_TURN_OPENER_ROLES / _LOCAL_TURN_PROMPT_ROLES): without it a crash before the flush loses that row, and the restore would walk past it to the previous, already-answered request. * fix(mcp): repair Windows command casing at every resolver, not only the rewriter On Windows `shutil.which` spells the extension it appends exactly as PATHEXT spells it, so a bare `demo-mcp` resolves to `demo-mcp.EXE` while the file on disk is `demo-mcp.exe`. A launcher that dispatches on its own argv[0] basename case-sensitively (a tool manager's multiplexer shim) refuses to run under that spelling and the MCP server never starts. The rewriter already restored the on-disk basename, but the agent-config resolver (`agent._resolve_command`) and the dashboard probe (`mcp_discovery`) consumed raw `which` output, and the resolver's result is PERSISTED as the spec's absolute `command`. An absolute command is accepted verbatim on every later pass, so the uppercase spelling written once looked operator-authored to the rewriter from then on and its repair never ran. Move the helper to `kiro_crew.env.resolved_command_casing`, beside the `mcp_search_path` the three resolvers already share, and apply it on both return paths of `_resolve_command` and in the probe. Repairing at the resolver also keeps the provenance record's `emitted` value repaired, so `command_is_ours` still recognises the entry and re-derivation stays on. Fixes #11627 (cherry picked from commit aa7c0bd, #15071; applied as its pre-#14919 revision 457210d plus the round-2 test and docstring delta, since release/0.8.0 predates the agent.py split)
|
@buluoray thanks for the review. Your points were addressed before merge:
This was admin-merged as |
Problem / Motivation
Goal: Every MCP server declared with a bare command name starts on Windows, including servers behind a tool manager's launcher shim.
On Windows,
shutil.whichspells the extension it appends exactly asPATHEXTspells it (.COM;.EXE;.BAT;.CMD, upper case on a stock install), so a baredemo-mcpinmcp.jsonresolves toC:\...\bin\demo-mcp.EXEwhile the file on disk isdemo-mcp.exe. A launcher that dispatches on its ownargv[0]basename case-sensitively refuses to run under that spelling, exits, and the user sees onlyMCP error -32000: Connection closed(or, in the MCP Management page,no response stderr: <launcher>: Unable to run demo-mcp.EXE: Command "demo-mcp.EXE" doesn't appear to be associated with any tool).Why it matters
On an affected host every MCP server whose command resolves to such a launcher fails to start: the report behind this fix counted 16 servers across 3 agent spec files on one machine. The only workaround is to hand-wrap each server in
cmd.exe /c <name>or hand-edit the generated spec, and the failure message names nothing that points at casing.Not a goal
acp/client.py's_normalize_exe_casing(kiro-cli launch path,realpathbased). It is a separate resolver with its own alias semantics; reconciling it is a follow-up.commandis accepted verbatim by design; the provenance record'scommand_is_oursdecides whether a stored value is re-derived, and this PR keeps that rule unchanged.mcp_search_path) or to which directories are consulted.What changed (motivation → approach → change)
agent._resolve_command), persisted to the specwhichresultmcp_discovery.probe_server)whichresultmcp_gateway/rewriter.py)_target_command_casingSymptom: uppercase
.EXEspellings are persisted into~/.kiro/agents/*.jsonand spawned by the dashboard probe.Root cause: the casing repair existed only in the gateway rewriter. The agent-config resolver writes its
whichresult as the spec's absolutecommand, and an absolute command is accepted verbatim on every later pass and treated by the rewriter as operator-authored. So an uppercase spelling written once became permanent and the rewriter's repair never ran for it. The probe spawned the raw spelling too. The three MCP resolvers agreed on WHERE they look (mcp_search_path) but not on WHAT they emit.Change: the helper moves to
kiro_crew.env.resolved_command_casinginsrc/kiro_crew/env.py, besidemcp_search_path, with the same algorithm: scan the parent directory for a unique case-insensitive match and rebuild the path lexically, so a file symlink keeps its own name and a junction route is preserved.Nonebecomes""; POSIX paths, an unreadable parent and an ambiguous directory keep thewhichresult. Both return paths of_resolve_commandand the probe route through it, and the rewriter imports it in place of its private copy. An absolute command that exists and is executable is the operator's own spelling: all three resolvers keep it verbatim, the probe by the sameisabs/isfile/X_OKpredicate_resolve_commanduses, so the probe never spawns a spelling the session does not. Repairing inside the resolver, not at the write site, keeps the provenance record'semittedvalue repaired, socommand_is_oursstill recognises the entry and re-derivation stays on. The helper's docstring anddocs/architecture/mcp.mdname its scope: the three MCP server command resolvers, not the resolvers of Kiro Crew's own binaries (agent._resolve_kirocrew_bin, andacp/client.py's_normalize_exe_casing).Backwards compatibility
Compatible: only the basename casing of a PATH-resolved command changes, only on Windows, and only when the parent directory holds exactly one case-insensitive match. Explicit absolute commands, POSIX paths, unresolved commands and ambiguous directories are emitted exactly as before. The rewriter's fingerprint schema already covers casing-only changes to bare-command probes.
Tests
New
test/test_mcp_command_casing_shared.py(14 tests). Windows is forced per helper call, not per test, so the rest of the rebuild and probe run on the host platform. No verdict depends on whether the host filesystem is case-sensitive.TestSharedHelper: repairs a PATHEXT-synthesized extension; repairs a stem that differs in case; exact match unchanged;Noneand""become""; POSIX untouched; an unreadable parent keeps thewhichresult. The ambiguous-directory case is described to the helper through a fakedos.scandirlisting (two case variants, and three entries with an unrelated one), because NTFS and APFS fold a second case-variant file onto the first. A one-entry control in the same parametrization proves the faked listing is what the helper reads.TestAgentConfigResolver: a realinstall_agentrebuild withwhichreturningdemo-mcp.EXEpersistsdemo-mcp.exeintokirocrew.json, on the PATH-search branch and on the directory-component branch.TestDashboardProbe:probe_serverspawns[demo-mcp.exe, --stdio], captured at the sandbox wrap; an operator-declared absolutebin/DEMO-MCP.exeis spawned verbatim even when the repair (faked to answerdemo-mcp.exe, as a case-insensitive directory would) disagrees. That test fails with the probe's absolute short-circuit removed.Negative controls: with the two call-site changes reverted (raw
shutil.whichrestored inagent.pyandmcp_discovery.py), the three call-site tests fail and the other eleven pass; with all production files reverted, every test fails. Weakening the helper'slen(matches) != 1guard tonot matchesfails both ambiguous cases while the control passes.Also run locally:
test_mcp_gateway_command_casing.py,test_mcp_gateway_rewriter*.py,test_mcp_discovery.py,test_mcp_rebuild_*.py,test_mcp_field_provenance.py,test_agent.py,test_env*.py(1032 passed). black, isort, flake8 and mypy clean.Manual verification
Not run on a Windows host with a launcher shim in this PR. The reproduction in #11627 (spawning
foo-mcp.EXEvsfoo-mcp.exeagainst the same launcher) is what the agent-config and probe tests encode; the Windows CI shards run the whole file on the real platform.Screenshots / video
N/A — no user-visible frontend surface is touched.
Related Issues
Fixes #11627
Follow-up to #11294
Pattern harvest
Rule candidate: review-prompt
Pattern: a normalization applied to one consumer of
shutil.whichoutput while sibling resolvers that share the same search path persist or spawn the raw value; the persisted value then launders a synthesized spelling into an operator-authored one.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)