Skip to content

fix(subagent): let a drive-root cwd allow-list entry admit its subtree - #24504

Merged
bolichen97 merged 1 commit into
mainfrom
fix/subagent-cwd-drive-root
Oct 29, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/subagent-cwd-drive-root

Conversation

@JLargent42

@JLargent42 JLargent42 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A drive root such as H:\ (or / on Linux and macOS) in agent.subagent_cwd_allowed_roots admits every directory below it as a sub-agent cwd.

With "subagent_cwd_allowed_roots": ["~/workspace", "H:\\"], a spawn_run with cwd="H:\\REPL\\project" (an existing directory) is refused with cwd is not under any allowed root: ['~/workspace', 'H:\\']. Nothing below a drive root can match.

Why it matters

A Windows user who keeps projects on a second drive cannot allow that drive with one entry; the only workaround is to list every top-level folder by hand. The same entry shape (/) is refused on POSIX too.

Not a goal

  • Making the comparison case-insensitive on Windows. realpath already returns one spelling per path on the host, and the refusal reported here is the separator, not the case.
  • Changing the same boundary shape in other modules; see the sibling sweep.

What changed (motivation → approach → change)

validate_cwd tested resolved.startswith(root + os.sep). os.path.realpath("H:\\") is H:\, which already ends in the separator, so the prefix became H:\\ and no path below the drive matched. validate_cwd now uses the boundary check the sandbox already has, sandbox_plan.path_within, which strips a trailing separator before adding one. A sibling like H:\REPL-extra is still refused for root H:\REPL, and a different drive is still refused. sandbox_plan joins the names the subagent facade (src/kiro_crew/subagent.py) binds for agent_policy.

Backwards compatibility

Compatible: every root that does not end in a separator gets the same root + sep prefix as before; only roots that already end in one (a filesystem root) change, from matching nothing below them to matching their subtree.

Removes nothing: no key, function or accepted input is removed; the validator accepts more, never less.

Tests

In test/test_subagent_cwd.py:

  • TestCwdRootBoundary::test_boundary (9 cases): runs sandbox_plan.path_within with ntpath and posixpath swapped in, so H:\REPL\project under H:\ and /srv/project under / are checked on any host, and a -extra sibling or another drive is refused.
  • TestValidateCwd::test_filesystem_root_entry_admits_a_directory_below_it: on the real host, an allow-list holding only the filesystem root of tmp_path admits tmp_path/project.

Proof: not provable -- other: prove.py's throwaway checkout errored at collection; a manual revert of validate_cwd to startswith(root + os.sep) turns test_filesystem_root_entry_admits_a_directory_below_it red and the fix turns it green (head 32c2969)

Determinism: the 10 boundary node ids ran green 20 times at -n0 and 10 times at -n 2 --dist loadgroup beside test/test_subagent_coverage.py; the whole file ran green in shuffled order (seed 4411).

Manual verification

Not run on a Windows host. The Windows cases run path_within with ntpath, the comparison validate_cwd makes on Windows after realpath. Local gates green on Linux: test_subagent_cwd.py, test_subagent_coverage.py, test_subagent_parts_composition_contract.py, test_facade_mirror_guards.py (321 passed, with the sandbox_plan tests), black, isort, flake8, mypy, semgrep, flake-pattern ratchet.

Related Issues

Closes #24475

Sibling sweep

Swept: git grep -nE "startswith((root|rootn|root_cf|root_resolved|root_folded)[^)]*+ *os.sep" -- src/
Sibling: src/kiro_crew/subagent_parts/agent_policy.py:942 -- changed here
Sibling: src/kiro_crew/dashboard/terminal_commands.py:472 -- not affected -- roots are agent-writable folders, and a filesystem root there over-refuses, it never admits
Sibling: src/kiro_crew/name_grant.py:534 -- not affected -- roots are grant folders under the crew home, never a filesystem root
Sibling: src/kiro_crew/apps/agent_launch.py:221 -- not affected -- roots are app install folders, never a filesystem root
Sibling: src/kiro_crew/apps/module_loader.py:199 -- not affected -- roots are app source folders, never a filesystem root
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- not affected -- refuses on a failed match, so a drive root over-refuses rather than admits
Sibling: src/kiro_crew/dep_sync.py:789 -- not affected -- root is a resolved repository folder, never a filesystem root
Sibling: src/kiro_crew/apps/builtins/md_notebook/server_paths.py:546 -- not affected -- root is the notebook folder, never a filesystem root

Pattern harvest

Rule candidate: semgrep
Pattern: a path-prefix boundary built as root + os.sep without checking whether root already ends in a separator

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

