Skip to content

fix(worktrees): report retained cleanup failures - #148962

Merged
vincentkoc merged 1 commit into
mainfrom
fix/gc-outcome-reporting-20260914
Sep 21, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/gc-outcome-reporting-20260914

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Managed worktree cleanup could retain many failed records while reporting a healthy result. The idle pass also tried the same failed worktree again during count or size enforcement, doubling work and producing misleading limits still exceeded logs.

User Impact

Operators now get a bounded per-worktree failure or deferral reason from openclaw worktrees gc --json. Partial cleanup returns a non-zero CLI status, scheduled cleanup writes a health error, and Gateway callers receive an explicit non-retryable error after any deletions that did succeed.

Why This Change Was Made

Each managed worktree ID now receives at most one automatic-removal decision in a GC pass. Failed records stay protected, confirmed removals continue, and up to 64 ID/reason dispositions are returned with a total count when additional results are omitted. The existing three-field Gateway success payload remains unchanged for completed cleanup.

Evidence

  • Blacksmith Testbox tbx_01m30yxdbzb5k2cn22m6wzx8xk: dependency install succeeded; formatter identified two files, then both were formatted with the repository command.
  • Focused coverage: a missing repository control path is retained, reported once by ID, and skipped by the limit pass; CLI JSON is written before failure; scheduled maintenance logs partial results; Gateway reports partial progress without retrying.
  • Hosted exact-head CI and ClawSweeper re-review requested on c80caf5854d413f240d549adb0425050040eae04.

Related: #150940

@vincentkoc vincentkoc self-assigned this Sep 15, 2026
@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.

@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 agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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: needs maintainer review before merge. Reviewed September 21, 2026, 2:48 AM ET / 06:48 UTC (Revision 13).

ClawSweeper review

What this changes

The PR reports retained worktree cleanup failures and deferrals through the CLI, Gateway responses, and maintenance logs while preventing repeated removal attempts within one pass.

Merge readiness

✅ Ready for maintainer review

The repair remains useful on current main. The prior inventory, Gateway fixture, and changelog findings are addressed; no remaining actionable defect was found in the pinned patch.

Priority: P2
Reviewed head: c80caf5854d413f240d549adb0425050040eae04

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful regression coverage and resolved prior findings; runtime validation was not rerun during this read-only review.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate, and the patch does not materially change authority. Its current tests cover service failures and caller reporting; historical UI evidence is not treated as execution proof for this head.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate, and the patch does not materially change authority. Its current tests cover service failures and caller reporting; historical UI evidence is not treated as execution proof for this head.
Evidence reviewed 10 items Pinned introduction and merge ownership: Reviewed the introduced delta from 051563c to c80caf5. The recorded test merge has the pinned base followed by the exact PR head as parents; unrelated base-branch changes were excluded.
Current main still needs the repair: Current main logs caught cleanup failures but returns only removal, orphan, and snapshot counts. Its limit pass can reconsider a record whose idle cleanup already failed.
Latest release contract: The v2026.9.5 source also exposes only the three original GC result fields; it does not contain the new outcome and disposition report.
Findings None None.
Security None None.

How this fits together

Managed worktrees provide isolated Git checkouts for agent tasks. Manual and scheduled cleanup use the worktree service to preserve protected checkouts, snapshot eligible work, and report removal results.

flowchart TD
  A[CLI or Gateway request] --> C[Worktree cleanup service]
  B[Scheduled maintenance] --> C
  C --> D[Eligibility and protection checks]
  D --> E[Snapshot and removal owner]
  D --> F[Bounded cleanup report]
  E --> F
  F --> G[CLI output, RPC result, or health log]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +209, Tests +228. Total +437 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 9 337 128 +209
Tests 5 238 10 +228
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 575 138 +437

Review metrics

Metric Value Why it matters
Diagnostic bounds 64 retained dispositions; 500 UTF-16 units per reason Reports retain a total count while bounding detailed error output.
Production versus tests Production net +209 lines; tests net +228 lines Production growth supports shared outcome accounting and caller reporting, with focused regression coverage.

Technical review

Best possible solution:

Keep one cleanup owner that preserves work and reports incomplete outcomes without inviting automatic retries after committed deletions.

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

Yes, from source: an idle worktree whose repository control path is missing can be retained while current main returns ordinary success counts and retries it during limit enforcement. The focused regression models that trigger; this review did not execute it.

Is this the best way to solve the issue?

Yes. Shared per-pass accounting repairs the existing service and its callers while preserving removal safeguards and the completed Gateway response contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs misleading cleanup results and repeated failed attempts without evidence of an urgent 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 MEMBER-authored PR is exempt from the external-contributor proof gate, and the patch does not materially change authority. Its current tests cover service failures and caller reporting; historical UI evidence is not treated as execution proof for this head.

