Skip to content

Tests that write an executable and then run it fail intermittently with "Text file busy" (seen in console_install) #1110

Closed

Description

@JacobStephens2

This was generated by AI during triage.

What happened

Cause

tests/console_install.rs writes executables in the test process and then runs them:

  • Machine::tool writes each fake tool, such as systemctl, caddy, getent and certbot, with fs::write and then set_permissions.
  • unit_preserves_literal_paths_with_shell_and_systemd_metacharacters copies the thirdshift binary with fs::copy.

cargo test runs the file's 15 tests on parallel threads. A child that another test spawns while one of those files is open for writing inherits the descriptor, and running the file then fails with ETXTBSY until that child execs or exits.

The install script runs getent hosts '<host>' >/dev/null 2>&1, so a fake getent that can't run looks the same as an address that doesn't resolve. The script prints the expected message, and the only symptom is the missing lookup file that the fake would have written.

The rest of the suite already guards against this, each with a comment saying why:

  • write_executable in src/test_support.rs writes the file through a child process: sh -c 'cat > "$1" && chmod 755 "$1"'.
  • tests/console.rs and tests/support/mod.rs copy the binary with cp.

The same pattern elsewhere

About 18 other places write an executable with fs::write and set_permissions in the test process, in:

  • src/session/execution_tests.rs
  • src/worktree/acquisition_tests.rs, preservation_tests.rs and review_recovery_tests.rs
  • tests/console.rs and tests/console/cronjobs.rs
  • tests/pickup_run.rs, tests/process_tree.rs and tests/release.rs

They haven't been seen failing yet, but they are open to the same race.

Cost

Each flake fails CI on an unrelated pull request. The Run delivering it then spends a CI-fix Repair (#1095's ran for more than 30 minutes) and a Check re-run before it can merge.

Activity

  1. added
    bug
    needs-triage
    on Oct 22, 2026
  2. JacobStephens2 commented on Oct 22, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: bug
    Summary: Write every test executable from a child process, so no test runs a file its own process may still hold open for writing.

    Current behavior:
    Tests write fake tools, shims, hooks and copies of the thirdshift binary in the test process, with fs::write and set_permissions or with fs::copy, and then run them. cargo test runs a test binary's tests on parallel threads. A child spawned by another test can inherit the open write descriptor, and running the file then fails with ETXTBSY ("Text file busy"). This failed CI on #1098, and #1095's Repair reproduced ExecutableFileBusy in the console install tests (details in the issue body, which lists every place with the pattern).

    Desired behavior:

    • Every test that writes a file and then executes it, whether directly, through PATH or as a git hook, writes it from a child process. That's what the binary's test-support write_executable already does, with sh -c 'cat > "$1" && chmod 755 "$1"'.
      • Unit tests use write_executable.
      • Integration tests get one shared equivalent with the same contract, and every integration test file that writes an executable uses it. That includes the console install tests' Machine::tool, though that file doesn't use the shared test support today.
      • The race is explained once, in the helpers' doc comments, rather than at each call site.
    • Copies of the thirdshift binary are made by cp in a child process rather than by fs::copy, as the Console tests already do.
    • Files that are only read, such as scripts run as sh <file>, and files that are never executed keep their current writes.

    Key interfaces:

    • write_executable(path, contents) in the binary's test support keeps its contract and is reused by unit tests.
    • A matching helper for integration tests, with the same contract, lives in the shared test support.
    • The console install tests' Machine::tool writes through that helper.

    Acceptance criteria:

    • No test writes an executable in the test process. A search of the tests for set_permissions with an executable mode, and for fs::copy of CARGO_BIN_EXE_thirdshift, finds only the helpers or files that are never executed.
    • Before the change, running cargo test --test console_install many times, several runs at once, reproduces "Text file busy" (Bring thirdshift.app's homepage, How it works and Architecture pages up to date with shipped features #1095's Repair saw it on its third repetition). After it, 50 such repetitions all pass.
    • cargo test, cargo clippy --all-targets -- -D warnings and cargo fmt --check pass.

    Out of scope:

    • How the Console install script treats a getent that can't run. Treating it as an unresolved address is a separate question for real installs.
    • Switching CI's Linux job from cargo test to nextest. CI keeps plain cargo test on purpose, so the suite runs the way a contributor runs it.
    • Flaky tests with other causes.
  3. added
    ready-for-agent
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Oct 22, 2026
  4. removed
    in-progress
    on Oct 23, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions