Repository navigation
fix: managed worktree cleanup can force-delete uncaptured work - #148765
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 15, 2026, 12:53 AM ET / 04:53 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR adds lossless CLI removal, preserves uncaptured branch tips and interrupted-removal snapshots, and documents managed-worktree recovery. Merge readiness⛔ Blocked before merge - 2 items remain This PR remains necessary: current main still contains the unsafe removal path. No blocking code findings remain, and the updated recovery proof and explicit maintainer disposition resolve the previous review’s compatibility question. Priority: P0 Review scores
Verification
How this fits togetherManaged worktrees give agent tasks isolated Git checkouts, with lifecycle records in OpenClaw’s shared database. CLI and session cleanup requests pass through one service that captures recoverable contents, removes eligible checkouts, and retains snapshots for restore. flowchart TD
A[CLI or session cleanup] --> B[Managed worktree service]
B --> C[Check ownership and removal policy]
C --> D[Retain checkout with outcome]
C --> E[Capture contents and pin recovery]
E --> F[Git checkout and branch removal]
F --> G[Snapshot restore or expiry]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +173, Tests +314, Docs +8. Total +495 across 7 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the accepted recovery fence and shared removal owner, preserving ordinary archival restore alongside genuinely non-force cleanup. Do we have a high-confidence way to reproduce the issue? Yes: switching or detaching a managed checkout before removal makes current main snapshot the replacement HEAD and forcibly delete the recorded branch. Source inspection confirms the path; this review did not execute it. Is this the best way to solve the issue? Yes: the patch repairs the existing owner, retains archival removal, and exposes its lossless path through the CLI; the previously questioned recovery policy now has explicit acceptance and compatibility evidence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3dbc8e2ffe76. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review The requested recovery compatibility proof is complete for head On configured AWS Linux, three managed worktrees were created by the pre-change CLI at Verified:
The injected failure used a task-local Git shim with PATH bootstrap marked complete. No database edits, production state, capacity changes, or gate waiver. All five checks passed at 04:39:51 UTC. The PR body now records this scope, the simulated-failure limitation, and the evidence archive digest. Fresh exact-head CI remains in progress: https://github.com/openclaw/openclaw/actions/runs/34929056595 |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…law#148765) * fix: managed worktree cleanup can force-delete uncaptured work * test: time checked managed branch deletion
Closes #148747
What Problem This Solves
Managed worktree removal always forced Git deletion, even when callers expected lossless cleanup, and could delete the recorded branch after HEAD had switched elsewhere.
User Impact
Operators can use
openclaw worktrees remove <id> --if-losslessto retain dirty or unpublished work and remove eligible checkouts without Git force. Ordinary snapshot-based archival remains available; its existing--forceoption still means permission to lose a failed snapshot.A refused or interrupted deletion preserves its recovery capture and may require operator reconciliation before another removal or restore. No deployed runtime is changed by this PR.
Why This Change Was Made
The existing managed-worktree owner now binds cleanup to the inspected HEAD and recorded branch, uses native checked branch deletion against the completed snapshot, and leaves sibling worktree registrations alone. The CLI flag and durable cleanup outcome distinguish lossless deletion from archival removal; the Gateway result format is unchanged.
A pending-removal Git ref protects a completed snapshot from being overwritten with the remnants of a partial deletion. Existing snapshot retention and provisioned-file storage remain unchanged.
Evidence
branch -D; changing its trigger tobranch -dpreserved every assertion and passed all nine removal-timing tests. Exact-head CI34929056595 passed at1ad3ce5f2b9: 123 successful jobs, 16 skipped, and the requiredopenclaw/ci-gategreen.ClawSweeper's recovery compatibility gap is now covered on Linux using the exact
1ad3ce5f2b9candidate and worktrees created by pre-change CLIa4790958b284. Both checkouts used independent pinned-pnpm installs. Supported CLI lossless removal and archival restore preserved the original commit plus dirty/untracked bytes. A controlled Git-child partial deletion then proved the pending-ref retry fence. After backing up the partial checkout, explicit Git reconstruction and exact-OID ref reconciliation allowed supported archive/restore to recover all bytes again. No registry/database edits, weakened limits, or deployed state were involved.The fault injection used a task-local Git shim with PATH bootstrap marked complete. This is simulated child failure through the real CLI, not an organic production interruption. Ordinary archive/restore used the unmodified CLI environment. All five checks passed at 04:39:51 UTC. The 95 captured artifacts have a sealed local manifest; the compressed evidence archive SHA256 is
d800b70f8cd316fa99a80615906f39efd8a060860a0c23d7a83552d9bb557ab6. AWS run and logs.Maintainer disposition after the exact-head recovery re-review: retain the documented recovery fence. Automatically retrying deletion could overwrite the completed capture after a partial failure. The explicit recovery sequence is verified, and all 95 captured artifacts were hashed locally and the decisive failure and restore records were inspected. ClawSweeper reports sufficient behavior proof and no code/security findings; its authenticated-archive access limitation remains noted. No CI or native landing gate is waived.