Skip to content

fix: stop retrying worktree cleanup that cannot preserve data - #200350

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-nested-repo-worktree-removal-retry-forever-20260919
Nov 17, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-nested-repo-worktree-removal-retry-forever-20260919

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Managed checkout cleanup keeps retrying snapshot refusals that require human repair. Nested repositories, unavailable Git objects and unreadable files remain safely preserved, but indefinite retries waste snapshot work and hide why disk space is not being reclaimed.

Related: #189288, #200299. Integrated with the landed checkout-custody changes in #200335.

User Impact

User impact: administrators can see why cleanup retained a checkout and when automatic retries have stopped. Nested repositories are preserved immediately; missing/corrupt objects and permission failures receive three attempts with 2h/4h backoff, then remain preserved. After repair, run openclaw worktrees gc --retry-deferred to reopen cleanup, including when capacity is exceeded.

Preserved files still occupy disk until an operator resolves them. These safety refusals also prevent force removal. No schema, migration, configuration or cache is added. The existing cleanup receipt stores the typed reason and terminal retry state; CLI status and administrator Gateway results expose the outcome.

Why This Change Was Made

The retry owner capped delays but never capped attempts. Typed snapshot refusals now reach that owner through the existing worker error transport. Both direct removal and capacity eviction record the outcome while holding checkout custody; automatic cleanup honors it before inspecting files. Explicit retry clears an obsolete receipt so a repaired checkout is not permanently blocked by an earlier failure.

Terminal preservation is the bounded option for nested Git repositories: a lossless nested snapshot would also need to preserve their refs, unreachable objects, alternate stores and linked worktrees. No checkout is removed without preserving its content.

Evidence

Real service/Git/registry regressions fail before the fix and pass afterward for nested preservation, capped missing-object/permission retries, and force-removal safety. The integrated focused worktree suites pass 78 tests. Wrapper closure and unreadable-path CLI regressions pass; affected CLI/Gateway mappings and UI browser/e2e consumers were checked. Codex autoreview is clean through P2 on the integrated diff.

A synthetic latest-stable 2026.11.4 CLI upgrade preserved the existing registry row, inner Git history and file hashes. Fresh CLI processes retained terminal receipts; automatic GC above capacity made no repeated attempts; after repair, explicit retry safely removed the selected checkout, and restore recovered its tracked content. The sibling's unsaved files remained intact. Doctor used the existing backed-up migration and skipped service management for the isolated state/config. No live deployment or user data was used.

Production-shaped synthetic btrfs proof uses 62,000 files / 1.1GB, 5,000 sessions / 35.11GiB DB, A/A controls and five interleaved A/B pairs. For missing objects, six failing baseline attempts become three attempts followed by unchanged terminal receipts. Late-sweep medians: wall 1804→753ms, process CPU 1993→953ms, main allocation 24.83→4.81MB. CPU excludes Git children; allocations exclude worker isolates; the DB is size-shaped with sparse transcript content. A/A wall3059/2592ms shows substantial host/cache noise, so operation counts are stronger than a production speedup claim. Nested late-sweep medians are 1055→719ms, CPU 1215→941ms, allocation 6.30→6.13MB; its baseline already avoids repeated snapshots through GC preflight, while the candidate records a durable typed terminal state. Runtime delta against the integrated baseline is +162 lines, covering typed outcomes, bounded persistence, recovery and status visibility.

Exact-head CI run is red only for the existing capacity concurrency test (service.capacity.test.ts:469, expected one successful create, received zero) and its aggregate gate. It reproduces on exact integrated main parent 9f441adc; the immediately preceding commit passes all24 tests. The introduction is #200335 (9f441adc), which narrowed allocation custody. The precise CI main parent 6ba51132 also reproduces the identical assertion in a bounded repetition of the original case, with unchanged production sources. Both requests reject at the4GiB safety reserve. The remaining repeats were stopped after two reproductions; passing isolated replays are not treated as a fix. The test and four allocation owners are byte-identical between main and the tested merge. This is an inherited main regression requiring follow-up, not a waived PR failure. Security-fast and all other selected jobs pass.

Final narrow pnpm check:changed --base 9f441adc passes every scoped gate (format, types, lint and structural/database ratchets); the full command exits1 only for six inherited dead-export diagnostic entries. All are also present on the exact main baseline, with no new entries. ClawSweeper's final-head re-review has zero open items and accepts the shipped-entry-point/upgrade proof. Native landing uses the explicitly authorized, pinned inherited-failure route and retains both red results honestly.

Record nested repositories as terminal preservation in the existing cleanup receipt. Cap missing-object and permission retries at three attempts, expose the reason to administrators, and require preserved contents before capacity or forced removal of these failures. No schema migration or configuration change.
@clawsweeper

clawsweeper Bot commented Nov 17, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes scripts Repository scripts agents Agent runtime and tooling size: L labels Nov 17, 2026
@steipete
steipete marked this pull request as ready for review November 17, 2026 02:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T03:05:14.005332Z 73bdceb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 553b6df94c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/worktrees/capacity-owner.ts Resolved
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR records bounded preservation failures, stops repeated automatic cleanup, and exposes recovery guidance to administrators.

Example: A checkout fails cleanup three times because Git objects are missing.

  • Before: Cleanup keeps retrying indefinitely with a capped delay.
  • After: The third failure records terminal preservation; automatic retries stop until explicit operator retry.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Behavior and upgrade proof are sufficient and earlier findings are fixed, but the remaining required CI failure limits validation confidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied synthetic CLI output exercises terminal nested preservation, restart visibility, repaired explicit retry above capacity, and restore on the integrated head; real-service evidence additionally covers capped missing-object and permission failures.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Unpreservable checkouts repeatedly consume cleanup work while continuing to occupy disk and worktree capacity.
Reason: The maintainer-authored direction makes persistent failures visible and bounded while retaining user data and an explicit recovery path.

Merge readiness

✅ Ready for maintainer review

Keep open: this useful, maintainer-directed fix resolves all five earlier findings; exact-head CI still has an unattributed disk-headroom test failure.

Priority: P2
Reviewed head: 73bdcebbde166d57157fe7447e1ddf011114f25a

Before merge

None.

Findings

None.

Agent review details

How this fits together

The managed-worktree service receives CLI, Gateway, idle-cleanup, and capacity requests, captures recovery snapshots, and records cleanup outcomes through the existing SQLite registry.

flowchart TD
  A[CLI and Gateway requests] --> B[Managed worktree service]
  B --> C[Idle and capacity cleanup]
  C --> D[Snapshot and removal owners]
  D --> E[Git checkout and objects]
  D --> F[SQLite cleanup receipt]
  F --> C
  F --> G[Administrator status and recovery guidance]
Loading

Technical review

Best possible solution:

Keep preservation policy in the existing removal and registry owners, with explicit recovery through the existing retry command.

Do we have a high-confidence way to reproduce the issue?

Current-main source shows unlimited retry attempts, while supplied real Git regressions and CLI results establish preservation and explicit recovery; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change reuses typed worker errors, revision-bound registry receipts, and existing cleanup owners without adding a competing store or configuration option.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b4fc05346afb.

Provenance checked

  • Persisted cleanup retry policy changes intended behavior with a stated reason (3c66417: Persist revision-bound timeout backoff and preserve removal recovery across cancellation and restart.)
  • Shared-repository corruption protection keeps the original intent (1c11277: Avoid repeated failed snapshots across sibling checkouts while allowing healthy repositories to continue cleanup.)
  • Snapshot-loss permission changes intended behavior with a stated reason (b4a720f: Separate snapshot-loss consent from active-run and Git-lock removal authority.)
  • Capacity snapshot and checkout custody keeps the original intent (9f441ad: Move slow checkout work outside allocation custody and preserve checkouts when capacity snapshots fail.)
  • Unreadable-checkout diagnostics keeps the original intent (59c02b8: Preserve inaccessible checkouts and report the offending path without repeated sweep warnings.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3c66417 adds src/agents/worktrees/registry-retirement.ts:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3c66417c08e3; files: src/agents/worktrees/registry-retirement.ts)

PR surface

Source +162, Tests +138, Docs +4, Other +181. Total +485 across 26 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 15 201 39 +162
Tests 8 160 22 +138
Docs 2 10 6 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 181 0 +181
Total 26 552 67 +485

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repeated failed cleanup wastes resources and retains capacity, with a bounded administrative recovery path.
  • merge-risk: 🚨 compatibility: Force removal now refuses nested-repository, corrupt-object, and permission preservation failures; retained receipts also affect capacity eviction, an explicitly accepted maintainer-directed tradeoff.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-17T02:18:31.103Z sha 553b6df :: blocked before merge. :: [P1] Include the new error module in the trusted-wrapper inventory | [P2] Honor explicit retries in capacity cleanup | [P2] Clear obsolete terminal receipts when reopening a repaired checkout | [P2] Preserve the offending permission path in deferred diagnostics | [P3] Update the remaining unreadable-checkout policy paragraph

