Skip to content

fix(test): the stop-signal tests signal the fake program before it records signals, so a signal in that gap is lost #1913

Closed

Description

@dan-petty

Problem

The stop-signal tests of devops ci test send their first signal before the fake program records signals. If the signal arrives in that gap, the program ignores it and records nothing, so the test fails with interrupted false. The failure depends on timing and shows up under load.

Evidence

  • tests/test_ci.py::test_a_second_signal_to_devops_ci_test_cannot_skip_the_sigkill[SIGTERM] failed in the remote Tests & Coverage check of pull request feat(tools): pin tuicr and ship its config template, ignore file and review round rules #1906 on 2026-10-22: assert (True, False, True, False) == (True, True, True, False). The second value, interrupted, is the wait for the record int in the signal log. The same test failed in a local gate earlier on 2026-10-22 and passed on the next run.
  • hung_script in tests/support/hung_children.py writes the pid file (echo "$$ $c" > "$0") before it runs after_start. For records_stop_signals, after_start installs the traps that record int and term. Until then the script runs under trap "" INT TERM, which ignores both signals.
  • watch.started is true as soon as the pid file exists. The test sends the first signal at once. A signal that arrives between the pid write and the trap installation is lost.

Remedy

Make the fake ready before the test signals it. For example, install the recording traps before the pid file is written, or write a ready marker after the traps and make the test wait for it. The test must still fail if the stop code skips the SIGKILL (show it with a mutation). Check the other users of hung_script with after_start for the same gap. No sleep or longer deadline is a fix.

Activity

  1. added
    source/agent
    type/bug
    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/bug. The candidate describes a defect in test behavior related to signal handling timing.
    • Priority: P2-Medium. The issue causes intermittent test failures under load, affecting test reliability but not core functionality. The failed run 1906 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. Fixing this improves test stability and reduces flakiness, benefiting developers working with the CI system.
    • Effort: Low. The fix involves reordering operations in the test setup to ensure proper signal recording before signaling.
  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
    0fafb24
  5. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1922, merged into release/v0.2.39 as 0fafb24.

    Cause: hung_script wrote the pid file and only then ran after_start. For records_stop_signals, after_start set the traps that record int and term. A test signals the child as soon as it reads the pids. The child lost a signal that came between the pid write and the traps. The test then failed with interrupted false. The production code has no defect.

    Change: hung_script has a new part, after_spawn. It runs after the grandchild starts and before the child writes the pids. records_stop_signals sets its traps there. The traps cannot go before the start of the grandchild, because the grandchild would then not ignore SIGTERM. The other users of hung_script set their traps in before or on_interrupt, or send no signal. They have no gap. The change touches no file in src/.

    Existing tool considered: the fix needs no tool. It moves two trap commands in a shell script. The new test reads the mask of caught signals from /proc/<pid>/status, as the module already reads /proc/<pid>/stat. psutil is not a dependency, and its Process class (version 7.2.2) has no call for that mask. I estimate that the two test helpers cost about 30,000 tokens and 45 minutes. They need no upkeep, because the kernel interface is stable.

    Tests: tests/test_support_hung_children.py makes the pid file a named pipe, so the child waits at the write of its pids. The test checks that the child already catches SIGINT and SIGTERM. It failed on the old order of the traps with `(Fa…

    4 file(s) changed.

    How it was verified

    Check runs at 39a86c0:

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

    Acceptance Criteria of docs/agent/tasks/task-1913-stop-signal-tests-wait-until-the-fake-records-signals.md:

    • The fake child catches SIGINT and SIGTERM before it writes its pids. So it always records a signal that a test sends after it reads the pids.
    • The new test fails on the old order of records_stop_signals and passes on the new order.
    • The new test fails with a message, and does not block, when the child exits before it opens the pipe.
    • The four tests that use records_stop_signals fail when the stop code does not send the SIGKILL.
    • With the gap widened, the four tests failed 4 of 4 before the fix and passed 4 of 4 after it.
    • The stop-signal test of tests/test_ci.py passed 40 of 40 repeats under a stress pinned to one core.
    • No sleep and no longer deadline is part of the fix.
    • uv run devops ci test tests/test_support_hung_children.py tests/test_process.py tests/test_ci.py passes.
    • Fail-to-pass: not applicable. The production code is correct and untouched, and the base passes on a quiet host.
  6. added a commit that references this issue on Oct 23, 2026
    f209f6c
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/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions