Skip to content

fix: skip repeated removal of preserved worktrees - #200434

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-preserved-worktree-fast-refusal-20260919
Nov 17, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-preserved-worktree-fast-refusal-20260919

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #200350

What Problem This Solves

A periodic cleanup script can repeatedly try to remove a worktree whose contents OpenClaw has already preserved because they cannot be snapshotted safely. Each call repeats snapshot work, while worktrees list --json omits the typed cleanup status the script needs to skip it.

User Impact

User impact: cleanup scripts can filter cleanup.state == "preserved"; unfiltered removal exits 1 immediately with removed: false and typed preserved metadata. After repairing the cause, an operator can explicitly run worktrees remove <id> --retry-preserved. This flag reopens the existing safe removal path; it does not permit snapshot loss. --force alone does not reopen a terminal receipt. Existing gc --retry-deferred remains an explicit retry.

Why This Change Was Made

The registry decoder projects the existing revision-bound receipt as cleanup: { state, reason, attempts, nextAttemptAt }. The removal owner checks it before acquiring the mutation lease or settling the workspace, so local CLI and Gateway callers share one decision. Session deletion continues reporting a retained worktree when removal returns that outcome. Clean-only cleanup releases its removal claim on refusal. The Worktrees UI offers an explicit safe Retry; the session organizer preserves its existing destructive confirmation and reports refused outcomes. No configuration, SQLite schema, cache, or preservation policy changes.

Production code grows by 77 lines to expose the typed contract, explicit retry, and visible outcome; tests grow by 190, generated validators by 3, docs by 16, and the existing benchmark by 11. The allocation-held implementation moves unchanged from the oversized service into its existing removal module; no duplicate owner is added.

Evidence

The nested-repository regression fails on the original service at the repeated removal and passes with the fix: no new snapshot or Git command, unchanged attempt count, and unsaved nested bytes retained. Explicit retry performs another safe attempt. Real Commander parser tests cover the flag, conflict, JSON/text refusal, and exit 1. Focused preservation, removal safety, exact-state, CLI, registry, protocol, and Gateway tests pass; the final affected UI browser suites (91 tests) and Chromium E2E suite (5 tests) also pass. Hosted review caught a leaked clean-only removal claim and unhandled UI results; both have red/green regressions and are fixed. All 35 preservation tests pass again, including a repaired checkout that can be explicitly retried after clean-only refusal.

A production-shaped synthetic fixture on btrfs contains 5,000 sessions, a 35 GiB size-shaped database, and 62,000 files totaling 1.1 GB. Five interleaved baseline/candidate pairs (25 repeat calls per arm) show median owner wall time 1283.724 → 1.176 ms, process CPU 1050.661 → 1.434 ms, and main-isolate allocation 22,132,280 → 351,320 bytes. Baseline calls range 848–2049 ms; candidate calls 0.60–6.25 ms. A/A controls have medians 3310/1310 ms, so host drift is substantial: these are synthetic work-count and cost measurements, not a production latency forecast. CPU excludes Git subprocesses; initial preservation is excluded. No production data was copied.

The isolated Linux pnpm openclaw flow also passes end to end: create → failed safe snapshot → list preserved state → fast refusal with exit 1 → explicit retry increments attempts to 2; unsaved bytes remain intact. All 12 session-lifecycle tests pass. Codex autoreview is scoped-clean through P2. pnpm check:changed exposes three inherited dead-export regressions, reproduced on exact main parent 346d231275b3930848b8e31239c74f689d361436: approval-shared.ts:isApprovalRecordVisibleToClient (#200360, ff2cb7e), spawn-broker/host.ts:BrokerNativeResourceLease (#200370, df78722), and operation-types.ts:SystemAgentPluginCapabilityReview (#200392, b0d95fd). These are reported main regressions, not silently ignored checks. The follow-up check also caught a missing required reason in the new regression fixture; that is corrected, the targeted regression passes again, and every core test typecheck shard passes. All other changed-file gates passed. Exact-head PR CI will determine landing eligibility.

Numbered review responses and inspected before/after screenshots.

CI follow-through: run 44029059502 exposed a lease test that still used force as an implicit preserved retry. The test now opts in with retryPreserved and releases its lease in finally, preventing assertion failures from hanging teardown. No production change. All 43 remaining #200350 GC, eviction, and lease tests pass (199.26s), completing that regression footprint; targeted typecheck/lint and a fourth Codex autoreview pass.

@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 app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 17, 2026
@steipete
steipete marked this pull request as ready for review November 17, 2026 05:50
@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-17T06:41:09.758727Z d80dbab 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: 6426954aad

ℹ️ 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/service.ts Resolved
Comment thread src/agents/worktrees/service.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. labels Nov 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed both hosted review findings on e61f2ac2dd1ccd70469a76de132e9de9307a22c4:

  1. Release the clean-only removal claim on refusal. gc-removal.ts:173–175 aborts the acquired claim when removal returns false. The real nested-repository regression moves the unsaved nested checkout to safety, attempts clean-only cleanup, then explicitly retries. Before this correction it failed with a live-remover busy error; now the retry succeeds and the saved bytes remain intact.
  2. Handle preserved results in both UI callers. worktrees-model.ts:180–200 displays the reason and offers a separate safe Retry, with retryPreserved: true and no force. session-organizer-operations.runtime.ts:677–684 explicitly retries under its existing destructive confirmation and reports preserved refusals. Browser/E2E regressions prove the visible reason and request contract.

Focused follow-up proof: 35 preservation tests, 91 UI browser tests, and 5 Chromium E2E tests pass. Fresh Codex autoreview is scoped-clean through P2. The test-fixture type error found by check:changed is fixed; the targeted regression and all core test typecheck shards pass. The three documented dead-export failures reproduce on the original main parent and remain inherited main regressions.

Synthetic UI proof below compares the original 6426954 UI with this correction: clean before/after first, annotated before/after second. The before frame shows the incorrect blank-reason force-delete prompt; after shows the preservation reason and safe Retry.

@clawsweeper re-review

Before: incorrect blank-reason force-delete prompt

After: preservation reason and explicit safe Retry

Before annotated: incorrect force-delete prompt

After annotated: explicit retry keeps snapshot safety

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 skips repeated removal of preserved worktrees, exposes typed cleanup status, and adds an explicit safe retry.

Example: A checkout containing nested/valuable.txt already has a terminal nested-repository receipt with attempts set to 1.

  • Before: Another removal repeats snapshot work and fails again.
  • After: Removal returns removed: false with preserved metadata without Git work; --retry-preserved explicitly attempts safe removal again.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source-correct, while inspectable production-entry-point evidence remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Cleanup scripts repeatedly perform expensive failed removal work and lack typed status for skipping preserved checkouts.
Reason: The maintainer-authored direction closes a concrete gap in the existing preservation contract and provides an explicit recovery action.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current removal-path defect, and the final lease-test correction preserves its safety assertions; no actionable correctness or security findings remain.

Priority: P2
Reviewed head: d80dbabf19671f9f6a14a0913c522f11d47f814f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide inspectable, redacted CLI or Gateway output showing preserved listing, repeated refusal with unchanged attempts and bytes, explicit retry, and an existing checkout carried through upgrade from v2026.11.4.
Agent review details

How this fits together

CLI, Gateway, session cleanup, and Control UI callers use the managed-worktree service, which reads revision-bound SQLite receipts before admitting Git snapshot and removal work.

flowchart LR
  A[CLI and Control UI] --> B[Gateway or local owner]
  B --> C[Managed worktree service]
  D[SQLite cleanup receipt] --> C
  C --> E[Preserved outcome]
  C --> F[Safe snapshot and removal]
  E --> A
  F --> A
Loading

Technical review

Best possible solution:

Keep the existing removal owner authoritative, reuse its terminal receipt, and require an explicit retry while retaining snapshot and lease protections.

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

Current-main source admits repeated direct removal despite a terminal receipt, and the extended real Git/registry regression exercises that path; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change fixes the decision at its existing owner, derives status from existing storage, updates affected consumers, and retains distinct lease, snapshot, and UI regressions without introducing another state owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Terminal preservation and registry projection keeps the original intent (b6db4fa: Bound unsafe snapshot retries while preserving checkout contents and allowing explicit operator recovery.)
  • Allocation-held removal implementation keeps the original intent (9f441ad: Keep slow cleanup outside competing session lifecycle work while retaining removal custody.)
  • CLI and Gateway removal outcomes changes intended behavior with a stated reason (4e8da9c: Route mutations through the live state owner and preserve explicit request and result semantics.)
  • Control UI deletion confirmation keeps the original intent (263e2c8: Require clear confirmation before destructive actions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +80, Tests +190, Docs +16, Other +11. Total +297 across 20 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 11 211 131 +80
Tests 7 208 18 +190
Docs 1 26 10 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 1 14 3 +11
Total 20 459 162 +297

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.

Review metrics

Metric Value Why it matters
Production versus tests Production +207/-130; tests +208/-18 The net production growth exposes the shared outcome and retry contract across existing consumers; the allocation-held implementation moves into the existing removal module.
New operator control 1 CLI flag and 1 corresponding RPC parameter --retry-preserved and retryPreserved explicitly reopen safe removal without granting snapshot-loss permission.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repeated removal wastes Git and snapshot work on preserved checkouts, with limited blast radius and existing data-preservation safeguards.
  • merge-risk: 🚨 compatibility: Scripts relying on --force to retry terminal preservation must use the explicit retry flag; this tradeoff is documented and accepted by the maintainer-authored direction.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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-17T06:17:37.433Z sha e61f2ac :: needs maintainer review before merge. :: none

Reviewed November 17, 2026, 1:43 AM ET / 06:43 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final head is d80dbabf19671f9f6a14a0913c522f11d47f814f. Since the zero-finding review of e61f2ac2dd1cc, the only change is to the existing lease test: it explicitly requests a preserved retry and releases its lease in finally. The old test expectation caused CI failure and stalled teardown. All 43 GC/eviction/lease tests from the remaining #200350 footprint now pass; focused typecheck, lint, and fresh Codex autoreview are clean. Production code, synthetic measurements, and the posted UI proof are unchanged.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 8e8203f into main Nov 17, 2026
144 of 146 checks passed
@steipete
steipete deleted the steipete/perf-micro-preserved-worktree-fast-refusal-20260919 branch November 17, 2026 07:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
* fix: skip repeated removal of preserved worktrees

* fix: settle preserved removal claims and UI retries

* test: explicitly retry preserved worktree lease checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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