Skip to content

Suspend running Tasks when their worker is evicted, instead of stopping the command #489

Open

Description

@mayawang

Problem

When a worker pod is evicted (node drain, node upgrade, worker pool change), Substrate sends the actor SIGTERM and gives the harness a window to suspend it before the actor is killed. Everything since the last snapshot is lost after that.

AX's runner treats SIGTERM as a shutdown: cmd/ax-task-runner/main.go cancels on SIGTERM, and the runner then stops the task command (SIGTERM, a grace period, SIGKILL) and exits. Nothing in ax-server suspends the Task. A node drain therefore stops every running Task's command and loses its work since the last snapshot. On the next resume, AX reverts the crashed actor to that snapshot.

This is from reading the code on main. An eviction hasn't been run against it.

Ask

Keep the runner alive on SIGTERM, and have ax-server suspend the Task within Substrate's eviction window, as Substrate's eviction guidance asks of a harness.

Related: #446 (SIGTERM grace period) and #451 (what suspend does to the command).

Activity

  1. added
    devx
    on Oct 15, 2026
  2. mastersingh24 commented on Nov 16, 2026

    @mastersingh24
    Contributor

    We hit this for real, built a fix on our fork, and it has held up on three GKE clusters, so here's what we found in case it saves you some work.

    What happened. GKE auto-upgraded our clusters on 2026-11-08 (RAPID channel, no maintenance window). Every task that was awake on a drained node died: its last condition said "worker pod went away while hosting the actor", and the task stayed failed. Suspended tasks were fine. It happened exactly as you describe: the runner stops the command on SIGTERM, nothing suspends the task, and the actor ends CRASHED when the worker goes.

    What we built, on Agent Substrate v1.0.0:

    1. The runner stays up on SIGTERM. On the first SIGTERM it keeps the task command running for a grace period (AX_RUNNER_SIGTERM_GRACE, 25 minutes by default, under Substrate's 30-minute window), so there's a live process to snapshot. A second SIGTERM or a SIGINT still stops it at once.

    2. ax-server suspends on drain. Every 10 seconds or so it calls ListWorkers. For each worker in WORKER_STATE_DRAINING it lists the actors assigned to it and calls SuspendActor with DURABILITY_MODE_SYNCHRONOUS for each running task's actor. Synchronous matters: an asynchronous suspend can lose the snapshot along with the node. The task records why it was suspended, and its next request resumes it on another worker. One catch: listing workers needs global access, which runs into Expose a worker's draining state on the actor, so an atespace-scoped driver can suspend before eviction agent-substrate/substrate#3818 for an atespace-scoped driver.

    3. Two safety nets.

      • An actor that still ends up CRASHED because its worker went away, say a Spot reclaim with about 30 seconds' notice, is reverted once to its last snapshot. Substrate only reports the crash reason as text, so this matches its worker-loss messages, which is fragile across Substrate versions.
      • An actor whose drain suspend failed, for example one whose runner had already exited, is also reverted once. That one keys on ax-server's own record of the suspend it attempted, not on Substrate's text.

      Other crashes are never reverted, so a task that fails at boot can't loop.

    Results. We deleted the worker pod under an awake task with the default grace period. The task was suspended about 2 to 11 seconds later, and a request through the router woke it on another worker with its in-memory session intact. That passed on all three clusters, and it now runs nightly.

    Things to watch for:

    • the synchronous suspend holds the task's lock until the snapshot is uploaded;
    • requests in flight when the actor is frozen are cut off;
    • the bookkeeping for the safety nets lives in memory, so it's lost if ax-server restarts during a drain.

    The code is on our fork, in case it helps: the runner and drain watcher in mastersingh24@d03b3e0, and the failed-suspend revert in mastersingh24@9a017f7. The write-up is in docs/worker-drain.md there. We'd be glad to send it as a PR once outside PRs are open, adapted to the new lifecycle states in #563.

  3. mayawang commented on Nov 16, 2026

    @mayawang
    CollaboratorAuthor

    Thanks, this is really useful, especially the data from a real GKE upgrade and the point about synchronous suspends.

    One question on where it should live: suspending actors on a draining worker feels like something Agent Substrate should handle itself, since it owns the worker lifecycle and the drain window, and it would avoid the global ListWorkers access you hit in agent-substrate/substrate#3818. I'll raise that on the Substrate side. The runner change, staying up on the first SIGTERM, belongs in AX either way.

    While outside PRs are closed, I'm happy to open one from your fork. It should build on the new lifecycle work in #591, so @siyuanfoundation, could you say where the drain handling fits?

  4. siyuanfoundation commented on Nov 18, 2026

    @siyuanfoundation
    Collaborator

    We do plan to add an eviction_notice event to the runner

    message RunnerEvent {
    . The runner sends the event to the server, and the server would suspend the actor.

    Current plan is to add in 1.0. Happy to collaborate if @mastersingh24 would like to work on this :)

  5. mayawang commented on Nov 18, 2026

    @mayawang
    CollaboratorAuthor

    Thanks Siyuan, v1.0 timing makes sense. Before @mastersingh24 starts, let's pick one path: a runner eviction_notice works when the runner gets a SIGTERM with time to spare, but a spot reclaim gives ~30s, which is why their fork also needed a revert fallback. I'll check with Substrate whether drain-suspend can live there, and share back here.

  6. mastersingh24 commented on Nov 19, 2026

    @mastersingh24
    Contributor

    We do plan to add an eviction_notice event to the runner

    message RunnerEvent {

    . The runner sends the event to the server, and the server would suspend the actor.
    Current plan is to add in 1.0. Happy to collaborate if @mastersingh24 would like to work on this :)

    @siyuanfoundation happy to work on this ... is there an open issue / design or do you want me to do a quick write up here on a proposed plan?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    devx

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions