Skip to content

fix(worktrees): stop extra eviction after incomplete cleanup - #156876

Closed
fuller-stack-dev wants to merge 3 commits into
openclaw:mainfrom
fuller-stack-dev:openclaw/gc-pressure-reconciliation-20260923
Closed

fuller-stack-dev wants to merge 3 commits into
openclaw:mainfrom
fuller-stack-dev:openclaw/gc-pressure-reconciliation-20260923

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Related: #148962

What Problem This Solves

Prevents extra worktree eviction when cleanup leaves removal accounting unresolved or pressure falls while GC waits for removal authority.

User Impact

GC pauses pressure-based eviction until incomplete removals reconcile and reports unknown limit compliance instead of trusting stale accounting. A reporting-lease failure returns a deferred/partial result without skipping later maintenance. Recovery snapshots, retention rules, and the bounded public issue schema remain intact; no migration is required.

Why This Change Was Made

Distinguish pending removals from ordinary protected worktrees, preserve initiating and rollback errors, and recheck count/measured-size pressure under the existing allocation lease. Final reconciliation uses the same authority and handles acquisition failures without discarding the GC result.

Evidence

  • Exact-head CI passed for dfc81630cf017a6ee6839eafb866366171ee1f74: 129 successful jobs, 18 workflow-selected skips, no failures; required openclaw/ci-gate is successful.
  • 76 selected GC/retention tests passed locally and in hosted CI using disposable real Git repositories and private SQLite state: pressure 30, existing GC 37, performance 2, reporting-lease 4, and existing retention 3.
  • Initial service regressions produced 16 intended failures and 2 passing controls on original production. Subsequent review-discovered races were reproduced before their fixes. All four reporting cases failed on the prior head, then passed while preserving the checkout, returning unknown compliance, and completing actual expired-snapshot cleanup.
  • Required changed-file gates passed through the recorded original prefix and affected continuations: production and all 25 test typecheck graphs, formatting, lint, ratchets, import cycles, and state/auth guards.
  • Independent review of production, unchanged authority callers, complete touched tests and the fixture helper found no actionable P0–P2 issues. Current-head ClawSweeper review is ready for maintainer review, with the reporting-lease finding resolved and no remaining actionable findings. These were source reviews, not independent test executions.

Test cost

The new suites exercise the real service, SQLite authority/claims, native Git deletion, and recovery boundary. Local wall times include wrapper/transform overhead; hosted figures below are sums of logged case durations, not whole-file wall times.

Suite Local wall Hosted case sum / receipt
Pressure (30) 225.30 s 61.792 s
Existing GC (37) 339.18 s 79.385 s
Reporting lease (4) 53.67 s 13.241 s
Performance (2) 44.40 s 1.651 s
Selected existing retention (3) 57.78 s 6.987 s

No live cleanup or deployment was performed. The final CI merge candidate includes the now-merged Web Push fix #156824. Earlier task-notification/task-list failures did not reproduce in bounded local replays; their causes were not established or claimed fixed by this PR. Those hosted groups pass on this head. One replay wrapper exited nonzero because auxiliary projects selected no files, despite all selected cases passing; it is not counted as an aggregate-green check.

@clawsweeper

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

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 24, 2026 00:37
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L labels Sep 24, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 8, 2026, 1:05 PM ET / 17:05 UTC (Revision 5).

ClawSweeper review

What this changes

Stops pressure-based worktree deletion when earlier removal accounting is unresolved, rechecks pressure after acquiring cleanup authority, and preserves partial cleanup reports.

Example: Cleanup processes two worktrees with maxCount set to 1

  • Before: If deleting the oldest checkout succeeds but finalization fails, cleanup can also delete the newest checkout using the stale count.
  • After: Cleanup preserves the newest checkout and reports limitsSatisfied as null until the incomplete removal reconciles.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful safeguards have meaningful native boundary coverage, but the report-only latency remains unresolved and current-main integration is unproven.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: This MEMBER-authored PR is outside the external-contributor proof gate. Its recorded native-service regressions exercise actual Git deletion, SQLite claims, retained sibling bytes, and snapshot expiry; they support the pinned implementation but do not prove an integration with rewritten main. The diff changes no stored schema or serialized format.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes
User problem: Cleanup can remove an additional session checkout after an earlier deletion leaves its accounting unresolved.
Reason: Preventing unnecessary checkout deletion and retaining truthful cleanup results has clear value. The change preserves existing recovery and removal protections rather than introducing a new user mode.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this maintainer-authored PR contains useful cleanup safeguards, but GitHub confirms merge conflicts and current main has replaced the affected cleanup architecture. The previous reporting-acquisition finding is fixed; no additional discrete patch defect was established.

Priority: P2
Reviewed head: dfc81630cf017a6ee6839eafb866366171ee1f74

Before merge

  • Resolve merge risk (P1) - Report-only reconciliation can wait ten minutes behind allocation even when no eviction is needed, delaying CLI/Gateway results and subsequent maintenance; remove that wait during integration or obtain explicit acceptance of this specific latency.
  • Complete next step (P2) - Reconcile this PR with current main and obtain a fresh review of the integrated changes.

Findings

None.

