Skip to content

A dispatcher-exec.test.ts stalled-delivery test passes against a broken runner when its child starts more than 600 ms late #1996

Done

Description

@V3RON

src/daemon/dispatcher-exec.test.ts:691 ("delivers every chunk in full, in order, even when one delivery stalls past the exit grace window") waits a fixed 600 ms, then checks that device.exec has not settled. If its child starts later than that, nothing has been delivered yet, so the check proves nothing. The product is correct; not seen on a real run.

Shown by breaking src/ports/node-process-runner.ts so it settles with a delivery pending (settleWhenDrained ignores #pendingDeliveries), with the child waiting before its first statement:

child delayed    0 ms: AssertionError: device.exec resolved while a chunk's delivery was still pending
child delayed  700 ms: 1 passed
child delayed 1500 ms: 1 passed

Found while triaging #1994.

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 the reporter's three outputs. On bug/1996-repro the existing test, now titled "delivers every chunk in full, in order, even when the child starts late and one delivery stalls past the exit grace window", delays its child 700 ms and asserts what its settle check depends on. It fails every run:

    pnpm exec vitest run --project unit src/daemon/dispatcher-exec.test.ts
    
    AssertionError: expected { childRunning: true, …(1) } to deeply equal { childRunning: false, …(1) }
    -   "childRunning": false,
    -   "firstChunk": "before-exit-A",
    +   "childRunning": true,
    +   "firstChunk": undefined,
     ❯ src/daemon/dispatcher-exec.test.ts:706:53
    Tests  1 failed | 33 passed (34)
    

    Root cause

    Defect in the test. src/daemon/dispatcher-exec.test.ts:691 on main sleeps 600 ms from the dispatch, but the 300 ms grace starts at the child's exit. New: :672 is a second race, which fails a correct runner. The chunks are 20 ms apart, so a busy event loop reads both as one:

    main, event loop blocked 1500 ms:
    expected [ 'before-exit-Abefore-exit-B' ] to deeply equal [ 'before-exit-A', 'before-exit-B' ]
    

    Simplest fix

    In this test file only: the child writes its second chunk once the test has the first, and the 600 ms start at the child's exit.

    const processRunner = new NodeProcessRunner({ exitDeferralCapMs: 30_000, exitGraceMs: 300 });
    const spawned = vi.spyOn(processRunner, "spawnStreaming");
    // child: write A; setTimeout(() => process.exit(1), 15_000) as orphan guard;
    // every 10 ms: if the `go` file exists, write B and process.exit(0)
    await vi.waitFor(() => expect(seen).toEqual(["before-exit-A"]), { interval: 10, timeout: 10_000 });
    writeFileSync(go, "");
    const { pid } = spawned.mock.results[0]?.value as { readonly pid: number };
    await vi.waitFor(() => expect(supervisor.isAlive(pid)).toBe(false), { interval: 10, timeout: 10_000 });
    await new Promise((resolve) => setTimeout(resolve, 600));
    /* the settle check and the rest, unchanged; remove the folder in finally */
    reproduction with the fix:  34 passed, 3 of 3
    fix:                        34 passed, 5 of 5; child 0, 700, 3000 ms late: passed; event loop blocked 1500 ms: passed
                                src/daemon 894 passed; pnpm test:changed 34 passed; pnpm typecheck clean
    broken runner, with the fix (child 0 and 700 ms late; the first also 3000 ms):
      settleWhenDrained ignores pending deliveries   device.exec resolved while a chunk's delivery was still pending
      exit grace ignores them                        the same
      close ignores them                             the same
      exit grace ignores them, at 500 ms             the same
      drops chunks while a delivery is pending       expected [ 'before-exit-A' ] to deeply equal [ …, 'before-exit-B' ]
    

    Alternatives rejected

    • A longer sleep: still a race with the host.
    • Waiting for the first chunk only: the grace starts at the exit, and the chunks can still merge.
    • Faking setTimeout: the pid can be gone before the runner arms its grace (Windows), so one advance may miss it.

    Risk

    • The 600 ms sleep is real. A correct runner never settles in it, so a slow host cannot fail it; a broken one's 300 ms timer is due first on the same event loop.
    • The raised cap keeps a slow host from failing the pending delivery.
    • 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: #2001 (#1996)

    Written by an agent.

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