Skip to content

fix(worktrees): prevent cleanup failures on large ignored trees - #148608

Merged
roboclaw-bot merged 1 commit into
mainfrom
fix/worktree-ignored-inventory-148599
Sep 15, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
fix/worktree-ignored-inventory-148599

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Closes #148599

What Problem This Solves

Fixes idle managed-worktree cleanup failing when large ignored dependency or temporary trees exceed Git's buffered filename-output limit.

User Impact

Eligible worktrees can be cleaned up while retaining restorable local edits and owned staged inputs. Nested repositories, origin mismatches and other protected worktrees remain retained. No configuration, retention-policy or schema change is required.

This bounds buffered Git output, not total traversal time. A flat ignored-file inventory can still exceed the unchanged capture limit and fail closed.

Why This Change Was Made

Request compact ignored-directory records from Git and walk those directories incrementally instead of buffering every generated descendant filename. Cleanup inspection and safety snapshots share that inventory owner. Preserve raw filename bytes through Node's unknown-directory-entry fallback, do not follow directory symlinks, and retain existing nested-repository and staged-input ownership checks.

Evidence

  • Original overflow reproduced with 64 empty generated files and a test-only 256-byte capture limit through both registered worker operations and actual managed-worktree garbage collection; the same cases pass after the fix.
  • Two additional regressions reproduce the raw-directory DT_UNKNOWN fallback failure before the review correction and pass afterward using real Node Dir type resolution and filesystem lookup.
  • Seven relevant suites passed: 83 tests, covering worker lifecycle, garbage collection/restoration, snapshots, origin/canonical paths, provisioning, run-end cleanup and private staged inputs.
  • Final focused rerun: 6 tests passed. Canonical changed-file checks, typechecks, formatting, lint and dead-export/lifecycle/import guards passed.
  • Linux/Node 26.8.2 proof. Invalid-byte cases are POSIX-only; the deterministic unknown-entry fallback injection runs through the production dispatcher in-process. Existing worker-lifecycle tests cover separate-thread operation. No production-scale tree or live cleanup was used as proof.
  • Independent review identified the unknown-entry fallback issue; it was corrected with fail-before/pass-after coverage. Renewed independent P0–P2 review is scoped-clean with no actionable findings.

@clawsweeper

clawsweeper Bot commented Sep 14, 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 agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 14, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 14, 2026 23:31
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 7:38 PM ET / 23:38 UTC.

ClawSweeper review

What this changes

The PR changes managed-worktree cleanup and snapshots to enumerate ignored directories incrementally, with regression coverage for restoration, nested repositories, and raw filenames.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful repair for a source-confirmed cleanup failure on current main. No blocking defect was found in the introduced patch, and the protected maintainer label excludes automatic closure.

Priority: P2
Reviewed head: ed5d842bb7f14c28e26bf0305d067716b1ef031f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful regression coverage and no identified blocking defect; reported execution was not independently rerun.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository context classifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported Linux/Node 26.8.2 validation exercises the changed inventory through registered workers and managed cleanup/restoration; production-scale traversal was not demonstrated.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository context classifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported Linux/Node 26.8.2 validation exercises the changed inventory through registered workers and managed cleanup/restoration; production-scale traversal was not demonstrated.
Evidence reviewed 9 items Verified introduced implementation: The pinned merge-base-to-head diff replaces both expanded ignored-file inventories with one shared directory scanner. Snapshot ownership filtering, nested-repository rejection, and the existing output limit remain intact.
Current main still contains the failure mechanism: Both inventory consumers on fetched main still buffer every ignored descendant before filtering. Large ignored inventories can therefore exceed the capture limit; this branch's repair is still necessary.
Latest-release implementation: The latest supplied release, v2026.9.4, keeps the older inventory owner in service.ts; its nested-repository inspection also expands ignored filenames without directory collapsing.
Findings None None.
Security None None.

How this fits together

Managed worktrees give agent tasks isolated Git checkouts. Cleanup inventories their contents, preserves protected repositories, and creates recovery snapshots before removing eligible checkouts.

