Skip to content

view switch to a vault-less view fails on untracked empty skeleton dirs under .vault #275

Open

Description

@geekgonecrazy

Summary

atomic view switch main fails with an internal error when the target view's change filter does not include the vault changes, because the directory-removal effect treats untracked children (including the empty skeleton dirs init_vault pre-creates) as a fatal error instead of leaving the directory in place.

Reproduce

Repro'd on macOS (should be platform-independent), today on main:

mkdir /tmp/test1 && cd /tmp/test1
git init
echo hi > hi && git add hi && git commit -m test
echo hi2 > hi2 && git add hi2 && git commit -m test2

atomic init                       # creates view `dev`, records .atomicignore + .vault/**
atomic git shim enable
atomic git shim reconcile

# make a working-copy edit (e.g. via agent), record it into a draft view
# (draft = hushed-rose-5438 in my repro, parent: main)

atomic view switch hushed-rose-5438   # works
atomic view switch dev                # works
atomic view switch main               # FAILS

Actual:

✗ Internal error: atomic:REPOSITORY: Invalid operation: cannot remove directory '/private/tmp/test1/.vault': untracked children are never removed recursively

What happens

  • main is the imported Git history (test, test2 — just hi/hi2) and contains no .vault at all.
  • atomic init created dev and recorded .atomicignore + .vault/** files. It also pre-created six skeleton dirs on disk: goals/, intents/, scratch/ stay empty forever (atomic-repository/src/repository/vault.rs, init_vault).
  • Empty dirs are invisible to Atomic (no files → no vertices → never tracked), so those three dirs are untracked residue.
  • Switching to any view whose filter includes the vault changes works (the draft's dependency closure inherits them). Switching to main must remove all of .vault. The tracked files delete fine, but then the journaled directory-removal effect runs fs::remove_dir('.vault') → DirectoryNotEmpty → deliberate fail-closed refusal → the whole switch aborts and is rolled back by recovery.

The fail-closed refusal itself is correct — untracked work must never be recursively deleted. The problem is that it aborts the entire switch instead of just leaving the directory behind.

Confirmation

Removing only the three empty untracked dirs makes the switch succeed:

rmdir .vault/goals .vault/intents .vault/scratch
atomic view switch main
# ✓ Switched to view: main (1 files updated)

No data is lost either way — the incomplete switch is recovered by an automatic recover op (verified via atomic op log).

Affected code

  • atomic-repository/src/repository/operation.rs — remove_filesystem_effect_path, DirectoryNotEmpty → RepositoryError::InvalidOperation
  • atomic-repository/src/repository/materialize.rs — remove_absent_entries, same pattern
  • atomic-repository/src/repository/vault.rs — init_vault pre-creates the empty skeleton dirs

Fix options

  1. Skip instead of fail (executor-level): when fs::remove_dir returns DirectoryNotEmpty during a switch/materialize removal, log and leave the directory on disk, do not error. Minimal change, unblocks every affected repo, keeps "never delete untracked work" intact. Downside: silently leaves any untracked content, not just empty dirs.
  2. Surgical empty-dir check: same skip behavior, but only when the directory's remaining children are all empty directories (recursive). Anything with an untracked file still fails closed. More precise, slightly more code.
  3. Plan-level: teach the switch/materialize plan (where EffectValue::Absent entries are built) to not emit a removal effect for directories whose only children are untracked empty dirs, keeping the executor's fail-closed behavior as a last-resort guard.

Regardless of choice, add a regression test reproducing the full sequence: git import → atomic init (vault) → record → switch to the imported view with untracked empty dirs under .vault, asserting the switch succeeds and the untracked dirs remain on disk.

Activity

  1. graywolf336 commented on Oct 29, 2026

    @graywolf336
    Contributor

    Proposed fix: decide which directories to retain while planning switch/materialization, rather than treating a failed remove_dir as a successful Absent effect.

    • For a directory absent from the target view, preserve it if entries will remain after planned tracked removals and shelving; propagate that decision to its ancestors. Still remove tracked children that are absent from the target. This can preserve any untracked content, not just empty directories, consistent with the switch policy of leaving novel untracked work alone.
    • Do not omit removals needed for a directory-to-file/symlink transition: if untracked content blocks the target, continue to fail safely. Keep the executor’s DirectoryNotEmpty guard for races after planning.
    • Share this policy between switch and direct materialization, and explicitly distinguish intentionally retained directories from unexpectedly unleased paths. No Absent effect or successful removal receipt should be recorded for a retained directory; that keeps verification, undo, and recovery honest.

    Regression tests should cover the reported vault-less switch, nested untracked files and directories, switch-back/undo, direct and partial materialization, type-change collisions, and a child appearing after planning. The existing test that expects materialization to fail on an untracked child would need updating if we choose the broader preservation policy.

  2. Zaba505 commented on Nov 11, 2026

    @Zaba505

    Another trigger for the same refusal, on atomic 0.21.0 (Linux x86_64). Two differences from the original report matter for the fix:

    1. The leftover is an ignored file, not empty directories. A fix limited to empty untracked directories (option 2) wouldn't cover this. Retaining the directory at planning time, as proposed in the comment above, would.
    2. The switch is between two views with identical state: a child draft view with no changes of its own, and its parent. A removal effect for the directory is still emitted. The target view genuinely lacks .claude, but so does the current view, so I'd expect no filesystem effects at all.

    Conditions. All three are needed. Dropping either of the first two makes the switch succeed with ✓ Switched to view: <parent> (0 files updated).

    • .claude is in [workspace] expose.
    • The parent view's change deleted the tracked .claude/commands/*, then untracked the directory with atomic remove --keep -r .claude.
    • .claude/settings.local.json (gitignored) remains on disk.
    $ atomic view switch keen-sunset-f626
    ✗ Internal error: atomic:REPOSITORY: Invalid operation: cannot remove directory '$REPO/.claude': untracked children are never removed recursively
    [exit 128]
    

    As in the original report, the aborted switch shows up in atomic op log as a switch_view op with verification: in_progress, followed by a recover op. .atomic/deferred-tree-ops.json still holds the delete .claude directory op.

    Repro script (isolated $HOME, temp repo; draft views created by simulating the Claude Code hooks)
    #!/usr/bin/env bash
    # Repro (atomic 0.21.0): `atomic view switch` to the parent draft view fails with an internal
    # error when the parent's change untracks a directory that is listed in [workspace] expose and
    # still holds a gitignored file. Both views have the same state.
    # Needs atomic, git, jq. Uses an isolated $HOME and temp repo. The draft views are created the way
    # the Claude Code hooks create them, by piping hook JSON into `atomic agent hooks claude-code <verb>`.
    set -u
    atomic --version
    export HOME="$(mktemp -d)"; cd "$(mktemp -d)"
    run()  { printf '\n$ %s\n' "$*"; "$@"; echo "[exit $?]"; }
    view() { atomic status 2>/dev/null | sed -n 's/^On view //p'; }
    hook() { jq -nc --arg sid "$SID" --arg cwd "$PWD" --arg tr "$HOME/t.jsonl" --argjson x "$2" \
               '{session_id:$sid, cwd:$cwd, transcript_path:$tr} + $x' | atomic agent hooks claude-code "$1"
             echo "[hook $1 exit $?] view=$(view)"; }
    new_session() { SID="$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)"; : > "$HOME/t.jsonl"
                    hook session-start '{"hook_event_name":"SessionStart","source":"startup"}'; }
    
    atomic identity new repro -e repro@example.invalid --set-default
    atomic identity agent create repro-claude --agent-type claude-code --local --expires 1d
    atomic agent identity set repro+repro-claude
    
    # tracked .claude/commands/hello.md, plus an ignored .claude/settings.local.json
    git init -q -b main repo && cd repo
    git config user.name repro && git config user.email repro@example.invalid
    mkdir -p .claude/commands && echo cmd > .claude/commands/hello.md && echo hello > README.md
    echo '.claude/settings.local.json' > .gitignore
    git add -A && git commit -qm init
    echo '{}' > .claude/settings.local.json
    atomic git import --no-vault
    printf '\n[workspace]\nexpose = [".claude"]\n' >> .atomic/config.toml   # needed to trigger
    
    # session 1 (draft view A): delete the tracked files, untrack .claude/ but keep its bytes
    new_session; PARENT="$(view)"
    hook user-prompt-submit '{"hook_event_name":"UserPromptSubmit","prompt":"drop .claude/commands"}'
    run atomic remove -r .claude/commands
    run atomic remove --keep -r .claude                                      # needed to trigger
    hook stop '{"hook_event_name":"Stop","stop_hook_active":false}'
    
    # session 2 creates draft view B as a child of A; switching back to A fails
    new_session
    run atomic view list -a
    run ls -A .claude
    run atomic view switch "$PARENT"
    run atomic status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions