Skip to content

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

Closed
coolpistachio wants to merge 1 commit into
kirodotdev:mainfrom
coolpistachio:fix/project-tree-file-directory-collision
Closed

coolpistachio wants to merge 1 commit into
kirodotdev:mainfrom
coolpistachio:fix/project-tree-file-directory-collision

Conversation

@coolpistachio

Copy link
Copy Markdown

Problem / Motivation

Opening a chat whose project directory holds one particular path shape crashes the whole route with:

Error: Path collides with an existing entry: "<dir>/<prefix>-[REDACTED: credential]"
    at Hn.createFileChild (PierreWorkspaceTreeImpl-*.js)
    at e.resetPaths

The Files rail, the folder tab and the chat itself go with it, because the throw happens inside the tree's useLayoutEffect and nothing catches 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 a secret. In my case a notes folder named after a case id, with two vendored packages cloned under it, was enough. The user gets no tree, no folder panel and no chat for that project until they find and rename the directory, and the error gives no hint which one.

What changed (motivation → approach → change)

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

Root cause: /api/project/tree redacts every listed path with redact_path_segments. When the whole-string credential pass matches a run that spans / (here: a case-id segment of digits followed by camel-case package segments, 43 chars, three slashes, which clears the bare-secret gates), the helper falls back to the whole-string result, so every path under that run collapses onto one shorter string such as notes/case-[REDACTED: credential]. The endpoint then de-duplicated paths and directories separately, so a collapsed Config file and a collapsed docs/plans directory both survived, with the same name.

Change:

  • api_project_tree drops a redacted file row that equals a directory row, or that is a proper parent of another file row (_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 touches a real path.
  • PierreWorkspaceTreeImpl applies the same rule to the merged path set before resetPaths, next to the existing duplicate de-dup, so an older gateway cannot crash a newer dashboard.
  • The Project tree paragraph in docs/system-specs/modules/learn-cron-dashboard.md records the rule.

I left the bare-secret detector alone. Its slash cap is a measured trade-off against real 40-char keys, and loosening it to save a tree row is not this PR's call; the tree must not crash on whatever the redactor returns.

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.
  • website/src/test/PierreWorkspaceTreeImpl.test.tsx "drops a file row whose name is also a directory before it reaches the model": the wrapper hands resetPaths a set with no file/directory name clash.

All three fail on main and pass with the change.

Manual verification

  • Rebuilt the directory names of the workspace that crashed (names only) under a temp project and served it through the patched api_project_tree with the real redactor: 200, 45 redacted entries, no file row equal to a directory row or to another file's parent; with the new filter neutralized the same run reports the one colliding string from the stack trace above.
  • python3 scripts/local-gate.py (related tests, both surfaces): frontend set 535 files / 14,133 tests green; backend sets 40,011 + 35,638 green with 61 + 15 failures that reproduce identically on main in this environment (a checkout and pytest basetemp under the agent's ~/.kiro/crew/scratch, which the file-explorer and design-tweak apps refuse as a sensitive path; no rg on the host; ssh -G on a data-home path; Playwright installer), plus one pty SIGINT terminal test that passed when re-run alone on both trees. None of them import the changed handler.
  • Static gates: check_black_formatting.py, check_subprocess_encoding.py, isort, flake8, mypy src/kiro_crew, scripts/docs-lint.sh, check_harness_parity.py, npx tsc -p tsconfig.app.json, eslint --max-warnings 0 on the two touched frontend files.
  • Not done: a live dashboard render against a patched gateway build. The unit test covers the wrapper's path set; the rendered tree is unchanged for every listing that did not crash before.

Screenshots / video

Why no screenshot: the change removes a crash; a listing that rendered before renders identically, and the listing that crashed now renders the ordinary tree with one inert redacted file row absent.

Related Issues

N/A — no open issue; the report and the reproduction are in this PR.

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)

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

The workspace tree crashed a whole chat route with "Path collides with
an existing entry" from @pierre/trees. The project-tree endpoint redacts
every listed path before egress, and when the whole-string match spans a
"/" (a bare-secret run made of a digit-heavy segment plus camel-case
segments, at most three slashes), every path under that run collapses
onto one shorter string. The endpoint de-duplicated files and
directories separately, so a collapsed FILE row and a collapsed
DIRECTORY row with the same name both reached the tree builder, which
throws on a name that is both, uncaught inside the layout effect.

The endpoint now drops a redacted file row that equals a directory row
or is a proper parent of another file row; the collapsed file has no
real path left to open, while the directory may still carry children.
The frontend applies the same rule to the merged path set before
resetPaths, so an older gateway cannot crash a newer dashboard. The
owning spec paragraph records the rule.
@dwu96

dwu96 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@dwu96

dwu96 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 26, 2026
@dwu96

dwu96 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

5 similar comments
@dwu96

dwu96 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

Copy link
Copy Markdown
Contributor

PR triage (automated, diff-level): PARTIALLY_COVERED by merged #14077. Please rebase.

I compared this PR's diff (merge base 5ad8818fa7) with current origin/main (cc7e79894e).

Already on main (frontend half): #14077 (PR, merged 2026-10-02) added dedupeTreePaths() in website/src/pierre/PierreWorkspaceTreeImpl.tsx. It drops a file row whose path equals an explicit dir/ row or the implied parent of another path, and the directory row is kept. That is the same rule as the directoryNames filter here. #14077 also applies it to mode === 'changed', which this PR does not, so the frontend change and its vitest case are now redundant and conflict with main.

Not on main (backend half): main has no server-side equivalent of _project_tree_drop_file_directory_collisions. api_project_tree no longer lives in dashboard/handlers/files.py. #16758 moved it to src/kiro_crew/dashboard/file_api/project_tree.py, and #16029 moved the redaction into _project_tree_body(). That function still only de-duplicates each list on its own (dict.fromkeys(redact_path_segments(...))). redact_path_segments still falls back to the whole-string result when a match spans a /, so paths ∩ directories can still be non-empty in the API response. Other clients of /api/project/tree would still get the colliding rows.

Suggested next step: rebase onto main and drop the PierreWorkspaceTreeImpl.tsx and test changes. Port the helper into file_api/project_tree.py::_project_tree_body after the per-list de-dup. Re-point the two test_project_tree.py cases at the new module's redact_path_segments binding, and rebase the spec paragraph onto the current Project tree text. The PR is currently mergeable_state: dirty.

I found no breaking change and no P0 bug.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you for this, @coolpistachio — the root-cause write-up on the redaction collapse was excellent and made the problem easy to confirm.

Since you opened this, the crash was fixed on main by #14077 (merged 2026-10-02). It added dedupeTreePaths in website/src/pierre/PierreWorkspaceTreeImpl.tsx, which drops a file row that collides with a directory row (and the implied-parent shape) before the paths reach @pierre/trees — the same rule your frontend change applied. Every client of /api/project/tree routes through that component, so the collision can no longer crash the tree.

Your backend _project_tree_drop_file_directory_collisions would be defence-in-depth on top of that, but a First Principles review confirmed there is no remaining client it would protect, so there is nothing left to merge here. I'm closing this as already fixed by #14077. Thanks again for the careful report and reproduction.

@iamwhatever iamwhatever closed this Oct 6, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants