Repository navigation
test(platform_compat): poll the argv fingerprint read after Popen - #21033
jeeshofone wants to merge 1 commit into
Conversation
Popen returns once the child's close-on-exec pipe closes, which Linux does before it publishes the new image's argv, so /proc/<pid>/cmdline can still read empty right after it and process_argv_fingerprint correctly answers None. The live fingerprint test read each child once, so it failed whenever that window was hit. Read each child's fingerprint through wait_until under the existing lost-run ceiling, and name in the failure which branch answered None: the exception the /proc read raised, or how many bytes it read. Closes kirodotdev#18310
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
First Principles Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the production recorder at [DESIGN-REVIEWED] 31b9495 Description read[DESCRIPTION-READ] f7e790d0bb68e5feb85e93c296ab8e1dde2a6fbfa612719652b2d5b70bf21794 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
|
Thank you @jeeshofone for this fix and the careful root-cause write-up on the exec/argv window. This PR went idle and no longer applied: on main the test moved from |
…1926) Popen returns once the child's close-on-exec pipe closes, which Linux does before it publishes the new image's argv, so /proc/<pid>/cmdline can still read empty right after it and process_argv_fingerprint correctly answers None. The live fingerprint test read each child once, so it failed whenever that window was hit. Read each child's fingerprint through wait_until under the existing lost-run ceiling, and name in the failure which branch answered None: the exception the /proc read raised, or how many bytes it read. Ported from #21033: the test moved from test/test_platform_compat.py to test/test_platform_compat_process_identity.py on main, so the original commit no longer applies; the change is the same. (hand-ported from commit 31b9495) Closes #18310 Co-authored-by: Will Laws <will.laws@me.com>
Problem / Motivation
Goal:
test_argv_fingerprint_is_stable_and_tells_processes_apartstops failing at random on Linux CI, and a real failure says which read answered None.The test fails with
assert (None is not None)on unrelated PRs, always onBackend Tests (3.12, 4). The two runs I read (38520843428, 38581781524) both fail at thebassertion: the second child's fingerprint, read once right after itsPopenreturned.Why it matters
13 unrelated PR runs went red on it from 10-09 to 10-14, and Coverage Gate and PR Readiness fail closed on each one.
Not a goal
process_argv_fingerprint. Answering None for an empty argv is correct for its callers, which compare a recorded fingerprint and must never record a fingerprint of nothing.test_exact_argv_matches_and_near_misses_do_not, which test(platform_compat): poll the Windows exact-argv read #19197 already polls.What changed (motivation → approach → change)
Symptom: the first fingerprint read after
Popensometimes answers None.Root cause: a kernel window, not leaked test state.
Popenreturns once the child's close-on-exec pipe closes, and Linux closes it during exec before it publishes the new image's argv. A read in that window finds/proc/<pid>/cmdlineempty, andprocess_argv_fingerprintanswers None for an empty argv, as documented. Measured on a Linux host, reading/proc/<pid>/cmdlineright afterPopen([sleep, "300"])returns:The single shard is placement, not a predecessor: file sharding assigns
test/test_platform_compat.pyto shard 4 of 8 (sha256 of the path), so this test only ever runs there. In the failing runs,aread twice through the same code just beforebfailed, which rules out a patchedpc.Path,sys.platformorIS_WINDOWSleft behind by an earlier test.Change, test only: the POSIX branch reads each child's fingerprint through
kiro_crew.testing.wait.wait_untilunder the file's existing_ARGV_READ_CEILING_SECSlost-run ceiling. If it never reads, the failure names the branch: the exception the/procread raised, or how many bytes it read (darwin: whatdarwin_process_argvanswered). The stability (== a) and distinctness (b != a) assertions are unchanged. The Windows branch is unchanged apart from inlining the two reads.Why not a readiness byte, as
_spawnuses: this test deliberately spawns the plainsleepbinary, which cannot signal, so that the argv the kernel reports is exactly the spawn argv on Linux and macOS.Open #21000 moves
process_argv_fingerprintanddarwin_process_argvintoplatform_compat_identity.pyand keeps both names on theplatform_compatfacade. This PR only calls them throughpc., so it applies unchanged on top of #21000, and the test target does not move.Backwards compatibility
Compatible: test-only change; no source file is touched.
Removes nothing: the change only adds a bounded retry and a diagnostic to one test.
Tests
test_the_fingerprint_read_retries_an_argv_that_is_not_published_yet: two None reads, then a value, give the value after exactly 3 reads.test_a_fingerprint_that_never_reads_fails_naming_the_branch(Linux): at a 0 s ceiling the failure names the pid and the/procbranch (FileNotFoundErrorfor an unallocatable pid).pytest -n 8 test/test_platform_compat.pyplus the wait-discipline, flake-pattern and pid-reader ratchets: 653 passed, 29 skipped. Alltest_*ratchet*.pyandtest_*facade*.pyplus importers of the module: 2734 passed, 11 skipped.semgrep/on the file: no new finding (3 before, 3 after, all pre-existing).Manual verification
N/A — test-only change. The race was measured directly on a Linux host as described above.
Related Issues
Closes #18310
Pattern harvest
Rule candidate: review-prompt
Pattern: a test reads a child's
/proc/<pid>state once, right afterPopenreturns, assuming exec has published it; poll it withwait_untilor have the child signal readiness.Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.