Skip to content

Preserve ignored user files during merged worktree cleanup - #1556

Merged
mergify[bot] merged 2 commits into
mainfrom
lean178/1534-preserve-ignored-files
Nov 26, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
lean178/1534-preserve-ignored-files

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Preserve ignored user files during merged worktree cleanup

Context and goal

  • Goal: After a merge, developers keep any ignored files they left in the task checkout.
  • Problem: Git reports ignored files as clean, and removing the worktree deletes those files with it.
  • Context: Cleanup can remove the task text and local receipts it generated. Other ignored files can hold developer notes or local configuration.

Closes #1534

Acceptance

  • Cleanup leaves the checkout and task branch in place when either an ignored local settings file or an unknown file under .loopzero is present.
  • A clean checkout containing only loop-zero artifacts still cleans up normally.

Base

main @ 11dc91c
Base: 11dc91c

Validation

Recorded for f48b9514ec7b

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

  • primary, claude, f48b951, approve

eowca and others added 2 commits November 26, 2026 04:53
Refuse local cleanup if Git reports ignored files other than task text and receipts. This keeps local notes and settings where the developer left them.

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero primary review by claude on f48b9514ec7b1fc3fcbe301a75d92356ed2fd754, 45.4s: approve (0 critical, 0 important, 4 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Findings without a file location:

  • suggestion: No direct test that checks.json and review receipts still allow cleanup — Acceptance requires that a checkout with only loop-zero artifacts still cleans up. test_cleanup_removes_worktree_and_branch covers only task.md. test_already_merged_finishes_partial_cleanup covers one review receipt, through the CLI. No test exercises .loopzero/checks.json, a delta receipt, or the symlinked-receipt refusal. Add these to the worktree-level test: write checks.json plus review-<12hex>-primary.json/-delta.json and assert removal succeeds, then make one of them a symlink and assert cleanup refuses.

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/worktree.py
for path in ignored.split("\0")[:-1]:
if (
(path in {".loopzero/task.md", ".loopzero/checks.json"}
or re.fullmatch(r"\.loopzero/review-[0-9a-f]{12}-(primary|delta)\.json", path))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Receipt filename allowlist duplicates the naming in cli._review_file and runners

The new regex \.loopzero/review-[0-9a-f]{12}-(primary|delta)\.json and the literals .loopzero/task.md and .loopzero/checks.json repeat naming that is also defined in three other places: cli._review_file (cli.py:1103), cli.CHECKS_FILE (cli.py:30) and the receipt-path strings in runners.py:672/1003. If a receipt name or review kind changes, cleanup will start refusing to remove every merged worktree. The only symptom is a warning, so the drift would go unnoticed. Smallest fix: define the receipt-name pattern once in worktree.py, next to task_file, and use it from cli/runners. Alternatively, add a test that builds the receipts through the real writers (cli._save_report / cli._save_review) and then calls worktree.cleanup, so drift fails CI.

Comment thread src/loopzero/worktree.py
ignored = _git(
wt, "ls-files", "--others", "--ignored", "--exclude-standard", "-z", preserve_newlines=True
)
for path in ignored.split("\0")[:-1]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Leftover atomic-write temp files permanently block cleanup

_write_json_atomically (cli.py:384) and _initialize_task (worktree.py:190) create temp files inside .loopzero/ named .checks.json-*, .review-…json-* and .task.md-*. If the process is killed before the temp file is unlinked, it stays behind as an unknown ignored file. Cleanup then refuses on every loopzero merge rerun until the user finds and deletes it by hand. Refusing is the safe choice, but these are loop-zero's own artifacts. Consider allowing those exact temp-name prefixes, or have the error message say that .loopzero/.*-XXXX temp files are safe to delete.

Comment thread src/loopzero/worktree.py
raise WorktreeError(f"no such worktree: {wt}")
if is_dirty(wt):
raise WorktreeError(f"worktree is dirty, refusing to remove: {wt}")
ignored = _git(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Ignored build/dependency caches now block cleanup and are fully enumerated

ls-files --others --ignored without --directory walks into every ignored tree, such as .venv/, node_modules/ or __pycache__/. Two effects: (a) any developer who ran tests or installed dependencies in the task worktree now gets a refusal that names only the first file, and (b) the listing can be very large and slow under the git timeout. Refusing on these files matches the stated goal, but the warning only says "fix the cause" (cli.py:1162). Consider reporting the top-level ignored directory, or a count of ignored files, so the user can decide quickly. Also consider documenting that build caches have to be removed before cleanup.

@eowca
eowca marked this pull request as ready for review November 26, 2026 07:15
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 89be895 at 07:26 UTC

11 min in the queue, 3 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 07:15 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1627
  • ✅ Merged 07:26 · 89be895 · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit 89be895 into main Nov 26, 2026
18 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1534-preserve-ignored-files branch November 26, 2026 07:27
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.

Preserve user files ignored by Git during merged worktree cleanup

1 participant