Skip to content

Tests: a grandchild reaped while its /proc stat is read counts as gone - #14268

Merged
danielhanchen merged 2 commits into
mainfrom
fix/kernel-install-reaped-grandchild
Oct 19, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/kernel-install-reaped-grandchild

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

studio/backend/tests/test_kernel_install.py::test_a_timed_out_build_stops_its_whole_process_tree flakes in the (Python 3.13, a-k) shard (seen on #14240):

tests/test_kernel_install.py:1041: in test_a_timed_out_build_stops_its_whole_process_tree
    if stat.read().split()[2] == "Z":
E   ProcessLookupError: [Errno 3] No such process

Cause

The test polls the killed grandchild until it is gone. That means kill(pid, 0) fails, or /proc/<pid>/stat shows a zombie, or that file is missing. The grandchild can be reaped between opening /proc/<pid>/stat and reading it. On Linux that read raises ProcessLookupError (ESRCH), not FileNotFoundError. So the test failed exactly when the process had already gone, which is the outcome it was waiting for. The product (kernel_install.run_process_tree) is fine. The poll came in with #13971.

Reproduced directly: open /proc/<pid>/stat of a live child, kill and reap it, then read. The read raises ProcessLookupError: [Errno 3] No such process.

Change

Test-only:

  • _process_gone(pid): the same three checks, with (FileNotFoundError, ProcessLookupError) both counted as gone.
  • test_a_process_reaped_while_its_stat_is_read_counts_as_gone: makes the race deterministic. open of the child's stat file kills and reaps the child right after opening, and kill(pid, 0) reports it alive, as at the start of the race. It is skipped where there is no procfs.

Testing

  • studio/backend/tests/test_kernel_install.py: 119 passed.
  • Sabotage: with the helper back to catching only FileNotFoundError, the new test fails with ProcessLookupError: [Errno 3] No such process. That is the CI failure.

test_a_timed_out_build_stops_its_whole_process_tree polls /proc/<pid>/stat
for a zombie. The grandchild can be reaped between the open and the read,
and that read raises ProcessLookupError (ESRCH), not FileNotFoundError, so
the test failed exactly when the process had gone. Treat both as gone, in a
helper with a deterministic test of that race.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T15:05:45.122415Z 7ddcf9b Manual request
🔒 Security Review ⚠️ Failed 2026-10-19T14:55:21.718916Z 1471a6c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1471a6c359

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1016 to +1017
@pytest.mark.skipif(os.name == "nt", reason = "POSIX process groups")
def _process_gone(pid):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the Windows skip to the process-tree test

Move this marker back onto test_a_timed_out_build_stops_its_whole_process_tree; pytest does not apply a mark attached to an ordinary helper when that helper is called. On Windows, the formerly POSIX-only test now runs, and _process_gone() treats the missing /proc/<pid>/stat as proof that the grandchild exited, so it can pass without verifying that taskkill actually removed the process tree.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed in the next commit. I inserted _process_gone between @pytest.mark.skipif(os.name == "nt", reason = "POSIX process groups") and test_a_timed_out_build_stops_its_whole_process_tree, so the mark landed on the helper, where pytest ignores it, and the test lost its Windows skip. The mark is back on the test (its pytestmark is skipif again, and the helper has none). test_kernel_install.py: 119 passed.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 7ddcf9b095

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 21c0205 into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the fix/kernel-install-reaped-grandchild branch October 19, 2026 15:06
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