Skip to content

ci(desktop): start git without forking in the release tooling and its tests - #2277

Merged
abrichr merged 2 commits into
mainfrom
ci/desktop-git-no-fork
Nov 19, 2026
Merged

abrichr merged 2 commits into
mainfrom
ci/desktop-git-no-fork

Conversation

@abrichr

@abrichr abrichr commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Packages run 44545930563 (push to main at 108ee9b, the Desktop 0.30.2 release commit) failed on both macOS engine-test jobs: three tests in packages/desktop/tests/test_release_intent.py hit the 300-second deadline that #2237 added. The next Desktop run on main, 44550058867 (9eaa375, Desktop 0.30.3), failed the same way in two more tests. Both releases are blocked.

Cause

A forked copy of the pytest process never reached exec, and pytest waited for it inside Popen, where the 120-second git timeout cannot apply.

The evidence, from the two failed jobs of run 44545930563:

  • All three tracebacks end at the same line, in the parent's wait for the child to exec. Two came from the release script's own _git, one from the test fixture's git config:

    scripts/prepare_release.py:82: in _git
        return subprocess.run(["git", *args], cwd=root, check=True, capture_output=True).stdout.decode(
    .../lib/python3.11/subprocess.py:1026: in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
    .../lib/python3.11/subprocess.py:1908: in _execute_child
        part = os.read(errpipe_read, 50000)
    
  • The git command differs each time (ls-tree, cat-file -s, config), and so does the test. The py3.12 job stalled in the setup of test_exact_reversion_after_combination_discards_merged_feature_intent[chore-None], not in either test the py3.11 job lost.

  • The runner's cleanup step found leftover Python processes and no git process, one per stalled call: two in the py3.11 job (Terminate orphan process: pid (57253) (python3.1…, pid (25563)) and one in the py3.12 job (pid (23924)).

  • Run 44550058867 repeats the pattern on py3.11: test_stateful_copy_histories_preserve_feature_bytes_at_every_prefix[fanout-True-chore] and [reversion-True-fix] both stopped at prepare_release.py:82 in the same os.read(errpipe_read, 50000), and the cleanup step ended two leftover python3.11 processes (pids 20423 and 11284).

  • The other 385 tests in the module took a median of about 1 second and at most 17 seconds in the same jobs, so nothing was slow; one call in tens of thousands stopped.

  • Only macOS is affected (image macos-26-arm64, Homebrew Git 2.56). The Linux and Windows jobs of the same run passed.

Which lock the child stops on is not established; I could not reproduce the stall on a local Mac (macOS 15). A local probe shows the condition that makes a fork risky on macOS: by the time these tests start, earlier tests in the same pytest process have loaded Foundation, CoreFoundation, AppKit and Quartz, and the process has a second native thread.

How often: macOS engine tests run only on pushes to main that touch Desktop. Since #2237 merged on November 14, three such runs have finished a macOS job: both jobs passed in run 43546222113, both failed in 44545930563, and one failed in 44550058867 (the other was cancelled). From November 11 to 13, before #2237, 12 macOS jobs were cancelled at the 45-minute limit and 4 passed in the runs the API returned.

Fix

Every git call in prepare_release.py, check_release_intent.py and the test module now goes through one helper, prepare_release.run_git. It follows the step #2237 named as next:

  • Python starts the child with posix_spawn instead of fork when the program path is absolute, no cwd is passed and close_fds is false. The helper meets those conditions and gives git its directory with -C. Python opens its own descriptors close-on-exec, so git still inherits only its pipes.
  • With no fork, the per-call timeout covers the whole call. It stays at 120 seconds and fails with the command and the directory (GitTimeout).
  • stdin is /dev/null unless the call passes input (hash-object --stdin).
  • The tests keep the environment and repository settings from fix(desktop): stop the release-intent tests hanging on macOS #2237: no system or global configuration, no editor, pager, prompt, askpass or optional locks, and no signing, fsmonitor, auto gc or auto maintenance.

A guard in the test module (_no_fork) replaces the fork path with a failure for every test, wherever Python can spawn. A later change that brings back subprocess.run(["git", ...], cwd=...) fails on the pull request's Linux lane instead of stalling on main. test_a_subprocess_that_would_fork_pytest_fails asserts the guard is active on macOS and that the old call pattern fails under it, and test_a_stuck_git_command_fails_with_its_name checks the timeout against a stand-in git that never returns.

The 300-second deadline is unchanged, no test is skipped, and there are no retries.

The release workflow

Its git calls cannot stall this way. prepare_release.py runs on a developer's machine, not in a workflow. check_release_intent.py runs on ubuntu-latest. The other scripts that call git (native_release.py, check_source_boundary.py) run only on ubuntu-22.04 in desktop-release.yml and desktop-build.yml, in short single-threaded processes, so they are left alone. Other macOS jobs still fork for subprocesses that are not git; none of them has shown this stall.

Release intent

The commit type is ci, so this pull request needs no version bump. Its merge run on main will still release the Desktop versions already waiting (0.30.2 and 0.30.3) if it passes. python scripts/check_release_intent.py --base origin/main --head HEAD reports "Desktop release intent is consistent."

Proof

  • The guard is the main proof: a green job means no git call in the module forked pytest. test_a_subprocess_that_would_fork_pytest_fails shows the guard refuses the old pattern, and it passed on macOS and on the pull request's Linux lane.
  • macOS CI: pull requests run Linux only, so Packages was dispatched on this branch at a8195ce (run 44554323294). The macOS py3.11 engine-test job passed in 10 minutes 27 seconds: 2037 passed, 9 skipped, all 389 tests in the module passed, and the cleanup step found no leftover process. The macOS py3.12 job and the Windows jobs of that run had not finished when this was written.
  • Local, macOS 15: the two tests from the failed run passed 25 times out of 25 in a loop on Python 3.12, and the whole module passed on Python 3.12 (389 passed) and 3.11 (389 passed). This Mac never showed the stall, so these runs show no regression, not the fix.

… tests

On the hosted macOS runners a forked copy of the pytest process sometimes
never reached exec, so the parent waited inside Popen where the per-call
timeout could not apply, and the test hit its 300-second deadline. The
release scripts and the tests now run every git command through one helper
that uses posix_spawn, takes the directory through git -C, gives each call
a 120-second timeout that names the command, and reads no terminal input.
A guard in the test module fails any subprocess that would fork pytest.
@abrichr

abrichr commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: a8195ce

The fix does what it says. Every git call in prepare_release.py, check_release_intent.py and test_release_intent.py now goes through run_git, which meets CPython's posix_spawn conditions. The guard catches any return to the forking call pattern on Linux. I found nothing blocking.

Tests at this head (Linux x86_64, locked desktop env)

  • tests/test_release_intent.py: 389 passed on Python 3.11.17 and 389 passed on Python 3.12.15.
  • ruff check and ruff format --check are clean on the three changed files.

The three things to attack

  1. Does the helper silently fall back to fork? I spied on subprocess._fork_exec with no guard installed, the way the release script runs outside pytest. The plain, check=False and input= (hash-object --stdin) shapes made 0 forks. P3: there is one silent fallback. If the parent has fd 0, 1 or 2 closed, the new pipe or /dev/null descriptor can land on fd ≤ 2, which fails CPython's p2cread > 2 / c2pwrite > 2 / errwrite > 2 checks, and Popen quietly forks. I reproduced it: closing fd 0 and then calling run_git gave 1 fork. Under pytest the guard turns this into a loud failure, and on a developer machine a fork there does no harm, so this isn't blocking. One sentence in the docstring would cover it.
  2. Is the release tooling's behaviour unchanged on Linux? I ran check_release_intent.py from the base (9eaa375) and from this head over five ranges: 108ee9bac~1..108ee9bac, 9eaa37539~1..9eaa37539, 108ee9bac~1..9eaa37539, 9eaa37539..a8195ce72 and 9eaa37539~5..9eaa37539~2. The exit codes and output matched in every case, including the two expected refusals, which name the same --version/--base and CHANGELOG errors. git -C root with absolute temp paths for merge-file resolves the same way cwd=root did. close_fds=False on POSIX leaves the child with the same descriptors in practice, because Python opens its own descriptors non-inheritable.
  3. Can a call that skips the helper get past the guard?
    • Mutation: I changed prepare_release._git back to subprocess.run(["git", *args], cwd=root, ...). The result was 318 failed and 71 passed on the Linux lane, so a regression shows up on the PR and not on main.
    • The guard covers only the Popen fork path (subprocess._fork_exec). It doesn't cover os.system, os.popen, os.fork or multiprocessing. None of these appear in the module or the two scripts (grep is clean), so this is a known limit, not a hole.
    • P3 (scope): the guard is local to test_release_intent.py. The same macOS pytest tests/ process still forks git with no timeout in tests/test_native_release.py (_git at line 559 and the rev-parse at line 1419, used from about 27 call sites) and in native_release.py as called by those tests. The rate is far lower than the tens of thousands of calls in the intent module, but it is the same class of stall in the same job. A follow-up could apply run_git or the guard there too.

CI

  • PR checks are green, including Evaluate protected-path evidence (the fix(ci): bind pull_request_target safety runs to the PR head, not GITHUB_SHA #2275 fix) and Linux desktop engine tests.
  • Dispatched Packages run 44554323294 at this head is still in progress. macOS py3.11 engine tests passed, and so did all four native installers and the macOS/Windows sidecars.
  • The macOS py3.12 engine-test job was cancelled with "The job was not acquired by Runner of type hosted even after multiple attempts" (macOS arm64 capacity). It never ran, so there is no macOS py3.12 evidence at this head. The Windows engine-test jobs had not finished when I checked.

Generality gate: these are generic release-tooling and test-harness changes with no app- or customer-specific terms. Pass.

Limits: I couldn't run anything on macOS. The fix's real proof is a green macOS run, and one job (py3.11) gives that so far. Whether the merge run on main releases 0.30.2 and 0.30.3 is a release decision for the maintainers and isn't covered by this review.

@abrichr
abrichr merged commit 43402aa into main Nov 19, 2026
112 of 116 checks passed
@abrichr
abrichr deleted the ci/desktop-git-no-fork branch November 19, 2026 16:00
abrichr added a commit that referenced this pull request Nov 19, 2026
…dows (#2281)

Since #2277 the test helper returns git output without text-mode newline
translation. Two tests wrote a CRLF blob back with write_text, which on
Windows turned each CRLF into CR CR LF, so the reversion was no longer
exact and the feature commit stayed in the release intent. The tests now
write the blob's bytes back, and the helper normalizes line endings as the
text-mode call did.
abrichr added a commit that referenced this pull request Nov 19, 2026
…ng (#2279)

* ci(desktop): keep native-release git calls and their tests from forking

native_release.py now owns the git helper, and its three git calls and the
git calls in tests/test_native_release.py go through it. The fork guard
moves to conftest.py and covers both release test modules. The helper also
holds descriptors 0, 1 and 2 open for the length of a call when the process
was started with one closed, because Python otherwise falls back to fork.

* test(desktop): restore exact host bytes in the reversion tests on Windows

Since #2277 the test helper returns git output without text-mode newline
translation. Two tests wrote a CRLF blob back with write_text, which on
Windows turned each CRLF into CR CR LF, so the reversion was no longer
exact and the feature commit stayed in the release intent. The tests now
write the blob's bytes back, and the helper normalizes line endings as the
text-mode call did.
abrichr added a commit that referenced this pull request Nov 20, 2026
)

* ci(desktop): keep native-release git calls and their tests from forking

native_release.py now owns the git helper, and its three git calls and the
git calls in tests/test_native_release.py go through it. The fork guard
moves to conftest.py and covers both release test modules. The helper also
holds descriptors 0, 1 and 2 open for the length of a call when the process
was started with one closed, because Python otherwise falls back to fork.

* test(desktop): restore exact host bytes in the reversion tests on Windows

Since #2277 the test helper returns git output without text-mode newline
translation. Two tests wrote a CRLF blob back with write_text, which on
Windows turned each CRLF into CR CR LF, so the reversion was no longer
exact and the feature commit stayed in the release intent. The tests now
write the blob's bytes back, and the helper normalizes line endings as the
text-mode call did.

* test(desktop): start every test subprocess without forking pytest

The session now defaults close_fds to false, which lets Python start a
child with posix_spawn, and fails any call that would still fork unless the
test asks for the forking_allowed fixture. The summary prints how many
subprocesses forked. The wheel tests no longer pass cwd, and the three
installer launch tests that need a new session are the only ones allowed
to fork.

* test(desktop): give the engine's process tests Python's real subprocess defaults

The session's close_fds default made the engine's own no-fork tests pass
whatever the engine did. Those tests now ask for python_subprocess_defaults,
which restores Popen's real behaviour for them, and their negative control
passes close_fds=True explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant