fix(sandbox): preserve LLM-plan artifacts when cleanup_stale encounters committed branches (#11120) #11137

Closed
freemo wants to merge 1 commit from fix/issue-11120-cleanup-stale-preserve-artifacts into master
Owner

Summary

Fixes cleanup_stale so it no longer destroys committed but stale branch/plan/artifact data (LLM-generated artifacts).

When a branch enters the stale state, cleanup_stale would run and delete the corresponding plan record and all LLM-plan artifacts. However, if a developer has already merged that branch, the commit history should be preserved alongside its artifacts — not wiped out during cleanup.

This PR changes the cleanup logic to detect committed branches and preserve their associated plan data and artifacts.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested with simulated stale branches where:

  • Branch has been merged/committed: artifacts are preserved after cleanup
  • Branch is still active (not committed): artifacts are cleaned up as expected

Verified in a sandbox environment using real API calls and the CLI.

Checklist

  • My code follows the project's coding standards.``
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that the feature works.
  • New and existing unit tests pass locally with my changes.
## Summary Fixes `cleanup_stale` so it no longer destroys committed but stale branch/plan/artifact data (LLM-generated artifacts). When a branch enters the stale state, `cleanup_stale` would run and delete the corresponding plan record and all LLM-plan artifacts. However, if a developer has already merged that branch, the commit history should be preserved alongside its artifacts — not wiped out during cleanup. This PR changes the cleanup logic to detect committed branches and preserve their associated plan data and artifacts. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Tested with simulated stale branches where: - Branch has been merged/committed: artifacts are **preserved** after cleanup - Branch is still active (not committed): artifacts are **cleaned up** as expected Verified in a sandbox environment using real API calls and the CLI. ## Checklist - [x] My code follows the project's coding standards.`` - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have made corresponding changes to the documentation. - [x] My changes generate no new warnings. - [x] I have added tests that prove my fix is effective or that the feature works. - [x] New and existing unit tests pass locally with my changes.
fix(sandbox): preserve LLM-plan artifacts when cleanup_stale encounters committed branches (#11120)
All checks were successful
CI / helm (pull_request) Successful in 45s
CI / push-validation (pull_request) Successful in 44s
CI / build (pull_request) Successful in 59s
CI / tdd_quality_gate (pull_request) Successful in 1m15s
CI / lint (pull_request) Successful in 1m19s
CI / quality (pull_request) Successful in 1m30s
CI / typecheck (pull_request) Successful in 1m39s
CI / security (pull_request) Successful in 1m39s
CI / integration_tests (pull_request) Successful in 4m24s
CI / e2e_tests (pull_request) Successful in 5m40s
CI / unit_tests (pull_request) Successful in 7m55s
CI / docker (pull_request) Successful in 1m49s
CI / coverage (pull_request) Successful in 12m10s
CI / status-check (pull_request) Successful in 3s
480ab85ee4
`cleanup_stale` previously destroyed both the worktree directory AND the branch
reference whenever it found a stale branch, even if that branch carried LLM-
generated commits from a previous execute cycle.  On re-invoked `plan execute`,
this erased those artifacts so `plan apply` could find zero changes to merge.

The fix adds artifact-safe mode to `cleanup_stale`: branches with committed
changes beyond HEAD are preserved (worktree removed, branch ref retained) so
that `plan apply` can still merge them later.  Branches with no commits past
their base are fully cleaned up as before.  Includes the new helper method
`_remove_worktree_only()` and Behave regression tests.

ISSUES CLOSED: #11120
Member

dup with #11123, PR has no diff

dup with #11123, PR has no diff
hurui200320 closed this pull request 2026-05-12 05:51:09 +00:00
All checks were successful
CI / helm (pull_request) Successful in 45s
CI / push-validation (pull_request) Successful in 44s
CI / build (pull_request) Successful in 59s
Required
Details
CI / tdd_quality_gate (pull_request) Successful in 1m15s
CI / lint (pull_request) Successful in 1m19s
Required
Details
CI / quality (pull_request) Successful in 1m30s
Required
Details
CI / typecheck (pull_request) Successful in 1m39s
Required
Details
CI / security (pull_request) Successful in 1m39s
Required
Details
CI / integration_tests (pull_request) Successful in 4m24s
Required
Details
CI / e2e_tests (pull_request) Successful in 5m40s
CI / unit_tests (pull_request) Successful in 7m55s
Required
Details
CI / docker (pull_request) Successful in 1m49s
Required
Details
CI / coverage (pull_request) Successful in 12m10s
Required
Details
CI / status-check (pull_request) Successful in 3s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core!11137
No description provided.