flowchart TD
  A[Eligible managed checkout] --> B[Git file inventory]
  B --> C[Incremental ignored-directory scan]
  C --> D{Nested repository found?}
  D -->|Yes| E[Retain checkout]
  D -->|No| F[Snapshot owned files]
  F --> G[Remove checkout with recovery available]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +48, Tests +279. Total +327 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 74 26 +48
Tests 2 279 0 +279
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 353 26 +327

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +48 lines; tests +279 lines Production growth implements the shared incremental traversal; the added tests exercise cleanup, restoration, and filesystem edge cases.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #148599
Summary: This PR is the explicit implementation candidate for the linked ignored-inventory cleanup issue.

Members:

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

Technical review

Best possible solution:

Keep incremental enumeration in the shared inventory owner while preserving lossless snapshots, nested-repository retention, and fail-closed capture limits.

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

Yes, from source: an ignored filename inventory exceeding the Git capture limit prevents cleanup. The supplied reduced-cap regression targets that path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Compact Git directory records plus incremental traversal repair the inventory owner without increasing global limits or bypassing snapshot safety.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: Large ignored trees prevent eligible cleanup and retain disk usage, without evidence of data loss or a core runtime outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository context classifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported Linux/Node 26.8.2 validation exercises the changed inventory through registered workers and managed cleanup/restoration; production-scale traversal was not demonstrated.

Label justifications:

  • P2: Large ignored trees prevent eligible cleanup and retain disk usage, without evidence of data loss or a core runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository context classifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported Linux/Node 26.8.2 validation exercises the changed inventory through registered workers and managed cleanup/restoration; production-scale traversal was not demonstrated.

Evidence

What I checked:

  • Verified introduced implementation: The pinned merge-base-to-head diff replaces both expanded ignored-file inventories with one shared directory scanner. Snapshot ownership filtering, nested-repository rejection, and the existing output limit remain intact. (src/agents/worktrees/snapshot-inventory.ts:47, ed5d842bb7f1)
  • Current main still contains the failure mechanism: Both inventory consumers on fetched main still buffer every ignored descendant before filtering. Large ignored inventories can therefore exceed the capture limit; this branch's repair is still necessary. (src/agents/worktrees/snapshot-inventory.ts:53, 2e7aa1b7d86b)
  • Latest-release implementation: The latest supplied release, v2026.9.4, keeps the older inventory owner in service.ts; its nested-repository inspection also expands ignored filenames without directory collapsing. (src/agents/worktrees/service.ts:528, 3a9d69db306c)
  • Cleanup and restoration coverage: The new service regression uses real Git with a reduced capture limit, requires successful garbage collection, restores the tracked edit, and verifies generated dependencies were excluded. Worker regressions cover staged-input preservation, raw-byte names, symlinks, unknown directory-entry types, and remaining flat-inventory overflow. The captured PR body reports 83 passing tests and a six-test focused rerun; this review did not execute tests. (src/agents/worktrees/service.gc.test.ts:94, ed5d842bb7f1)
  • Safety and ownership boundaries: Removal still claims the worktree, checks live locks, snapshots before deletion, and stops on snapshot failure unless explicitly forced. The patch changes enumeration rather than authority, stored schemas, retention settings, or plugin contracts. (src/agents/worktrees/service.ts:877, ed5d842bb7f1)
  • Node filename-byte contract: The production opendir call and DT_UNKNOWN regression explicitly depend on Node's directory implementation. Inspected Node v26.8.2 source accepts buffer encoding and joins Buffer paths and names before the unknown-type lstat fallback, supporting the PR's raw-byte handling. (lib/internal/fs/utils.js:229, f2f2c2f246c3)

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.

@roboclaw-bot
roboclaw-bot merged commit 28484b2 into main Sep 15, 2026
169 checks passed
@roboclaw-bot
roboclaw-bot deleted the fix/worktree-ignored-inventory-148599 branch September 15, 2026 00:10
@roboclaw-bot

Copy link
Copy Markdown
Collaborator 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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

Idle worktree cleanup fails on large ignored dependency trees

1 participant