Skip to content

fix(notes): open notes in a vault at a drive root - #24788

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
leonlaiyc:claude/md-notebook-drive-root-vault
Nov 4, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
leonlaiyc:claude/md-notebook-drive-root-vault

Conversation

@leonlaiyc

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A Notes vault whose folder is a drive root (D:\) or a share root opens, reads and saves its notes instead of refusing every one as escaping the vault.

md_notebook.server_paths.safe_join refuses a note unless its realpath starts with root_resolved + os.sep. os.path.realpath keeps a root's trailing separator, so for a vault at D:\ the prefix is D:\\ and no path matches. Attaching the folder succeeds (it passes the sensitive-path floor), then every note request answers 400 path escapes vault, and so does a subfolder content root, which also goes through safe_join.

Why it matters

A dedicated notes drive, or a mapped share whose root is the git checkout, is a normal Windows layout. The vault looks attached but is unusable, and the error blames the note path rather than the check.

Not a goal

What changed (motivation → approach → change)

Symptom: every note in a drive-root vault is refused. Cause: the containment prefix doubles the separator a root already ends with. Change: strip the trailing separator before appending one, the rule sandbox_plan.path_within uses. The check stays an inline startswith on the realpath, because the function's docstring records that this shape is the py/path-injection barrier for the returned value. For every non-root vault the prefix is unchanged, since a realpath ends in a separator only at a root.

Backwards compatibility

Compatible: the check now admits paths under a root vault that it wrongly refused. For any other vault the comparison is byte-identical.

Removes nothing: no path, key or record is hidden or removed.

Tests

Proof: not provable -- other: prove.py on this Windows host reported INCONCLUSIVE (its mutated run errored at collection); the manual revert below shows the test red without the fix

test_md_notebook_git_trust.py::test_safe_join_admits_a_note_below_a_drive_root_vault uses the drive root of tmp_path as the vault and asserts a note below it resolves. On main it fails with ApiError: path escapes vault (server_paths.py:547). The six existing test_safe_join_rejects_escapes_before_touching_the_filesystem cases still pass, so every escape is still refused.

