Repository navigation
test(desktop): start every test subprocess without forking pytest - #2282
Conversation
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.
…dows 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.
…ows-newlines' into ci/desktop-native-release-no-fork
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.
Independent adversarial review: APPROVEFrom: Grok Verdict: APPROVE. I reviewed the delta over #2279 ( What I checked
Tests at this head (Linux, Python 3.12, whole Desktop suite)
P3s (non-blocking)
Generality gateThis is test infrastructure only. It names no application. CI at this head25 checks pass and 32 are skipped. The ubuntu desktop engine tests, release intent and desktop build all pass. The macOS and Windows engine jobs and the native installer were skipped on this PR event. Merging is a maintainer decision. #2279 should merge first, as the PR says, or this PR alone. Wait for the macOS runs before merging. |
# Conflicts: # packages/desktop/tests/conftest.py
Independent adversarial review: REQUEST CHANGESFrom: Grok Verdict: REQUEST CHANGES. At its own head the branch is correct, but merging it into current main (89883a4, which now includes #2287) breaks one of #2287's tests. It also stops #2287's no-fork tests from catching a regression. GitHub reports no textual conflict, and CI (25 pass) ran before #2287 landed, so neither one shows the problem. P1: semantic conflict with #2287 (
What the coordinator asked me to check (all fine at 9c53dea):
Generality gate: test-only change, with no workflow-, app- or vendor-specific code paths. The issue above is about the test harness hiding production regressions, not about generality. Limits: Linux py3.12 only. I ran nothing on macOS or Windows, and I have no CI on the merged tree. I pushed nothing to the branch. |
…ss 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.
Independent adversarial review: APPROVEFrom: Grok Verdict: APPROVE. The P1 from my REQUEST CHANGES at 9c53dea is fixed at this head. What changed since 9c53dea: main is merged in (8824529, which includes #2287 and #2290; current Evidence (Linux, Python 3.12, exact head):
Review of the fixture:
CI at this head: green. That includes the desktop Python engine tests (ubuntu-latest, py3.12), the qualification contract, the sidecar build, packages-gate and CodeQL. The macOS and Windows native jobs were skipped by path scope. P3 (not blocking):
Limits: I ran this on Linux only; I didn't run it on macOS, where posix_spawn is the real production path. Merge and release decisions remain with the maintainers. |
Builds on #2279 and includes its commits; merge #2279 first, or merge this one alone.
Why
#2277 stopped the release tests' git calls from forking pytest, and both macOS engine-test jobs then passed on main. One macOS job (135716931302, run 44568487040) still stopped for 45 minutes right after an ACL test in
tests/test_engine/test_approver_anchor.py, whose next step runs/bin/chmodthroughsubprocess.run. That job was cancelled, so it left no traceback; the cleanup step ended two leftoverpython3.12processes, as in the earlier stalls. It is consistent with the same stall in a subprocess that is not git.Cause
A forked child stops in
close()while it closes inherited descriptors, because Tcl has started a thread in it. Three things have to be true, and all three were in the pytest process:openadapt_capture.recorderin the published openadapt-capture 1.3.0 imports pympler, andpympler.util.compatimports tkinter. Collecting the tests is enough to load it.close_fds=True, Python's forked child closes every inherited descriptor before exec. On the macOS 26 runners thatclose()sometimes never returns while Tcl's thread is inselect().Evidence from the macOS runners (macOS 26.7.2):
Run 44594236897 ran the suite as it was before ci(desktop): start git without forking in the release tooling and its tests #2277 under a supervisor that samples any forked copy of pytest alive for more than 20 seconds. It caught 12 stuck children in three jobs. All 24 samples show the same two threads:
A standalone script that only imports tkinter and starts
/usr/bin/truein a loop:Popendefault)close_fds=Falsewithcwd)The same script without tkinter, with or without the macOS frameworks loaded (run 44579317417): 1,600,000 forks and 800,000 spawns, 0 stalls.
That is about one stall per 8,000 forks. The suite forked tens of thousands of times before #2277 and 170 times after it, which matches most macOS jobs stalling before and one in six after.
What still forked
A recorder on the fork path, run over the whole Desktop suite on main (macOS 15, Python 3.12), counted 170 forks from 25 call sites:
scripts/native_release.pyandtests/test_native_release.pycwd,close_fds(fixed by #2279)/bin/chmodinopenadapt_desktop/approver_anchor.py(51), ffmpeg, and test helpersclose_fdsdefaultscripts/smoke_test_native_installer.pylaunch probestart_new_sessiontests/test_wheel_layout.pycwdFix
tests/conftest.pynow applies to the whole session, on Linux and macOS:close_fdsdefaults to false for subprocesses started during the tests. Python then starts them withposix_spawn. Python opens its own descriptors close-on-exec, so a child still inherits only its standard streams. No engine code changes.forking_allowedfixture.subprocesses that forked pytest: Nand each command.cwd.forking_allowed, becausestart_new_sessioncannot be spawned on Python 3.11 or 3.12. They account for 4 forks per session.The per-module guard from #2277 and #2279 is replaced by this one. Windows has no fork and is left alone. Tests that check how the engine itself starts a process opt out with the
python_subprocess_defaultsfixture.Not covered: the installed app
The installed engine can hit the same stall on macOS 26. Desktop's lock pins openadapt-capture 1.3.0 from PyPI, which imports pympler and so tkinter when the recorder is imported, and the engine then forks with the default
close_fdsfor/bin/chmod(approver_anchor.py) and ffmpeg (presentation_export.py). At one stall per 8,000 forks and a few forks per session it would be rare, but a stalled call never returns. This pull request changes no shipped code. Two shipped fixes are possible and belong in their own pull requests: release the in-tree capture change that makes pympler optional (a0d1733) and raise Desktop's pin, and passclose_fds=Falsein the engine's own subprocess calls. Whether the frozen engine bundles tkinter was not checked.Testing
Local, macOS 15, Python 3.12, whole Desktop suite: 2037 passed, 8 skipped, and the summary reports 4 forks (the launch-probe tests), down from 170. The two failures are the local-only ones explained in ci(desktop): keep native-release git calls and their tests from forking #2279 (released Flow 2.4.1 in the local environment).
check_release_intent.pypasses; commit types areciandtest, so no version bump.After the review at 9c53dea:
tests/test_engine/test_child_process.py(from fix(desktop): start the engine's child processes without forking on macOS #2287) asks for apython_subprocess_defaultsfixture that restores Python's realPopenbehaviour, so the session default cannot make the engine's own no-fork tests pass whatever the engine does. Withoptions.setdefault("close_fds", False)removed fromopenadapt_desktop/child_process.py, that module fails 3 tests on this branch, as it does on main. Dispatched Packages run 44634719141 at af43e78: all six engine-test jobs passed; both macOS jobs report 4 forks and 2055 passed, 9 skipped.macOS CI before that: two dispatched Packages runs at 8781c29, 44608267378 and 44614364813. All twelve engine-test jobs passed (macOS, Windows and Linux on Python 3.11 and 3.12). Each of the four macOS jobs reports
subprocesses that forked pytest: 4and 2041 passed, 9 skipped, and none left an orphan process.