NeMo-Relay icon indicating copy to clipboard operation
NeMo-Relay copied to clipboard

[Enhancement]: Relaunch a daemon worker at once when its process has exited

Open Somay-kousis opened this issue 3 weeks ago • 3 comments

Affected area

Daemon

Problem or opportunity

When a plugin worker process exits, the daemon still waits the full 30-second reconnect window before it relaunches one. The replacement is ready in under a second, so for 30 seconds the route either passes through or blocks.

The window makes sense when a live worker lost its socket and can come back. An exited worker can't. Today a worker that gets SIGTERM calls request_exit("signal") and then control_task.abort() (crates/cli/src/daemon/worker/runtime.rs:414-443), so the daemon sees a dropped socket, the same as a network blip. expire_disconnected_peer then sleeps out GRACE (crates/cli/src/daemon/broker/server/socket.rs:827, common/socket.rs:22).

Real Claude Code 2.1.316 through the daemon on main, mock provider, ATOF file sink:

Worker exit Time to relaunch Claude turns during the window
SIGTERM, default mode 30.0 s, replacement ready 0.34 s later succeed in 0.4 s but write 0 ATOF lines (3 before and after)
SIGKILL, --require-worker 30.0 s, replacement ready 0.6 s later one turn took 39.4 s (0.4 s normally)

So in default mode Relay drops everything it should record for those turns, and with --require-worker the agent stalls.

Proposed enhancement

Treat a known exit as final instead of a disconnect:

  1. A worker that is shutting down on a signal sends an explicit release on its control socket before it closes it, like an MCP client already can. The daemon fails that worker at once and relaunches.
  2. For SIGKILL or OOM, the MCP that launched the worker keeps watching the child after it's ready (today it drops the handle at ReuseWorker, crates/cli/src/daemon/mcp/mod.rs:518) and reports its exit.

The 30-second window stays for real socket loss.

Runtime contract and binding impact

Daemon and worker control protocol only. One new control message, or reuse of the existing release. No binding or plugin API change.

Alternatives considered

  • A shorter GRACE for loopback workers. Simpler, but it still guesses, and it would cut real reconnects short.
  • Only part 1. It covers clean stops (kill, logout, upgrades) and is about 40-80 lines plus a test. Part 2 covers crashes.

Acceptance criteria

  • After a worker exits on SIGTERM, a replacement is launched within a second, and the next request goes through it.
  • With part 2, the same holds for SIGKILL.
  • A worker that only loses its socket still gets the 30-second window.
  • A test for each case.

#1701 is changing the same control and MCP code, so I would build this on top of it once it lands.

Do you want both parts, or only the signal path for now? I'd like to work on this. Can you assign it to me?

Somay-kousis avatar Nov 09 '26 18:11 Somay-kousis

Both parts seem reasonable to me.

Assigned to you, @Somay-kousis

Please target release/0.11

willkill07 avatar Nov 09 '26 20:11 willkill07

Part 1 is in via #1709 on release/0.11. Do you want me to take part 2 (SIGKILL/crash via the launching MCP), or are you doing it?

Somay-kousis avatar Nov 11 '26 17:11 Somay-kousis

You can do it!

willkill07 avatar Nov 11 '26 18:11 willkill07