Related tests on Windows / Python 3.13: test_md_notebook_git_trust.py, test_md_notebook_notes.py, test_md_notebook.py: 170 passed, 17 skipped (-n 4). flake8, isort, black, comment-history, brand, subprocess-encoding and test_flake_pattern_ratchet.py (62 passed) are clean. Not run locally: semgrep (not installed on this host; CI's SAST job runs it). mypy on this host reports one error, in publish_governance.py:299, a file this diff does not touch.

Manual verification

N/A — unit coverage sufficient: the defect is pure path arithmetic in one function, and the test runs it against a real drive root.

Related Issues

Closes #24785

Sibling sweep

Swept: git grep -nE "startswith(.{0,70}(+ ?os.sep|+ ?os.path.sep)" origin/main -- 'src/*.py'
Sibling: src/kiro_crew/apps/builtins/md_notebook/server_paths.py:546 -- changed here
Sibling: src/kiro_crew/dashboard/file_api/pinned_io.py:430 -- tracked in #24742
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- tracked in #24742
Sibling: src/kiro_crew/folder_steering.py:339 -- tracked in #24743
Sibling: src/kiro_crew/dashboard/terminal_commands.py:472 -- tracked in #24694
Sibling: src/kiro_crew/edition_install_fence.py:42 -- not affected -- each root is rstripped of separators before the separator is appended
Sibling: src/kiro_crew/apps/agent_launch.py:221 -- not affected -- its roots are the launch directory the crew chose, never a drive root
Sibling: src/kiro_crew/apps/module_loader.py:199 -- not affected -- its roots are app source directories, never a drive root

Pattern harvest

Rule candidate: semgrep
Pattern: x.startswith(<realpath or normpath result> + os.sep) without an rstrip(os.sep), which refuses everything under a drive root

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

🤖 Generated with Claude Code

@leonlaiyc
leonlaiyc requested review from a team and KiroCrewCaptain as code owners October 27, 2026 07:20
@leonlaiyc
leonlaiyc requested a review from iamwhatever October 27, 2026 07:20
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 4efe0ebd3aba669197ef5bdbcdceadfa631f6b44 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 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 4efe0ebd3aba669197ef5bdbcdceadfa631f6b44 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns. The change is small and fixes the root cause. Linux CI runs the same branch, because the vault root / keeps its trailing separator through realpath just as D:\ does on Windows.

[DESIGN-REVIEWED] 4efe0eb

Description read

[DESCRIPTION-READ] 1e576f2cae4c8aeb8903e40c7cf6e789397a9654dfecade6f5277be49485389c

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 4efe0ebd3aba669197ef5bdbcdceadfa631f6b44 via the fork AI-review pipeline — 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

This is a one-line fix to the code that caused the bug, and it has a test that fails on main. The four sibling sites it leaves alone already have their own issues (#24742, #24743, #24694).

What this change ships

Inventory (2 items) — 2 justified

Intent: let a Notes vault set to a drive root or a share root open, read and save its notes. FIX.

  1. Notes under a drive-root or share-root vault now open and save, where before each one was refused with "path escapes vault" — justified
  2. A new test treats the drive root of tmp_path as the vault and checks that a note below it resolves — justified

[FIRST-PRINCIPLES-REVIEWED] 4efe0eb

Description read

[DESCRIPTION-READ] 72206ca2469412637a4d6524353793b19b52db23b4eb20ed686570f89438c58c

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 4efe0ebd3aba669197ef5bdbcdceadfa631f6b44 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4efe0eb

@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 27, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

CI attribution for the red checks on this head. None of them comes from this diff, which only changes the Notes vault path code.

Bringing this branch up to date with main clears the stale-xfail failure. No code change is needed for either test failure.

Failing checks on head 145e0bc21901be5eac2158fa6e4db24f6bdaa302:

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 4efe0ebd3aba669197ef5bdbcdceadfa631f6b44 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4efe0eb

@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 27, 2026
safe_join compared the note realpath against root_resolved + os.sep. A
vault at a drive or share root keeps its trailing separator through
realpath, so the prefix became D:\\ and every note, and every
subfolder content root, was refused as escaping the vault. Strip the
separator first, the rule sandbox_plan.path_within uses; every escape
is still refused.

Closes kirodotdev#24785

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamwhatever
iamwhatever force-pushed the claude/md-notebook-drive-root-vault branch from 7cf2af2 to 4efe0eb Compare November 2, 2026 13:30
@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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 2, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 2, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

CI attribution for head 4efe0ebd3a: Backend Tests (3.12, 6) failed in test_subagent_stop_reason_consistency.py::test_whatever_lands_after_the_claim_the_run_is_completed_once[deadline]. That test has nothing to do with this Notes diff. Its captured log shows the claimed result write's 5 s drain bound expiring on the loaded runner (did not finish in 5s). I filed this as #28239, and #28247 fixes it in the test alone. A re-run of that shard should clear it.

@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 2, 2026
@iamwhatever iamwhatever self-assigned this Nov 2, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Holding for a human reviewer under the sensitive-change rule, not because of a defect.

This PR changes the containment check in safe_join (server_paths.py#L548), the Notes vault's path-escape guard. Any change to what a path guard admits is reserved for a person to sign off.

The code looks correct to me. rstrip(os.sep) only changes the prefix when the realpath ends in a separator, which happens only at a root, so every other vault compares exactly as before. The component checks above it still refuse absolute paths, .., drive letters and UNC paths. The new test (test_md_notebook_git_trust.py#L388) uses / as the vault on Linux, so it fails on the old code there as well. All AI lanes are clean, CI is green, and the sibling sites are tracked in #24742, #24743 and #24694.

What clears it: a human maintainer's review of the guard change.

Reviewed head: 4efe0ebd3aba669197ef5bdbcdceadfa631f6b44

— crew-pr-reviewer (r141)

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at head 4efe0eb.

What changed: safe_join in md_notebook/server_paths.py now strips a trailing separator from the resolved vault root before appending os.sep. A drive-root vault (D:\ or /) keeps its separator through realpath, so the old root + os.sep check became D:\\ or // and rejected every note inside the vault.

Containment check: this cannot widen access outside the vault.

  • os.path.realpath only returns a trailing separator for a filesystem or drive root, so for any non-root vault rstrip(os.sep) is a no-op and the check is byte-identical to before.
  • For a root vault, the prefix becomes exactly / or D:\, which is the vault itself. Every path below a root is by definition inside it.
  • The earlier path escapes vault guard on the candidate and the resolved != root_resolved equality are unchanged.
  • Plain string prefix handling, no pattern matching added. This also matches how sandbox_plan.path_within handles the same case.

Test: the new test_safe_join_admits_a_note_below_a_drive_root_vault builds a drive root from the real tmp path and asserts the nested note resolves, which fails on the old prefix.

Gates at this head: 92 checks passed, 0 red, 0 pending, including E2E, both E2E Gateway Boot jobs and PR Readiness; readiness label passed; all AI lanes green; no other open change requests; mergeable.

@bolichen97
bolichen97 enabled auto-merge (squash) November 4, 2026 09:06
@bolichen97
bolichen97 merged commit 75a23cb into kirodotdev:main Nov 4, 2026
138 of 140 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 4, 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notes: every note in a vault at a drive root is refused as escaping the vault

3 participants