Skip to content

Allow actors to self-suspend #483

Open

Description

Substrate's value comes from suspending idle actors and multiplexing many of them onto few workers. But today nothing decides when an actor is idle: suspend is only triggered by an external SuspendActor/PauseActor API call, presumably a higher order system.

We discussed an automatic idle-detection, but doesn't exist yet and I'm not sure if it can realistically work for session-based protocols such as websockets or grpc (with stream).

For some use cases, actors reliably know when they are idle, "I finished my turn / my streams are dormant / checkpoint me."

We should consider a cooperative model where actors yield by writing to a well-known file (e.g. /var/ate/state/suspend).

Activity

  1. added
    kind/feature
    on Jul 21, 2026
  2. EItanya commented on Jul 24, 2026

    @EItanya
    Collaborator

    This feels like a dupe of #257?

  3. juli4n commented on Jul 24, 2026

    @juli4n
    CollaboratorAuthor

    Yes, both seem to propose the same feature, they differ on the mechanism to accomplish it, but better to merge and have a single discussion.

  4. ronlv10 commented on Jul 29, 2026

    @ronlv10
    Collaborator

    +1 for this feature.

    I'd like to add that calling SuspendActor doesn't reliably work right now. When the actor calls the ate-api, the actor gets suspended, and upon resuming, an HTTP error occurs because the (previous) connection dropped (I talked about this issue here). This leaves no good way to verify if the suspension actually succeeded. I think writing to a file instead would make the process more atomic and robust.

  5. sfunkenhauser commented on Sep 16, 2026

    @sfunkenhauser
    Collaborator

    Actor idleness probe

    I propose adding an idleness probe, instead of a self-suspend action.

    Why not self-suspend

    The obvious way to let an actor give its worker slot back is to let it ask: the actor tells ateom it has nothing left to do, and ateom proxies the suspend. The practical problem is that there is no actor→host channel today, and adding one is not cheap: HTTP means configuring the actor's egress and pinning a static endpoint IP:port into the sandbox, vsock exists only on some runtimes and would need a UDS on gVisor, and either way the actor carries client code and a protocol it did not previously need. That makes the actor non-portable — the workload has to know it is running on Substrate (and potentially which sandbox class).

    The deeper problem is that self-suspend asserts a transition rather than a fact, and a transition is a lifecycle the actor then has to own and manage: stop serving, request the suspend, wait to be woken, resume serving — along with whatever edge cases fall out of the request being asynchronous, since the actor goes on running for an indeterminate time after asking.

    Rather than the actor asserting "suspend me," the platform asks "are you idle?" and the actor answers. The answer is a fact about the actor, which the actor is the only party qualified to state; the decision remains the platform's. The actor needs no client, no protocol, and no knowledge that Substrate exists beyond serving one more HTTP endpoint on the interior network it already serves readyz on.

    Design

    API

    One optional field on Container, alongside readyz:

    // idle_probe is an optional HTTP probe the platform polls to ask whether the
    // container is idle. 200 means idle; any other status or a failure to
    // connect means busy. path defaults to "/idlez".
    //
    // +k8s:optional
    HTTPGetAction idle_probe = N;

    There is deliberately no threshold, no period, and no minimum-uptime configuration. The response is a bare boolean and the actor integrates whatever duration or heuristic it wants behind it. This keeps the platform from second-guessing an answer it has strictly less information to produce, and lets each workload define "idle" for itself.

    Data path

    1. ateom polls. While the actor is RUNNING, its ateom GETs /idlez over the existing interior veth, using the same client shape as the readyz probe. Nothing polls a SUSPENDED actor — it has no sandbox to dial, and a suspended actor is idle by definition.
    2. ateom proposes. On a 200, ateom requests a suspend through the broker chain it already uses: ateom → atelet → ateapi.
    3. ateapi disposes. The suspend is a proposal, and the control plane has the final veto — the same one it already applies to any suspend. Keeping the decision there means other signals can be folded in: an in-progress request that arrived after the idle probe fired, for example, could veto the suspend. Additional policy can be added in the future.

    The split is that the data plane detects and proposes; the control plane decides.

    Integrating

    Serve one endpoint. Return 200 when you have nothing in flight, 503 otherwise:

    func (a *app) idlez(w http.ResponseWriter, r *http.Request) {
        if a.busy() {
            w.WriteHeader(http.StatusServiceUnavailable)
            return
        }
        w.WriteHeader(http.StatusOK)
    }

    Use readyz to avoid suspend loops. An actor that reports idle immediately after waking can be suspended again before it ever receives the request that woke it. readyz is the signal that prevents this: it is polled on every activation — first run and every restore:

    readyz 200 ──▶ Activate ──▶ ateom → atelet → ateapi ──▶ RUNNING ──▶ atenet unparks ──▶ first request
               └──────────────── actor is up but not yet reachable ────────────────┘
    

    So arming "busy" from the readyz handler guarantees the actor is marked busy before any /idlez poll and before the first post-resume request arrives:

    func (a *app) readyz(w http.ResponseWriter, r *http.Request) {
        a.armBusy() // idempotent; readyz may be polled many times per activation
        w.WriteHeader(http.StatusOK)
    }

    The actor then decides when to disarm — after the first request completes, after a quiet period, or on whatever condition matches its workload. The platform stays out of it.

    Known gap: suspend cancels in-flight requests

    Suspend does not drain today, it cancels. atunnel's Deactivate rejects new requests, cancels the requests already in flight for the active actor, and waits for their handlers to exit.

    That leaves a race here. The probe can report idle and a request can arrive before the freeze lands, and that request is canceled. Narrowing the window does not close it: idleness is a fact about the past the moment it is reported, so some interval always exists between the answer and the freeze.

    This is not specific to the probe. Anytime suspend is triggered this can be an issue. The probe adds a new trigger, not a new failure mode. The fix is lifecycle hooks: a pre-checkpoint hook that lets the actor finish or shed what it is holding before the freeze. That is tracked by #450.

  6. thockin commented on Sep 16, 2026

    @thockin
    Collaborator

    Serve one endpoint. Return 200 when you have nothing in flight, 503 otherwise:

    What does it mean to get any other code?

    ateom polls. While the actor is RUNNING, its ateom GETs /idlez over the existing interior veth, using the same client shape as the readyz probe.

    Polls how often? Do we need any guarantees on this? If I have a machine with "task runner" actors on it, I don't have visibility into when a task starts/finishes, so this polling loop becomes critical in driving overall efficiency / density. If I have 1000 such actors, do I poll once per second? That's 1000QPS of traffic being sent, and 1 second idle detection isn't really that impressive...

    Did we consider something like a long-poll model? Ateom does a GET on /idlez and the actor does not respond until it actually is idle (or times out). Ateom needs to keep the socket(s) open but it can select() on input rather than poll.

    The actor then decides when to disarm — after the first request completes, after a quiet period, or on whatever condition matches its workload. The platform stays out of it.

    Are we guaranteeing that we will never look at idlez while readyz is false? Are we guaranteeing that we will not strobe readyz at any other time besides right after wakeup? Do we need a way to signal "I just woke you up" instead?

    I'm concerned that we will hit readyz in other cases and trigger actors to think they are busy, and then they don't properly idle. I'd like to see the "is is idle" state machine which includes both probes.

    If we go this way, we should provide a Go library which implements and demonstrates the correct behavior.

  7. EItanya commented on Sep 17, 2026

    @EItanya
    Collaborator

    Going to start by saying I don't have a great solution to the problem I'm going to lay out, but thinking it through out loud.

    I'm not sure idlez would fix the problem unless we're willing to pull the polling time down to near 0. Let's take the use case outlined during the offsite of suspending while waiting for LLM or any long-running HTTP/IO call to return. O(250ms), (a potential polling time) could already be a sizable chunk of that call.

    In this case, whatever broker is managing the handoff of said LLM/HTTP calls for the actor could suspend them, but just wanted to think through the timing guarantees we're trying to have for self-suspending

  8. 20 remaining items

  9. sfunkenhauser commented on Sep 23, 2026

    @sfunkenhauser
    Collaborator

    I want to push back on cutting this from M3. Without a self-suspend mechanism eviction / upgrade is pretty much unusable. The only option is for the actor to crash, which is bad enough for every workerpool update, but even worse there is no way to recover a crashed actor.

  10. thockin commented on Sep 23, 2026

    @thockin
    Collaborator

    Is it unusable? I understood self-suspend to be the less common case and the harness-calls-suspend to be more common. IOW an upgrade relies on the "natural" conclusion of a turn, not actors recognizing the need to self-suspend?

  11. sfunkenhauser commented on Sep 23, 2026

    @sfunkenhauser
    Collaborator

    I'm not familiar which is more common between self-suspend vs harness-suspend. But any off the shelf binaries (Claude code) aren't going to have a dedicated harness and will need to self-suspend. If we think the majority of agents will have a dedicated harness and we want to explicitly excluded off the shelf binaries, than self-suspend definitely loses some priority.

    As for upgrade, the conclusion of a turn isn't sufficient, unless we require harnesses to suspend after every turn. Upgrade relies on a suspend happening within 30 minutes of the eviction, which the harness has no easy way of detecting. We can say an actor needs to be suspended at least every 30 minutes or risk crashing, but that seems pretty embarrassing.

  12. added this to the v1.1 milestone on Oct 27, 2026
  13. sfunkenhauser commented on Nov 16, 2026

    @sfunkenhauser
    Collaborator

    Getting back to this for v1.1. Here's an overview for the updated design based on the all the discussion above.

    There was some discussion on whether this API should mean 'suspend me' or 'I am idle'. I believe the later is a bit too rigid, and I've already heard that some folks want a general suspend API that isn't limited to 'idleness'. I've opted to go with 'suspend me' for the initial API which is more general and straight forward. We can revisit the overall idle story and automatic suspension with #424.

    • Each actor gets an HTTP endpoint on its default gateway, http://169.254.17.1:8. Every container gets an env var called ATE_ENDPOINT which contains the base URL.
    • PUT $ATE_ENDPOINT/v1/suspend asks for the actor to be suspended. Only PUT is accepted: a browser can't send one cross-origin without a CORS preflight, which the worker refuses, so no extra header is needed to prevent accidental calls.
    • The optional JSON body is a SuspendOptions, same as SuspendActor, e.g. {"mode": "DURABILITY_MODE_SYNCHRONOUS"}. Without one, the defaults apply (asynchronous).
    • The call is async. The return codes are:
      • 202: which means the request was accepted, not that the suspend has started. This API is best effort, and if the actor hasn't been notified of the suspend after X seconds, the actor will need to decide how to response (eg. crash or retry). The actor will need to register life cycle hooks (Actor lifecycle hooks #450) to know when the suspend is triggered.
      • 400: a malformed body.
      • Control plane errors are only logged on the worker, the actor never learns about them.
    • Detecting the actual suspend and wake-up isn't covered and will depend on life cycle hooks Actor lifecycle hooks #450. These need to land at the same time.
    • The request goes worker -> atelet -> ate-api-server through the existing RequestActorSuspend, which runs the same SuspendActor workflow and preconditions.
    • Always on, on both gVisor and microVM.
    • It ships over two releases: first RequestActorSuspend gains the options field, then the endpoint ships.
  14. raravena80 commented on Nov 16, 2026

    @raravena80

    One request while SuspendOptions is still being added to RequestActorSuspend: could it get an optional reason field, for example {"mode": "DURABILITY_MODE_SYNCHRONOUS", "reason": "human_input"}?

    Today nothing in Substrate records why an actor suspended, so runtime telemetry can't say it. The OTel GenAI agent lifecycle events in open-telemetry/semantic-conventions-genai#445 have a gen_ai.agent.pause.reason attribute (human_input or external_system). I have a prototype that emits the checkpoint and resume events from ateapi, but it has to skip the pause event because it has no cause: https://github.com/raravena80/substrate/tree/genai-lifecycle-events/examples/genai-lifecycle

    Because PUT /v1/suspend and SuspendActor share SuspendOptions, one field would cover both a self-suspend and a harness-driven suspend. Since the endpoint returns 202 before the suspend starts, the reason would need to stay on the actor record until the suspend commits, so that the event written at commit can carry it. A free-form string is enough. Substrate doesn't need to validate it against the OTel values.

  15. sfunkenhauser commented on Nov 18, 2026

    @sfunkenhauser
    Collaborator

    One request while SuspendOptions is still being added to RequestActorSuspend: could it get an optional reason field, for example {"mode": "DURABILITY_MODE_SYNCHRONOUS", "reason": "human_input"}?

    Could you file a separate issue to track this feature request? We will want to think about how attribution should be designed for all suspend / resume API calls, but potentially other APIs as well (not just RequestActorSuspend).

    RequestActorSuspend will likely never to be triggered by "human_input", so is this field required for RequestActorSuspend? We can discuss that on the new issue.

  16. raravena80 commented on Nov 18, 2026

    @raravena80

    Sure, filed #3972 for it and widened it to cover attribution in general.

    I think I wasn't clear on human_input. In the OTel spec it doesn't mean a human triggered the suspend. It means the agent is paused waiting for a human, e.g. it needs someone to approve something before it can keep going. So the self-suspend path is where it shows up the most: the agent calls PUT /v1/suspend itself and waits for the reply.

    Who made the call is a separate question. I put both in the new issue.

  17. ronlv10 commented on Nov 22, 2026

    @ronlv10
    Collaborator

    Hey! Great to see that we plan to work on this.

    Scott Funkenhauser (@sfunkenhauser), regarding your proposal: when I tested suspending from inside the actor a while ago (comment), I hit a race between the response travelling back to the actor over the TCP connection and the suspend itself. If the response is delayed, the actor can be suspended before the suspend call returns, and the call then fails with a connection error when the actor resumes.

    The async 202 makes that much less likely, but I'm not sure it removes it. The worker writing the 202 doesn't mean the actor has received it, so the freeze can still land first if delivery is slow.

    Have you considered this in your design?

  18. sfunkenhauser commented on Nov 23, 2026

    @sfunkenhauser
    Collaborator

    Yes, this can happen. When calling the self-suspend API you can't treat connection failures (reset, EOF, timeout) as suspend failures. On these errors (and 202) it's possible a suspend will happen. You would need to back off (eg. reset the idleness time / loop / detection) before trying again to avoid suspending right after being resumed.

    One idea to improve this experience, is to use an actor_exeuction_id but this might not land until v1.2.

    Expose an actor_execution_id to the actor. This is a unique ID that changes on every run / restore. This ID can be passed in the /v1/suspend call, and atelet / ate-api-server will reject suspend requests targeting a stale actor's execution ID. This prevents a stale self-suspend from being processed, so the actor can just keep retrying without risk.

  19. sfunkenhauser commented on Nov 23, 2026

    @sfunkenhauser
    Collaborator

    An example of what a client integration would look like.

    asked = ""  
    
    loop:
        if !isIdle():  # actor specific idle check
          continue
    
        current = readExecutionId()
        if asked != "" and asked != current:
          # execution ID changed, the actor was resumed so start a fresh idle window
          asked = ""
          idle = 0
          continue
    
        flush() # flush any state before suspending
        asked = current
        status = PUT $ATE_ENDPOINT/v1/suspend Execution-Id: current
        idle = 0
        if status is 4xx:
          log(status)
    
  20. raravena80 commented on Nov 23, 2026

    @raravena80

    Scott Funkenhauser (@sfunkenhauser) this sounds like the activation ID in #1041 (ActorStatus.activation_id, emitted as ate.actor.activation.id). #3065 proposes using it as a precondition on SuspendActor and ResumeActor for the same stale-run race. One ID could cover all three.

    On naming: the OTel GenAI agent conventions (open-telemetry/semantic-conventions-genai#445) use gen_ai.agent.execution.id for an ID that stays the same across suspend and resume. In Substrate that maps to the actor UID. A per-restore ID called Execution-Id would be easy to confuse with it. "Activation" from #1041 avoids that.

    One question on readExecutionId(): after a MEMORY restore, a value the process read from its environment is the old one. Would the actor read it from $ATE_ENDPOINT instead?

  21. sfunkenhauser commented on Nov 23, 2026

    @sfunkenhauser
    Collaborator

    Yes, I think it makes sense to use activation_id instead of execution_id

    One question on readExecutionId(): after a MEMORY restore, a value the process read from its environment is the old one. Would the actor read it from $ATE_ENDPOINT instead?

    I'm hoping we can re-use the existing SystemInfoVolumeSource.

    message SystemInfoVolumeSource {

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

Metadata

Metadata

Labels

area/nodearea/schedulingkind/feature

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions