Skip to content

Stop the npm cache from growing without bound - #61750

Merged
probably-neb merged 1 commit into
mainfrom
bound-npm-cache
Jul 29, 2026
Merged

Stop the npm cache from growing without bound#61750
probably-neb merged 1 commit into
mainfrom
bound-npm-cache

Conversation

@probably-neb

Copy link
Copy Markdown
Collaborator

Objective

  • Fixes Managed npm cache (node/cache) grows unbounded, never pruned #59409. Closes FR-143. Zed's managed npm directory reaches 10–17GB on machines that use
    external agents, and is never pruned.
  • Two independent causes: registry agents are launched with npm exec, which keys its
    install directory on the requested version, so every agent release leaves a full
    ~250MB copy behind; and npm never evicts anything from its download cache.

Solution

  • Install registry agents into a directory we reuse, so npm replaces the previous
    version in place instead of accumulating one copy per release. As a side effect,
    updates now download only the changed dependencies rather than the whole tree.
  • Empty the download cache on startup. Nothing in it needs to survive a restart, since
    packages are installed elsewhere. It has to go wholesale: deleting individual
    downloads leaves npm's index pointing at missing files, and npm then fails with
    ENOENT rather than fetching them again.
  • The first launch after this does one full agent install as it moves into its new
    home, and reclaims whatever the old directories were holding.

Testing

  • Installed the real agent at 0.33.1, then upgraded to 0.42.0 in the same directory:
    253MB → 256MB, against two separate copies today. The resolved executable answers an
    ACP initialize.
  • macOS only. Windows deserves a look — it should be better than before, since the
    agent is now launched as a plain .js file with Node instead of through npm's .cmd
    shim, but I can't verify it.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed the bundled npm cache growing without bound, which could consume many gigabytes of disk.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 27, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jul 27, 2026
@probably-neb
probably-neb force-pushed the bound-npm-cache branch 3 times, most recently from 9ebc0b2 to 111ef0e Compare July 28, 2026 01:25
Registry agents were launched with `npm exec`, which installs into a
directory named after the requested version. Every agent release therefore
left a full ~250MB copy behind, and nothing ever removed them. Install into
a directory we reuse instead, so npm replaces the previous version in place.

npm also never evicts from its download cache. Empty it on startup: nothing
in it needs to survive a restart, since packages are installed elsewhere. It
has to go wholesale, as deleting individual downloads leaves npm's index
pointing at missing files and it fails with ENOENT rather than refetching.
@probably-neb
probably-neb added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit b9256fa Jul 29, 2026
36 checks passed
@probably-neb
probably-neb deleted the bound-npm-cache branch July 29, 2026 15:19
AtlantisPleb pushed a commit to OpenAgentsInc/omega that referenced this pull request Jul 30, 2026
# Objective

- Fixes zed-industries#59409. Closes FR-143. Zed's managed npm directory reaches
10–17GB on machines that use
  external agents, and is never pruned.
- Two independent causes: registry agents are launched with `npm exec`,
which keys its
install directory on the requested version, so every agent release
leaves a full
~250MB copy behind; and npm never evicts anything from its download
cache.

## Solution

- Install registry agents into a directory we reuse, so npm replaces the
previous
version in place instead of accumulating one copy per release. As a side
effect,
updates now download only the changed dependencies rather than the whole
tree.
- Empty the download cache on startup. Nothing in it needs to survive a
restart, since
packages are installed elsewhere. It has to go wholesale: deleting
individual
downloads leaves npm's index pointing at missing files, and npm then
fails with
  `ENOENT` rather than fetching them again.
- The first launch after this does one full agent install as it moves
into its new
  home, and reclaims whatever the old directories were holding.

## Testing

- Installed the real agent at 0.33.1, then upgraded to 0.42.0 in the
same directory:
253MB → 256MB, against two separate copies today. The resolved
executable answers an
  ACP `initialize`.
- macOS only. Windows deserves a look — it should be better than before,
since the
agent is now launched as a plain `.js` file with Node instead of through
npm's `.cmd`
  shim, but I can't verify it.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed the bundled npm cache growing without bound, which could consume
many gigabytes of disk.

(cherry picked from commit b9256fa)
@Third-Thing

Copy link
Copy Markdown

Thank you.

playdohface pushed a commit to playdohface/zed that referenced this pull request Aug 29, 2026
# Objective

- Fixes zed-industries#59409. Closes FR-143. Zed's managed npm directory reaches
10–17GB on machines that use
  external agents, and is never pruned.
- Two independent causes: registry agents are launched with `npm exec`,
which keys its
install directory on the requested version, so every agent release
leaves a full
~250MB copy behind; and npm never evicts anything from its download
cache.

## Solution

- Install registry agents into a directory we reuse, so npm replaces the
previous
version in place instead of accumulating one copy per release. As a side
effect,
updates now download only the changed dependencies rather than the whole
tree.
- Empty the download cache on startup. Nothing in it needs to survive a
restart, since
packages are installed elsewhere. It has to go wholesale: deleting
individual
downloads leaves npm's index pointing at missing files, and npm then
fails with
  `ENOENT` rather than fetching them again.
- The first launch after this does one full agent install as it moves
into its new
  home, and reclaims whatever the old directories were holding.

## Testing

- Installed the real agent at 0.33.1, then upgraded to 0.42.0 in the
same directory:
253MB → 256MB, against two separate copies today. The resolved
executable answers an
  ACP `initialize`.
- macOS only. Windows deserves a look — it should be better than before,
since the
agent is now launched as a plain `.js` file with Node instead of through
npm's `.cmd`
  shim, but I can't verify it.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed the bundled npm cache growing without bound, which could consume
many gigabytes of disk.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Managed npm cache (node/cache) grows unbounded, never pruned

3 participants