@JLargent42
JLargent42 requested review from a team and KiroCrewCaptain as code owners October 26, 2026 17:48
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: e96bb14

  • What rule changed: the sub-agent cwd allow-list boundary test in validate_cwd (src/kiro_crew/subagent_parts/agent_policy.py) appends the path separator to a root only when the root does not already end in one.
  • Before -> after: before, a root entry that is a filesystem root (H:\ on Windows, / on POSIX) admitted only the root itself and nothing below it; after, it admits its subtree. Every root that does not end in a separator keeps the exact same root + sep prefix test.
  • Worst case if wrong: a cwd outside every configured root is accepted for a sub-agent spawn. The tests pin the refusals that guard this: a -extra sibling of a root, a different drive letter, and the existing symlink-to-outside case all stay refused.
  • Evidence checked: 9 parametrized boundary cases with both \ and / separators, one end-to-end case on the real filesystem, and the existing test_subagent_cwd.py refusal cases; reverting the change turns 3 new tests red. GPT and Opus local reviews returned no findings on this diff.
  • Tools still work: spawns with a cwd under an ordinary root behave as before; only a filesystem-root entry, which matched nothing below it, changes. The four validate_cwd callers are unchanged.
  • Backward compatible: yes, the validator accepts strictly more inputs (subtrees of a filesystem-root entry, which the operator explicitly listed) and rejects nothing it accepted before.
  • Existing tests: test/test_subagent_cwd.py, test/test_subagent_coverage.py, test/test_subagent_parts_composition_contract.py and test/test_facade_mirror_guards.py all pass locally (256 tests).
  • How to undo: revert this single commit; the boundary test returns to startswith(root + os.sep) and filesystem-root entries again admit nothing below them.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4b78802cd72f8f94fe03641452d43c3d3acbc05b 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 added the readiness: checking Automated validation is still running label Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Reusing the sandbox's existing path_within boundary fixes the cause on both separators, and the allow-list only gets wider, so nothing is taken away.

[DESIGN-REVIEWED] 4b78802

Description read

[DESCRIPTION-READ] f591f150e191d1e983059ae96c04354775f22bb975787bb90ba11ec3648b2d24

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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4b78802cd72f8f94fe03641452d43c3d3acbc05b — 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: this is a mechanism-level fix that reuses sandbox_plan.path_within rather than adding a second boundary helper.

What this change ships

Inventory (3 items) — 3 justified