Evidence

What I checked:

  • Pinned introduction and merge ownership: Reviewed the introduced delta from 051563c to c80caf5. The recorded test merge has the pinned base followed by the exact PR head as parents; unrelated base-branch changes were excluded. (4523993bd1f8)
  • Current main still needs the repair: Current main logs caught cleanup failures but returns only removal, orphan, and snapshot counts. Its limit pass can reconsider a record whose idle cleanup already failed. (src/agents/worktrees/service.ts:1356, beaf348df230)
  • Latest release contract: The v2026.9.5 source also exposes only the three original GC result fields; it does not contain the new outcome and disposition report. (src/agents/worktrees/types.ts, ec9c1a13db89)
  • Prior findings resolved: The initial inventory refresh now precedes the below-limit return and records newly created, unmeasured worktrees. Both Gateway success fixtures supply completed results while retaining the original wire payload assertion. No release-owned changelog path remains in the introduced delta. (src/agents/worktrees/gc-limits.ts:72, c80caf5854d4)
  • Single cleanup decision and preserved safety: Idle and limit cleanup share attempted IDs, while actual removals retain the existing allocation lease, snapshot protection, current owner/activity guards, and fresh lock checks. The report is transient and introduces no persisted schema or authority-bearing value. (src/agents/worktrees/service.ts:1379, c80caf5854d4)
  • Caller compatibility: Completed Gateway cleanup preserves the three-field success payload. Incomplete cleanup includes progress in a non-retryable error; the existing worktrees page reloads its list in finally, including after errors. CLI partial results are printed before the shared exit-finalization path receives status 1. (src/gateway/server-methods/worktrees.ts:162, c80caf5854d4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-15T22:43:39.948Z sha 0e4b4f9 :: blocked before merge. :: none
  • reviewed 2026-09-15T23:19:54.602Z sha 0e4b4f9 :: blocked before merge. :: none
  • reviewed 2026-09-16T07:04:48.718Z sha 63e7032 :: blocked before merge. :: none
  • reviewed 2026-09-16T07:23:05.062Z sha 63e7032 :: blocked before merge. :: none
  • reviewed 2026-09-21T03:56:09.384Z sha 696df53172c8c5571ead2a85b8089e028ce0d195 :: needs changes before merge. :: [P2] [P2] Record incomplete inventory before the below-limit return | [P2] [P2] Update the existing Gateway GC success fixture | [P3] [P3] Remove the release-owned changelog entry
  • reviewed 2026-09-21T05:52:20.711Z sha fe22008cbc2be18075bfb1cd8250f516a1ddb400 :: needs changes before merge. :: [P2] [P2] Record incomplete inventory before the below-limit return | [P3] [P3] Remove the release-owned changelog entry
  • reviewed 2026-09-21T06:12:45.346Z sha 2bfa0825356eb91d1bdb7d2ce9fb2755d877d44d :: needs changes before merge. :: [P2] Record incomplete inventory before the below-limit return | [P3] Remove the release-owned changelog entry
  • reviewed 2026-09-21T06:34:11.985Z sha 0d33ca9c56ce46d54af074f80318410a06cff664 :: needs changes before merge. :: [P3] Remove the release-owned changelog entry

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 15, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Current head: 2ae5afae4acfd7c216d6949692c4f76aee5370cc. The snapshot-ref fault is narrowed, the complete GC suite passes, and inspected before/after images are embedded. Required CI still has the separately recorded startup-boundary failure; this PR remains draft.

@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 proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 15, 2026
@fuller-stack-dev

fuller-stack-dev commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Coordinating adjacent managed-worktree retention presentation work with this canonical GC-outcome repair.

The planned change only displays the existing per-record runEndCleanup as Last cleanup attempt, with its recorded time, reason, and next action. It does not infer current eligibility or add storage, cleanup policy, or a new removal path.

At 2ae5afae4acfd7c216d6949692c4f76aee5370cc, the shared files have separate sections:

  • CLI: planned list and remove --if-lossless text; this PR owns gc output.
  • Worktrees page: planned renderRecordRow history; this PR owns gcResult, GC requests, and the page-level result callout.
  • CLI/page tests and English locale: separate retention cases/keys versus GC cases/keys.
  • Managed-worktree docs: adjacent per-record versus aggregate-GC explanation.

There is no planned dependency on the new GC report schema. This PR remains the canonical aggregate cleanup fix; no duplicate replacement is planned.

@vincentkoc, please confirm the current active writer and whether this branch is being edited, plus any section or merge-order coordination needed. No source changes have begun for the adjacent retention work. If follow-through on this canonical PR needs a handoff, please identify the existing checkout/evidence owner so useful work and attribution are preserved.

Canonical integration follow-through

I am carrying the integration/review follow-through on this existing PR; the original branch and Vincent's attribution remain canonical. No branch writes have been made. Please flag any concurrent branch edits so the exact head can be reconciled before a push.

Source comparison: merge base 03c158fb469c93cd9d4253cc577de512297ddcb1, PR head 2ae5afae4acfd7c216d6949692c4f76aee5370cc, current-main comparison e7dde047904e749ad5a642443092f9108f2a99d4.

  • Resolve the GC-owner overlap by retaining main's createWorktreeLockPrefilter() and passing the same prefilter through idle and limit passes alongside this PR's WorktreeGcProgress. Keep removal's fresh under-lease lock check and the current hasTemplates() probe. Preserve both sets of regression tests.
  • Keep OpenClawStateLeaseError in service.ts when the separately coordinated mechanical allocation-lease extraction moves withOpenClawStateLease. Preserve this PR's collectWorktreeTemplates error callback and all transaction scopes.
  • Preserve main's newer runtime-auth test fixture and avoid replaying already-present provider/setup expectation fixes. Regenerate protocol/Workboard output from the integrated source, retaining newer main fields.
  • Confirmed the separate exact-head CI run 34958807486 failed (188 success, 8 failure, 5 skipped); the mostly skipped PR rollup is not qualification. Main now contains the three UI expectation fixes, but the integrated head still requires real execution. The removal-child cancellation, package-exit lease, and startup-boundary failures need qualifying proof; fix(agents): avoid loading transcript storage during model selection #149079 remains an open candidate, not proof of a fix. fix(ci): retain safe dirty-source diagnostics for desktop proof #149085 is diagnostic follow-through, not a substitute for green CI.

This is a source/conflict plan, not a completed rebase, test result, or merge recommendation. Execution remains pending the serialized work allocation. Required independent review, exact-head CI, operator/recovery proof, screenshot-delivery verification, and native preparation/landing still apply.

@vincentkoc

Copy link
Copy Markdown
Member Author

@fuller-stack-dev thanks for preserving the existing PR and evidence. I am the active writer for this landing attempt on Vincent’s behalf. The current remote head is still 2ae5afae4acfd7c216d6949692c4f76aee5370cc; no integration or branch push has been made in this attempt. Please hold branch writes while I carry the native integration, review, and qualification through this PR, and flag any active unpublished edits or lock before I start the GC-owner merge.

Your integration notes match the boundaries we need to preserve: main’s lock prefilter and fresh under-lease checks, this PR’s recorded GC progress, both regression sets, and canonical generated outputs from the integrated source. The adjacent per-record retention presentation remains separate; please keep its changes off this branch so the aggregate GC reporting fix has one source owner. I will report the frozen integrated head here after review and push.

The other two follow-ups remain separate: #149079 and #149085. Their current CI failures are being attributed before landing; neither is being treated as qualifying proof for this PR.

@fuller-stack-dev

Copy link
Copy Markdown
Member

@vincentkoc I have now received the WDE native source/proof slot after #149193 landed. I saw your 21:12 active-writer notice before any source or branch write. The canonical .worktrees/pr-148962 path, operation lock and merge outcome are absent on this host; remote head remains 2ae5afae4acfd7c216d6949692c4f76aee5370cc.

Please identify the active checkout/operation and any unpublished integrated head so we can adopt that work and avoid duplicate writers. I will preserve your branch-write hold while reconciling custody, and keep the per-record retention patch separate. Baseline/source inspection and focused proof can proceed within the admitted native checkout; no competing push has been made. The existing WDE orchestrator is coordinating the handoff.

@vincentkoc
vincentkoc force-pushed the fix/gc-outcome-reporting-20260914 branch from 696df53 to fe22008 Compare September 21, 2026 05:46
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 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:

@vincentkoc
vincentkoc force-pushed the fix/gc-outcome-reporting-20260914 branch from fe22008 to 73c60aa Compare September 21, 2026 06:03
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 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:

@vincentkoc
vincentkoc force-pushed the fix/gc-outcome-reporting-20260914 branch from 73c60aa to 2bfa082 Compare September 21, 2026 06:04
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 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:

@vincentkoc
vincentkoc force-pushed the fix/gc-outcome-reporting-20260914 branch from 2bfa082 to 0d33ca9 Compare September 21, 2026 06:28
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@clawsweeper clawsweeper Bot added 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 21, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 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:

@vincentkoc
vincentkoc force-pushed the fix/gc-outcome-reporting-20260914 branch from 0d33ca9 to c80caf5 Compare September 21, 2026 06:41
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@vincentkoc
vincentkoc merged commit 585312d into main Sep 21, 2026
213 of 214 checks passed
@vincentkoc
vincentkoc deleted the fix/gc-outcome-reporting-20260914 branch September 21, 2026 07:02
@vincentkoc

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 gateway Gateway runtime 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: 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.

2 participants