Skip to content

fix(worktrees): keep worktrees placed directly under the worktrees root (#119691) - #119709

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
licheer-zte:fix/worktrees-reconcile-orphans-119691
Aug 6, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
licheer-zte:fix/worktrees-reconcile-orphans-119691

Conversation

@licheer-zte

@licheer-zte licheer-zte commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #119691

What Problem This Solves

Fixes an issue where operators with a Git worktree placed directly under OpenClaw's worktrees state root could have that checkout's child directories recursively deleted by orphan garbage collection. The same risk also affected registered unborn worktrees and path aliases such as a symlinked state root.

Why This Change Was Made

Orphan reconciliation now classifies each top-level and nested candidate with one preservation rule before descending or deleting. It uses Git's stable worktree list --porcelain -z registry from checkout roots, canonicalizes target and listed paths, preserves committed and unborn worktrees, and aborts cleanup when checkout metadata cannot be inspected safely. The existing commit-required repository resolver remains unchanged.

User Impact

Registered Git worktrees remain intact whether they use OpenClaw's fingerprint layout or live directly below the worktrees root. Genuine unregistered debris still gets removed.

Evidence

Before the repair on origin/main baseline a20746e3abf7:

Test Files  1 failed (1)
Tests       4 failed | 2 passed (6)

The failing cases were direct committed, direct unborn, nested unborn, and symlinked-state-root worktrees.

After the repair at 7aa31a2ae395:

macOS real-Git regression suite: 7/7 passed, repeated 3 times
macOS existing worktree service suite: 48/48 passed
Linux Blacksmith Testbox: check-changed passed; focused suites 55/55 passed
Autoreview (Codex, max P1): no accepted/actionable findings

Linux proof: https://github.com/openclaw/openclaw/actions/runs/31059656680

The new failure-path regression also verifies that a broken checkout control path aborts garbage collection before its payload can be deleted.

Release note: prevent managed-worktree orphan cleanup from recursively deleting registered direct-root or unborn Git worktrees.

[AI-assisted]

Punchcard-Session: amber-meadow-timber-8r

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 5, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 8:44 PM ET / August 6, 2026, 00:44 UTC.

ClawSweeper review

What this changes

The PR changes managed-worktree orphan cleanup to preserve registered direct-root, nested, unborn, and canonical-path-alias Git worktrees while deleting genuine debris.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

The rewritten patch addresses the confirmed destructive cleanup path at its owner boundary and resolves the prior unborn-worktree finding. No actionable patch defect was found; keep this PR open for exact-head CI completion and normal merge gating.

Priority: P0
Reviewed head: 7aa31a2ae39522b37a02e58c4131f2a6f6a48f47

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused owner-boundary repair with real-Git regression proof and no actionable findings; exact-head CI remains the normal landing gate.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body records before/after real-Git regression results, including direct-root and unborn cases, plus a linked Testbox run; no private data is exposed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records before/after real-Git regression results, including direct-root and unborn cases, plus a linked Testbox run; no private data is exposed.
Evidence reviewed 5 items Current-main failure path: Current main still treats every top-level worktree directory as a fingerprint container, descends into it, and removes unregistered child directories; a direct-root checkout therefore exposes its normal children to deletion.
Owner-boundary repair: The exact PR head canonicalizes paths and checks a candidate’s Git worktree registration before both top-level descent and nested deletion; lookup runs from the checkout so unborn worktrees do not require a commit.
Boundary regression coverage: Real-Git tests cover direct and nested committed/unborn worktrees, canonical state-root aliases, genuine debris removal, and failure before deletion when checkout metadata is broken.
Findings None None.
Security None None.

How this fits together

The managed-worktree service periodically scans OpenClaw’s state-directory worktree tree and removes unregistered leftovers. It must identify registered Git checkout roots before recursive descent so garbage collection cannot delete a user’s working tree.

flowchart TD
A[Gateway maintenance sweep] --> B[Managed worktree cleanup]
B --> C[Classify directory]
C --> D[Git worktree registry]
D --> E[Preserve registered checkout]
C --> F[Remove genuine orphan]
E --> G[User worktree intact]
F --> H[State directory cleaned]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still in progress and GitHub reports the branch behind main; recheck mergeability and required checks on the reviewed head before landing.
  • Complete next step (P2) - No mechanical repair remains; await normal exact-head CI and mergeability gates.
Agent review details

Security

None.

PR surface

Source +44, Tests +149. Total +193 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 53 9 +44
Tests 1 149 0 +149
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 202 9 +193

Review metrics

Metric Value Why it matters
Production versus regression-test delta production +53/-9 (net +44); tests +149/-0 The production growth is justified by a single canonical preservation classifier at a destructive filesystem-cleanup boundary; the added tests exercise real Git rather than mocks.

Stored data model

Persistent data-model change detected: serialized state: src/agents/worktrees/service.orphans.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119691
Summary: This PR is the focused candidate fix for the direct-root registered-worktree deletion bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the fail-closed, registry-based preservation flow after exact-head CI passes, retaining the real-Git regression suite as protection for direct-root and unborn checkouts.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the fail-closed, registry-based preservation flow after exact-head CI passes, retaining the real-Git regression suite as protection for direct-root and unborn checkouts.

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

Yes. Current main’s top-level scan descends into a direct-root checkout and deletes child directories; the PR’s real-Git regression suite directly exercises that path and its unborn variants.

Is this the best way to solve the issue?

Yes. The preservation decision now occurs in the orphan-reconciliation owner before descent or deletion; a root-only .git skip would miss nested, unborn, and canonical-path cases.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d28371e95d70.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before/after real-Git regression results, including direct-root and unborn cases, plus a linked Testbox run; no private data is exposed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records before/after real-Git regression results, including direct-root and unborn cases, plus a linked Testbox run; no private data is exposed.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 other: Current PR review selected no merge-risk labels.

Label justifications:

  • P0: The underlying bug can silently and recursively delete registered worktree contents during scheduled garbage collection.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records before/after real-Git regression results, including direct-root and unborn cases, plus a linked Testbox run; no private data is exposed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before/after real-Git regression results, including direct-root and unborn cases, plus a linked Testbox run; no private data is exposed.

Evidence

What I checked:

  • Current-main failure path: Current main still treats every top-level worktree directory as a fingerprint container, descends into it, and removes unregistered child directories; a direct-root checkout therefore exposes its normal children to deletion. (src/agents/worktrees/service.ts:1238, d28371e95d70)
  • Owner-boundary repair: The exact PR head canonicalizes paths and checks a candidate’s Git worktree registration before both top-level descent and nested deletion; lookup runs from the checkout so unborn worktrees do not require a commit. (src/agents/worktrees/service.ts:215, 7aa31a2ae395)
  • Boundary regression coverage: Real-Git tests cover direct and nested committed/unborn worktrees, canonical state-root aliases, genuine debris removal, and failure before deletion when checkout metadata is broken. (src/agents/worktrees/service.orphans.test.ts:83, 7aa31a2ae395)
  • History provenance: Blame ties the current destructive loop to a grafted commit; shallow history prevents reliable predecessor-PR attribution. (src/agents/worktrees/service.ts:1238, 3d669c761666)
  • Patch hygiene: The exact base-to-head diff is whitespace-clean; production growth is the preservation classifier needed at the destructive cleanup boundary. (src/agents/worktrees/service.ts:1275, 7aa31a2ae395)

Likely related people:

  • Peter Lee: Current-main blame attributes the destructive reconciliation loop to this grafted commit; repository history is incomplete. (role: original-path author; confidence: medium; commits: 3d669c761666; files: src/agents/worktrees/service.ts)
  • steipete: Recent worktree history contains multiple repairs to related Git-worktree lifecycle behavior. (role: recent area contributor; confidence: medium; commits: f30d9b3474a8, a53795e64d63; files: src/agents/worktrees/service.ts, src/agents/worktrees/git.ts)
  • yetval: Recent work addressed preservation of worktree-local state during cleanup, a neighboring invariant. (role: adjacent cleanup contributor; confidence: medium; commits: af05f64f0a35; files: src/agents/worktrees/service.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for required exact-head checks, then refresh mergeability before landing.

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 (2 earlier review cycles)
  • reviewed 2026-08-05T19:32:14.832Z sha d3a0bef1aba591a278c46e0b013bdbf70ad82b0e :: needs real behavior proof before merge. :: [P1] Recognize unborn worktrees before scanning the root
  • reviewed August 5, 2026, 4:44 PM ET / 20:44 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Preserve direct-root unborn worktrees

Classify direct and nested checkout roots through Git worktree registration before recursive orphan cleanup, including unborn and canonicalized paths. Fail closed when checkout metadata cannot be inspected.

Co-authored-by: 李琪0668001400 <[email protected]>
Punchcard-Session: amber-meadow-timber-8r
@vincentkoc
vincentkoc force-pushed the fix/worktrees-reconcile-orphans-119691 branch from d3a0bef to 7aa31a2 Compare August 6, 2026 00:38
@vincentkoc vincentkoc self-assigned this Aug 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

The contributor branch was rewritten at 7aa31a2ae39522b37a02e58c4131f2a6f6a48f47 to cover the prior rank-up moves: direct and nested committed/unborn worktrees, canonical path aliases, marker-first debris classification, and fail-closed Git lookup behavior. The PR body now includes the fail-before/pass-after transcript and fresh Linux Testbox proof.

@clawsweeper

clawsweeper Bot commented Aug 6, 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 repository_dispatch).
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 proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 6, 2026
@vincentkoc
vincentkoc merged commit 1e347e2 into openclaw:main Aug 6, 2026
138 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…claw#119709)

Classify direct and nested checkout roots through Git worktree registration before recursive orphan cleanup, including unborn and canonicalized paths. Fail closed when checkout metadata cannot be inspected.


Punchcard-Session: amber-meadow-timber-8r

Co-authored-by: Vincent Koc <[email protected]>
vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 6, 2026
…cope

* origin/main: (24 commits)
  fix(backup): skip transient gateway lock databases (openclaw#119782)
  test(agents): use canonical auth session fixtures (openclaw#119821)
  fix(memory): keep QMD file hints after stale docid misses (issue openclaw#113041) (openclaw#113515)
  test(doctor): align fast-path repair contracts (openclaw#119812)
  perf(agents): index subagent recovery ownership (openclaw#119793)
  fix(gateway): keep chat startup off catalog discovery (openclaw#119742)
  fix(test): keep TUI PTY suites in their owner lane (openclaw#119787)
  docs: correct dashboard auth precedence (openclaw#119785)
  docs: document control ui owner handoff
  fix: grant host-authorized control ui owner access
  fix(worktrees): preserve registered roots during orphan cleanup (openclaw#119709)
  fix(matrix): prevent shared client key collisions (openclaw#119667)
  fix(diagnostics-otel): propagate exported span context (openclaw#112283)
  fix(worker): isolate state observer failures (openclaw#117507)
  fix(qa): attest realized profile executions (openclaw#119761)
  fix(gateway): finish successful sessions after timestamp races (openclaw#119752)
  fix(agents): fence restart recovery lifecycle (openclaw#119776)
  fix(ui): preserve chat history and active run timing (openclaw#119729)
  improve(ollama): reduce inactive startup cost (openclaw#119745)
  improve(gateway): defer inactive plugin runtime imports (openclaw#119733)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: M 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.

Bug: reconcileOrphans() deletes worktree contents when worktree is placed directly under worktreesRoot (no fingerprint subdir)

2 participants