Repository navigation
feat(host): give back the space Apple sandboxes freed as they stop - #120
Merged
kalaspuff merged 3 commits intoOct 20, 2026
Merged
Conversation
An Apple container sandbox's root filesystem is a sparse disk image that only shrinks where the guest discards blocks, and nothing discarded them: the guest mounts it without discard and the container has no CAP_SYS_ADMIN for fstrim. So a stopped sandbox held the most its session ever stored. Before the host stops a running Apple sandbox, it now runs `sync` in it and then `container clean` (Apple's container 1.4 and later), whose init in the VM trims the root filesystem. The container gets no new capability. A runtime without `clean` stops the sandbox as before, and the host log says the sandbox keeps the space. ADR 0025 records the decision; docs/architecture.md and docs/cli.md say what a stopped Apple sandbox keeps on the Mac. Refs #92
1 of 3 tasks
…heir files The check on a Mac showed the space of a deleted file coming back, but the image still holds the filesystem's own blocks: Apple's unpacker gives each root filesystem a journal, 1 GiB for a 512 GiB filesystem. So the docs no longer say that a stopped sandbox takes what its files take. Refs #92
kalaspuff
approved these changes
Oct 20, 2026
kalaspuff
deleted the
fctl/63-can-you-fix-https-github-com-hyperstruct
branch
October 20, 2026 09:49
kalaspuff
pushed a commit
that referenced
this pull request
Oct 20, 2026
) Sessions showed one pull request: the one fctl-agent reported last, the primary repository's first, as `#120` with no repository. A session that opened pull requests in several of its project's repositories, or a second one after the first was merged, listed only one of them and didn't say where it was. ## What changed - **The control plane keeps every pull request a session's agent finds.** After each turn fctl-agent reports the pull request of the branch each repository has checked out, so it only ever reports the latest one per repository. SessionDO now adds the new ones to the session's list, in the order they come, and takes the newer title and state of the ones it has (`fctl_domain::pulls`, at most 20). Each carries the repository it was opened in: the one its URL names, or else the repository whose state it came in. The list is written to D1 in a new `sessions.pull_requests` column (migration 0014) and is part of the account export. - **Protocol.** `Session.pull_requests` and `PullRequestRef.repo` are new and optional; `Session.pull_request` stays for clients a version behind. Agents and hosts don't change. Sessions from before this get their one pull request in the list, with its repository, when they are read, from D1 or from their SessionDO. - **Web app.** The session header links every pull request as `repository#number` (`fctl#120`, `design#14`), with its title on hover; they wrap together as one list. The rail has a **Pull requests** section with each one's title and `owner/name#number`, in place of the card under **Changes**. The floor, a workspace's page and a project's page say `PRs fctl#120, design#14`. - **The floor stays current.** SessionDO told the dashboards about a session when its status changed, and a turn's git report arrives after the turn ends. So a new pull request, and the +/− counts, reached the floor's rows only after a reload or the next turn. A git report that changes what the lists show now goes to the dashboards too. - **CLI.** `fctl show` prints each pull request with its repository (below); `--json` has the list. - **Docs.** `getting-started.md` and `cli.md` say so. The privacy policy's "branch and pull request" becomes "pull requests" in hyperstructure/fctl-site#28. ``` $ fctl show playground#3 playground#3 Name every pull request a session opens … prs: fctl#121 #121 design#15 hyperstructure/design#15 fctl-site#32 hyperstructure/fctl-site#32 ``` ## Verification - Unit tests for `fctl_domain::pulls` (repositories from URLs and from repository states, merging over turns, the limit, sessions from before the list), for `fctl show`'s lines (also from a control plane before the list) and for the web app's helpers. `cargo xtask check` passes. - End to end with `cargo xtask dev`. The dev instance has no GitHub, so the dev agents got a stand-in `gh` that answers `gh pr view` with a pull request in another repository after each turn, and the project a setup script that pushes each commit to a local remote, so fctl-agent sees its branch pushed and looks the pull request up. - On `main`, a session whose agent found fctl#120, design#14 and fctl-site#31 showed only `#31`. - I restarted the stack on this branch with the same data, and migration 0014 applied. The sessions `main` made read with their one pull request in the list, with its repository. Another turn in one of them added sandbox#7 after fctl-site#31. - A new session's agent found fctl#121, design#15 and fctl-site#32: D1, the API, `fctl show` and the web app list all three. With the session page and the floor open, the pull request a further turn found showed up on both without a reload. ## Screenshots At b04cf34, with the dev stack's data. Both columns show the same sessions, read from this branch's control plane: on the left `main`'s web app, on the right this branch's. Playground #3's agent found a pull request in four repositories. | Before | After | |---|---| |  |  | |  |  | |  |  | |  |  | |  |  | Made in fctl session https://app.fctl.sh/s/ses_01M5CBQV867BG6ARZKJHZPGVY0 --------- Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com> Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
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.
An Apple
containersandbox's root filesystem is a sparse 512 GiB disk image on the Mac. It grows as the session writes, and it never shrank: the guest mounts it withoutdiscard, the runtime never trimmed it, and the container can't runfstrimwithoutCAP_SYS_ADMIN. So a stopped sandbox held the most its session ever stored (onecargo xtask check --quickof fctl leaves 5.5 GB). Since #93, a host low on disk removes such sandboxes early, and those sessions resume without their conversation (#92).What changed
Hosts trim Apple sandboxes as they stop them. Before the Apple driver stops a running sandbox, it runs:
container exec <sandbox> sync, because ext4 trims only the blocks whose release its journal has committed.container clean <sandbox>, which is new in Apple'scontainer1.4 (apple/container#1949). The VM's init, vminitd, enters the container's mount namespace and runsFITRIMon/, so the Mac gets back the space of the files the session deleted.container stop, as before.That covers every stop of a sandbox the host keeps: the end of a session's run (idle stops included), a stop before the sandbox started, and leftover sandboxes the control plane asks to stop.
Best effort. When
cleanfails, the sandbox stops as before and the host logs, for example,fctl-ses-… keeps the disk space of the files deleted in it: container clean failed: Error: Plugin 'container-clean' not found.(whatcontainerbefore 1.4 says). When thesyncdoesn't finish within a minute (a VM that doesn't answer), the host skips the trim.Docs.
docs/architecture.md(Sandboxes and drivers) anddocs/cli.md(Hosts) say what a stopped Apple sandbox keeps on the Mac. The new ADR 0025 records the decision.The decision #92 left to a person
#92 asked whether to give Apple sandboxes
CAP_SYS_ADMINso that fctl-agent could runfstrim. This takes an alternative the issue named instead, trimming the image from the Mac, which Apple's runtime now offers. Sandboxes get no new capability, nothing in the sandbox decides when the trim happens, and fctl-agent doesn't change. The person who started the session chose trimming as sandboxes stop over trimming after each turn: idle sessions stop ten minutes after their last turn, and stopped sandboxes are what a host keeps for days. ADR 0025 has the reasons, and why notdiscard.Compatibility
Only the host changes: no protocol, control plane or sandbox image change.
containerbefore 1.4 stop sandboxes as before, and log it at each stop. Sandboxes made bycontainer1.0 or earlier have an init without the trim, and keep their space too.Verification
A unit test with a stand-in CLI (
apple_sandboxes_give_back_the_space_of_deleted_files_as_they_stop):inspect,exec … sync,cleanandstop -t 20, in that order.cleanstill stops it.syncnorclean.Checks:
cargo xtask check --quickpasses.In this session's sandbox, which is an Apple
containersandbox on the hyperstructure Mac:lsblk -D: the root diskvdbtakes discards, with a granularity of 512 B and up to 513G per request./proc/self/status:CapBnd: 00000000a80425fb, withoutCAP_SYS_ADMIN./.cz-init, the init binary the runtime puts in the container, was built on 2026-09-24 and has the trim messages (FilesystemOperation,FiTrimParams). containerization 0.47.0 is from that day, andcontainer1.5.0 ships it, so the Mac most likely hascleanalready.Apple's sources and tests at apple/container@ca4884f and apple/containerization@836080d:
cleanin the runtime service, andfilesystemOperationin vminitd.TestCLIClean, which Apple's CI runs on Macs with macOS 26. It writes 10 MiB in a container, deletes it, runssyncandclean, and checks that the container'srootfs.ext4on the Mac lost at least 80% of what the write allocated.On a Mac, the check Stopped Apple sandboxes keep the space their sessions freed #92 asked for, by the person who started the session:
The image's allocated size fell by 1,081,404 KiB (1.03 GiB) once the 1 GiB file was deleted and trimmed.
Not run: a host with this change on a Mac. The unit test checks that the Apple driver runs those same commands.
Not done
Running sandboxes keep the space of what their sessions deleted until they stop. A host low on disk could trim them before it removes stopped sandboxes. #92 is about stopped sandboxes, so this pull request doesn't do that.
Fixes #92
Session: https://app.fctl.sh/s/ses_01M5C8QXR7X7WV5F31111V8KE0