Skip to content

engine host handover: an exit with a call in flight is counted as a crash #473

Closed

Description

@SSFSKIM

Cites: P5 composite docs/doperpowers/plans/2026-10-27-p5-org.md, child O16 (the engine host's handover, M3/M3b/M3c).

What happens

On an update with a session live, the old engine host hands its session over and exits (exiting (handover)), and the successor adopts it. If main has a host.interest call in flight to the old host at that moment, main logs [sessions] host.interest failed … engine-host disconnected before answering host.interest and then [hosts] engine-host exited unexpectedly (code null). So the handover's planned exit is counted as a crash: lastExit is set, it is entered in the crash window, and the app may say so.

Seen once: e2e/supervisor.spec.ts:847 case (f), first attempt, failing at :859 ('no unexpected exit'), green on retry. Run 41960398446 (O7 M9's final gate, 2026-11-05 03:56Z, tree 4899a282f). M9 does not reach this path. The host log has handover armed: 1 hosted rows frozen, 0 calls in flight and exiting (handover), and adoption: 1 of 1 … adopted. So the host-side handover is correct, and the defect is in how main classifies the exit.

Where

src/shared/host/host-supervisor.ts: exited() (:925) and the detached transport's unexpected (:696) both log "exited unexpectedly". Find which path a handover exit takes when a request was pending on the transport, and why the handover's expected-exit state is not applied there. Likely an ordering issue: the pending call's disconnect is processed before the handover cause is recorded.

Acceptance

  • A handover exit is never classified unexpected, whatever main has in flight to the old host at the time. The pending call is held and re-sent to the successor, or fails as host_unavailable without counting as an exit.
  • Red first: a unit test in the host supervisor's test file that holds a host.interest (or any) request in flight while the host reports its handover and exits. It must fail on master and pass after.
  • e2e/supervisor.spec.ts (f) stays green, and there is no new flaky signature in e2e:supervisor-daemon.

Not in scope: changes to the handover protocol itself (M3c's D63 first-quiet-report rule stands).

Activity

  1. added
    bug
    status:ready-for-implementer
    priority:P2
    on Nov 5, 2026
  2. self-assigned this
    on Nov 5, 2026
  3. SSFSKIM commented on Nov 5, 2026

    @SSFSKIM
    OwnerAuthor

    Diagnosis (maws-24): the in-flight call is incidental; the cause is the daemon shape's relay dropping main before the handover

    Read from run 41960398446's artifacts (e2e-supervisor-daemon, case (f) first attempt vs -retry1).

    The failure is on the daemon shape, and main's host.interest failure is a symptom of its link closing, not the cause. Timeline (mawsd log, main stdout/stderr):

    time what
    04.705 main's hello on mawsd's engine-host.sock is welcomed: main is served old host pid 9237 through the relay
    04.715 mawsd's own host supervisor: 9237 "is quiet; asking it to hand its sessions over" → drain(): setHandover(draining) (posted on machine.sock), then transition(restarting)
    04.716 mawsd daemon.ts:874 → engineRelay.dropApp('the engine host is restarting'): main's engine-host link is closed with no reason on the wire
    04.729 main's machine.sock link connects, after the draining post; the next resend would come 5 s later, and the drain is over by then
    04.743 9237 exiting (handover)
    ~04.92 main's transport closed() (exitAsked null) looks at the pid one PID_POLL_MS (200 ms) after the close: gone → lost({crash}) → unexpected → lastExit set
    05.396 mawsd's own supervisor correctly reads it as planned ("asked to hand over, is gone; starting its successor")

    Main has no evidence of the handover at its verdict:

    • the host's holder.detached status goes out on mawsd's draining link, and mawsd relays engine-host events only to the attached app, whose link is already dropped, so handedOver in main's host-supervisor.ts is never marked;
    • daemon.engineHandover's draining was posted before main's machine link was up, and handingOverAt feeds only the start budget anyway.

    The retry passed only because main's first hello reached mawsd after the handover was finished. Main never had a welcomed link to 9237, so it never had a verdict to make. In general, on the daemon shape, a quick handover (0 calls in flight, the common case) is read as a crash whenever main is attached when mawsd asks: the old pid dies about 30 ms after the drop, well inside main's 200 ms look. Deferred handovers escape it because the old pid is still alive at the look (quiet).

    Proposed fix (needs a call from O16's owner: it touches the daemon.engineHandover report)

    1. mawsd reports the outcome along with the intent. At the drain's end, daemon.engineHandover names the old host's incarnation and mawsd's own evidence-based verdict (the planned it already computes in lost's replace branch). It also posts the current state to each machine.sock client as it attaches, not only at changes and every 5 s.
    2. main, for a relayed engine host whose welcomed pid is gone: if a drain was reported for that incarnation, it waits for the end report, bounded by ENGINE_HANDOVER_FRESH_MS, before judging. Handed over is read as replace/planned, so the successor starts with no crash count. Crashed mid-drain is read as a crash, as before. This keeps the wave-2 rule that the verdict rests on evidence, not intent.
    3. Red first: a supervisor unit test on the relayed shape (link dropped while draining, pid gone before the end report arrives) that fails on master today. Plus a daemon-side test that the end report carries the verdict.

    The issue's acceptance criteria still hold. The one exception is "Red first … a host.interest request in flight": the in-flight request isn't needed to reproduce the bug.

  4. added
    status:in-progress
    and removed
    status:ready-for-implementer
    on Nov 5, 2026
  5. SSFSKIM commented on Nov 5, 2026

    @SSFSKIM
    OwnerAuthor

    [board] in-progress: maws-24 implementing the re-diagnosed fix (mawsd end-report verdict + main defers relayed gone-pid verdict); O16 owner approved

  6. SSFSKIM commented on Nov 10, 2026

    @SSFSKIM
    OwnerAuthor

    Sighting at the mini's swap to cf30daf (2026-11-10, reported by mini-ops): one 'error: [hosts] engine-host exited unexpectedly (code null)' at 01:07:08.212Z, 5 ms after the old supervisor (asked to hand over, 6 live) was logged gone; the successor came up 1.2 s later with all 6 sessions live. The mini's 1-minute load was 40.7. It reads as this ticket's mislabelled planned exit. The MacBook and dc-linux171-1e68 swaps at the same master logged no error.

  7. SSFSKIM commented on Nov 15, 2026

    @SSFSKIM
    OwnerAuthor

    Diagnosis of the 11-13 reading (run 43425585102): a second path, and maws-24's race still open on master

    What of maws-24's plan landed: nothing. fix/473-handover-inflight has no commit beyond master's 11-05 head (01c0b239c, an ancestor of master), no PR was opened from it, and daemon.engineHandover on master still carries only {state, inFlight, tool?, at}: no end report, and main has no deferred verdict. PR #490 is a tracker-row update and #650 (U9) only cites this ticket.

    The case. The 11-13 red is (f) … an update waits for a running tool call (e2e/supervisor.spec.ts:802), the deferred update. maws-24 thought a deferred handover escapes because the old pid still lives at main's look. Here it doesn't escape: the hold ends, the next status is quiet, and the drain runs at once with 0 calls in flight.

    Timeline (failing attempt; scratch-mawsd.log, scratch-host.log, main's stdout and stderr, all on one clock):

    time (12:38:…) who line
    38.046 mawsd engine-host pid 20112, of another build, is quiet; asking it to hand its sessions over
    38.064 mawsd engine-host.sock: closing the app's connection: the engine host is restarting
    38.095 mawsd asking supervisor pid 20112 to hand its sessions over
    38.101 host handover armed: 2 hosted rows frozen, 0 calls in flight
    38.102 host both rows detached (handover); Supervision's detached callback publishes the status with holder.detached: true
    38.103 host exiting (handover)
    38.113 mawsd engine-host.sock: client disconnected (main's side of the relay has ended)
    38.152 mawsd is handing its sessions over; its successor follows its exit: it read the host's answer about 50 ms after the host wrote it, so mawsd was slow to read
    38.305 main lastExit.at: main's own verdict, its transport's 200 ms look after its relay closed ([hosts] engine-host exited unexpectedly (code null) in main's stderr; no left after handing its sessions over line)
    38.356 mawsd supervisor pid 20112, asked to hand over, is gone; starting its successor, then error: [hosts] engine-host exited unexpectedly (code null)

    The retry's main logs engine-host pid 21379 left after handing its sessions over; starting its successor.

    Path 1 (new): the host's last status dies with the process, so mawsd misjudges too. mawsd's own supervisor counted the exit as a crash. maws-24's 11-05 run didn't show that line, and the 11-10 mini sighting does ("5 ms after the old supervisor (asked to hand over, 6 live) was logged gone"). In lost's replace branch, the exit had code null and no signal, and mawsd's drain link heard the host's events (drainHears: an app was streaming). So the only way to read it as planned is the holder.detached mark. That status was published at 38.102 and never reached mawsd. The cause is the host's exit order (socket-host.ts stop): clients.closeClient() calls socket.end(), and then proc.exit(code) runs at once. Whatever the kernel has not yet taken from the socket's user-space write queue is lost with the process. On macOS an AF_UNIX stream holds 8 KiB (net.local.stream.sendspace: 8192), and the freeze, the detaches and their statuses add up to more than that while mawsd is behind on reading. A standalone experiment showed it: a server writes 22.8 KB plus one last line to a client that has paused, then calls end() and process.exit(0). The client received 7.6 KB, and the last line was not among it. Main gets the mark only from mawsd's relay, so this path breaks main's verdict as well.

    Path 2 (maws-24's, still open): main's verdict on the relayed shape is a race even when mawsd hears the mark. Main's relayed link was dropped at 38.064 and its side ended at 38.113, before the host even froze. Main hears holder.detached only through the departing relay, and only if mawsd reads it before main's side ends. Main then judges 200 ms after its own close (38.305), not after mawsd's verdict (38.356). In the retry the mark crossed in time. Here it could not have. Fixing path 1 alone leaves (f) flaky.

    The test reads the right signal. lastExit is main's verdict, which the app shows. So this is a product fix:

    1. Host: the exit order waits, within a bound, for each client's writes to leave before proc.exit, so the evidence the drain published reaches mawsd.
    2. mawsd: daemon.engineHandover's end report (none) names the drained host's incarnation and mawsd's evidence-based verdict (lost's planned). mawsd also tells the current state to a machine.sock client when it says ready, not only at changes and every 5 s (maws-24's late-attach case). This is a wire minor.
    3. Main: for a relayed engine host whose welcomed process is gone with no mark, while a drain was reported, it waits, within a bound, for that end report before judging. Handed over reads as planned. Crashed mid-drain reads as a crash, as before. A mawsd that sends no end report keeps today's verdict once the bound runs out.
  8. added 3 commits that reference this issue on Nov 15, 2026
  9. added
    status:in-review
    and removed
    status:in-progress
    on Nov 15, 2026
  10. SSFSKIM commented on Nov 15, 2026

    @SSFSKIM
    OwnerAuthor

    [board] in-review: two paths fixed: host flushes its last status before exit; main waits for mawsd's end-report verdict (wire minor 47); gates green, review clean

  11. added 2 commits that reference this issue on Nov 15, 2026
  12. removed
    status:in-review
    on Nov 15, 2026
  13. SSFSKIM commented on Nov 15, 2026

    @SSFSKIM
    OwnerAuthor

    [board] done: Landed by PR #683, merge 63c97b5. Row (29) case (f) stays open until it stops flaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpriority:P2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions