Repository navigation
feat: share package caches between a project's sessions on each runner - #240
Merged
kalaspuff merged 8 commits intoOct 23, 2026
Merged
Conversation
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.
…tps-github-com-hyperstructur
…made The host decides a session's caches once, as it prepares the sandbox, and passes that to fctl-agent.
…tps-github-com-hyperstructur # Conflicts: # web/src/routes/new-project.tsx
3 tasks
kalaspuff
previously approved these changes
Oct 23, 2026
…tps-github-com-hyperstructur # Conflicts: # crates/fctl/src/cmd/projects.rs # docs/adr/README.md
kalaspuff
approved these changes
Oct 23, 2026
kalaspuff
deleted the
fctl/186-look-into-https-github-com-hyperstructur
branch
October 23, 2026 17:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tomlsettings:max_cache_gb(10 by default): past it, the host empties a project's caches.0keeps none.keep_caches_days(14 by default): after that long without a session, the host removes a project's caches.fctl host statusshows the caches and their limits.Where the caches live:
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, thenchownas root).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.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.
npm_config_cachepnpm_config_store_dir,pnpm_config_cache_dir~/.config/pnpm/rc, since they read onlynpm_config_*variables and npm 11 warns about those at every commandCOREPACK_HOMEYARN_CACHE_FOLDER,YARN_GLOBAL_FOLDERBUN_INSTALL_CACHE_DIRUV_CACHE_DIR, plusUV_LINK_MODE=copywhen the cache is on another filesystem, which uv otherwise warns about at every installPIP_CACHE_DIRGOMODCACHEPLAYWRIGHT_BROWSERS_PATHregistry,gitand its two lock files in~/.cargobecome links into the cache, sinceCARGO_HOMEalso holds Cargo's tools; sharing the locks keeps cargo runs in two sandboxes from writing the registry at onceFCTL_CACHE_DIRnames the directory itself, and the system prompt tells Claude where the caches are and to leave them be.Bounds.
<data dir>/caches.jsonrecords, 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: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.keep_caches_days. While a stopped sandbox here still mounts them, it only empties them, and removes them once that sandbox goes.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 editinghost.toml. fctl-site's privacy policy needs no change, since the caches stay on hosts.How I verified it
du,find -delete, andvolume rmrefused while a container mounts the volume.fallocate, Linux only), andmax_cache_gb = 0removes them.keep_unsentkeeps the stored setting on updates that leave it out.cargo xtask checkpasses.cargo xtask dev(process driver), with the setting on: the setup script got every variable, Cargo's links and pnpm's rc file, andnpm cache addwrote into the project's cache./procshowed 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").FCTL_DOCKER_BIN, with a test image (Debian, git, fake-claude, user 1000). Checked there:fctl-cache-<project>at/var/cache/fctl, fctl-agent wrote to it, and Cargo's links and pnpm's rc file landed in it.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.chownstep had nothing to do there; the fake CLI's tests cover Docker's behavior.npm_config_store_dir, that uv warns withoutUV_LINK_MODE=copyacross filesystems, and that Cargo fetches and builds offline with its registry and locks linked onto another filesystem.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.
Fixes #3
Session: https://app.fctl.sh/s/ses_01M5MHVTRRP9QZBV3AVHN1EHK6