Skip to content

fix(folders): refuse an agent move that makes a same-name sibling folder - #25627

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/folder-move-same-name-15343
Oct 29, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/folder-move-same-name-15343

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: an agent cannot make two sibling folders with the same name by moving one.

#15186 made POST /api/chat/folders refuse an agent caller a same-name sibling, and #15158 applies the rule to an agent rename through PATCH /api/chat/folders/{id}. A reparent still gets around it: chat_folder_move sends a parent_id-only PATCH, so an agent can move its folder Alpha under a parent that already has an Alpha.

Why it matters

The two folders then share one path, and every later path lookup of either one is refused as ambiguous, so the agent (and the person's own path-based tools) can no longer address either folder by path.

Not a goal

Intended? / Repro

Intended? No. The rename check's own comment says "an agent never makes a same-name sibling, because the two then share one path" (src/kiro_crew/dashboard/chat_folders_routes.py:560-567), and the issue is the First Principles finding on #15158.

Repro (read on current main): in api_chat_folder_update._apply the sibling test is guarded by if refuse_duplicate_name and "name" in changes: (chat_folders_routes.py:560). chat_folder_move builds move_body = {"parent_id": dest_id} with no name (mcp_dashboard_folder_runs.py:343-345), so the test is skipped: moving Alpha (top level) under Bravo, which holds another Alpha, returns 200 and leaves two Alphas under Bravo.

What changed (motivation → approach → change)

Symptom: a move makes a same-name pair. Cause: the sibling test ran only when the PATCH carried a name. Change: run it when the name OR the parent changes.

  • chat_folders_routes.py _apply: for an internal-transport caller, the test runs when name is in the PATCH or the resulting parent differs from the current one. It compares the folder's resulting name (the new one, else its own) with the destination's children, case-folded and trimmed, under the folder-store lock, over the whole tree; the folder's own row is excluded. A PATCH that keeps both (a reposition, a colour) is not tested, so a folder that already has a twin can still be reordered. Same 409 folder_name_exists; the audit line now reads "rename or move".
  • mcp_dashboard_folder_runs.py chat_folder_move: turns folder_name_exists into a plain explanation and names the remedy (rename one first), as chat_folder_update does.
  • src/kiro_crew/docs/session-control.md (tool table) and docs/system-specs/modules/session-control.md: name the rule for moves.

Security

area: dashboard route; no listener, bind or auth change. The new refusal only narrows what an agent caller may write; browser callers are unchanged.

Backwards compatibility

Behavior change for agent callers only: a move that would make a same-name sibling is refused with the code create and rename already use. Every other move is unchanged.

Removes nothing: no key, field or error path is removed.

Tests

test/test_mcp_dashboard_folder_update.py (the endpoint, through a real aiohttp app, and the tool):

  • test_an_agent_cannot_move_a_folder_beside_its_namesake: fails on main (200).
  • test_an_agent_cannot_move_a_namesake_to_the_top_level: fails on main.
  • test_an_agent_may_move_a_folder_where_its_name_is_free.
  • test_a_move_and_rename_in_one_write_checks_the_new_name.
  • test_a_reposition_in_place_is_not_checked.
  • test_the_person_may_still_move_a_folder_beside_its_namesake.
  • test_the_move_tool_explains_a_same_name_refusal.
  • Adjusted: test_a_move_is_left_to_its_own_tool moved the nested Alpha to the top level beside the other Alpha, which this change now refuses (409). It now moves Bravo under Alpha, where the name is free, so it still checks only the channel rule.

Proof: not provable -- other: this host runs no local tests; CI runs them

Manual verification

N/A: no UI change. Static gates run locally: black, isort, flake8, scripts/docs_lint.py, comment-history gate.

Related Issues

Fixes #15343

Sibling sweep

Swept: git grep -n "refuse_duplicate_name|folder_name_exists" -- src/
Sibling: src/kiro_crew/dashboard/chat_folders_routes.py -- changed here (PATCH)
Sibling: src/kiro_crew/dashboard/chat_folders_records.py -- not affected (create already refuses)
Sibling: src/kiro_crew/mcp_dashboard_folder_runs.py -- changed here (move tool message; the rename tool already explains the code)
Sibling: POST /api/chat/folders/reorder -- not affected (changes order only, never a parent)

Pattern harvest

Not generalizable: one guard extended to the write that bypassed it.

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

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 29, 2026 03:45
@CrysisDeu
CrysisDeu requested a review from iamwhatever October 29, 2026 03:45
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 964ad2fb7d9f00b25c50304b71a4121b5735e279 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 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the PATCH route's existing sibling-name check now also covers a parent change, and nothing is taken away.

[DESIGN-REVIEWED] 964ad2f

Description read

[DESCRIPTION-READ] 9af95146633fd36a4f6302fc9623e10c125b0fbf261a94a40535465b6bba232d

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

The fix extends the existing agent same-name guard to the one write that skipped it, so nothing blocks.

What this change ships

Inventory (5 items) — 5 justified

Intent: stop an agent from ending up with two sibling folders that have the same name and so can't be told apart by path, by moving one of them. This is a FIX (#15343).

  1. An agent moving a folder into a parent that already holds a folder of the same name now gets a 409 folder_name_exists — justified
  2. When an agent moves a folder and renames it in the same write, the check uses the new name — justified
  3. The chat_folder_move tool now explains a same-name refusal and tells the agent to rename one folder first — justified
  4. The audit line now says "rename or move" — justified
  5. The tool table and the session-control spec now describe the move rule — justified

[FIRST-PRINCIPLES-REVIEWED] 964ad2f

Description read

[DESCRIPTION-READ] 3ecb96de9a4ffed418a8ffba40117e61be4b0ee33138c4111340871809deb398

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 964ad2f

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

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

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 964ad2f

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

@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 29, 2026
Create and rename already refuse an agent caller a sibling whose
case-folded name is taken under the same parent, but chat_folder_move
sends a parent_id-only PATCH, so an agent could move Alpha under a parent
that already holds an Alpha; the two then share one path and every later
path lookup of either is refused as ambiguous.

PATCH /api/chat/folders/{id} now runs the same test, under the same lock,
when an internal-transport caller changes the parent, comparing the
folder's resulting name with the destination's children (409
folder_name_exists). A write that keeps both the name and the parent is
not tested. chat_folder_move explains the refusal and names the remedy.
The browser keeps a person's freedom to put two alike.

Fixes #15343
@CrysisDeu
CrysisDeu force-pushed the fix/folder-move-same-name-15343 branch from d44a6d3 to 964ad2f Compare October 29, 2026 11:31
@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 Oct 29, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 29, 2026 18:04

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

Tier 1 auto-approve: fix (5 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the folder PATCH route's agent same-name-sibling check now also runs on a reparent (chat_folder_move sends a parent_id-only PATCH), not only on a rename; the move tool explains the 409, and tests cover move, move-and-rename, reposition in place and the person's unchanged freedom. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/session-control.md.

@KiroCrewCaptain
KiroCrewCaptain merged commit e3b9f4a into main Oct 29, 2026
135 of 157 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/folder-move-same-name-15343 branch October 29, 2026 18:06
@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.

Refuse an agent reparent that would make a same-name sibling folder

2 participants