Skip to content

fix(capsule): prune by age only, drop size-based eviction#10408

Merged
davidfirst merged 3 commits into
masterfrom
capsule-prune-drop-size-target
Jun 8, 2026
Merged

fix(capsule): prune by age only, drop size-based eviction#10408
davidfirst merged 3 commits into
masterfrom
capsule-prune-drop-size-target

Conversation

@davidfirst

Copy link
Copy Markdown
Member

Problem

The capsule auto-prune (bit capsule prune --size-target 10) was wiping scope-aspects capsules across all repos sharing the global cache. With ~10 bit checkouts, every aspect capsule got evicted daily, making rebuilds slow.

Root cause is in applySizeTarget: it measured the whole cache total but could only evict scope-aspect children. When the un-evictable remainder (workspace/scope caps, ~11 GB of legacy unmarked dirs, each aspect-root's own node_modules) already exceeded the target, the loop evicted 100% of aspect capsules across every repo and still never reached the target. Evidence from logs: 569 removals tagged size-target-10gb vs only 14 for older-than-30d, and the cache stayed at 18 GB after "pruning" to a 10 GB target.

Size accounting also forced an expensive recursive lstat walk of the entire cache on every auto-prune.

Change

Drop size-based eviction entirely; prune by age + orphan only.

  • Auto-prune spawns bit capsule prune --older-than <N> (no --size-target); no size walk → O(1) rename-to-trash deletes.
  • Removed applySizeTarget, the --size-target flag, and CFG_CAPSULES_MAX_SIZE_GB.
  • --with-sizes stays as an opt-in for byte totals in the report.

The cache now self-bounds to "workspaces touched within --older-than (default 30d)"; throwaway/temp scopes are still caught by the orphan check.

The size-target LRU eviction counted the whole cache total but could only
evict scope-aspect children. When un-evictable content (workspace/scope caps,
legacy unmarked dirs) alone exceeded the target, it wiped 100% of aspect
capsules across all repos and still missed the target. Computing sizes also
required an expensive recursive lstat walk on every auto-prune.

Auto-prune is now age + orphan based only (no size walk), so the cache
self-bounds to workspaces used within --older-than and deletes are O(1).
Copilot AI review requested due to automatic review settings June 8, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes capsule cache pruning to remove size-based eviction entirely, addressing cases where --size-target caused widespread eviction of scope-aspect capsules across repos sharing the same global cache and incurred expensive full-cache size walks. Pruning now relies on age- and orphan-based rules only, keeping size computation as an explicit opt-in for reporting.

Changes:

  • Removed --size-target support from bit capsule prune and its config constant (CFG_CAPSULES_MAX_SIZE_GB).
  • Updated auto-prune to spawn bit capsule prune --older-than <N> only (no size target), avoiding full-cache size traversal by default.
  • Removed size-target enforcement logic (applySizeTarget) from the capsule cache prune pipeline; --with-sizes remains for report byte totals.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
scopes/workspace/workspace/capsule.cmd.ts Drops the --size-target CLI flag/config usage and only forwards age/orphan-related options to pruning.
scopes/harmony/cli-reference/cli-reference.mdx Removes --size-target from the published CLI reference for capsule prune.
scopes/component/isolator/capsule-cache.ts Removes size-target-based eviction and updates auto-prune spawning to prune by age only; keeps size computation opt-in.
components/legacy/constants/constants.ts Removes the CFG_CAPSULES_MAX_SIZE_GB config key constant.

Comment thread scopes/harmony/cli-reference/cli-reference.mdx
Copilot AI review requested due to automatic review settings June 8, 2026 20:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread scopes/harmony/cli-reference/cli-reference.mdx
@davidfirst davidfirst merged commit ef98ade into master Jun 8, 2026
13 checks passed
@davidfirst davidfirst deleted the capsule-prune-drop-size-target branch June 8, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants