Skip to content

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

Merged
abrichr merged 3 commits into
mainfrom
ci/desktop-native-release-no-fork
Nov 19, 2026
Merged

abrichr merged 3 commits into
mainfrom
ci/desktop-native-release-no-fork

Conversation

@abrichr

@abrichr abrichr commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #2277, covering the two findings from its review and one check.

Closed standard descriptors

Python starts a child with posix_spawn only when the child's pipes are numbered above 2. When the process was itself started with descriptor 0, 1 or 2 closed, a pipe gets one of those numbers and Python falls back to fork without saying so. run_git now holds any closed standard descriptor open on the null device for the length of the call and closes it again afterwards, so the process is left as it was found.

A scratch check with descriptor 0 closed counts 1 fork without the hold and 0 with it. test_git_does_not_fork_when_standard_input_is_closed covers this under the fork guard.

native_release.py and its tests

tests/test_native_release.py runs in the same pytest process as the release-intent tests, and its git calls still forked.

  • The helper (run_git, GitTimeout, GIT_TIMEOUT) moves from prepare_release.py to native_release.py, because prepare_release.py already imports native_release.py and the reverse import would be circular. prepare_release.run_git and prepare_release.GitTimeout remain as names for the same objects.
  • The three git calls in native_release.py (_resolve_commit, _git_bytes, and the diff in the version-transform check) go through run_git. A missing root now makes git exit non-zero, which these functions already turn into ValueError.
  • _git and the rev-parse call in tests/test_native_release.py go through run_git.
  • The fork guard moves to tests/conftest.py as the no_subprocess_fork fixture. Both release test modules apply it with pytestmark, so a subprocess that would fork pytest fails in either one.

The two test_engine failures seen locally

test_learns_the_binding_a_person_would_type_from_the_read_after_the_save and test_complete_dry_evidence_projects_codes_without_values do not fail in CI. Both passed in the macOS py3.11 and Linux py3.12 jobs of run 44554323294. They failed locally because uv sync --locked installs the released Flow 2.4.1, which has no records_complete field, while desktop-test.yml installs the in-tree packages/flow over it before running the tests. No change is needed.

Release intent

The commit type is ci, so no version bump. python scripts/check_release_intent.py --base origin/main --head HEAD reports "Desktop release intent is consistent."

Testing

  • Local, macOS 15, Python 3.12, with the guard active: tests/test_native_release.py and tests/test_release_publication.py pass (76 passed). The whole of tests/test_release_intent.py passes too (390 passed).
  • macOS CI does not run on pull requests, and Packages was not dispatched for this change. The guard behaves the same on the pull request's Linux lane, where Python also spawns without forking. The merge run on main is the first macOS run.

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
@abrichr

abrichr commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: cf55f73

This closes both P3s from my #2277 review. I found nothing blocking.

Head: the coordinator asked for 757161f. The head is now cf55f73, a merge of #2281's branch (d3b20c4) into it. I checked that its tree equals a clean git merge-tree of the two parents (d412147a5), so no other change came in. This review covers both commits.

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

  • tests/test_release_intent.py + tests/test_native_release.py: 456 passed on Python 3.11.
  • The same two modules: 456 passed on Python 3.12.
  • Ruff check and format are clean on all five changed files.

The things to attack

  1. Closed standard descriptors. I spied on subprocess._fork_exec with no guard installed. I then called native_release.run_git with fd 0, 1, 2, 0+2 and all three closed in turn. Each call made 0 forks and returned the right HEAD. Afterwards the process held no extra descriptors, so the held null-device fds are closed again. On ci(desktop): start git without forking in the release tooling and its tests #2277 the same probe with fd 0 closed gave 1 fork.
  2. Does the guard now cover test_native_release.py? It does. I mutated that module's _git back to subprocess.run(["git", ...], cwd=tmp_path, text=True), and the result was 3 failed / 63 passed. The fixture moved to conftest.py, and both modules opt in with pytestmark. It is active wherever subprocess._USE_POSIX_SPAWN is true, which covers Linux and macOS.
  3. Did the helper move change behaviour? prepare_release.run_git and GitTimeout are now the native_release objects. prepare_release already imported native_release, and native_release doesn't import prepare_release, so there's no import cycle. _resolve_commit and the diff listing now decode with errors="replace" where they used to use text=True. The decoded output is still validated afterwards (GIT_COMMIT_PATTERN and the allowed-path set), so a bad byte still fails closed.

P3 (scope, not for this PR): other Desktop scripts still start git or other tools through plain subprocess.run, for example check_source_boundary.py:173 (git ls-files with cwd=root) and release_publication.py. They are outside the guarded modules. If any of them runs inside the same macOS pytest process, it is the same class of stall. If it shows up again, the next step would be the guard in conftest.py with autouse.

CI: 22 pass, 29 skipped by the path filter, and one pending (desktop build / Python sidecar (ubuntu-22.04)) when I looked. The PR has no macOS run yet, as the coordinator noted. Given #2277, merge should wait for a green Windows and macOS engine-test run that includes #2281's fix.

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

Limits: Linux only. I couldn't run anything on macOS or Windows.

@abrichr
abrichr merged commit f21b34b into main Nov 19, 2026
114 of 117 checks passed
@abrichr
abrichr deleted the ci/desktop-native-release-no-fork branch November 19, 2026 21:45
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