Skip to content

fix: pin the two remaining bare-name kiro-cli spawns off PATH - #11209

Merged
iamwhatever merged 2 commits into
mainfrom
fix/pin-kiro-cli-spawns-8495
Sep 16, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
fix/pin-kiro-cli-spawns-8495

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Pins the two remaining bare-name kiro-cli spawns to an absolute path resolved with the inherited PATH excluded, refusing rather than falling back to the bare name:

  • src/kiro_crew/cli_server.py — _update (the kirocrew update command): shutil.which("kiro-cli") as a discarded existence test, then subprocess.run(["kiro-cli", "update"]).
  • src/kiro_crew/diagnostics.py — _kiro_cli_version: subprocess.run(["kiro-cli", "--version"]), unguarded, reached from the dashboard's POST /api/diagnostics/collect.

Both now call kiro_crew.kiro_cli.pin_kiro_cli(), the sync form of the pin the gateway's unattended spawns use (slack/gateway._pinned_kiro_cli). An AST-based structural guard keeps the count of bare-name kiro-cli spawns (and which("kiro-cli") probes) under src/kiro_crew at zero.

Closes #8495

Why

argv0 is re-resolved off the inherited PATH inside exec, and a gateway PATH can lead with an agent-writable directory (a worktree venv's bin). Anything able to drop an executable named kiro-cli there runs as the gateway user — on kirocrew update, or on a diagnostics click. An operator being present lowers likelihood, not harm; nobody watches exec resolve. In the update path the which probe's answer was thrown away, so the probe and the spawn could resolve to different files.

Live count on main before this change: 2 (cli_server.py:1711/1715, diagnostics.py:803).

How

  • kiro_cli.pin_kiro_cli() returns (pinned path or None, an unpinned install exists): resolve_kiro_cli(include_inherited_path=False) — the fixed known install directories plus the operator's own KIROCREW_KIRO_BIN — and, only when that is empty, a PATH-inclusive lookup that decides the WORDING of the refusal and never names what gets spawned. Absolute or nothing: a relative KIROCREW_KIRO_BIN (e.g. kiro-cli) passes the resolver's existence check against the current directory while exec would re-resolve that bare argv0 off PATH, so a relative pin is refused and reported like a PATH-only install. kiro_cli.PATH_ONLY_INSTALL_NOTE is the shared sentence naming the override (absolute path).
  • cli_server._update: None skips the step (fail-closed, like the git spawns beside it when trusted_git_bin() returns None). A PATH-only install prints a one-line warning with the override; an absent backend prints nothing (it is optional). The which probe is gone.
  • diagnostics._kiro_cli_version: three answers for versions.txt and the bug-report footer — the version, plain unavailable (not installed / probe failed), and not pinned (...) naming KIROCREW_KIRO_BIN when kiro-cli exists only through PATH, so a working install is not misreported as absent. The lookup sits inside the existing containment: a raising resolver degrades like a failed spawn.
  • The gateway's own _kiro_cli_pin_probe is deleted: _pinned_kiro_cli hands pin_kiro_cli to asyncio.to_thread and logs the shared PATH_ONLY_INSTALL_NOTE; its eleven tests now bind the resolver through kiro_crew.kiro_cli.resolve_kiro_cli, where the lookup lives. One spelling of the pin, three consumers.

Tests

test/test_kiro_cli_pin.py (new, 17 tests), all RED on the unmodified base except the two detector self-checks:

  • pin_kiro_cli: pinned install returned and not flagged; PATH-only install refused and flagged (first lookup is include_inherited_path=False, the second only decides wording); absent backend refused quietly.
  • cli_server._update (reusing the coverage module's _GitStub / git_checkout harness): argv0 is the resolved absolute path; the deciding lookup excludes the inherited PATH; unresolvable → step skipped, rest of the update runs, nothing printed; PATH-only → skipped AND reported with KIROCREW_KIRO_BIN; end-to-end with the REAL resolver against a fake home and a PATH leading with a shim — the shim is never spawned (POSIX; PATH shadowing with a chmod +x shim is a POSIX shape).
  • diagnostics._kiro_cli_version: argv0 is the resolved absolute path; deciding lookup excludes PATH; absent → unavailable without spawning; PATH-only → a distinct line naming PATH and KIROCREW_KIRO_BIN; failed spawn → unavailable; raising resolver → unavailable; end-to-end real-resolver shim test as above.
  • Structural guard over the shared source_corpus (RED-before: exactly the two sites), seeing both spellings of the name — the literal and the KIRO_CLI_BIN / KIRO_CLI_NAME constants — in subprocess.* list argv, create_subprocess_exec varargs and shutil.which probes, attributed to the enclosing function. A shrink-only known set admits the three INTERACTIVE sites (cli_doctor._kiro_cli_signed_in, cli_doctor._doctor, cli_setup._ensure_prerequisites, see Other); any other hit fails, and an entry whose site stops spawning by bare name must be deleted. Self-check pins every shape the detector must see and the two it must ignore ([binary, ...], which("git")).
  • pin_kiro_cli: a relative override is refused and flagged (unit, plus an end-to-end test with the real resolver: KIROCREW_KIRO_BIN=kiro-cli with a shim in the current directory and first on PATH yields no pin).

Adapted: test/test_cli_server_more_coverage.py (stub matches argv0 by basename; the git_checkout fixture pins the resolver to "nothing installed" so the host's own install cannot leak in; three tests resolve /usr/bin/kiro-cli explicitly and assert the absolute argv). test/test_spawn_audit.py: allowlist comment for diagnostics.py::_kiro_cli_version updated to describe the pinned path (entry key unchanged).

Ran by path with -n0: test/test_kiro_cli_pin.py test/test_cli_server_more_coverage.py test/test_diagnostics.py test/test_spawn_audit.py → 192 passed. test/test_windows_logs_and_diagnostics.py also green. isort / flake8 / mypy clean on the changed files; check_black_formatting.py, check_subprocess_encoding.py and check_comment_history.py pass against origin/main.

Other

  • Backend-only; no user-visible frontend change, so no-screenshots applies. The only visible text change is one CLI warning line in kirocrew update and the versions.txt line in the diagnostics bundle.
  • Overlap: open PR fix(diagnostics): resolve kiro-cli before probing its version #7692 (Diagnostics reports "kiro-cli: unavailable" for a working install: the version probe spawns a bare name instead of resolve_kiro_cli() #7674) rewrites the same diagnostics._kiro_cli_version but resolves via resolve_kiro_cli() WITH the inherited PATH, which is the shape this issue asks to refuse; it also does not touch cli_server. That PR is currently CONFLICTING against main; whichever lands second rebases onto the other. This PR also resolves Diagnostics reports "kiro-cli: unavailable" for a working install: the version probe spawns a bare name instead of resolve_kiro_cli() #7674's complaint for the pinned case (a real install in the known directories is no longer reported unavailable) and names the operator override for the PATH-only case.
  • Cross-platform: no path logic added beyond what resolve_kiro_cli already owns (os.path.isabs for the relative-override refusal); the three shim tests are POSIX-only by marker.
  • Scope, stated: kirocrew doctor (cli_doctor._kiro_cli_signed_in, cli_doctor._doctor) and kirocrew setup (cli_setup._ensure_prerequisites) still probe and spawn kiro-cli by bare name through KIRO_CLI_BIN. They are interactive TTY commands run by the operator, where the inherited PATH is the documented default (resolve_kiro_cli docstring) and the exposure this issue names — an unattended or click-reachable spawn — does not apply; doctor's rows exist to report what a session would run. They are NOT hidden: the guard sees them and admits exactly those three, shrink-only. Converging them on resolve_kiro_cli() (absolute argv0, PATH kept) is a separate change because ~15 doctor/setup tests pin shutil.which as their seam.

Pattern harvest

Rule candidate: semgrep
Pattern: subprocess.run([ "kiro-cli", ... ]) / create_subprocess_exec("kiro-cli", ...) / shutil.which("kiro-cli") under src/kiro_crew — a bare argv0 or a probe whose answer is discarded; route through kiro_cli.pin_kiro_cli (sync) or _pinned_kiro_cli (async). The AST guard in test/test_kiro_cli_pin.py is the in-repo form of the same rule.

@CrysisDeu CrysisDeu added the no-screenshots PR has no visual delta; screenshot gate exempt label Sep 16, 2026
@CrysisDeu
CrysisDeu requested review from a team and hoang-phan98 September 16, 2026 05:43
@CrysisDeu CrysisDeu added the no-screenshots PR has no visual delta; screenshot gate exempt label Sep 16, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify no documented install method leaves kiro-cli PATH-only, since kirocrew update now silently-ish skips updating it behind one warning line.

[DESIGN-REVIEWED] ea04b26

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ea04b26

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

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

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of ea04b269e9233d9715be860bbffc562ee6d1051c and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ea04b26

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

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of ea04b269e9233d9715be860bbffc562ee6d1051c — 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

Confirm #8495 itself asks to refuse a PATH-only install: kirocrew update now skips that backend step until the operator sets KIROCREW_KIRO_BIN.

Not justified as shipped

  • Item 6 — rides along: the gateway's PATH-only warning is reworded to the shared PATH_ONLY_INSTALL_NOTE sentence; harm-free log-line relabel that comes with the consolidation.
  • Item 7 — rides along: the AST ratchet is not the fix (the two sites are already pinned without it); it is a declared regression pin for the fixed class, shrink-only, no premise risk.

What this change ships

Inventory (7 items) — 5 justified

Intent: stop kirocrew update and the diagnostics bundle from exec-ing whatever kiro-cli the inherited PATH names — a FIX (issue #8495; RED-before tests in the diff).

  1. kirocrew update's kiro-cli step spawns a pinned absolute path; a PATH-only install is skipped with a warning naming KIROCREW_KIRO_BIN — justified
  2. The discarded which("kiro-cli") existence probe before that spawn is gone — justified
  3. The diagnostics versions.txt line spawns the pinned path and reports a PATH-only install as not pinned (…) rather than absent — justified
  4. Shared kiro_cli.pin_kiro_cli() replaces the gateway's private _kiro_cli_pin_probe (net deletion; 3 counted consumers: slack/gateway.py:1586, cli_server.py:1717, diagnostics.py:819, grepped pin_kiro_cli) — justified
  5. A relative KIROCREW_KIRO_BIN is now refused on every pinned spawn, gateway included — justified
  6. Gateway's PATH-only warning reworded to the shared sentence — rides along (harm-free relabel)
  7. New shrink-only AST guard failing any new bare-name kiro-cli spawn or which probe — rides along (regression pin; the 3 admitted interactive siblings cli_doctor._kiro_cli_signed_in, cli_doctor._doctor, cli_setup._ensure_prerequisites are counted — grepped KIRO_CLI_BIN, 5 call sites — and their deferral rests on resolve_kiro_cli's own docstring, which documents inherited PATH as the interactive default)

[FIRST-PRINCIPLES-REVIEWED] ea04b26

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

[worker note on the GPT 5.6 BLOCKING for c28c70259f39f664fcc72061b621bdb6bf319904]

Finding: "PATH exclusion still selects agent-writable home binaries" — ~/.local/bin is in the pinned candidate set and is same-uid-writable; suggested fix: restrict unattended pins to KIROCREW_KIRO_BIN or non-agent-writable system directories.

Why this PR does not adopt that fix (measured, not argued):

  1. It is the same finding GPT raised on PR fix(gateway): pin both unattended kiro-cli spawns off PATH #8396 for the identical candidate set, where a repository writer recorded a human judgment (#8396 (comment)). Issue Pin the two remaining bare-name kiro-cli spawns off PATH #8495 was written after that ruling and prescribes routing both remaining sites "through the same pin PR fix(gateway): pin both unattended kiro-cli spawns off PATH #8396 introduces". This PR does exactly that; the candidate set is not new.
  2. The rationale still holds on this head: install.sh:549-552 runs ln -sf "$_venv/bin/kirocrew" "$HOME/.local/bin/kirocrew" — the gateway's own launcher lives in the very directory the finding wants refused. An agent that can plant ~/.local/bin/kiro-cli can already replace the entry point the gateway is started from; refusing the directory removes no capability from that agent.
  3. kiro-cli's documented install location is ~/.local/bin, so restricting to KIROCREW_KIRO_BIN + system directories would make kirocrew update skip the backend and make versions.txt report kiro-cli as not pinned on every standard install — the same "refuse every standard install while buying nothing" outcome the fix(gateway): pin both unattended kiro-cli spawns off PATH #8396 ruling named.
  4. What the PR does close is the vector the issue names: the inherited PATH (a worktree venv bin that the agent creates and that the gateway process inherits) no longer decides argv0, and the which-then-discard probe is gone. Live count of bare-name spawns under src/kiro_crew: 2 → 0, pinned by the structural guard in test/test_kiro_cli_pin.py.

The lane withheld this security-class finding from adjudication, so the blocking verdict stands until a repository writer records a judgment for this head. No /ai-review override is posted from this account.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 16, 2026
`kirocrew update` (`cli_server._update`) and the diagnostics support bundle
(`diagnostics._kiro_cli_version`) both spawned `"kiro-cli"` by bare name, so
the lookup that decides which file runs happened inside `exec` against the
process's inherited `PATH`. That `PATH` can lead with an agent-writable
directory (a worktree venv's `bin`); anything able to drop an executable of
that name there runs as the gateway user. The update path also gated on
`shutil.which("kiro-cli")` and threw the answer away, so the probe and the
spawn could resolve to different files. The diagnostics probe is reached from
the dashboard's `POST /api/diagnostics/collect`, so it fires on a click.

Both sites now resolve through `kiro_cli.pin_kiro_cli`, the sync form of the
pin the gateway's unattended spawns use: `resolve_kiro_cli` with the inherited
`PATH` excluded, leaving the fixed known install directories plus the
operator's own `KIROCREW_KIRO_BIN`. `None` fail-closes to skipping the spawn.
As in the gateway, a refusal is distinguished from an absent backend: an
install that exists only through `PATH` is reported with the override that
puts it back (`PATH_ONLY_INSTALL_NOTE`), so `kirocrew update` says why the
backend step was skipped and `versions.txt` does not misreport a working
install as absent.

Tests: the pinned absolute path reaches `subprocess.run` at both sites, the
deciding lookup excludes the inherited `PATH`, an unresolvable kiro-cli spawns
nothing while the rest of the update runs, a PATH-only install is refused AND
reported at both sites, an absent backend is refused quietly, a raising
lookup degrades like a failed spawn in diagnostics, and two end-to-end tests
with the real resolver prove a shim first on `PATH` is never spawned. An
AST-based structural guard keeps the count of bare-name kiro-cli spawns
(and `which("kiro-cli")` probes) under `src/kiro_crew` at zero.

Closes #8495
Two First Principles review items on the first commit, both subtraction:

The gateway's `_kiro_cli_pin_probe` was byte-identical to the new
`kiro_cli.pin_kiro_cli`, and its warning spelled `PATH_ONLY_INSTALL_NOTE`'s
sentence a third way. The gateway copy is deleted; `_pinned_kiro_cli` hands
`pin_kiro_cli` to `asyncio.to_thread` and logs the shared note. The eleven
gateway tests that bound the resolver through the gateway module now bind it
through `kiro_crew.kiro_cli.resolve_kiro_cli`, which is where the lookup lives.

The structural guard hand-rolled an `rglob` + `ast.parse` walk over the whole
package. It now iterates `source_corpus.parsed_candidates` pre-filtered on the
`"kiro-cli"` literal, like `test_spawn_audit.py`: one cached corpus read, a
handful of parses.

Behaviour is unchanged at every site; the gateway's pin tests, the new pin
tests, and the restart-respawn tests all pass unmodified in assertion.
@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 Sep 16, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/pin-kiro-cli-spawns-8495 branch from 907155c to ea04b26 Compare September 16, 2026 06:49
@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 Sep 16, 2026
@iamwhatever
iamwhatever merged commit 9d0c48a into main Sep 16, 2026
82 checks passed
@iamwhatever
iamwhatever deleted the fix/pin-kiro-cli-spawns-8495 branch September 16, 2026 20:44
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 16, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…tdev#11209)

* fix: pin the two remaining bare-name kiro-cli spawns off PATH

`kirocrew update` (`cli_server._update`) and the diagnostics support bundle
(`diagnostics._kiro_cli_version`) both spawned `"kiro-cli"` by bare name, so
the lookup that decides which file runs happened inside `exec` against the
process's inherited `PATH`. That `PATH` can lead with an agent-writable
directory (a worktree venv's `bin`); anything able to drop an executable of
that name there runs as the gateway user. The update path also gated on
`shutil.which("kiro-cli")` and threw the answer away, so the probe and the
spawn could resolve to different files. The diagnostics probe is reached from
the dashboard's `POST /api/diagnostics/collect`, so it fires on a click.

Both sites now resolve through `kiro_cli.pin_kiro_cli`, the sync form of the
pin the gateway's unattended spawns use: `resolve_kiro_cli` with the inherited
`PATH` excluded, leaving the fixed known install directories plus the
operator's own `KIROCREW_KIRO_BIN`. `None` fail-closes to skipping the spawn.
As in the gateway, a refusal is distinguished from an absent backend: an
install that exists only through `PATH` is reported with the override that
puts it back (`PATH_ONLY_INSTALL_NOTE`), so `kirocrew update` says why the
backend step was skipped and `versions.txt` does not misreport a working
install as absent.

Tests: the pinned absolute path reaches `subprocess.run` at both sites, the
deciding lookup excludes the inherited `PATH`, an unresolvable kiro-cli spawns
nothing while the rest of the update runs, a PATH-only install is refused AND
reported at both sites, an absent backend is refused quietly, a raising
lookup degrades like a failed spawn in diagnostics, and two end-to-end tests
with the real resolver prove a shim first on `PATH` is never spawned. An
AST-based structural guard keeps the count of bare-name kiro-cli spawns
(and `which("kiro-cli")` probes) under `src/kiro_crew` at zero.

Closes kirodotdev#8495

* refactor: converge the gateway pin and the spawn guard onto shared code

Two First Principles review items on the first commit, both subtraction:

The gateway's `_kiro_cli_pin_probe` was byte-identical to the new
`kiro_cli.pin_kiro_cli`, and its warning spelled `PATH_ONLY_INSTALL_NOTE`'s
sentence a third way. The gateway copy is deleted; `_pinned_kiro_cli` hands
`pin_kiro_cli` to `asyncio.to_thread` and logs the shared note. The eleven
gateway tests that bound the resolver through the gateway module now bind it
through `kiro_crew.kiro_cli.resolve_kiro_cli`, which is where the lookup lives.

The structural guard hand-rolled an `rglob` + `ast.parse` walk over the whole
package. It now iterates `source_corpus.parsed_candidates` pre-filtered on the
`"kiro-cli"` literal, like `test_spawn_audit.py`: one cached corpus read, a
handful of parses.

Behaviour is unchanged at every site; the gateway's pin tests, the new pin
tests, and the restart-respawn tests all pass unmodified in assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-screenshots PR has no visual delta; screenshot gate exempt

Projects

None yet

2 participants