Skip to content

fix: managed worktree cleanup can force-delete uncaptured work - #148765

Merged
fuller-stack-dev merged 2 commits into
mainfrom
openclaw/managed-nonforce-cleanup-20260915
Sep 15, 2026
Merged

fuller-stack-dev merged 2 commits into
mainfrom
openclaw/managed-nonforce-cleanup-20260915

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

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-lossless to retain dirty or unpublished work and remove eligible checkouts without Git force. Ordinary snapshot-based archival remains available; its existing --force option 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

  • Three real-Git regressions failed on the original behavior. Eleven safety cases passed before host disk pressure, covering non-force argv, switched/detached HEAD, tracking configuration, hidden edits, late changes, and partial deletion. A later review found a recovery-ref expiry gap; its added regression failed before the correction and now passes.
  • Earlier broader service coverage passed 138 tests. The final narrowed run passed 32 tests and had 19 disk-admission failures; all failures reported about 15 GiB free against the unchanged 16 GiB reserve.
  • Supported CLI proof verified real non-force removal, sibling registration preservation, dirty/untracked/unpublished retention, and archival capture. Restore stopped at disk admission before side effects; independent Git reads confirmed the original commit and saved dirty/untracked bytes remain in the snapshot. Earlier service-level archive/restore cases passed. No capacity limit or test expectation was weakened.
  • Two independent review passes completed. The recovery-ref expiry finding is fixed; a rollback finding was rejected against the existing targeted cleanup and a real-Git reproduction. The final six-file changed-check plan passed, including core and test typechecks, targeted lint, formatting, import-cycle and storage guards. The first hosted run found a stale timing fixture that still recognized branch -D; changing its trigger to branch -d preserved every assertion and passed all nine removal-timing tests. Exact-head CI34929056595 passed at 1ad3ce5f2b9: 123 successful jobs, 16 skipped, and the required openclaw/ci-gate green.

ClawSweeper's recovery compatibility gap is now covered on Linux using the exact 1ad3ce5f2b9 candidate and worktrees created by pre-change CLI a4790958b284. 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.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 15, 2026 04:15
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 15, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 15, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 12:53 AM ET / 04:53 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: 1ad3ce5f2b9e6b7cf5516c9d2b48552f406680c7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful Git boundary coverage and accepted recovery proof; no actionable correctness findings remain.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The exact-head Linux report exercises the supported CLI and managed removal owner against pre-change records, observing preserved commits/files, partial-failure retry refusal, and successful reconciled restore. The archive-access restriction is a reviewer limitation, not a new contributor proof gap.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The exact-head Linux report exercises the supported CLI and managed removal owner against pre-change records, observing preserved commits/files, partial-failure retry refusal, and successful reconciled restore. The archive-access restriction is a reviewer limitation, not a new contributor proof gap.
Evidence reviewed 9 items Verified scope and review continuity: The merge-base-to-head comparison contains the seven reported files. Comparing the earlier reviewed head a8edf99 with this head shows only the timing fixture’s -D to -d correction; the previous completed review reported no code findings.
Current main still needs the repair: Fetched main still unconditionally invokes forced checkout removal, deletes the recorded branch with -D, and runs repository-wide worktree prune. The affected service and CLI have no changes between the PR merge base and fetched main.
Latest release also contains the unsafe path: The service at the supplied v2026.9.4 release commit uses forced worktree removal and unconditional branch -D at lines 1338–1347; this is not an already-shipped repair.
Findings None None.
Security None None.

How this fits together

Managed 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]
Loading

Before merge

  • Resolve merge risk (P1) - After refused or interrupted deletion, subsequent removal intentionally stops for operator reconciliation; a retained branch can also block automatic restore. The maintainer explicitly accepts this tradeoff and reports successful recovery proof.
  • Resolve merge risk (P1) - The detailed proof report was inspected, but the linked evidence archive was inaccessible under this reviewer’s network policy.
Agent review details

Security

None.

PR surface

Source +173, Tests +314, Docs +8. Total +495 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 197 24 +173
Tests 3 315 1 +314
Docs 1 11 3 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 523 28 +495

Review metrics

Metric Value Why it matters
Removal policy surface 1 CLI flag added; 0 Gateway parameters added The explicit lossless option reuses the existing cleanup owner while archival Gateway behavior remains intact.
Production versus test growth Production net +173 lines; tests net +314 lines Production growth implements capture custody and checked deletion, with boundary regressions covering the added safety behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #148747
Summary: This PR is the explicit candidate fix for the paired managed-worktree removal issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Retain the accepted recovery fence (recommended)
    Proceed with the documented operator-reconciliation behavior supported by the reported old-record and partial-deletion recovery checks.

Technical review

Best 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.

Labels

