Skip to content

The EXEC_TIMEOUT-over-stalled-delivery test in dispatcher-exec.test.ts passes against a broken dispatcher when its child starts more than 200 ms late #2000

Done

Description

@V3RON

src/daemon/dispatcher-exec.test.ts:729 ("reports EXEC_TIMEOUT, not the stalled-delivery error it provokes, ...") waits a fixed 200 ms (line 750), then expires the exec timeout. If its child starts later than that, no chunk was delivered, nothing is stalled, and the test proves only a plain timeout. The product is correct; not seen on a real run.

Shown by breaking src/daemon/dispatcher-exec.ts:239 (await waited.catch(() => undefined) becomes await waited), with the child waiting before its first statement:

child delayed    0 ms: AssertionError: expected ExecOutputDeliveryStalledError ... to match object { code: 'EXEC_TIMEOUT' }
child delayed  700 ms: 1 passed

Found while triaging #1996.

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 dispatcher is correct.

    Confirmed, with the reporter's two outputs. On bug/2000-repro the existing test, now titled "reports EXEC_TIMEOUT, not the stalled-delivery error it provokes, when the child starts late and a consumer that stopped reading is why the command outran its timeout", delays its child 700 ms and also asserts that the command's own outcome was the stalled delivery. It failed 3 of 3 runs:

    pnpm exec vitest run --project unit src/daemon/dispatcher-exec.test.ts
    
    AssertionError: promise resolved "{ code: null, signal: 'SIGTERM' }" instead of rejecting
     ❯ src/daemon/dispatcher-exec.test.ts:763:33
    Tests  1 failed | 33 passed (34)
    

    Root cause

    Defect in the test. src/daemon/dispatcher-exec.test.ts:750 on main sleeps 200 ms from the dispatch, whether or not the child has written. A late child is killed before any chunk is pending, so wait() resolves, dispatcher-exec.ts:239 has no rejection to swallow, and the only assertion (:753) holds for any timeout.

    Simplest fix

    In this test file only: expire the timeout once the test has the chunk. Keep the reproduction's wait() assertion, drop its 700 ms delay and restore main's title.

    // child: process.stdout.write('x'); setTimeout(() => process.exit(1), 15_000);  (orphan guard)
    onOutput: (_stream, chunk) => {
      seen.push(chunk);
      return new Promise<void>(() => { /* why: unchanged */ });
    },
    // instead of the 200 ms sleep:
    await vi.waitFor(() => expect(seen).toEqual(["x"]), { interval: 10, timeout: 10_000 });
    reproduction with the fix:  34 passed, 3 of 3; child 0 and 3000 ms late: 34 passed
    fix, delay dropped:         34 passed, 3 of 3
                                src/daemon 898 passed; pnpm test:changed 34 passed; pnpm typecheck clean
    event loop blocked 1500 ms, child 0 and 700 ms late: passed
    broken code, with the fix:
      dispatcher `await waited`, child 0, 700, 3000 ms late   expected ExecOutputDeliveryStalledError … to match { code: 'EXEC_TIMEOUT' }
      runner settles with a delivery pending                  promise resolved "{ code: null, signal: 'SIGTERM' }" instead of rejecting
    

    Alternatives rejected

    • A longer sleep: still a race with the host.
    • The wait without the wait() assertion: a runner that stops reporting the stall would hollow the test out again.
    • A scripted runner: it cannot model an exit with a delivery outstanding (the comment at main's :643).

    Risk

    Fast track

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

    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: #2002 (#2000)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  8. added a commit that references this issue on Nov 30, 2026
    a03340b
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