Skip to content

fix: drop redacted file rows that collide with a directory in the tree - #17460

Closed
iamwhatever wants to merge 1 commit into
mainfrom
replace/project-tree-collision-13580
Closed

iamwhatever wants to merge 1 commit into
mainfrom
replace/project-tree-collision-13580

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: stop GET /api/project/tree from returning a redacted file row that collides with a directory row, which crashes the whole chat route.

Opening a chat whose project directory holds one particular path shape crashes the entire route with Error: Path collides with an existing entry: "<dir>/<prefix>-[REDACTED: credential]", thrown inside the tree's useLayoutEffect and caught by nothing. The Files rail, the folder tab and the chat all go down with it.

Why it matters

Any workspace can trigger it by containing a directory whose name plus its children form a base64-alphabet run the redactor treats as one secret (e.g. a case-id segment of digits followed by camel-case package segments, ~43 chars with slashes in it). The user gets no tree, no folder panel and no chat for that project until they find and rename the directory, with no hint which one is at fault.

Not a goal

Not loosening the bare-secret detector's slash cap: that is a measured trade-off against real 40-char keys, and the tree must not crash on whatever the redactor returns regardless. Not fixing the separate +/= byte-sort-vs-segment-sort ordering crash tracked in #14289 (same error string, different root cause). Not changing the frontend: its half already landed on main via dedupeTreePaths (#14077).

What changed (motivation → approach → change)

Symptom: a redacted file row and a redacted directory row reach @pierre/trees with the same name; the tree models a name as one or the other and throws on the second.

Root cause: _project_tree_body (in src/kiro_crew/dashboard/file_api/project_tree.py) redacts every listed path with redact_path_segments. When the whole-string credential pass matches a run that spans /, the helper falls back to the whole-string result, so every deep path under that run collapses onto one shorter string such as notes/case-[REDACTED: credential]. The function then de-duplicates paths and directories each on its own, so a collapsed file row and a collapsed directory row can both survive with the same name, or a collapsed file row can become the proper parent of another file row.

Change:

  • _project_tree_body drops a redacted file row that equals a directory row, or that is a proper parent of another file row, after the per-list de-dup (_project_tree_drop_file_directory_collisions). The file row is the one to drop: its real path is gone, so nothing could open it, while the directory may still carry visible children. On an unredacted listing one name is one inode, so the filter never bites.
  • The new helper is registered on the dashboard/handlers/files facade (the composition contract), so the composed function resolves it.
  • The Project tree paragraph in docs/system-specs/modules/learn-cron-dashboard.md records the rule.

This ports the backend half of #13580 by @coolpistachio (Sergio Ramirez Martinez), with credit — the fix commit keeps their authorship. api_project_tree moved to file_api/project_tree.py in #16758 and the redaction moved into _project_tree_body in #16029, so the original PR's target (dashboard/handlers/files.py) no longer holds this code; the frontend half already landed on main via #14077.

Backwards compatibility

Compatible: the response shape is unchanged; the only difference is that a redacted file path which the tree could not represent (and no client could open) is absent from paths. Unredacted listings are byte-identical.

Tests

  • test/test_project_tree.py::test_a_file_that_redacts_onto_a_directory_row_is_dropped: the collapsed name stays a directory row, leaves paths, neighbours keep their rows, and paths ∩ directories is empty.
  • test/test_project_tree.py::test_a_file_that_redacts_onto_another_files_parent_is_dropped: the other shape, where the collapsed file is a parent of a deeper file.
  • Full test/test_project_tree.py (64) green; test/test_dashboard_files_composition_contract.py (84) green; mypy src/kiro_crew/dashboard/file_api/project_tree.py, isort, flake8, scripts/docs-lint.sh all clean.

Pattern harvest

Rule candidate: review-prompt
Pattern: a list de-duplicated per collection is handed to a consumer whose invariant spans the collections (a file name and a directory name share one namespace).

Fixes #17459

When /api/project/tree redaction falls back to the whole-string result
(a match straddling a /), deep paths collapse onto one shorter string,
so a redacted file row can equal a directory row or become another
file's parent. @pierre/trees throws "Path collides with an existing
entry" on a name that is both, uncaught inside the tree's layout effect,
crashing the whole chat route.

_project_tree_body now drops such a file row after the per-list de-dup
(_project_tree_drop_file_directory_collisions), keeping the directory
row (the collapsed file has no real path left to open). On an
unredacted listing one name is one inode, so the filter never bites.

The frontend half of the original PR (#13580) is already on main via
dedupeTreePaths (#14077); this ports only the still-missing server-side
guard onto the relocated file_api/project_tree.py module.
@iamwhatever
iamwhatever requested a review from a team as a code owner October 6, 2026 17:31
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

Premise-level review of 2a93beed71ae91164263b7798651ec3b45bd392c — 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: BLOCK

The backend filter re-implements dedupeTreePaths, which already drops the same file-vs-directory collision before the only consumer that could crash on it.

Not justified as shipped

  • Item 1 — duplicate of website/src/pierre/PierreWorkspaceTreeImpl.tsx:409: the description itself says "its half already landed on main via dedupeTreePaths (fix(files): drop file rows that shadow a same-named directory #14077)". That function drops a file that equals an explicit dir/ entry or an implied parent, which covers both shapes this PR's tests exercise.
  • Item 2 — rides along: a facade re-export of the duplicate helper.
  • Item 3 — rides along: the spec sentence describes the duplicate. Its line "so an older gateway cannot crash a newer dashboard" argues for the frontend copy, not this one.

What this change ships

Inventory (4 items) — 1 justified

Intent: stop a redacted path collision from crashing the chat route's file tree. This is a FIX.

  1. The tree payload no longer lists a redacted file whose name is also a directory — duplicate of website/src/pierre/PierreWorkspaceTreeImpl.tsx:409 (dedupeTreePaths)
  2. _project_tree_drop_file_directory_collisions exported on the handlers/files facade — rides along
  3. The Project tree spec paragraph records the drop rule — rides along
  4. Two tests pin the two collision shapes — justified

Blockers

  • Duplicates an existing mechanism, and the zero option costs nobody. I grepped project/tree outside the tests. Only one non-capture place renders tree rows: PierreWorkspaceTreeImpl (FolderPanel renders the same component). At :806 it already runs dedupeTreePaths([...tree.paths, ...directories.map(d => d + '/')]), and the dashboard ships in the same package as the gateway. Neither added test shows a crash on base; both assert only on the backend payload.
    Subtraction: delete _project_tree_drop_file_directory_collisions, its call in _project_tree_body, its facade re-export and the spec sentence.
    Clears when: the helper is removed, or the PR names a client of /api/project/tree that bypasses dedupeTreePaths and still crashes on main.

[FIRST-PRINCIPLES-REVIEWED] 2a93bee

Description read

[DESCRIPTION-READ] d70607a8f5ae211b97ad006ccd9e6e791b6bdb496719ef80b13a56bd680e5295

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

There's no evidence the crash still happens on main: the frontend already drops these exact rows, so this filter is either redundant or aimed at the wrong code path.

Watch

  • The stated root cause doesn't match the code on main. The description says "a redacted file row and a redacted directory row reach @pierre/trees with the same name". But PierreWorkspaceTreeImpl.tsx:806 already passes [...tree.paths, ...tree.directories+'/'] through dedupeTreePaths. That function drops any file row that matches a directory or is the parent of another row, which is the same rule _project_tree_drop_file_directory_collisions adds. That leaves two possibilities, and the PR shows neither:

    1. The crash in Workspace file tree crashes when redaction collapses two paths onto one string ("Path collides with an existing entry") #17459 comes from somewhere the backend filter can't reach. Candidates are fedStateRows.paths (added after the de-dup at :810) and mode === 'changed' (built from statusEntries). If so, the reported crash survives this PR.
    2. This is defence-in-depth for a crash that's already fixed. If so, the Goal and "Why it matters" overstate it.

    Clears when: the PR shows a payload that crashes the current main frontend and stops crashing with this change, with a reproduction or a test against the tree component, or the description is corrected to say this is backend defence-in-depth and the actual crash site in #17459 is named.

[DESIGN-REVIEWED] 2a93bee

Description read

[DESCRIPTION-READ] 7935b66e4e9d94cd4511c1d5986e5161925ede91fe5f792af93a92794dd81d1a

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 2a93bee

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

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

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Closing: the crash this targeted is already fixed on main. #14077 added dedupeTreePaths in website/src/pierre/PierreWorkspaceTreeImpl.tsx, which drops the file-vs-directory collision (and the implied-parent shape) before the paths reach @pierre/trees — and every client of /api/project/tree routes through that component. First Principles Review correctly flagged this backend filter as redundant defence-in-depth rather than a live fix, so there is nothing left to ship here. Thanks for the thorough root-cause write-up on the original report.

@iamwhatever iamwhatever closed this Oct 6, 2026
@iamwhatever
iamwhatever deleted the replace/project-tree-collision-13580 branch October 6, 2026 18:57
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2a93bee

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

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.

Workspace file tree crashes when redaction collapses two paths onto one string ("Path collides with an existing entry")

2 participants