Skip to content

A host test fails at random when the fake CLI's script is busy #100

Closed

Description

@fctl-sh

CI failed on the v0.7.0 release commit because a host unit test failed at random: refresh::tests::the_host_leaves_a_current_build_as_it_is in crates/fctl-host/src/refresh.rs. That run skipped its deploy, so app.fctl.sh got 0.7.0 only from the next push to main. The same test passed on the next commit, at the same version.

How it works now

Run 39169569130, cargo xtask check:

thread 'refresh::tests::the_host_leaves_a_current_build_as_it_is' panicked at crates/fctl-host/src/refresh.rs:437:9:
assertion `left == right` failed
  left: ["image inspect --format {{.Id}} ghcr.io/hyperstructure/sandbox:latest", "pull ghcr.io/hyperstructure/sandbox:0.7.0"]
 right: ["image inspect ghcr.io/hyperstructure/sandbox:0.7.0", "image inspect ghcr.io/hyperstructure/sandbox:0.7.0", "image tag …", …]

The test puts the published image on a fake host and expects refresh to inspect it and pull a newer build over it. In this run, refresh acted as if the image wasn't there at all: it checked the fallback (:latest) and pulled. The calls the fake recorded don't include the first image inspect …:0.7.0, so the fake CLI never ran for it.

Most likely cause:

  • FakeCli::empty (crates/fctl-host/src/driver/fake.rs) writes a shell script into a temporary directory for each test and runs it as the CLI.
  • Tests run in parallel threads that start processes. A child forked while another test has its script open for writing keeps that file open until the child execs. Running the script in that window fails with ETXTBSY ("Text file busy").
  • ContainerDriver::image (crates/fctl-host/src/driver/container.rs) turns every error except a timeout into Ok(None), "no such image", so the failed spawn reads as a missing image.

That fits the recorded calls, but I haven't seen the ETXTBSY itself, because image drops the error. Logging it in the test would confirm the cause.

What should happen

Compatibility

The first item touches tests only. The second changes the host, but not the protocol, and ships with the next host release.

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

Activity

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

    @fctl-sh
    ContributorAuthor

    #106 (merged as 337a1b4) fixes the test side and confirms the cause.

    • The ETXTBSY is real. With the driver printing its spawn errors (a throwaway change), a failing run showed /tmp/.tmpwoGJFM/cli: Text file busy (os error 26). The same race failed driver::container::tests::the_docker_vm_is_measured_in_a_short_lived_container on 65dcbe1 (run).
    • Tests now have sh write their scripts (write_script in crates/fctl-host/src/driver/fake.rs), so the test binary never has them open for writing. That takes none of the options above. fctl-agent's stand-ins for Claude Code, which could fail the same way, use the same helper.
    • 400 runs of fctl-host's tests: 11 failed before the fix, none after. CI passed on test: fix flaky tests that run a script right after writing it #106 and on main after the merge (run).

    Left: the second item. ContainerDriver::image still reads a CLI that couldn't start as "no such image", and so do has_image and vm_disk_free_mb in the same file. That changes the host, so it ships with a host release.

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

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

    bughost

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions