Skip to content

test: fix flaky tests that run a script right after writing it - #106

Merged
kalaspuff merged 1 commit into
mainfrom
fctl/51-the-ci-workflow-for-fctl-seems-to-have-f
Oct 19, 2026
Merged

kalaspuff merged 1 commit into
mainfrom
fctl/51-the-ci-workflow-for-fctl-seems-to-have-f

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

cargo xtask check failed on main twice in two days, each time in an fctl-host test that drives a stand-in docker CLI, on a commit that didn't touch the host. The next run on the same code passed both times.

Why they failed

The tests write the stand-in, a shell script, and run it right away. A test binary runs its tests on many threads, and a process that another test starts holds copies of the binary's open files until it execs. When one starts while a test is writing its script, that copy keeps the script open for writing a moment longer, and running the script fails with ETXTBSY ("Text file busy"). The driver reads that failure as "the image isn't here" and carries on, so the test sees other calls than it expects.

Both failures show it: the stand-in's first call is missing from its log, and the calls after it are there. In the refresh test, the failed image inspect sent refresh down its path for a missing image, which runs exactly the image inspect --format {{.Id}} …:latest and pull …:0.7.0 that CI logged.

#84 fixed the same kind of race in the agent's socket test.

What changed

Tests write their scripts with write_script, which has sh write the file, so the test binary never has it open. fctl-host's stand-in CLI (FakeCli) and disk_cli use it. So do fctl-agent's two stand-ins for Claude Code (in sessions_need_a_recent_claude_code and the supervisor tests' stub_claude), which wrote and ran their scripts the same way. They haven't failed on CI yet, but they fail the same way when the machine is busy (below).

Only tests change. The one script fctl itself writes and runs, the agent's git credential helper, runs well after it is written.

How I verified it

  • fctl-host's tests, 400 runs of the test binary on a 4-CPU sandbox. Before: 11 runs failed, in 5 tests that use the stand-in CLI, the_host_leaves_a_current_build_as_it_is among them with the same calls as on CI. After: none failed.
  • With the driver printing its spawn errors (a throwaway change), a failing run showed /tmp/.tmpwoGJFM/cli: Text file busy (os error 26).
  • A standalone program that writes a script and runs it at once got ETXTBSY in 20 of 3,000 runs while another thread started processes, and in none without that thread.
  • fctl-agent's tests: none of 1,000 runs failed, before the fix or after. With every CPU kept busy, so that a starting process waits longer before it execs, runs before the fix failed now and then, for instance supervisor::tests::turns_claude_starts_while_paused_or_stopping_are_interrupted with starting /tmp/.tmpasfbTp/claude (is Claude Code installed?), caused by Text file busy (os error 26). After the fix, none of 1,000 such runs failed.
  • cargo xtask check --quick passes.

Also

The failed run skipped Pin fctl.sh to these docs, and the release commit's run found no docs/ change since 65dcbe1, so fctl.sh still shows the docs from before #103 and #104. hyperstructure/fctl-site#25 pins them, and #105 is about making the job catch up after a failed run.

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

Tests that write a stand-in CLI and run it at once failed now and then
with ETXTBSY ("Text file busy"): a process another test starts holds
copies of the test binary's open files until it execs, so the script can
still be open for writing when the test runs it. fctl-host's driver takes
that for a missing image and carries on, which made
the_docker_vm_is_measured_in_a_short_lived_container and
the_host_leaves_a_current_build_as_it_is fail on main.

The scripts are now written by sh (write_script), so the test binary
never has them open.
@kalaspuff
kalaspuff merged commit 337a1b4 into main Oct 19, 2026
6 checks passed
@kalaspuff
kalaspuff deleted the fctl/51-the-ci-workflow-for-fctl-seems-to-have-f branch October 19, 2026 19:13
@fctl-sh
fctl-sh Bot restored the fctl/51-the-ci-workflow-for-fctl-seems-to-have-f branch October 19, 2026 19:20
@kalaspuff
kalaspuff deleted the fctl/51-the-ci-workflow-for-fctl-seems-to-have-f branch October 20, 2026 09:01
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.

1 participant