Skip to content

fix(mcp): repair Windows command casing at every resolver, not only the rewriter - #15071

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
bolichen97:fix/mcp-command-casing-11627
Oct 1, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
bolichen97:fix/mcp-command-casing-11627

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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.which spells the extension it appends exactly as PATHEXT spells it (.COM;.EXE;.BAT;.CMD, upper case on a stock install), so a bare demo-mcp in mcp.json resolves to C:\...\bin\demo-mcp.EXE while the file on disk is demo-mcp.exe. A launcher that dispatches on its own argv[0] basename case-sensitively refuses to run under that spelling, exits, and the user sees only MCP 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

  • Changing acp/client.py's _normalize_exe_casing (kiro-cli launch path, realpath based). It is a separate resolver with its own alias semantics; reconciling it is a follow-up.
  • Repairing spellings already persisted in an existing user's agent spec. An absolute command is accepted verbatim by design; the provenance record's command_is_ours decides whether a stored value is re-derived, and this PR keeps that rule unchanged.
  • Any change to the search path (mcp_search_path) or to which directories are consulted.

What changed (motivation → approach → change)

Resolver Before After
agent-config (agent._resolve_command), persisted to the spec raw which result on-disk basename
dashboard probe (mcp_discovery.probe_server) raw which result on-disk basename; an existing absolute command runs verbatim, as in the other two
gatewayd rewriter (mcp_gateway/rewriter.py) private _target_command_casing the same shared helper

