Repository navigation
Conversation
`atomic init` records the vault defaults but leaves `goals/`, `intents/`, and `scratch/` as untracked empty scaffolds on disk. Switching to a view that no longer projects `.vault` planned the directory's removal while those scaffolds remained, so `fs::remove_dir` failed with DirectoryNotEmpty and the switch failed closed with "untracked children are never removed recursively" -- on every platform, in the plain quick-start flow (init -> view create -> view switch). Plan the removal of untracked directories that hold no files and no symlinks anywhere beneath them (they carry no user bytes) alongside the parent directory, deepest first, in both the journaled switch planner (`expand_removals_with_data_free_dirs`) and the direct materialize path (`remove_data_free_untracked_children`). Untracked files and symlinks beneath a removed directory still block the removal with the same fail-closed guard, and non-UTF-8 directory names are left for it as well. Vault commands already create their directories on demand, so the scaffolds do not need to survive a view round-trip.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: sweep untracked data-free scaffold dirs when removing a directory
The bug
The plain quick-start flow is broken on every platform:
Reproduced identically on Linux (WSL2, Ubuntu, rustc 1.98.0) and Windows
(x86_64-pc-windows-msvc, NTFS), with and without
--force.Root cause
init_vault()creates six scaffold subdirectories on disk(
goals/,memory/,skills/,intents/,scratch/,prompts/), but only thefour default files are tracked and recorded.
goals/,intents/, andscratch/hold no files, so they never get path claims.
When a switch targets a view that no longer projects
.vault(e.g. a defaultview createoverlay, which anchors on the shared root with an empty own log),the removal plan includes the recorded files, their recorded parent dirs, and
.vaultitself — but nothing for the untracked scaffolds. The executor'sfs::remove_dir(".vault")then fails withDirectoryNotEmpty, and the operationcorrectly fails closed ("untracked children are never removed recursively"),
leaving the switch aborted and recovered.
The bash harness never caught this: CI runs only suites
09and46(
ci.yml), and01_single_file.sh— which exercises exactly this flow — is notin the CI set.
The fix
Untracked directories that hold no files and no symlinks anywhere beneath
them carry no user bytes, so their removal is safe to plan:
expand_removals_with_data_free_dirs(switch planner): expands the plannedremoval set with data-free untracked subdirectories, deepest first, before the
removal scope is cloned — so every swept directory gets its own journaled
effect, observation, and receipt.
remove_data_free_untracked_children(direct, unjournaled materialize path):sweeps the same class bottom-up immediately before the parent's
remove_dir.The fail-closed contract is unchanged for everything that matters: an untracked
file or symlink beneath a removed directory still blocks the removal
with the same guard, and directories with non-UTF-8 names are left for it too.
Mid-flight races degrade to the same
DirectoryNotEmptyfailure rather thandata loss. A Windows junction encountered as a "directory" is removed with
remove_dir, which unlinks the reparse point without touching the target.Vault commands already create their directories on demand, so the scaffolds do
not need to survive a view round-trip; after switching back only the recorded
vault content returns.
Tests
atomic-repository/tests/it/switch_untracked_dir_removal_test.rs:switch_to_empty_view_sweeps_untracked_scaffold_dirs— scaffold dirs(including nested ones) are planned and removed; fails on unfixed
dev.switch_to_empty_view_still_fails_closed_on_untracked_files— an untrackedfile beneath the removed directory keeps the fail-closed error and its bytes
survive.
vault_scaffold_dirs_do_not_block_switching_away— the exactatomic initvault shape; switching away and back round-trips the recorded vault content.
Verified: with the fix, all three pass on Windows (MSVC/NTFS) and Linux
(Ubuntu/ext4); without the fix, the two sweep tests fail on both platforms.
cargo fmt --checkandcargo clippy -p atomic-repository --all-featuresareclean for the touched files (the three remaining warnings are pre-existing
#[cfg(windows)]sites never linted by the ubuntu clippy job).