Skip to content

Hosts never refresh a rebuilt sandbox image or remove old ones #47

Closed

Description

@fctl-sh

What is wrong or missing. With #39, a host on the default image pulls ghcr.io/hyperstructure/fctl-agent:<its version> once and keeps it:

  • The Image workflow rebuilds the latest release's image when Claude Code has a newer release, so that sessions don't run an old Claude Code (fctl turns off its auto-updater, Prebuilt sandbox images #2). A host that already has the tag keeps its first pull until fctl is upgraded or someone runs fctl host image pull, so between upgrades its sessions' Claude Code ages anyway.
  • Each upgrade leaves the previous version's image on the host, and nothing removes it. fctl host image build already left behind the image it replaced, untagged, but now every upgrade does it.

How it works now.

  • The daemon pulls the host's image at start only when it is missing (prefetch_image in crates/fctl-host/src/daemon.rs), and a session pulls a missing image (ContainerDriver::create in crates/fctl-host/src/driver/container.rs). Nothing pulls over an image that is there, because fctl host image build tags its local build with the same name and a pull would replace it.
  • docker image ls ghcr.io/hyperstructure/fctl-agent on a host lists one image per version it has run, and docker image rm (Apple: container image delete) is the only way to remove them.

What should happen

Compatibility. Host only: no protocol or control-plane change, and it reaches hosts with a release.

Decisions for a person.

  • How the host tells a local build from a pulled image: a note that fctl host image build writes in the host's data directory, or the image's org.opencontainers.image.revision label, which only the Image workflow sets.
  • How often to pull: at start and once a day, or before each new session (docker pull of an unchanged tag only fetches its manifest, but needs the registry to answer).

Split from #2.

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

Activity

  1. added
    enhancement
    host
    on Oct 18, 2026
  2. fctl-sh commented on Oct 18, 2026

    @fctl-sh
    ContributorAuthor

    #62 (released in v0.5.0) doesn't refresh or remove images, so this stays open. It adds one more image that stays behind: a host whose version's image isn't published yet pulls ghcr.io/hyperstructure/sandbox:latest instead, and keeps it after the next session pulls the version's image. The removal in the second item should cover that latest too, but only once the version's image is on the host: until then, sessions start from latest.

    The default image is also named differently since this was written: ghcr.io/hyperstructure/sandbox:<version>, not ghcr.io/hyperstructure/fctl-agent (#39, ADR 0012).

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

  3. fctl-sh commented on Oct 18, 2026

    @fctl-sh
    ContributorAuthor

    The person who started https://app.fctl.sh/s/ses_01M5813Y3P1VY7K0ZSS6PKRS9V decided the open questions:

    1. How the host tells a local build from a pulled image: the org.opencontainers.image.revision label. Only hyperstructure/sandbox's Image workflow sets it (docker buildx build --label …); the Dockerfile sets no labels, so fctl host image build and builds by hand have none. It needs no state, covers builds made by hand or by older versions of fctl, and when it can't be read (Apple's image inspect JSON has changed shape between releases) the host leaves the image alone, as it does now. An image built FROM the published one inherits the label, so a derived build tagged with the default image's own name would be replaced.
    2. How often: at start and every 6 hours, in the background. Sessions never wait for the registry. The tag changes at most about once a day (the daily run at 05:41 UTC, or a change to the image), and a pull of an unchanged tag costs one manifest request with Docker and with Apple's container.

    What I found while looking into the second item, which shapes how removal works:

    • Docker refuses to remove an image that a container uses, stopped ones included, unless forced. A pull that moves a tag leaves the build it replaced as <none>; with the containerd image store nothing finds it again by name. So the host keeps the IDs of the builds it replaced in its data directory, and tries them again after the sweeps that remove sandboxes.
    • Apple's container image delete doesn't check whether a container uses an image, but each container gets a clone of the image's filesystem when it is created (Bundle.cloneContainerRootFs in apple/container), and starting it again uses only that clone. So a stopped sandbox still starts after its image is removed. A pull that moves a tag leaves the old build's blobs and snapshot orphaned until an image delete runs cleanUpOrphanedBlobs.

    I'm implementing both items on that basis.

  4. fctl-sh commented on Oct 18, 2026

    @fctl-sh
    ContributorAuthor

    #89 is merged (12e285e) and ships with the next release: it changes only the host, and no release contains it yet. hyperstructure/sandbox#3, which lists the revision label among what fctl relies on, is merged too.

    Once hosts run that release:

    • A host on the default image pulls its tag again at start and every 6 hours, unless the image there lacks org.opencontainers.image.revision (a local build). fctl host doctor shows the image's Claude Code version, or says the host doesn't pull over a local build.
    • It removes, without force, the default images sessions no longer start from: builds a newer one replaced (they keep the name <tag>-replaced-<the start of their ID> while a Docker sandbox uses them), other versions' images, and latest once the version's image is there. It does this at start, after each pull and after sweeps that remove sandboxes. fctl host image pull does the same and says what it removed.

    Verified with unit tests, with rootless Podman running the real fctl host run, and with the stand-in CLI (details in #89). Still to try on real hosts after the release: Docker, where a stopped sandbox should keep its image until the sweep removes the sandbox, and a Mac with Apple's container, where old images go right away and stopped sandboxes still start.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhost

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions