Skip to content

fix: start a worktree from a repo nested in another session's project - #31414

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/22137-nested-worktree-root
Nov 7, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/22137-nested-worktree-root

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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 with 400 {"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

  • Changing which directories POST /api/worktree/create accepts: the allow-list (every open session's project, plus the toplevel re-check) is unchanged.
  • Rewording the Not a git repository error 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.
  • Investigating the stray commit the reporter saw once on 0.8.0; nothing on this path commits.

What changed (motivation → approach → change)

The endpoint checks the submitted repo against the realpath'd project of every open chat session and then runs git in the matching root. _match_allowed_root returned the first root that equals or contains repo, so when /Workshop came before /Workshop/cafe-breakout, git probed /Workshop and the request failed.

_match_allowed_root in dashboard/handlers/worktree.py now 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 repo accepted 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_wins is renamed test_only_the_containing_root_matches; its assertion is unchanged (two unrelated roots, the containing one wins).
  • Pure string function, no filesystem, clock or ordering dependence. The targeted files (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 (no website/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_project accepts only an exact match, so no two known directories can both match
Sibling: 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

  • 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 6, 2026 12:38
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 12:38
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision ba81d6fde7ea88de12a0e7ac9634a6e4f3654eae 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 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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

  • Git still probes the matched session root, not the submitted subdirectory. A repo pointing at a folder inside a non-repo root that holds no nested session would still return Not a git repository. That case is outside this PR's goal.

[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 .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 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ba81d6fde7ea88de12a0e7ac9634a6e4f3654eae — 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: 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 ships

Inventory (3 items) — 3 justified

Intent: 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).

  1. When several open session projects contain the submitted repo, "Start in new worktree" now runs git in the most specific one, whatever order the sessions are listed in. Before, it used whichever was listed first. — justified
  2. The owning spec, learn-cron-dashboard.md, now records the most-specific-root rule. — justified
  3. The test test_first_matching_root_wins is renamed to test_only_the_containing_root_matches. Its assertion is unchanged and used two unrelated roots, so it never pinned first-wins ordering. — justified

[FIRST-PRINCIPLES-REVIEWED] ba81d6f

Description read

[DESCRIPTION-READ] 3c0b2506df164a42cbde7b1047b85b690e5a60f6eba8292c3247165176cfc1fd

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ba81d6f

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

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

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ba81d6f

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 12:43
@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 Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/22137-nested-worktree-root branch from de2e393 to ae045d5 Compare November 6, 2026 15:31
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/learn-cron-dashboard.md (and files beside src/kiro_crew/dashboard/handlers/worktree.py) since this head went green (090dad8 -> b3c17ad); CI re-running.

[operator: bolichen97]

@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: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests shard 2 (Linux and Windows) is red on test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget, which fails on main as well and is outside this diff. #31625 fixes it. This PR waits for that to merge, then rebases onto it and re-runs CI.

@bolichen97
bolichen97 force-pushed the fix/22137-nested-worktree-root branch from ae045d5 to ba81d6f Compare November 6, 2026 23:19
@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 6, 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 ba81d6f, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit 678769e into main Nov 7, 2026
152 of 154 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/22137-nested-worktree-root branch November 7, 2026 01:24
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start in new worktree fails for a nested git project when another session uses its parent directory

2 participants