Skip to content

feat: share package caches between a project's sessions on each runner - #240

Merged
kalaspuff merged 8 commits into
mainfrom
fctl/186-look-into-https-github-com-hyperstructur
Oct 23, 2026
Merged

kalaspuff merged 8 commits into
mainfrom
fctl/186-look-into-https-github-com-hyperstructur

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Every session starts in a new sandbox, so its setup script downloads everything again: npm ci, cargo fetch, uv sync, Playwright's browsers. #3 asks for a cache per project, mounted into its sandboxes, for npm, pnpm, Cargo, uv and pip, bounded in size, cleaned by the host, and optional.

What changes

Projects opt in. A new project setting, Package caches (Settings → Sandbox, or fctl projects set --package-caches on; ProjectSettings.package_caches), off by default. The project's sessions on a runner then share what npm, pnpm, Yarn, Bun, Cargo, uv, pip, Go and Playwright download. Projects never share caches. Review sessions never get them, since a pull request's text could steer their agent into leaving something for later sessions: the control plane turns the setting off in their spec, and the host checks too.

Runners bound them. Two new host.toml settings:

  • max_cache_gb (10 by default): past it, the host empties a project's caches. 0 keeps none.
  • keep_caches_days (14 by default): after that long without a session, the host removes a project's caches.

fctl host status shows the caches and their limits.

Where the caches live:

  • Docker: a named volume per project, fctl-cache-<project id>, mounted at /var/cache/fctl. Docker makes a new volume owned by root, so as the host creates the sandbox it gives the volume to the image's user (id -u, then chown as root).
  • Apple container: a directory in the host's data directory, caches/<project id>, bind-mounted at /var/cache/fctl. Apple's named volumes are ext4 disk images, and nothing in its source stops two running VMs from mounting one read-write at once, which would corrupt it.
  • Process driver: that same directory, used where it is.
  • Lima: none for now. Its VMs get no mounts at all; sessions there say so in their log. Lima sandboxes get no package caches #241 follows that up.

In the sandbox, fctl-agent first checks it can write to the caches. If it can't, it says why and leaves the package managers alone, so a cache problem never breaks a session. Otherwise it points the tools there, for the setup script and for Claude. The project's own environment comes after, so it wins, and so does whatever the image sets.

Tool How it's pointed at the cache
npm npm_config_cache
pnpm 11 pnpm_config_store_dir, pnpm_config_cache_dir
pnpm 9 and 10 ~/.config/pnpm/rc, since they read only npm_config_* variables and npm 11 warns about those at every command
Corepack COREPACK_HOME
Yarn 1 and Berry YARN_CACHE_FOLDER, YARN_GLOBAL_FOLDER
Bun BUN_INSTALL_CACHE_DIR
uv UV_CACHE_DIR, plus UV_LINK_MODE=copy when the cache is on another filesystem, which uv otherwise warns about at every install
pip PIP_CACHE_DIR
Go GOMODCACHE
Playwright PLAYWRIGHT_BROWSERS_PATH
Cargo registry, git and its two lock files in ~/.cargo become links into the cache, since CARGO_HOME also holds Cargo's tools; sharing the locks keeps cargo runs in two sandboxes from writing the registry at once

FCTL_CACHE_DIR names the directory itself, and the system prompt tells Claude where the caches are and to leave them be.

Bounds. <data dir>/caches.json records, for each project's caches, when a session last started with them and what they took when last measured. It also records which sandboxes were made with them, so a restarted host still knows whose caches its sandboxes use. The sweep that removes stopped sandboxes (when the host starts, every hour, and while the disk is low) now also:

  • measures the caches used since their last measurement and empties those past max_cache_gb. With Docker, measuring (du) and emptying (find -delete) run in a short-lived container of the host's image, without a network.
  • removes caches unused for keep_caches_days. While a stopped sandbox here still mounts them, it only empties them, and removes them once that sandbox goes.
  • below min_free_disk_gb, empties caches, least recently used first, before it removes stopped sandboxes: an emptied cache costs the next session some downloads, a removed sandbox costs Claude's conversation.

The sweep never touches the caches of a project with a session on the host, and a session that starts while its project's caches are being measured or emptied waits for that.

ADR 0048 records these choices. The architecture, CLI, sandbox images and security pages describe how it works.

Compatibility

Only new optional fields (ProjectSettings.package_caches, AgentConfig.cache, SandboxCache). Older hosts ignore the setting, and older control planes don't keep it, so their sessions get no caches. A host that upgrades keeps caches for projects that turn them on, within the defaults, without editing host.toml. fctl-site's privacy policy needs no change, since the caches stay on hosts.

