Skip to content

perf(worktrees): consolidate shared packs and reclaim stale temp packs - #167453

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-shared-clone-pack-and-tmp-pack-hygiene-20260919
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-shared-clone-pack-and-tmp-pack-hygiene-20260919

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Shared partial clones accumulate packs and abandoned temporary packs until fetch connectivity checks become impractically slow and disk use grows without bound.

A read-only large-clone snapshot found 4,719 packs / 246.60 GiB, including 4,701 promisor packs, plus 198 temporary packs / 79.86 GiB. Of those temporary packs, 175 / 76.31 GiB were older than 24 hours. Root inspection found no open users at that instant. The filesystem is Btrfs with kernel file leases enabled; no production files were changed or leased.

User Impact

The next ordinary worktree maintenance pass consolidates eligible small packs and reclaims abandoned temporary packs on Linux. Kept packs, locally available objects, promised missing objects, and reflog history remain intact. No configuration or schema migration is required.

The first pass processes at most 1 GiB of source pack bytes across the two pack classes, plus replacement writes and MIDX metadata, rather than rewriting the observed 246.6 GiB repository. Temporary files are unlinked without reading their contents. Expect seconds to a few minutes for the small-pack tail, with a five-minute budget per packing batch plus existing metadata budgets; this is an estimate, not a production timing. Production effects and timings await a separate deployment.

Why This Change Was Made

Repairing the complete MIDX immediately before automatic incremental repack makes Git's trigger see zero unindexed packs. Replace that ineffective task with native streaming consolidation: separate promisor/ordinary groups, at least 16 eligible packs, at most 1,024 source packs and 512 MiB per group. Git publishes the replacement and expires redundant sources through a batch-only MIDX before rebuilding the complete index. Packing uses one thread per process, low CPU priority, and idle I/O priority where available. The existing repository mutation owner serializes fetch and MIDX repair around the operation.

An unprivileged fuser census can silently miss another user's open files. A disposable Linux helper instead acquires an exclusive kernel file lease and rechecks identity and timestamps before removing a temporary pack older than 24 hours. Busy files and unsupported lease operations are retained. Each pass removes at most 256 files; retained entries do not consume the removal budget. Other platforms retain temporary files.

Production LOC is +222 net (254 added, 32 removed). Growth is required for the input-byte/count limits, promisor-safe publication on older Git, and cross-user cleanup custody. The old automatic incremental-repack path is removed; there is one consolidation path and no new maintenance scheduler or cache.

Evidence

A real filtered synthetic clone contained 36,001 local objects and one deliberately missing promised object. Nine warmed samples used the exact fetch connectivity command, git rev-list --objects --stdin --exclude-promisor-objects --not --all, on Linux/Git 2.55.0:

State Packs Connectivity median p95 Median peak Git RSS
Old automatic maintenance 2,002 43.65 ms 48.10 ms 18.61 MiB
One bounded pass 979 35.75 ms 37.15 ms 14.57 MiB
Two bounded passes 2 23.75 ms 26.29 ms 10.60 MiB

Overall connectivity improved 1.84×. The passes took 1.87 s and 2.04 s; pack bytes fell from 27.88 MiB to 18.12 MiB. Every pass preserved the complete local-object inventory and missing-object set, passed MIDX verification and connectivity fsck, and made zero fetch attempts. Maintenance RSS includes TypeScript harness startup: 384.3 MiB baseline versus 393.9/389.6 MiB for the two passes; pack data streams between native children.

Blacksmith Testbox proof:

  • tbx_01m4ef4gchahw1q2k3g2p5xhd4: benchmark; initial 11-test focused suite (37.81 s cold); both new regressions fail on the original owner; core types and all 27 dependent test graphs pass, including the follow-up for the review correction.
  • tbx_01m4egetas7hktg5dt7at2a32n: full worktree/runtime siblings, 602 passed / 33 skipped, 54 files passed / 6 skipped, 796.11 s; export collisions and 20 closure tests pass; pnpm build passes in 305.5 s and emits the cleanup worker. The final new cases took 455 ms and 200 ms in the sibling run. Restoring the old cleanup budget makes the starvation regression fail; the candidate bytes were restored afterward.
  • The exact Linux helper preserved synthetic read-only files held open by root while running as their unprivileged owner, then reclaimed them after root closed the handles. Btrfs support is source-verified; the cross-user live proof used an ext-family filesystem.
  • Independent Codex review at P0–P2 is scoped-clean after fixing cleanup starvation behind retained files. Subsequent edits only added required control-flow braces.

