Skip to content

fix: escape % in the pi gate launcher's cmd paths on windows - #32142

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/27851-pi-launcher-percent
Nov 7, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/27851-pi-launcher-percent

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Windows, a % in the pi path or the gate extension path reaches pi as written, so pi sessions on that install start.

On Windows the pi harness writes a .cmd launcher that names the pi binary and the sealed gate extension. cmd.exe expands %NAME% in a batch file even inside double quotes, so a folder a%OS%b reaches the harness as aWindows_NTb. A % in the pi path makes the launcher exit 1; a % in the extension path hands pi another file. Either way the gate read-back refuses every pi session, and the message does not point at the %.

Why it matters

Windows allows % in folder and account names. On such an install every pi session is refused before the first prompt, with a remedy (reinstall pi) that does not help.

Not a goal

What changed (motivation → approach → change)

cmd.exe re-expands % in the launcher line, so the paths pi gets are not the paths Crew wrote. The Windows branch of _pi_gate_launcher_body in src/kiro_crew/acp/harness/pi.py now passes both paths through a small local helper, _pi_cmd_literal, with the same rule pod/windows.py _cmd_literal already uses: % doubles, and a ", CR or LF is refused with an AcpError naming the path, because cmd.exe cannot express it. The helper is local so it raises the harness's own error, as testing/harness.py does.

%* stays bare. The POSIX branch, the --extension order and the launcher cache key (raw values) do not change. A path without % gives byte-identical launcher text.

Backwards compatibility

Compatible: a path without %, " or a newline gives the same launcher bytes as before. A path with " or a newline already could not work (cmd.exe cannot quote it); it is now refused with a message naming it.

Removes nothing: the change only escapes % in two paths and refuses two shapes that could never run.

Tests

  • test/test_acp_pi_backend.py::TestGateLauncher::test_the_windows_body_keeps_a_percent_in_either_path_literal: with IS_WINDOWS patched, C:\a%OS%b\pi.cmd and C:\x%y\g.ts come out as %%, %* stays bare, and a path with " raises AcpError naming it.
  • Targeted: test_acp_pi_backend.py, test_acp_pi_node_guard.py, test_acp_refactor_facade.py (506 passed, 36 skipped) and scripts/local-gate.py (5614 passed). Its 3 failures (test_pi_real_adapter pinned pi-acp version, two test_pid_lifecycle reclaim tests) fail the same way on main on this host.
  • Determinism: TestGateLauncher (14 tests) run 10 times, each in a different shuffled order (seeds 0-9): 10 of 10 green. The new test is a pure function of its inputs.

Proof: PROVEN test/test_acp_pi_backend.py::TestGateLauncher::test_the_windows_body_keeps_a_percent_in_either_path_literal (head e522729)

Manual verification

On native Windows 11, against the real module and real cmd.exe (cmd.exe /d /c <launcher> --mode rpc, a pi.cmd stub that echoes its arguments):

Paths main this PR
p%OS%i\pi.cmd, x%OS%y\gate.ts exit 1, "The system cannot find the path specified." exit 0, extension passed byte-for-byte
a%b\pi.cmd, c%d\gate.ts exit 1, same error exit 0, byte-for-byte
no % exit 0 exit 0, launcher bytes identical

The issue's portable script: unescaped: FAIL rc=1, doubled: PASS rc=0.

Real pi (pi.cmd from npm) gate read-back, data home kc%27851: on main pi fails with Extension path does not exist: ...\kcrpc7851\... (cmd.exe read %2 as the second argument), so the session would be refused; with this PR the gate extension loads from the sealed copy.

Related Issues

Closes #27851
Refs #10439

Sibling sweep

Swept: git grep -n "@echo off" -- src
Sibling: src/kiro_crew/pod/windows.py:423 -- not affected -- already doubles % through _cmd_literal
Sibling: src/kiro_crew/testing/harness.py:429 -- not affected -- already doubles % in the exe path
Sibling: src/kiro_crew/apps/builtins/pptx_maker/backend/preview_tools.py:111 -- not affected -- already escapes through _cmd_escape

Pattern harvest