Reviewed November 16, 2026, 10:19 PM ET / November 17, 2026, 03:19 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed every item in the latest ClawSweeper review on 73bdceb, including the landed #200335 integration:

  1. Trusted-wrapper closure: moved the transported preservation error to the existing worktree error owner. Snapshot inventory imports that already-inventoried module. Both failing extracted-wrapper closure tests were reproduced red and pass after relocation; no inventory expansion is needed.
  2. Explicit capacity retry: the capacity decision consumes guard.retryDeferred and forwards it to eviction. The real-service regression was red on the reviewed head and now passes, including repaired explicit removal above capacity and restoration while a sibling is leased. This also resolves the linked Codex finding.
  3. Obsolete receipts: explicit idle retry clears the superseded receipt; capacity retry does so under removal custody. The existing inventory regression now passes through repaired retry, an unrelated transient removal failure, and later automatic recovery. Its owner-change case also exposed a stale-revision bug: nested preflight now passes the inspected record to the existing revision-bound persistence owner. New failures during eviction are recorded before releasing the removal claim.
  4. Permission diagnostics: the persisted permission disposition retains bounded error detail, including the offending path. Both actual unreadable-parent CLI regressions pass across repeated sweeps, then explicit repair/removal and byte-preserving restore.
  5. Data-model compatibility and product proof: installed the published npm stable 2026.11.4 (d843d6a) into an isolated fixture. Its shipped CLI created a managed checkout and refused nested-repository removal. The candidate CLI read the existing row unchanged. Candidate Doctor then backed up and upgraded the fixture through the existing schema-22-to-40 migrations, explicitly reporting that host service management was skipped. This PR adds no schema migration. After upgrade, candidate CLI removal recorded one terminal attempt; separate CLI processes retained it, reported the operator action, and did no further removal after repair until explicit retry. With two retained checkouts and cap one, gc --retry-deferred safely removed the repaired checkout and reported limitsSatisfied: true; restore recovered the original outer file. The recovered inner Git repository has the identical HEAD and file hash and passes git fsck --full; the second nested checkout remains intact at one attempt. Existing numeric timeout/backoff receipts also pass the restart regressions.

The additional permission-policy documentation finding is corrected in managed-worktrees.md.

Sanitized shipped-entry-point results (separate CLI processes, synthetic data only):

stable worktrees create --base-ref main: exit 0
stable worktrees remove: exit 1, nested repositories cannot be snapshotted losslessly
candidate worktrees list: existing id/branch/path unchanged
candidate doctor --fix --non-interactive: exit 0, backup retained, schema 40
candidate worktrees remove: exit 1, stage=nested-repository attempts=1 retryAt=null
candidate worktrees list after restart: preserved reason and operator retry command visible
candidate automatic gc after repair: removed=[], outcome=deferred
candidate gc --retry-deferred above capacity: removed=[repaired-id], limitsSatisfied=true
candidate worktrees restore: original outer bytes restored
inner repository: identical HEAD + SHA-256, git fsck --full passed
untouched sibling: preserved, attempts=1, retryAt=null

All 78 integrated worktree tests pass, as does core typecheck. Fresh Codex autoreview of the complete integrated diff is clean through P2. Exact-head CI is running at https://github.com/openclaw/openclaw/actions/runs/44007250774. The final expanded local check and refreshed synthetic paired timing run remain in progress; these are not being represented as completed or green.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Nov 17, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 17, 2026
@steipete
steipete merged commit b6db4fa into main Nov 17, 2026
165 of 169 checks passed
@steipete
steipete deleted the steipete/perf-micro-nested-repo-worktree-removal-retry-forever-20260919 branch November 17, 2026 03:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…aw#200350)

* fix(worktrees): stop retrying preserved checkouts

Record nested repositories as terminal preservation in the existing cleanup receipt. Cap missing-object and permission retries at three attempts, expose the reason to administrators, and require preserved contents before capacity or forced removal of these failures. No schema migration or configuration change.

* fix: preserve explicit cleanup recovery and diagnostics
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 gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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.

1 participant