The changed gate has one pre-existing failure: ClientVoiceToolEffect is an unused export in untouched src/talk/client-voice-session-store.ts. Fully installed, unchanged main at 8879e5ef4b98e7ff17b0ac04e7695f66f3e143b2 reproduces the identical production/full-tree findings with node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts. This prepublication local failure is recorded as inherited; it is not reported as a passing scan.

After the long-lived Testbox expired and AWS/Hetzner both refused new leases at the broker's fleet limit, the remaining checks ran on an isolated Linux rig with the staged patch pinned to the same base. Final formatting, line-cap, and all remaining static guards passed:

Remaining owner-plan check Result Seconds
Changed-file lint Pass, zero warnings/errors 23.45
Native schema version Pass 0.05
Database-first legacy store Pass 163.86
Media download helper Pass 0.72
Runtime sidecar loader Pass 37.64
Runtime import cycles Pass 32.09
Webhook body Pass 0.61
Pairing store Pass 25.84
Pairing account scope Pass 24.76

Final-source focused rig proof passed 11/11 tests in 54.51 s Vitest / 57.63 s wall time with --maxWorkers=1. An initial rig replay exposed fixture discovery escaping into the outer checkout because the required TMPDIR is inside it; original HEAD reproduced that failure. Setting GIT_CEILING_DIRECTORIES to the same TMPDIR isolates the fixtures and restores the expected 30 cold / 0 warm Git-call counts without changing source. All five final source hashes match. The build also emitted a nonfatal UI startup-gzip audit warning (365.2 KiB versus 364.7 KiB); no unchanged-main attribution was performed for that warning. All new production behavior awaits deployment; no live clone mutation was used as proof.

Final publication: CI run 37843346957 passed for the exact published head, and squash auto-merge completed at 69e38767e7fe6d57346ab507908a4aa65c51cd37 with all required checks green. No admin exception was needed. The maintenance file’s 11 CI cases passed in 17.736 seconds of test time; the added cases took 0.528 and 0.162 seconds. The landed tree was verified against the reviewed head merged onto its actual main parent.

Replace auto incremental repack with bounded promisor-aware native batches
so full MIDX repair cannot suppress consolidation. Preserve kept packs,
local objects, missing promises, and reflog history under the existing
repository mutation and maintenance owners.

Reclaim old temporary packs through isolated Linux file leases that detect
open users across UIDs. Retained files do not starve later cleanup.

Synthetic partial-clone connectivity improved 1.84x after two bounded
passes (2,002 to 2 packs). Remote tests, build, and static guards passed;
the unrelated ClientVoiceToolEffect dead-export failure reproduces on main.
@clawsweeper

clawsweeper Bot commented Oct 8, 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 agents Agent runtime and tooling size: M labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 20:57
@steipete
steipete enabled auto-merge (squash) October 8, 2026 21:00
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The branch consolidates small Git packs in bounded batches and removes abandoned temporary packs on Linux while retaining files still in use.

Example: Ordinary maintenance runs on the reported synthetic partial clone

  • Before: The old maintenance path leaves 2,002 packs.
  • After: Two bounded passes reduce the repository to 2 packs while preserving its local objects and deliberately missing promised object.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and scoped-clean, with convincing native-boundary observations but harness-level rather than shipped-CLI proof.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The supplied after-fix record exercises production maintenance with real Git on Linux filtered clones, showing pack reduction with unchanged local/missing-object inventories and zero fetches; the exact cleanup helper also retains root-held files and removes them after release. Existing native Git formats remain unchanged, so no stored-data migration is required. Production deployment timings and Btrfs runtime cleanup were not demonstrated.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Large shared partial clones accumulate pack files and abandoned temporary files, consuming disk space and slowing fetch connectivity checks.
Reason: The reported repository size and measured improvement justify bounded maintenance. The author’s prior merged area work establishes owner direction, and this patch preserves the existing local-only and history-preservation contracts.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main retains the ineffective consolidation path, and the reviewed patch has no concrete blocking finding.

Priority: P2
Reviewed head: a8426851c94e154c27a2b32127c779c965150c20

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A shipped openclaw worktrees gc invocation is not recorded; supplied proof exercises the production service and native Git through synthetic repository harnesses.
Agent review details

How this fits together

Managed worktrees are separate working directories that share a Git repository’s object storage. Their maintenance owner repairs object lookup and reduces accumulated pack files without fetching missing objects or expiring conversation worktree history.