Label justifications:

  • P0: The source-proven defect can delete the last branch reference to unpublished work that the snapshot did not capture.
  • merge-risk: 🚨 compatibility: Failed removal now retains a recovery fence that can require operator reconciliation before retry or restore, an explicitly accepted behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The exact-head Linux report exercises the supported CLI and managed removal owner against pre-change records, observing preserved commits/files, partial-failure retry refusal, and successful reconciled restore. The archive-access restriction is a reviewer limitation, not a new contributor proof gap.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head Linux report exercises the supported CLI and managed removal owner against pre-change records, observing preserved commits/files, partial-failure retry refusal, and successful reconciled restore. The archive-access restriction is a reviewer limitation, not a new contributor proof gap.

Evidence

What I checked:

  • Verified scope and review continuity: The merge-base-to-head comparison contains the seven reported files. Comparing the earlier reviewed head a8edf99 with this head shows only the timing fixture’s -D to -d correction; the previous completed review reported no code findings. (src/agents/worktrees/service.diagnostics.test.ts:494, 1ad3ce5f2b9e)
  • Current main still needs the repair: Fetched main still unconditionally invokes forced checkout removal, deletes the recorded branch with -D, and runs repository-wide worktree prune. The affected service and CLI have no changes between the PR merge base and fetched main. (src/agents/worktrees/service.ts:989, 3dbc8e2ffe76)
  • Latest release also contains the unsafe path: The service at the supplied v2026.9.4 release commit uses forced worktree removal and unconditional branch -D at lines 1338–1347; this is not an already-shipped repair. (src/agents/worktrees/service.ts:1338, 3a9d69db306c)
  • Removal and recovery ownership: The service checks the pending recovery ref before recapturing, validates the managed HEAD, pins the completed capture before deletion, and selects non-force removal for lossless callers. Branch deletion uses native ancestry checks against the snapshot. Restore and expiry clear the recovery ref through the existing lifecycle. (src/agents/worktrees/service.ts:891, 1ad3ce5f2b9e)
  • Focused regression coverage: The new service tests exercise real Git for switched/detached HEAD, hidden edits, tracking configuration, late writes, partial deletion, and recovery-ref expiry. Fault injection surrounds actual service operations; CLI tests separately protect routing and conflicting options. Tests were inspected, not executed in this read-only review. (src/agents/worktrees/service.removal-safety.test.ts:49, 1ad3ce5f2b9e)
  • Compatibility proof and accepted recovery policy: The captured PR body and fix: managed worktree cleanup can force-delete uncaptured work #148765 (comment) report five successful Linux checks using pre-change CLI-created records and the exact candidate: lossless removal, archival restore, partial-deletion capture preservation, retry refusal, and explicit reconciliation followed by successful restore. The body explicitly accepts retaining the recovery fence. It identifies archive digest d800b70f8cd316fa99a80615906f39efd8a060860a0c23d7a83552d9bb557ab6 and sourceRevision 677134eebb1451baa870eaa049c34f15d2ff19f9ba41e7fe2127932d16637a46. The linked Crabbox archive could not be independently opened because this reviewer’s network allowlist blocks that host. (1ad3ce5f2b9e)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-15T04:26:54.520Z sha a8edf99 :: blocked before merge. :: none
  • reviewed 2026-09-15T04:38:31.878Z sha 1ad3ce5 :: blocked before merge. :: none
  • reviewed 2026-09-15T04:44:48.333Z sha 1ad3ce5 :: blocked before merge. :: none

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The requested recovery compatibility proof is complete for head 1ad3ce5f2b9e6b7cf5516c9d2b48552f406680c7. The only source change since your review is a one-character timing-fixture correction from branch -D to branch -d; all nine timing tests pass with unchanged assertions.

On configured AWS Linux, three managed worktrees were created by the pre-change CLI at a4790958b284dfa50fed9c4ae4a5e6685e798435, using the same isolated registry later consumed by the candidate CLI. Independent pinned-pnpm installs were used.

Verified:

  • Supported worktrees remove --if-lossless on an old clean record.
  • Supported archive/restore preserving the original unpublished HEAD and tracked/untracked bytes.
  • Simulated Git child failure after removing a tracked file. The completed snapshot remained pinned and a retry refused to overwrite it.
  • Explicit operator reconciliation on that synthetic checkout: back up partial files; restore the snapshot with git read-tree --reset -u <snapshot>; reset the index to the original HEAD; verify both files; clear only the exact pending-ref OID; then run supported archive/restore and verify HEAD and bytes again.

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.

AWS run: https://crabbox.openclaw.ai/portal/runs/run_28614ca2a32097b6a501494fa5643a76

Fresh exact-head CI remains in progress: https://github.com/openclaw/openclaw/actions/runs/34929056595

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 15, 2026
@fuller-stack-dev
fuller-stack-dev merged commit 530ce23 into main Sep 15, 2026
219 of 220 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the openclaw/managed-nonforce-cleanup-20260915 branch September 15, 2026 05:00
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Managed worktree cleanup forces deletion and can remove an uncaptured branch

1 participant