Tests

  • Missing end-to-end proof: Recorded proof covers the pinned service with native Git and SQLite, not the conflicted integration with current main; repeat the relevant failure and contention scenarios after reconciliation.
Agent review details

How this fits together

Managed worktrees give agent sessions separate Git checkouts. Cleanup uses registry records, run leases, and recovery snapshots to decide which checkouts can be removed and report the result.

flowchart TD
  A[Cleanup request] --> B[Registry and checkout inventory]
  B --> C[Count or size pressure]
  C --> D[Allocation lease]
  D --> E[Recheck pressure and pending removals]
  E --> F[Snapshot and remove eligible checkout]
  E --> G[Defer unresolved cleanup]
  F --> H[Cleanup result]
  G --> H
Loading

Technical review

Best possible solution:

Carry any still-needed incomplete-removal safeguards into main’s capacity and worker owners, preserving recovery captures and avoiding allocation waits solely for reporting.

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

Unclear on current main: the PR records failing native-service regressions on its original production base, but main has since replaced the cleanup path and those scenarios were not rerun here.

Is this the best way to solve the issue?

Yes for the original invariant: unresolved removal accounting must not justify another eviction. The maintainable integration now belongs in main’s capacity and worker owners rather than restoring the old loop.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Use the current cleanup owner (recommended)
    Integrate the remaining safeguards into current main and retain its under-cap return without a report-only lease wait.
  2. Accept reporting latency explicitly
    If integration retains the reporting lease, record owner acceptance that contention can delay results and later maintenance by ten minutes.

Provenance checked

Testing

Proof path: in-process harness. Added test files: 4.

Security

None.

Evidence

What I checked:

  • Verified introduced production changes: The pinned merge-base-to-head diff adds unresolved-removal tracking, recovery-pin and claim checks, pressure revalidation, and reporting-acquisition error handling. (src/agents/worktrees/gc-limits.ts:137, dfc81630cf01)
  • Previous finding resolved: Final reporting catches lease acquisition or loss errors, returns unavailable inventory explicitly, and records unknown compliance rather than throwing past later maintenance. Four reporting regressions exercise held SQLite leases, preserved checkout bytes, and actual expired-snapshot removal. (src/agents/worktrees/service.gc-reporting.test.ts:34, dfc81630cf01)
  • Reporting wait remains: Even the under-limit branch acquires the allocation lease for reporting. That owner uses a 600,000 ms acquisition wait; the reporting call supplies no cancellation signal. This independently confirms the prior availability concern. (src/agents/worktrees/gc-limits.ts:139, dfc81630cf01)
  • Allocation wait contract: WORKTREE_CREATE_LEASE_WAIT_MS is ten minutes and is passed to lease acquisition. (src/agents/worktrees/allocation.ts:13, dfc81630cf01)
  • Current GitHub conflict state: The REST response confirms the pinned head remains open with mergeable=false and mergeable_state=dirty. (dfc81630cf01)
  • Current-main architecture: Current main uses a capacity owner, slot accounting, and allocation-held eviction batches; its under-cap cleanup returns without a report-only allocation acquisition. The old count/size loop is substantially rewritten, so the branch cannot be assessed as a ready integration. (src/agents/worktrees/capacity-owner.ts:187, 95baa6d9510c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +206, Tests +615. Total +821 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 7 256 50 +206
Tests 4 627 12 +615
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 883 62 +821

Review metrics

Metric Value Why it matters
Reporting acquisition budget 600 seconds The new report-only acquisition inherits the full allocation wait even for an under-limit result.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded worktree-cleanup correctness improvement without evidence of an urgent current-release outage.
  • merge-risk: 🚨 availability: The introduced report-only lease acquisition can delay cleanup responses and later maintenance for ten minutes under contention.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Resolve conflicts against the current capacity and worker owners, then rerun the incomplete-removal and contention regressions.
  • Eliminate the report-only allocation wait or record explicit owner acceptance of its ten-minute maximum.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-24T01:02:17.710Z sha c7f3b43 :: blocked before merge. :: [P2] Return a GC result when report-only lease acquisition fails
  • reviewed 2026-09-24T01:30:35.543Z sha dfc8163 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-24T02:00:47.259Z sha dfc8163 :: blocked before merge. :: none
  • reviewed 2026-09-28T00:00:40.180Z sha dfc8163 :: blocked before merge. :: none

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Fixed the reporting-lease finding in dfc81630cf017a6ee6839eafb866366171ee1f74. Final reporting now catches acquisition/loss errors, preserves the original deferred classification for a held lease, reports unknown compliance, and lets later GC maintenance continue. Callers do not consume an unavailable inventory.

Four actual held-lease service cases (count/size, under/over cap) failed on the prior head and pass now; they verify preserved checkout bytes and actual expired-snapshot pruning. The three existing retention cases exposed by CI also pass. The complete focused rerun passed 76 selected tests; affected required checks and fresh independent review are clean. Current-head CI is running.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Current head: dfc8163. The prior reporting-lease finding is addressed with real held-lease red/green regressions and the three existing retention failures now passing; see the disposition above. This requests review only, not merge or autofix.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 8, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Closing: current main has replaced the worktree cleanup architecture this PR changed, and the branch conflicts. Any remaining safeguard should be re-authored against current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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