Skip to content

fix(test): the process-group timeout test waits for its grandchild to start, not for 0.6 seconds #1888

Closed

Description

@dan-petty

Problem

tests/test_process.py::test_run_subprocess_async_timeout_kills_process_group fails when the machine is busy. The test starts a Python process with run_subprocess_async(cmd, timeout=0.6). That process must start, start a second Python process and write the pid file before 0.6 seconds pass. On a busy machine the timeout fires first. The pid file does not exist, and the test fails at assert pid_file.exists().

Evidence

  • The failure happened in the pre-push gate (devops ci) on 2026-10-22. Result: 1 failed, 11357 passed, 1 skipped in 595 seconds.
  • Three gates and two targeted test runs ran at the same time on one machine.
  • The failing line is tests/test_process.py:208. The test passes on a quiet machine.
  • Issue test(cli): tests wait for a background thread with one generous bound, not a 1-second deadline, so they pass under load #1664 fixed the same class of defect for another test: a fixed short deadline fails under load.
  • A search of tests/ finds one more timeout=0.6-style race around a real child process. The other short timeouts (timeout=0.01 at tests/test_process.py:113 and timeout=0.1 at tests/test_host_sandbox.py:516) expect the timeout, so they do not race.

Remedy

The test must not depend on a wall-clock deadline for the child to start. The timeout path must fire only after the pid file exists. Choose a design that is deterministic. For example, run the command with a long bound and let the test cause the timeout after it sees the pid file. The test must still prove that the timeout kills the grandchild, and it must still run in under one second on a quiet machine. A new test of the fix must fail on a busy machine before the change. A stress run with many parallel CPU tasks can show this.

Activity

  1. added
    source/agent
    type/test
    on Oct 22, 2026
  2. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/test. The candidate is about fixing a test that fails under load.
    • Priority: P2-Medium. The issue affects test reliability but does not break functionality. The failed run 1664 does not set P0: the author has no write access, and no caller attached it as evidence. A person can set P0 on the board.
    • Value: Medium. Improves test stability and reliability for CI environments.
    • Effort: Low. The fix involves adjusting the test logic to wait for a condition rather than using a fixed timeout.
  3. added this to the v0.2.39 milestone on Oct 22, 2026
  4. added a commit that references this issue on Oct 22, 2026
    bfe20ee
  5. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1897, merged into release/v0.2.39 as bfe20ee.

    Cause: test_run_subprocess_async_timeout_kills_process_group gave a Python child 0.6 s to start, start a second Python process and write a pid file. On a busy host the timeout fired first, and the test failed at assert pid_file.exists(). It failed in a pre-push gate on 2026-10-22. Under a stress of six busy loops on one core, the old test text failed in 15 of 15 runs. The production code has no defect.

    Change: run_subprocess_async waits with asyncio.wait_for(proc.communicate(), timeout), so its timeout counts from when it starts to wait for its child. The test now replaces asyncio.create_subprocess_exec with a wrapper that returns only once the child has written its pids. The timeout is then STARTED_RUN_TIMEOUT_SECONDS = 0.2. The child hangs, so the timeout always fires, and it fires after the child and the grandchild exist. The test uses hung_with_grandchild and watching from tests/support/hung_children.py in place of a hand-written script and os.kill(pid, 0). The task file docs/agent/tasks/task-1888-process-group-timeout-waits-for-the-child.md and the fragment changelog.d/1888.md are included. Only tests/test_process.py changes.

    Existing tool considered: tests/support/hung_children.py and tests/support/waits.py cover the child and the waits. time-machine moves time.time() but not loop.time() or time.monotonic(). A virtual-clock library such as aiotools is a new dependency, so I did not use one. A first design with a jump of the loop…

    3 file(s) changed.

    How it was verified

    Check runs at d0333fc:

    • Audit Defect PR Hardening: skipping
    • Prune PR DevContainer Images: pending
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Service Image: skipping
    • Static Analysis: pass
    • Rule Pack Tests: pass
    • Changed-Test Independence: pass
    • Fail-to-Pass Self-Check: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1888-process-group-timeout-waits-for-the-child.md:

    • The timeout of the test fires after the child and its grandchild exist, whatever the load: the spawn returns only once the child has written its pids.
    • The timeout path of run_subprocess_async still fires and still stops the whole group: the test fails when the stop kills only the leader.
    • The old text failed in 15 of 15 runs under the stress, and the new test passed 40 of 40 runs under the same stress.
    • The test takes 0.22 s on a quiet host.
    • uv run devops ci test tests/test_process.py passes.
    • Fail-to-pass: not applicable. The production code is correct and the base passes on a quiet host.
  6. added 2 commits that reference this issue on Oct 23, 2026
    f209f6c
    dd6052c
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

    source/agenttype/test

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions