Skip to content

fix(worktree): preserve index-hidden changes - #487

Open
testikun wants to merge 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-472-index-safety
Open

fix(worktree): preserve index-hidden changes#487
testikun wants to merge 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-472-index-safety

Conversation

@testikun

@testikun testikun commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #472. Automatic worktree reclamation trusted git status and non-force git worktree remove to detect local work. assume-unchanged and skip-worktree index flags can hide a modified tracked file, allowing the only copy to be deleted.

Value

A child worktree is preserved whenever its index contains state that can hide local changes. This prevents silent loss of uncommitted work while retaining the existing automatic cleanup behavior for provably clean worktrees.

Approach

  • Read a bounded, NUL-delimited git ls-files -v -z inventory before cleanup.
  • Preserve the worktree for assume-unchanged, skip-worktree, unknown entries, truncated output, or inspection failure.
  • Keep the check read-only: no index flag clearing, reset, clean, checkout, or force removal.
  • Add real temporary-Git-repository regression coverage for both flags, clean and modified files, index-byte preservation, unusual paths, and malformed/unavailable inventory.
  • Record the design and ablation result in docs/design/WORKTREE_INDEX_SAFETY.md.

Validation

  • node --test --experimental-strip-types tests/extensions/shared/worktree.test.ts passed: 37/37.
  • bun run check passed: config contract, discipline ledger, Web build/typecheck, format, lint, and TypeScript typecheck.
  • bun run test passed: 1476 passed, 1 platform-specific test skipped, 0 failed; Web suite 113/113.
  • Ablation: removing the index inventory gate reproduced the reported unsafe cleanup for both hidden index flags, so the gate is required.
  • Runtime Pi smoke: not applicable; this is a local Git cleanup invariant.

Impact

  • User-visible behavior: worktrees with hidden or uncertain index state remain available for inspection instead of being automatically removed.
  • Model-visible context/tools: none.
  • Runtime/lifecycle: cleanup gains a fail-closed, read-only index inspection step.
  • Persisted config/data: none.
  • Compatibility/risk: ordinary clean worktrees and committed work retain existing behavior; Git inventory is bounded to 1 MiB and unusual paths are handled with NUL framing.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(worktree): 自动回收会删除被 index flags 隐藏的未提交修改 [P1]

1 participant