Skip to content

The SIGKILL escalation test passes without escalation when its child starts later than 100 ms #1986

Done

Description

@V3RON

src/ports/process-runner.test.ts, "escalates to SIGKILL when a timed-out process ignores SIGTERM, within the configured grace": run sends SIGTERM 100 ms after the spawn. A child that has not installed its SIGTERM handler by then dies from SIGTERM. Line 808 asserts code: null and no signal, so that passes too.

Shown by removing the SIGKILL in src/ports/node-process-runner.ts (run):

child as it is:             1 failed   expected 'still running after 2 s' to match object { code: null, ... }
child waits 300 ms first:   1 passed

Found while triaging #1982.

Written by an agent.

Activity

  1. added
    bug:new
    on Nov 30, 2026
  2. self-assigned this
    on Nov 30, 2026
  3. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Seen on: test output with a slowed child, not a real run. The runner is correct.

    Confirmed, with both of the reporter's outputs. On bug/1986-repro the existing test, now titled "escalates to SIGKILL when a timed-out process that starts late ignores SIGTERM, within the configured grace", delays its child 600 ms and asserts the signal. It fails every run (5 of 5):

    pnpm exec vitest run --project unit src/ports/process-runner.test.ts
    
    AssertionError: expected { code: null, … } to match object { code: null, signal: 'SIGKILL', … }
    -   "signal": "SIGKILL",
    +   "signal": "SIGTERM",
     ❯ src/ports/process-runner.test.ts:821:23
    Tests  1 failed | 45 passed (46)
    

    Root cause

    Defect in the test. src/ports/process-runner.test.ts:811 on main starts timeoutMs: 100 at the spawn, so SIGTERM can precede the child's handler; :818 accepts code: null from either signal. On Windows any signal ends the child, so by reading the code the test never escalates there; the branch skips it on win32.

    Simplest fix

    In this test file only: fake setTimeout, advance it once the child has logged that it is ready, then that it handled SIGTERM. Straddle the 100 ms grace and assert the signal. waitUntil polls on the real timer. The real-time bound goes (testing rule 5).

    vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
    const outcome = runner.run(/* child appends "ready", then " SIGTERM", to log */);
    await waitUntil(() => readFileSync(log, "utf8") === "ready");
    vi.advanceTimersByTime(100);
    await waitUntil(() => readFileSync(log, "utf8") === "ready SIGTERM");
    vi.advanceTimersByTime(99);
    expect(killSpy.mock.calls.map(([, signal]) => signal)).toEqual(["SIGTERM"]);
    vi.advanceTimersByTime(1);
    expect(await outcome).toMatchObject({ code: null, signal: "SIGKILL", stderr: "", stdout: "" });
    fix:            46 passed, 5 of 5; child 0, 300, 3000 ms late: passed
                    src/ports 438 passed | 11 skipped; pnpm typecheck clean
    broken runner, with the fix:
      no SIGKILL, or the default grace → code: 0, expected signal: 'SIGKILL'
      grace 1 ms short                 → [ 'SIGTERM', 'SIGKILL' ], expected [ 'SIGTERM' ]
      SIGKILL first                    → timed out waiting for a process condition
    

    Alternatives rejected

    • Assert the signal only: a slow start then fails instead of passing, a flake.
    • A longer timeoutMs: still a race with the host.

    Risk

    • waitUntil gives up after 5 s, and the child exits by itself 4 s after its start.
    • Restore the timers, the process.kill spy and the log folder in finally.
    • Windows and the commit hook were not run on the fix.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Side findings

    Written by an agent.

  4. removed their assignment
    on Nov 30, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 30, 2026
  6. self-assigned this
    on Nov 30, 2026
  7. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1995 (#1986)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  8. added a commit that references this issue on Nov 30, 2026
    f3410e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-track

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions