Skip to content

Fix flaky tests in TestChildProcessCleanup (test_stdio.py) #1775

Description

@maxisbey

Initial Checks

Description

Three tests in TestChildProcessCleanup are flaky. They fail intermittently on macOS (darwin) with the same root cause: the child process hasn't started writing to the marker file before the assertion checks.

Affected tests:

  • TestChildProcessCleanup.test_basic_child_process_cleanup
  • TestChildProcessCleanup.test_nested_process_tree
  • TestChildProcessCleanup.test_early_parent_exit

CI evidence: Tests observed failing on 2025-11-12 and continue to be flaky.

Output:

________ TestChildProcessCleanup.test_basic_child_process_cleanup ________
[gw9] darwin -- Python 3.11.14

    async def test_basic_child_process_cleanup(self):
        ...
        # Verify child is writing
        if os.path.exists(marker_file):  # pragma: no branch
            initial_size = os.path.getsize(marker_file)
            await anyio.sleep(0.3)
            size_after_wait = os.path.getsize(marker_file)
>           assert size_after_wait > initial_size, "Child process should be writing"
E           AssertionError: Child process should be writing
E           assert 0 > 0

tests/client/test_stdio.py:310: AssertionError
________ TestChildProcessCleanup.test_nested_process_tree ________
[gw9] darwin -- Python 3.11.14

>           assert new_size > initial_size, f"{name} process should be writing"
E           AssertionError: parent process should be writing
E           assert 0 > 0

tests/client/test_stdio.py:413: AssertionError
________ TestChildProcessCleanup.test_early_parent_exit ________
[gw9] darwin -- Python 3.11.14

>           assert size2 > size1, "Child should be writing"
E           AssertionError: Child should be writing
E           assert 0 > 0

tests/client/test_stdio.py:494: AssertionError

Python & MCP Python SDK

Python 3.11.14, macOS (darwin)
Latest SDK version

AI Disclaimer

Activity

  1. added
    bugSomething isn't working
    P3Nice to haves, rare edge cases
    on Dec 11, 2025
  2. BabyChrist666 commented on Feb 17, 2026

    @BabyChrist666
    Contributor

    Opened a PR to fix this: #2071

    The fix replaces the fixed-duration anyio.sleep() calls with a _wait_for_file_growth() polling helper that waits until the marker file exists and is actively growing, with a 10s timeout. This eliminates the race condition where assertions fire before child processes have started writing on slow CI machines.

  3. added 9 commits that reference this issue on Mar 10, 2026
    68c6e0b
    840c0db
    324bbc2
    160999f
    0e80918
    54295dd
    a070356
    d8c7de2
    0554fe0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions