Repository navigation
fix: start a worktree from a repo nested in another session's project - #31414
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. Returning the longest matching root fixes the root cause. The set of accepted paths stays the same, and the toplevel re-check still runs. Notes
[DESIGN-REVIEWED] ba81d6f Description read[DESCRIPTION-READ] 0b9aa170c9d254b1fe98f38a6146d0783e46e319f1892de63fd47c6d5db6a18d That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: a single mechanism-level fix to how the matcher chooses among roots that contain the path. The accept set is unchanged and there are no riders. What this change shipsInventory (3 items) — 3 justifiedIntent: let a person start a follow-up in a new worktree from a repository nested inside another open session's project directory. This is a FIX (#22137).
[FIRST-PRINCIPLES-REVIEWED] ba81d6f Description read[DESCRIPTION-READ] 3c0b2506df164a42cbde7b1047b85b690e5a60f6eba8292c3247165176cfc1fd That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
de2e393 to
ae045d5
Compare
|
[operator: bolichen97] Backend Tests shard 2 (Linux and Windows) is red on |
ae045d5 to
ba81d6f
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on ba81d6f, no conflict, no open change request.
Problem / Motivation
Goal: "Start in new worktree" works for a git repository nested inside a directory that another open session uses as its project.
Session A has project
/Workshop(not a git repository) and session B has project/Workshop/cafe-breakout(a healthy repository). Clicking Start in new worktree on a follow-up card in session B fails with400 {"error": "Not a git repository"}and creates no branch, worktree or session. Whether it fails depends only on which session the gateway happens to list first.Why it matters
Anyone who keeps a broad workspace session open (an IDE-style parent folder) alongside sessions for the repositories under it cannot fork follow-ups into worktrees from those repositories. The error also blames a healthy repository, so nothing tells the user what to change. When the parent directory is itself a repository, the worktree is created from the parent instead of the nested repository the user asked for.
Not a goal
POST /api/worktree/createaccepts: the allow-list (every open session's project, plus the toplevel re-check) is unchanged.Not a git repositoryerror or surfacing git's stderr. The card sends the active session's own project, which is always an exact match in the allow-list, so git now probes the submitted directory and that message is accurate again.What changed (motivation → approach → change)
The endpoint checks the submitted
repoagainst the realpath'd project of every open chat session and then runs git in the matching root._match_allowed_rootreturned the first root that equals or containsrepo, so when/Workshopcame before/Workshop/cafe-breakout, git probed/Workshopand the request failed._match_allowed_rootindashboard/handlers/worktree.pynow returns the most specific (longest) matching root, whatever the session order. An exact match is always the longest, so it wins whenever it exists. It still only returns a value taken from the server-held roots, and the set of accepted paths is the same. The owning spec (learn-cron-dashboard.md) records the rule.Backwards compatibility
Compatible: every
repoaccepted before is still accepted and every refused one is still refused; only the choice among several containing roots changes, from "first listed" to "most specific".Removes nothing: no path, key, route or check is taken away; the barrier keeps the same accept set.
Tests
test/test_worktree_create.py::TestAllowedRootBoundary::test_nested_root_wins_over_its_parent_in_either_order(new, both orders): with a parent and a nested root in the allow-list, the nested root wins for the nested path itself and for a folder inside it.test_first_matching_root_winsis renamedtest_only_the_containing_root_matches; its assertion is unchanged (two unrelated roots, the containing one wins).test_worktree_create.py,test_dashboard_worktree_coverage.py,test_windows_extended_prefix_containment.py) pass with-n 4, and the local gate's related backend set passed (12316 passed). The frontend half of the local gate could not run on this host (nowebsite/node_modules); this diff changes no frontend file, and CI runs that suite.Proof: PROVEN test/test_worktree_create.py::TestAllowedRootBoundary::test_nested_root_wins_over_its_parent_in_either_order[True] (head ae045d5)
Manual verification
N/A — unit coverage sufficient: the defect is a pure ordering choice inside
_match_allowed_root, and the new test reproduces the reporter's exact root list in both orders.Screenshots / video
N/A — backend only; no frontend file changes.
Related Issues
Closes #22137
Sibling sweep
Swept: git grep -nE "startswith(.*rstrip(os.sep) + os.sep" -- src/
Sibling: src/kiro_crew/dashboard/file_api/project_dirs.py:122 -- not affected --
_match_known_projectaccepts only an exact match, so no two known directories can both matchSibling: src/kiro_crew/dashboard/handlers/worktree.py:1010 -- not affected -- the reuse check asks whether ANY session sits in the tree, a yes/no answer that order cannot change
Pattern harvest
Not generalizable: a one-off selection bug in the only matcher that returns one root out of several containing roots.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)