Fix cleanup_stale to preserve branches with commits beyond HEAD (#11121) #11141

Closed
HAL9000 wants to merge 2 commits from fix/cleanup-stale-preserve-commits into master

2 Commits

Author SHA1 Message Date
HAL9000 61a0647837 fix(sandbox): update cleanup_stale docstring and fix preservation test step
CI / helm (pull_request) Successful in 1m1s
CI / build (pull_request) Successful in 1m19s
CI / quality (pull_request) Successful in 1m49s
CI / lint (pull_request) Failing after 1m51s
CI / typecheck (pull_request) Successful in 1m54s
CI / push-validation (pull_request) Successful in 1m48s
CI / security (pull_request) Successful in 2m13s
CI / integration_tests (pull_request) Successful in 6m16s
CI / unit_tests (pull_request) Successful in 9m46s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 9s
The cleanup_stale code (guarding against extra commits beyond HEAD) was
already present on this branch. This commit adds:

- Updated docstring for cleanup_stale to document the new preservation
  behavior described in issue #11121
- Added a dedicated "should still exist" step pattern for clarity
- Fixed step_add_extra_commit_to_branch: removed the checkout which
  conflicts with git worktrees, now correctly commits inside the linked
  worktree directory where the branch is already checked out
2026-05-14 01:04:57 +00:00
HAL9000 6216b2e843 fix: cleanup_stale preserves branches with extra commits beyond HEAD (#11121)
CI / lint (pull_request) Failing after 57s
CI / quality (pull_request) Successful in 50s
CI / typecheck (pull_request) Successful in 59s
CI / push-validation (pull_request) Successful in 30s
CI / helm (pull_request) Successful in 39s
CI / security (pull_request) Successful in 1m19s
CI / build (pull_request) Successful in 47s
CI / integration_tests (pull_request) Successful in 4m3s
CI / unit_tests (pull_request) Failing after 4m28s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 4s
Fix the bug where GitWorktreeSandbox.cleanup_stale() unconditionally destroyed
all cleveragents/plan-{plan_id} worktree branches, including those committed LLM
output from a previous plan execution. This caused zero artifacts when re-invoked
execute called plan apply because the branch had already been wiped.

The fix adds a HEAD...branch_name log check before destruction:
- Branch has extra commits -> preserve (has committed work)
- No extra commits (truly stale) -> proceed with cleanup logic

Added 2 new BDD/Behave scenarios for preservation and stale cleanup testing.
Updated CHANGELOG.md and CONTRIBUTORS.md per PR Compliance Checklist.

ISSUES CLOSED: #11121
2026-05-12 11:57:06 +00:00