Symptom: uppercase .EXE spellings are persisted into ~/.kiro/agents/*.json and spawned by the dashboard probe.

Root cause: the casing repair existed only in the gateway rewriter. The agent-config resolver writes its which result as the spec's absolute command, 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_casing in src/kiro_crew/env.py, beside mcp_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. None becomes ""; POSIX paths, an unreadable parent and an ambiguous directory keep the which result. Both return paths of _resolve_command and 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 same isabs/isfile/X_OK predicate _resolve_command uses, so the probe never spawns a spelling the session does not. Repairing inside the resolver, not at the write site, keeps the provenance record's emitted value repaired, so command_is_ours still recognises the entry and re-derivation stays on. The helper's docstring and docs/architecture/mcp.md name its scope: the three MCP server command resolvers, not the resolvers of Kiro Crew's own binaries (agent._resolve_kirocrew_bin, and acp/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; None and "" become ""; POSIX untouched; an unreadable parent keeps the which result. The ambiguous-directory case is described to the helper through a faked os.scandir listing (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 real install_agent rebuild with which returning demo-mcp.EXE persists demo-mcp.exe into kirocrew.json, on the PATH-search branch and on the directory-component branch.
  • TestDashboardProbe: probe_server spawns [demo-mcp.exe, --stdio], captured at the sandbox wrap; an operator-declared absolute bin/DEMO-MCP.exe is spawned verbatim even when the repair (faked to answer demo-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.which restored in agent.py and mcp_discovery.py), the three call-site tests fail and the other eleven pass; with all production files reverted, every test fails. Weakening the helper's len(matches) != 1 guard to not matches fails 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.EXE vs foo-mcp.exe against 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.which output 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

  • 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

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of d1b78da5c0b87c7331d240c1a0b0fc28423af85d via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 .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

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of d1b78da5c0b87c7331d240c1a0b0fc28423af85d via the fork AI-review pipeline — 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

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 ships

Inventory (5 items) — 5 justified

Intent: On Windows, make every MCP server declared by bare name start even behind a case-sensitive launcher shim, by repairing which's PATHEXT casing at all three MCP resolvers — a FIX (#11627, follow-up to #11294).

  1. Agent specs now persist a bare command's on-disk basename casing, on both resolver branches — justified
  2. The dashboard probe now spawns the on-disk casing instead of the raw which spelling — justified
  3. The probe runs an existing absolute, executable command verbatim, skipping PATH search and repair — justified
  4. The casing repair becomes one shared helper env.resolved_command_casing, replacing the rewriter's private copy — justified
  5. docs/architecture/mcp.md updated to name the shared repair and its scope in the same commit — justified

Counts run: resolved_command_casing has 6 call sites across 3 modules (agent.py ×2, mcp_discovery.py ×1, rewriter.py ×3) — no zero-consumer or single-consumer surface. One sibling resolver (acp/client.py:_normalize_exe_casing, realpath-based, 7 call sites) stays unfixed; the description declares it, names why its alias semantics differ, and defers it — accepted-and-deferred, not a point patch. The fix sits at cause level: the persisting resolver, not the write site.

[FIRST-PRINCIPLES-REVIEWED] d1b78da

Description read

[DESCRIPTION-READ] 411fcdc5d7b146504b33ca3832c6f5bec6baff065a1e88899dff7ccc483bea78

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

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed d1b78da5c0b87c7331d240c1a0b0fc28423af85d via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d1b78da

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed b1a11b3bc39fa48e5c66058882100b48cc007840 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] b1a11b3

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Sep 29, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) September 30, 2026 01:55

@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.

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.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Heads-up: I'm force-pushing this branch (457210dd65 → aa7c0bd85e) to rebase onto current main (the agent.py import conflict) and to fix the Windows-failing ambiguous-directory test. It stays one commit; per-point replies to the review follow once it is up.

@bolichen97
bolichen97 force-pushed the fix/mcp-command-casing-11627 branch from 457210d to aa7c0bd Compare October 1, 2026 00:08
@bolichen97

bolichen97 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: ambiguous directory described via a scoped os.scandir fake, plus a one-entry control

  • span=af01f1795ea1 fixed: ambiguous-directory test wrote two case-variant files that NTFS/APFS fold into one

fixed in aa7c0bd: test_an_ambiguous_directory_keeps_the_which_result no longer writes files; it hands the helper a faked os.scandir listing, scoped with MonkeyPatch.context() to the one helper call.
Parametrized: two case variants, and three entries including an unrelated one, both keep the which result; a one-entry control is repaired, which proves the fake is what the helper reads (it also asserts the listed parent).
Mutation: weakening len(matches) != 1 to not matches fails both ambiguous cases while the control passes. The verdict no longer depends on host case sensitivity.

@bolichen97

bolichen97 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=f6ebc043cec9 fixed: resolved_command_casing docstring claimed every spawned/persisted which consumer routes through it

fixed in aa7c0bd: the docstring and the docs/architecture/mcp.md paragraph now name the scope as the three MCP server command resolvers (agent-config resolver, dashboard probe, rewriter).
Both name the resolvers of Kiro Crew's own binaries that stay outside it: the kirocrew lookup in agent._resolve_kirocrew_bin, and the kiro-cli launch path in acp/client.py with its own _normalize_exe_casing (already a Not-a-goal of this PR).

@bolichen97

Copy link
Copy Markdown
Contributor Author

@buluoray thanks, both points are addressed in aa7c0bd85e. Your review has no inline threads, so I'm replying per point here.

1. test_an_ambiguous_directory_keeps_the_which_result on NTFS. I took your second option. The test no longer writes two case-variant files. It describes the directory to the helper through a faked os.scandir, which is the only thing the helper reads. The fake is scoped with MonkeyPatch.context() to the one helper call, so tmp_path teardown still lists real directories. The test is parametrized:

  • [demo-mcp.exe, Demo-Mcp.exe] → keeps demo-mcp.EXE
  • [Demo-Mcp.exe, DEMO-MCP.exe, unrelated.exe] → keeps demo-mcp.EXE
  • [demo-mcp.exe] (control) → repaired to demo-mcp.exe. This proves the fake is what's being read; the test also asserts the parent it was asked to list.

It now runs, and means the same thing, on Windows, macOS and Linux. Mutation check: weakening the helper's len(matches) != 1 guard to not matches fails both ambiguous cases while the control passes. The file's other tests each put a single real file on disk, so their verdicts don't depend on case sensitivity either.

2. agent.py conflict. Rebased onto main @ d979c2af64. The only conflict was the kiro_crew.env import block, which main collapsed to mcp_search_path, spec_path_key; I kept main's imports and added resolved_command_casing. _resolve_command itself is still in agent.py, and both of its return paths route through the helper as before.

Also folded in: the Opus lane's advisory that the helper's docstring over-claimed "every consumer of a which result". The docstring and docs/architecture/mcp.md now scope it to the three MCP server resolvers and name agent._resolve_kirocrew_bin and acp/client.py's _normalize_exe_casing as outside it.

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 src/ fails all 13. Locally: the casing, rewriter, discovery, rebuild, provenance, test_agent.py and test_env*.py suites (1031 passed), plus black, isort, flake8 and mypy, are clean.

I'll ping again once CI is green.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 1, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 1, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Pushed ba68853872 (one commit, rebased onto current main): the only change from aa7c0bd85e is rewording one test docstring that tripped the Comment History Gate ("no longer" → "does not"). I cancelled aa7c0bd85e's in-flight runs first.

@bolichen97
bolichen97 force-pushed the fix/mcp-command-casing-11627 branch from aa7c0bd to ba68853 Compare October 1, 2026 00:32
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…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)
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=a529eb4d03b6 rebutted: fold shutil.which + resolved_command_casing into one mcp_which()

The three resolvers share only the step this helper owns, "repair a which result", and differ on the branches a mcp_which() would have to absorb.
Dead absolute path: agent._resolve_command falls through to which (directory-component branch); rewriter._resolve_target_command returns "" and records nothing; the probe reports an unresolved error with reported_path="".
Search-path reporting: agent and probe return/report the searched path, while the rewriter records each which result in notes.which_results for its fingerprint cache.
One wrapper would either change one resolver's contract or take per-caller flags, i.e. a new abstraction with three modes.
The drift risk it names is pinned per call site instead: TestAgentConfigResolver (both branches) and TestDashboardProbe fail when a call site drops the repair (negative control in the PR body).

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 1, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: probe keeps an existing absolute command verbatim (agent._resolve_command's isabs/isfile/X_OK predicate)

  • span=e35c60ed3f61 fixed: probe repaired an operator-declared absolute command the other two resolvers keep verbatim

fixed in b1a11b3: probe_server uses server.command verbatim when it is absolute, a file, and executable, the same predicate as agent._resolve_command's short-circuit and rewriter._resolve_target_command's absolute branch. Everything else still goes through resolved_command_casing(shutil.which(...)).
Regression test TestDashboardProbe::test_an_absolute_command_keeps_the_operator_spelling: a real executable bin/DEMO-MCP.exe with the repair faked to answer demo-mcp.exe (a case-insensitive directory's view), so it doesn't depend on the host's case sensitivity. It fails with the short-circuit removed and passes with it.
A dead or non-executable absolute command still falls through to which, as on main.

@bolichen97
bolichen97 force-pushed the fix/mcp-command-casing-11627 branch from ba68853 to b1a11b3 Compare October 1, 2026 01:45
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…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)
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 1, 2026
…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
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 1, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

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 Backend Tests (Windows) (2) red in test_native_skill_projection.py that b1a11b3bc3 inherited. The PR diff itself is unchanged.

@bolichen97
bolichen97 force-pushed the fix/mcp-command-casing-11627 branch from b1a11b3 to d1b78da Compare October 1, 2026 02:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 1, 2026
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…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)
@bolichen97

Copy link
Copy Markdown
Contributor Author

@buluoray could you re-review? Both of your points are addressed (replies above). The current head d1b78da5c0 is rebased onto main @ 746028435c, which includes #15633, so Backend Tests (Windows) (2) should clear; that run is in progress now. Backend Tests (Windows) (4), the shard that held point 1, already passed on the previous head b1a11b3bc3 (same diff). On that head the GPT, Opus, Design and First Principles lanes all came back with no findings, and every other check was green. The one code change since your review beyond your two points: the probe keeps an operator's absolute command verbatim, matching _resolve_command and the rewriter (Opus finding, disposition above). The release/0.8.0 backport is #15619.

@bolichen97
bolichen97 merged commit ecdc59a into kirodotdev:main Oct 1, 2026
95 of 96 checks passed
bolichen97 added a commit that referenced this pull request Oct 1, 2026
… 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)
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 1, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

@buluoray thanks for the review. Your points were addressed before merge:

  • Ambiguous-directory test on NTFS: it now hands the helper a faked os.scandir listing (with a one-entry control), so it runs, and means the same thing, on any host filesystem. Backend Tests (Windows) (4) is green.
  • agent.py conflict: rebased onto current main; the import block was the only conflict.

This was admin-merged as ecdc59abf4 for the 0.8.0.4 hotfix, and the release/0.8.0 backport #15619 landed as f51e027cbf. Any further feedback is welcome, and I'll pick it up in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: #11294's command-casing repair is missing at the agent-config and probe resolvers, so PATHEXT-cased commands are still persisted

2 participants