How I verified it

  • Unit tests:
    • the sweep's plan: caches in use are left alone, unused ones go, and grown ones are measured, with records that survive a restart.
    • clearing directories, including Go's read-only module files, without following symlinks.
    • the Docker and Apple container command lines against the fake CLI: the mount, giving the volume to the user, du, find -delete, and volume rm refused while a container mounts the volume.
    • the daemon's sweep: caches go before sandboxes on a low disk, in-use caches stay, sessions wait while theirs are emptied, a cache past 1 GiB is emptied (made with fallocate, Linux only), and max_cache_gb = 0 removes them.
    • fctl-agent's variables, Cargo's links, pnpm's rc file, the writability check and the system prompt line.
    • keep_unsent keeps the stored setting on updates that leave it out.
  • cargo xtask check passes.
  • cargo xtask dev (process driver), with the setting on: the setup script got every variable, Cargo's links and pnpm's rc file, and npm cache add wrote into the project's cache. /proc showed fake-claude's environment with the variables and its system prompt with the caches line. A second session reused the cache, and the host's hourly sweep measured it ("the package caches of prj_… take 1 MiB").
  • The Docker driver against a real runtime: this sandbox can't run Docker, so I ran a second dev runner on root Podman, through a small wrapper as FCTL_DOCKER_BIN, with a test image (Debian, git, fake-claude, user 1000). Checked there:
    • a session's sandbox mounted fctl-cache-<project> at /var/cache/fctl, fctl-agent wrote to it, and Cargo's links and pnpm's rc file landed in it.
    • the host's startup sweep measured the volume in a short-lived container.
    • with max_cache_gb = 0, the sweep emptied the volume (5 MB to 4 KiB) and kept it while the stopped sandbox mounted it, then removed it once that sandbox was gone.
    • a session on that runner said why it got no caches.
    • Podman, unlike Docker, already gives a new volume to the container's user, so the chown step had nothing to do there; the fake CLI's tests cover Docker's behavior.
  • The package managers themselves: pnpm 9, 10 and 11, Yarn 1 and 4, Bun 1.4, uv 0.13 and pip 26 here showed which variables or files each reads, that npm 11 warns about npm_config_store_dir, that uv warns without UV_LINK_MODE=copy across filesystems, and that Cargo fetches and builds offline with its registry and locks linked onto another filesystem.
  • Not run: Apple's container (no Mac here). The bind mount follows its documented --mount type=bind,source=…,target=…. [Request]: Named volume permissions consistent with local folder share volume apple/container#745 shows non-root users writing to bind mounts, and fctl-agent's writability check keeps sessions working, without caches, if that doesn't hold. Please try a session on the Mac runner with the setting on before merging.

Screenshots

The project's Settings → Sandbox gets a Package caches switch, below the setup script. Shown with the switch on, at 1440 px wide in the light and dark themes, and at a phone's 390 px.

Before After
Before: Settings, Sandbox, light After: Settings, Sandbox with Package caches on, light
After, dark After, 390 px
After: Settings, Sandbox with Package caches on, dark After: Settings, Sandbox with Package caches on, at 390 px

Fixes #3

Session: https://app.fctl.sh/s/ses_01M5MHVTRRP9QZBV3AVHN1EHK6

fctl-sh Bot added 6 commits October 23, 2026 14:50
Docker sandboxes mount a named volume per project, Apple container
sandboxes a directory on the Mac, and the process driver's agents use
that directory directly. The sweep removes caches unused for
keep_caches_days, empties those past max_cache_gb, and on a low disk
empties them before it removes stopped sandboxes.
fctl-agent points npm, pnpm, Yarn, Bun, Cargo, uv, pip, Go and Playwright
at the caches the host mounts, and tells Claude about them. Projects turn
them on in Settings, Sandbox, or with fctl projects set --package-caches,
and fctl host status says what the host keeps.
Also leaves emptied caches that a sandbox still mounts alone in the
sweep, rather than emptying them again every hour.
…made

The host decides a session's caches once, as it prepares the sandbox, and
passes that to fctl-agent.
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 23, 2026 16:46
…tps-github-com-hyperstructur

# Conflicts:
#	web/src/routes/new-project.tsx
@fctl-sh fctl-sh Bot mentioned this pull request Oct 23, 2026
3 tasks
kalaspuff
kalaspuff previously approved these changes Oct 23, 2026
…tps-github-com-hyperstructur

# Conflicts:
#	crates/fctl/src/cmd/projects.rs
#	docs/adr/README.md
@kalaspuff
kalaspuff merged commit 29a5584 into main Oct 23, 2026
10 checks passed
@kalaspuff
kalaspuff deleted the fctl/186-look-into-https-github-com-hyperstructur branch October 23, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Shared package caches per project

1 participant