flowchart TD
  A[Worktree cleanup pass] --> B[Shared repository mutation queue]
  B --> C[Repair pack lookup]
  C --> D[Inspect temporary files]
  D --> E[Lease available and file unchanged]
  E --> F[Remove abandoned files or retain busy files]
  C --> G[Select bounded homogeneous pack batches]
  G --> H[Publish replacement and rebuild pack lookup]
Loading

Technical review

Best possible solution:

Keep bounded consolidation in the existing repository maintenance owner, using native Git publication and conservative Linux lease-based temporary-file cleanup.

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

Not applicable as a functional bug report; the supplied native-Git benchmark establishes the performance problem and improvement, while current main confirms the old maintenance ordering.

Is this the best way to solve the issue?

Yes: replacing the suppressed automatic task within the existing owner avoids another scheduler, preserves local-only operation, and limits destructive cleanup to files with verified custody.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main still needs the change: Current main repairs the complete multi-pack index before requesting automatic incremental repack and contains neither bounded consolidation nor temporary-pack reclamation. (src/agents/worktrees/git-maintenance.ts:83, cfe61f23f927)
  • Bounded native publication: The introduced owner separates promisor and ordinary packs, excludes kept and cruft packs, bounds source bytes and counts, publishes through native Git, expires only the selected batch, and rebuilds the complete index. (src/agents/worktrees/git-maintenance.ts:136, a8426851c94e)
  • Temporary-file custody: The disposable Linux helper refuses symlinks, requires an exclusive file lease, and rechecks device, inode, size, timestamps, and lease state before unlinking; unsupported or busy files remain. (src/agents/worktrees/git-pack-cleanup.worker.ts:25, a8426851c94e)
  • Meaningful owner-boundary regressions: The added tests drive ManagedWorktreeService.gc with real Git repositories, checking object preservation, missing promises, kept packs, index verification, absence of fetches, and removal only after an open writer closes. (src/agents/worktrees/service.gc-performance.test.ts:252, a8426851c94e)
  • Recorded after-fix behavior: The fully supplied PR body records a real filtered synthetic clone with 36,001 local objects and one missing promised object: two passes reduced 2,002 packs to 2, improved connectivity 1.84×, preserved both inventories, passed native verification, and attempted no fetches. It also records cross-user open-file retention and reclamation after handles closed. Captured body identity: 69b4e5f2d5326a1fed9989007650fc02959011f0e46a2eec1d4613bd110dc3cd. These are author-recorded boundary observations, not reviewer execution or deployed measurements. (a8426851c94e)
  • Native Git preservation contract: The patch executes Git’s native pack and index commands. Upstream source confirms that explicit pack selection excludes reuse of the old complete index, expiry retains kept/cruft packs, and index-pack publishes the promisor marker before the pack index: MIDX writer and index-pack. (midx-write.c:1051)

Likely related people:

  • Peter Steinberger: Raw commit 3c66417 adds src/agents/worktrees/git-maintenance.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3c66417c08e3; files: src/agents/worktrees/git-maintenance.ts)

PR surface

Source +222, Tests +122, Docs +4. Total +348 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 254 32 +222
Tests 1 127 5 +122
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 386 38 +348

Review metrics

Metric Value Why it matters
Maintenance resource bounds 2 pack classes × 512 MiB source bytes; up to 256 temporary-file removals per pass These limits keep the ordinary maintenance pass from rewriting the entire observed large repository.

Labels

Label changes:

  • add P2: This addresses evidenced repository maintenance cost and disk accumulation without an established urgent runtime outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This addresses evidenced repository maintenance cost and disk accumulation without an established urgent runtime outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

Reviewed October 8, 2026, 5:04 PM ET / 21:04 UTC.

@steipete
steipete merged commit 69e3876 into main Oct 8, 2026
214 of 215 checks passed
@steipete
steipete deleted the steipete/perf-micro-shared-clone-pack-and-tmp-pack-hygiene-20260919 branch October 8, 2026 21:09
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
openclaw#167453)

Replace auto incremental repack with bounded promisor-aware native batches
so full MIDX repair cannot suppress consolidation. Preserve kept packs,
local objects, missing promises, and reflog history under the existing
repository mutation and maintenance owners.

Reclaim old temporary packs through isolated Linux file leases that detect
open users across UIDs. Retained files do not starve later cleanup.

Synthetic partial-clone connectivity improved 1.84x after two bounded
passes (2,002 to 2 packs). Remote tests, build, and static guards passed;
the unrelated ClientVoiceToolEffect dead-export failure reproduces on 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 docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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