Skip to content

fix: reclaim stale scratch clones and Git repack leftovers - #202122

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-stale-repack-temps-and-nested-clones-20260919
Nov 20, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-stale-repack-temps-and-nested-clones-20260919

Conversation

@steipete

@steipete steipete commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A local clone created in a managed worktree's scratch directory can make automatic cleanup preserve the whole checkout forever as a nested repository. Those clones keep base Git packs hardlinked, and abandoned repack temporary files are also missed by maintenance.

User Impact

Idle managed worktrees can clean themselves up again, including previously stopped scratch-only checkouts, so their pack hardlinks stop pinning storage. Real user nested repositories and live or queued work remain protected. Completed sessions no longer stay active solely because their activity timestamp is recent. No configuration or migration is required.

Why This Change Was Made

The shared snapshot/nested-repository inventory excludes disposable .openclaw/tmp/ content. Existing stopped receipts are re-evaluated through the existing fingerprint owner, then eligible removals use the normal serial pacing and leases. Session idleness comes from session completion and live custody instead of the worktree activity stamp.

On Linux, temporary-pack cleanup also recognizes repack .tmp-<pid>-pack-* files and sidecars. It requires age over 24 hours, a definitely dead PID, and the existing exclusive file lease and inode checks. Any live or unknown PID is retained, including closed sidecars awaiting publication. Logs report removed file count and apparent bytes; hardlinks elsewhere can still retain physical storage.

Evidence

145 focused tests plus the corrected retention case pass across the affected maintenance, GC, snapshot, session-facts, scratch, and Gateway owners. Regressions fail on the exact base for scratch nested-repository detection, automatic re-arming, terminal-session facts, and stale repack selection. A separate Linux production-path test passes with the fix, and a real Git subprocess protects its closed sidecar until exit. Real local clones prove pack nlink drops after cleanup; the unchanged consolidation owner then folds the formerly shared packs.

The overdue snapshot retry fixture succeeds on both base and candidate at attempt five with retryAt six weeks overdue. No retry cap was reproduced, so this change does not invent a scheduler repair.

Worktrees UI boundary checks pass: 28 component tests and five Chromium E2E tests. pnpm check:changed passes for the full change and the one-line CI correction. Initial CI caught a retained-checkout fixture that still supplied an idle owner; it now supplies an active owner, preserving every snapshot-retention and lookup-count assertion. The exact failing case reproduces before that correction and passes afterward. Production code is unchanged by this correction. Codex autoreview is scoped-clean with no accepted/actionable P0–P2 findings. Production code grows by 58 lines for PID safety, scratch exclusion, receipt re-evaluation, byte accounting, and terminal owner facts; no new cache or schema.

Serial synthetic btrfs A/A controls and A/B measurements use a 62,000-file, 1.14 GB checkout and a separate 35 GiB/5,000-row background SQLite storage fixture. This is a reclamation-cost comparison: the base preserves the clone while the candidate snapshots and removes it. Across five interleaved pairs, first-GC wall median is 110.5 ms before (checkout retained) and 9.31 s after (snapshot saved, checkout removed, pack nlink 2 -> 1). Process CPU medians are 102 ms / 6.17 s; main-isolate allocation medians are 9.68 MB / 961.11 MB. A/A wall controls are 117.3 / 124.1 ms. These numbers measure newly enabled removal work, not a speedup. CPU excludes Git children; allocation excludes worker/native memory. The background DB is not a copied production DB or a claim to exercise the complete agent schema.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T23:19:10.074040Z 8b89605 PR opened
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review head 8b8960562afedbec43bdb0fca9ece955ffef18cb. The PR body now includes the completed btrfs A/A and paired results, the real-Git hardlink/consolidation proof, and the snapshot-retry limitation. Focus on preserving real nested repositories and live/queued custody while re-arming scratch-only deferrals, and on PID plus file-lease protection for repack sidecars.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. 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 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets cleanup reclaim disposable scratch clones and abandoned Git repack files while using session completion and live custody to determine idleness.

Example: An eligible checkout contains a local clone at .openclaw/tmp/landing/native.

  • Before: Nested-repository protection retains the checkout indefinitely and leaves the base pack with two hardlinks.
  • After: Cleanup re-evaluates the stopped receipt, saves the tracked snapshot, removes the checkout, and reduces the pack link count to one.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and fixture correction look sound; service-level evidence supports the repair but leaves required product-entry-point validation 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: Disposable scratch clones can permanently prevent checkout cleanup and pin shared Git storage.
Reason: Reclaiming disposable storage has clear value, and the maintainer-authored PR explicitly chooses completion and live custody over recent timestamps for completed sessions.

Merge readiness

✅ Ready for maintainer review

This PR addresses a concrete disk-reclamation failure and resolves the earlier GC fixture finding; no new actionable code defect was found.

Priority: P2
Reviewed head: f14fb9772382372c50fd9ce02d6d41b87496a88a

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply shipped CLI/Gateway evidence of scratch-only receipt recovery and completed-owner cleanup, including upgrade behavior with existing records and preservation of user repositories and live work.
Agent review details

How this fits together

The managed-worktree service consumes registry records, session-owner facts, filesystem inventories, and Git state to preserve active work, snapshot eligible checkouts, and reclaim disposable storage.

flowchart TD
 Registry[Worktree registry] --> GC[Managed worktree GC]
 Sessions[Session custody facts] --> GC
 GC --> Inventory[Shared checkout inventory]
 Inventory --> Snapshot[Safety snapshot]
 Snapshot --> Removal[Checkout removal]
 GC --> Packs[Linux temporary pack cleanup]
Loading

Technical review

Best possible solution:

Keep the focused repair in the existing inventory, receipt, session-custody, and pack-cleanup owners.

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

Current-main source admits scratch clones into nested-repository inspection and short-circuits stopped receipts; the supplied real-Git regressions and measurements describe that failure without an independent execution in this review.

Is this the best way to solve the issue?

The patch restores reclamation through existing owners without adding a scheduler, cache, schema, or parallel cleanup path, and preserves the relevant custody and nested-repository safeguards.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared snapshot and nested-repository inventory changes intended behavior with a stated reason (fix(worktrees): prevent cleanup failures on large ignored trees #148608: Bound ignored-tree traversal while preserving nested repositories and restorable user content; scratch now has a separately documented disposable contract.)
  • Stopped nested-repository receipts changes intended behavior with a stated reason (b6db4fa: Stop repeated preservation attempts requiring human repair; this PR narrowly reopens nested receipts through existing fingerprints.)
  • Session checkout retention changes intended behavior with a stated reason (fix: keep recently used session worktrees from idle cleanup #201333: Recent checkout use should refresh its retention window; this PR explicitly makes terminal completion and live custody authoritative for session-owned eligibility.)
  • Temporary Git pack cleanup keeps the original intent (69e3876: Reclaim abandoned temporary packs using bounded Linux file-lease protection; repack names and PID protection extend that owner.)
  • Narrow session-owner facts keeps the original intent (4de57f2: Avoid parsing full session payloads during GC while preserving current custody facts; terminal status joins the existing narrow projection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4de57f2 adds src/agents/worktrees/owner-protection.ts:51 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4de57f22aa1d; files: src/agents/worktrees/owner-protection.ts)
  • Vincent Koc: Raw commit 67ecf6b adds src/agents/worktrees/owner-protection.ts:147 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 67ecf6bf352d; files: src/agents/worktrees/owner-protection.ts)

PR surface

Source +58, Tests +141, Docs 0, Other +41. Total +240 across 17 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 76 18 +58
Tests 8 159 18 +141
Docs 1 4 4 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 54 13 +41
Total 17 293 53 +240

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.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The change fixes persistent storage retention in background maintenance with a bounded affected surface.
  • 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-19T23:32:16.055Z sha 8b89605 :: needs changes before merge. :: [P2] Update the GC retention test for session-owner idleness

Reviewed November 19, 2026, 6:47 PM ET / 23:47 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the one open item in the review of 8b8960562afedbec43bdb0fca9ece955ffef18cb:

  1. GC retention fixture / session-owner idleness: fixed in f14fb9772382372c50fd9ce02d6d41b87496a88a. The deliberately retained checkout now supplies an active owner at service.gc.test.ts:790. The existing assertions at lines 794–805 still prove that the removed owner is not queried, its snapshot remains intact, and the active checkout remains. I retained the one-lookup assertion: this active-owner path does not enter removal or its live custody guards, so it is still a useful work-count check. No assertion was loosened.

The exact CI case fails locally before this correction and passes after it. Changed-file pnpm check:changed and a fresh Codex autoreview both pass. Production code is unchanged; the existing 145-test, real-Git, Linux lease/PID, and btrfs evidence remains applicable. Fresh exact-head CI is running; the previous failed run is not treated as green. The reported reclamation proof is through the production service and native helper, not a shipped CLI/Gateway campaign.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 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 Nov 19, 2026
@steipete
steipete merged commit 3f07886 into main Nov 20, 2026
142 of 144 checks passed
@steipete
steipete deleted the steipete/perf-micro-stale-repack-temps-and-nested-clones-20260919 branch November 20, 2026 00:11
@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 20, 2026
…202122)

* fix: reclaim stale scratch clones and Git repack leftovers

* test: retain an active owner in the snapshot GC fixture
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
* fix: keep agent temporary files in owned scratch

* fix: preserve sandbox temp access and queued isolation custody

(cherry picked from commit f91bc99)

Release adaptation: keep the staged #202815 Git shim implementation and independently assert both Git shim execution and writable owned temp in its merged Docker/Podman fixture. Use the beta.3 isolated custody configuration (896f33d52174), not ambient sandbox inventory.

Companions: #193677 scratch expiry owner is present (99ba844); #202815 is present-equivalent (7d33d1a). #202122 is independent Git/scratch clone reclamation, #202428 is CLI history ownership, #202644 is host file-write authority, and #202874 is workspace cleanup scheduling; none prerequisite. Other later same-path commits concern separate template, sandbox, prompt, sharing, or run-lifecycle policy; see the lane companion audit.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a4070bc5b669308210b62a0b80b92c16af768b34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation 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: 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.

1 participant