Rule candidate: review-prompt
Pattern: a path interpolated into a generated .cmd/.bat line without doubling % (cmd.exe expands it even inside quotes)

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

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 7, 2026 06:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4f09a52f7c644f027266a032697ee8ef762627e7 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4f09a52f7c644f027266a032697ee8ef762627e7 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. This is a narrow fix at the root cause, with the same escaping rule as the existing pod/windows.py _cmd_literal, and the author tested it on real Windows cmd.exe.

Notes

  • _pi_cmd_literal copies the rule in pod/windows.py _cmd_literal but raises a different error type, so the two can drift apart. If a third .cmd writer appears, have one shared helper that takes the error class as a parameter.

[DESIGN-REVIEWED] 4f09a52

Description read

[DESCRIPTION-READ] a3062cceb82675fccea661dfef605c76143015695b46f94068f2bf3570874cf8

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 Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4f09a52f7c644f027266a032697ee8ef762627e7 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix is aimed at the cause, a real % path that cmd.exe expands. The only question is whether _pi_cmd_literal should exist as a second copy of _cmd_literal.

Notes

  • Item 3 — duplicate of src/kiro_crew/pod/windows.py:378 _cmd_literal: it uses the same rule (% doubles; ", CR and LF are refused) and differs only in the exception type and the message. The grep for replace("%", "%%") found 6 sites under src/. Swapping in _cmd_literal directly would raise a WindowsTaskError about pods, so this copy is meaningfully different as written. It stays a note, not a blocker.

What this change ships

Inventory (4 items) — 3 justified

Intent: on a Windows install whose pi or data-home path contains %, pi sessions start instead of being refused at the gate read-back. FIX.

  1. A % in the pi binary path now reaches pi unchanged, so the launcher no longer exits 1 — justified
  2. A % in the sealed gate extension path now reaches pi unchanged, so pi loads the right file — justified
  3. A pi or extension path containing ", CR or LF is now refused up front with an AcpError naming the path — duplicate of pod/windows.py _cmd_literal (rule identical, error differs)
  4. New test pins the doubled-% launcher bytes and the refusal of a quote — justified

[FIRST-PRINCIPLES-REVIEWED] 4f09a52

Description read

[DESCRIPTION-READ] b916bfa58baba4c8a73f9d27d8cd9a4dfba8cb4d83309ffc26b2826cdc947f1e

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 Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 4f09a52

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4f09a52f7c644f027266a032697ee8ef762627e7 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4f09a52

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4f09a52f7c644f027266a032697ee8ef762627e7 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 06:43
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/acp/client.py, src/kiro_crew/acp/harness/codex.py, src/kiro_crew/acp/harness/kas.py, test/test_acp_bindings.py, test/test_acp_client_new_conversation.py, test/test_acp_provider_new_conversation.py, test/test_codex_sqlite_home.py, test/test_harness_parity.py since this head went green (8544127 -> b65af1a); CI re-running.

@bolichen97
bolichen97 force-pushed the fix/27851-pi-launcher-percent branch from e522729 to 3f6ebff Compare November 7, 2026 07:15
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests (3.12, 2) and Backend Tests (Windows) (2) fail only on test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget (package at 34855 lines vs a 34845 budget). This PR does not touch that package; the red comes from main and #32183 raises the budget. Waiting for it to merge, then rebasing.

@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 Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/27851-pi-launcher-percent branch from 3f6ebff to 4f09a52 Compare November 7, 2026 11:38
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in. Old base b65af1a666d, new base bab2387339a. Files in this PR (unchanged): src/kiro_crew/acp/harness/pi.py, test/test_acp_pi_backend.py. Reason: the red test_the_package_stays_within_its_line_budget came from main; main now has _PACKAGE_LINE_BUDGET = 34_894 (#32183 closed unmerged). Related tests pass locally (99 passed, incl. the budget test). New head 4f09a52f7c6.

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

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved for the on-call. Review lanes pass on 4f09a52, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit 1ab5673 into main Nov 7, 2026
152 of 154 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/27851-pi-launcher-percent branch November 7, 2026 12:51
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
buluoray pushed a commit that referenced this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pi harness: Windows gate launcher lets cmd.exe expand a % in the pi or extension path, so every pi session is refused

2 participants