Intent: let a Windows or POSIX user allow a whole drive (H:\, /) as a sub-agent cwd root with one entry. This is a FIX (#24475).

  1. A filesystem-root entry in agent.subagent_cwd_allowed_roots now admits every directory below it; before, it admitted nothing below it. — justified
  2. validate_cwd now uses the existing sandbox_plan.path_within instead of its own startswith(root + os.sep), so one boundary spelling remains. — justified
  3. The subagent facade now imports sandbox_plan so agent_policy can reach it. — justified

[FIRST-PRINCIPLES-REVIEWED] 4b78802

Description read

[DESCRIPTION-READ] 2e16b36f58548be8eb5c5f7fc65577370d5daba2d7c3b7f20affd2731a8d43a2

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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 4b78802

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

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

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4b78802

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

@JLargent42
JLargent42 force-pushed the fix/subagent-cwd-drive-root branch from e96bb14 to 32c2969 Compare October 26, 2026 18:18
@JLargent42

Copy link
Copy Markdown
Contributor Author
  • span=811bbb4d5a8c Second spelling of the path-boundary check

fixed in 32c2969: validate_cwd calls sandbox_plan.path_within(resolved, root) and _is_at_or_under is removed, with its facade re-export and composition-contract entry.
The 9 Windows and POSIX boundary cases now exercise path_within itself with ntpath/posixpath swapped in; reverting validate_cwd to startswith(root + os.sep) turns the end-to-end filesystem-root test red.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 32c2969

  • What rule changed: the sub-agent cwd allow-list boundary test in validate_cwd (src/kiro_crew/subagent_parts/agent_policy.py) uses the existing sandbox_plan.path_within, which strips a trailing separator from the root before appending one.
  • Before -> after: before, a root entry that is a filesystem root (H:\ on Windows, / on POSIX) admitted only the root itself and nothing below it; after, it admits its subtree. Every root that does not end in a separator keeps the same root + sep prefix test. sandbox_plan.py itself is unchanged.
  • Worst case if wrong: a cwd outside every configured root is accepted for a sub-agent spawn. The tests pin the refusals that guard this: a -extra sibling of a root, a different drive letter, and the existing symlink-to-outside case all stay refused.
  • Evidence checked: 9 parametrized boundary cases run path_within under both ntpath and posixpath, plus one end-to-end case on the real filesystem and the existing refusal cases; reverting validate_cwd to the old prefix test turns the end-to-end case red.
  • Tools still work: spawns with a cwd under an ordinary root behave as before; only a filesystem-root entry, which matched nothing below it, changes. The four validate_cwd callers are unchanged.
  • Backward compatible: yes, the validator accepts strictly more inputs (subtrees of a filesystem-root entry, which the operator explicitly listed) and rejects nothing it accepted before.
  • Existing tests: test/test_subagent_cwd.py, test/test_subagent_coverage.py, test/test_subagent_parts_composition_contract.py, test/test_facade_mirror_guards.py and the sandbox_plan tests all pass locally (321 tests).
  • How to undo: revert this single commit; validate_cwd returns to startswith(root + os.sep) and filesystem-root entries again admit nothing below them.

@JLargent42

Copy link
Copy Markdown
Contributor Author

CI note: Backend Tests (Windows) (4) on 32c2969 fails only test/test_telegram_dispatcher.py::TestABusyReplyCarriesItsContext (2 cases, assert [] == ["telegram_reply_parent"]). That is main breakage tracked in #24514 (fix in #24531); this PR does not touch the Telegram dispatcher. Not re-running; waiting for #24531 to merge.

@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 26, 2026
@JLargent42
JLargent42 force-pushed the fix/subagent-cwd-drive-root branch from 32c2969 to 150f808 Compare October 26, 2026 23:03
@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 26, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased once onto main (5285bc2) with maintainer approval to pick up #24531 (main-red #24514); no code change.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 150f808

  • What rule changed: the sub-agent cwd allow-list boundary test in validate_cwd (src/kiro_crew/subagent_parts/agent_policy.py) uses the existing sandbox_plan.path_within, which strips a trailing separator from the root before appending one.
  • Before -> after: before, a root entry that is a filesystem root (H:\ on Windows, / on POSIX) admitted only the root itself and nothing below it; after, it admits its subtree. Every root that does not end in a separator keeps the same root + sep prefix test. sandbox_plan.py itself is unchanged.
  • Worst case if wrong: a cwd outside every configured root is accepted for a sub-agent spawn. The tests pin the refusals that guard this: a -extra sibling of a root, a different drive letter, and the existing symlink-to-outside case all stay refused.
  • Evidence checked: 9 parametrized boundary cases run path_within under both ntpath and posixpath, plus one end-to-end case on the real filesystem and the existing refusal cases; reverting validate_cwd to the old prefix test turns the end-to-end case red. This head is the same change rebased onto main 5285bc2 with no code change.
  • Tools still work: spawns with a cwd under an ordinary root behave as before; only a filesystem-root entry, which matched nothing below it, changes. The four validate_cwd callers are unchanged.
  • Backward compatible: yes, the validator accepts strictly more inputs (subtrees of a filesystem-root entry, which the operator explicitly listed) and rejects nothing it accepted before.
  • Existing tests: test/test_subagent_cwd.py, test/test_subagent_coverage.py, test/test_subagent_parts_composition_contract.py, test/test_facade_mirror_guards.py and test/test_telegram_dispatcher.py all pass locally on this head (355 tests).
  • How to undo: revert this single commit; validate_cwd returns to startswith(root + os.sep) and filesystem-root entries again admit nothing below them.

@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 27, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

CI note: Backend Tests (Windows) (6) on 150f808 has 7 failures. Six are test/test_slack_team_id_env.py::TestSpawnEnv (FileNotFoundError: [WinError 2]), main breakage from #22380 tracked in #24612 (fix #24613, open). The seventh, test_subagent_replay_scope.py::...::test_the_cost_does_not_grow_with_slots_nobody_views, is an xdist worker crash (worker gw2 crashed), not an assertion; it passes locally on this head and does not exercise validate_cwd. Not re-running (the shard stays red on #24612 regardless) and not rebasing.

@JLargent42
JLargent42 force-pushed the fix/subagent-cwd-drive-root branch from 150f808 to 4b78802 Compare October 27, 2026 16:19
@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased once onto main (0a864a5) to pick up the Windows shard 6 fix #24609 (#24612); no code change.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 4b78802

  • What rule changed: the sub-agent cwd allow-list boundary test in validate_cwd (src/kiro_crew/subagent_parts/agent_policy.py) uses the existing sandbox_plan.path_within, which strips a trailing separator from the root before appending one.
  • Before -> after: before, a root entry that is a filesystem root (H:\ on Windows, / on POSIX) admitted only the root itself and nothing below it; after, it admits its subtree. Every root that does not end in a separator keeps the same root + sep prefix test. sandbox_plan.py itself is unchanged.
  • Worst case if wrong: a cwd outside every configured root is accepted for a sub-agent spawn. The tests pin the refusals that guard this: a -extra sibling of a root, a different drive letter, and the existing symlink-to-outside case all stay refused.
  • Evidence checked: 9 parametrized boundary cases run path_within under both ntpath and posixpath, plus one end-to-end case on the real filesystem and the existing refusal cases; reverting validate_cwd to the old prefix test turns the end-to-end case red. This head is the same change (identical patch-id) rebased onto main 0a864a5 with no code change.
  • Tools still work: spawns with a cwd under an ordinary root behave as before; only a filesystem-root entry, which matched nothing below it, changes. The four validate_cwd callers are unchanged.
  • Backward compatible: yes, the validator accepts strictly more inputs (subtrees of a filesystem-root entry, which the operator explicitly listed) and rejects nothing it accepted before.
  • Existing tests: test/test_subagent_cwd.py, test/test_subagent_coverage.py, test/test_subagent_parts_composition_contract.py, test/test_facade_mirror_guards.py, test/test_sandbox_plan.py and test/test_slack_team_id_env.py all pass locally on this head (335 tests).
  • How to undo: revert this single commit; validate_cwd returns to startswith(root + os.sep) and filesystem-root entries again admit nothing below them.

@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 Oct 27, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 27, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD (policy-sensitive) at 4b78802cd72f8f94fe03641452d43c3d3acbc05b.

The change itself looks sound: validate_cwd now reuses sandbox_plan.path_within, which strips a trailing separator before adding one, so only roots that already end in a separator change behaviour, and the new tests pin the -extra sibling and other-drive refusals. All current-head AI lanes pass, the one First Principles finding was answered as fixed, and checks are green.

It is held only because it widens what the sub-agent cwd allow-list admits, a permission boundary that is reserved for a human maintainer to approve.

— crew-pr-reviewer (r130)

iamwhatever pushed a commit that referenced this pull request Oct 28, 2026
…le (#24694)

* fix(terminal): count paths under a drive-root project as agent-writable

The completion probe's _within tested `real.startswith(root + os.sep)`.
realpath keeps the separator a drive root already ends in (H:\, or /),
so with the project directory or workspace root at a drive root the
prefix became H:\\ and no PATH entry below it counted as agent-writable,
and _sanitized_path no longer dropped them for being agent-writable.

Route the test through sandbox_plan.path_within, which already treats
a root ending in a separator as its own prefix: the helper #24504
routes validate_cwd through for the same defect.

Part of #24475

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(name-grant): count paths under a drive-root project as agent-writable

name_grant._within compared against root + os.sep, the same test the
previous commit replaced in terminal_commands._within, over the same
agent_writable_roots(). A drive root (H:\ or /) already ends in a
separator, so no path below it counted as inside, and a program planted
under a drive-root project was honoured by a name grant instead of being
refused as agent-tree. Route it through sandbox_plan.path_within so one
containment rule serves both sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

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

LGTM. validate_cwd built its boundary as root + os.sep, so a root that already ends in a separator (H:\, /) matched nothing below it. Routing it through the existing sandbox_plan.path_within, which strips the trailing separator first, fixes the cause reported in #24475. For every other root the prefix test is unchanged, so the allow-list only widens for entries the operator listed as a filesystem root.

Verified: main still has the old startswith(root + os.sep) in agent_policy.validate_cwd, so this is not already done. No other open PR touches validate_cwd. #24694, #24743 and #24742 fix the same pattern in other modules (terminal, steering, file API), so they are siblings, not duplicates. test_filesystem_root_entry_admits_a_directory_below_it runs the real validate_cwd, and the author reports it goes red when the fix is reverted. The 9 ntpath/posixpath cases pin the -extra sibling and other-drive refusals. All AI lanes pass at this head, the First Principles finding was answered as fixed, and checks are green.

The open maintainer HOLD only asks for human sign-off on a widened permission boundary. This review is that sign-off.

AI-assisted review (Kiro), posted for bolichen.

@bolichen97
bolichen97 merged commit efbf47e into main Oct 29, 2026
161 of 167 checks passed
@bolichen97
bolichen97 deleted the fix/subagent-cwd-drive-root branch October 29, 2026 01:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

subagent cwd allow-list never matches anything under a drive-root entry (e.g. H:\) on Windows

3 participants