Skip to content

Task is marked Failed permanently when Substrate returns ResourceExhausted (no free workers) instead of staying Pending and retrying #367

Closed

Description

@zhoukuncheng

Summary

When Substrate has no free worker for a new actor, EnsureActor/resume returns ResourceExhausted: no free workers available and the controller marks the Task phase: Failed with Ready=False, reason=ActorResumeFailed. The Task is never reconciled again, so it stays Failed even after workers free up. For any workload that submits more Tasks than the WorkerPool has replicas, every Task beyond the pool size is lost instead of queued.

Combined with #346 (a finished command does not release its worker) this shows up quickly: after N completed Tasks in a pool of N workers, all further Tasks fail on creation.

AX d8ed0fe, Agent Substrate on a single-node kind cluster, gVisor WorkerPool with 4 replicas.

Reproduction

  1. Create a WorkerPool with replicas: 4 and apply 6 Tasks that run a long-lived command (e.g. sleep 3600) with the same image.
  2. ax get tasks: 4 are Running, 2 are Failed.
  3. ax describe task on a failed one:
Conditions:
  TYPE          STATUS  REASON             MESSAGE
  GatewayReady  True    PoliciesApplied    Network policies active
  Ready         False   ActorResumeFailed  resuming actor default/task-5: rpc error: code = ResourceExhausted desc = no free workers available
  1. Delete two of the running Tasks (or scale the pool to 6). The failed Tasks stay Failed; no reconcile is triggered.

Controller log:

level=ERROR msg="error processing task event" ... action=reconcile error="reconciling task default/task-5: resuming actor: resuming actor default/task-5: rpc error: code = ResourceExhausted desc = no free workers available"

Expected

ResourceExhausted is a transient scheduling condition, not a Task failure. The Task should stay in Pending (e.g. Ready=False, reason=WaitingForWorker) and be retried with backoff until a worker is available or a configurable deadline passes.

Suggested fix

In internal/controller/reconciler.go, distinguish codes.ResourceExhausted from other errors in the EnsureActor/resume path: set a Pending-style condition instead of phase: Failed, and re-publish the reconcile event with a delay (or let the worker loop requeue it). A --schedule-timeout flag could turn a long wait into a real failure.

Activity

  1. sharadregoti commented on Sep 22, 2026

    @sharadregoti

    Worth noting this isn't just a pool-exhaustion edge case. A fresh AX + Substrate install has zero WorkerPools, so this is literally the first thing you hit following the README's 3-step quickstart as written. None of the docs mention a WorkerPool needs to exist before ax apply -f examples/task.yaml will work. A docs callout might be a cheap near-term fix alongside the retry behavior you're proposing.

  2. self-assigned this
    on Oct 13, 2026
  3. erain commented on Oct 13, 2026

    @erain
    Collaborator

    I’m working on this. Current main uses direct reconciliation with resource locks rather than the former event queue, so the planned fix is to persist worker exhaustion as Pending / WaitingForWorker and retry it in ax-server with capped backoff, re-reading task state under its resource lock. Pending tasks should survive server restarts, and suspend/delete must prevent later activation.

    Validation will include regression tests for transient versus permanent errors and lifecycle cancellation, plus an end-to-end capacity-exhaustion/recovery test against Substrate. I also plan to attach a short terminal recording of the reproducible test for review. A configurable scheduling deadline will remain a separate follow-up to keep this change focused.

  4. rakyll commented on Oct 14, 2026

    @rakyll
    Member

    This is working as intended at this point. We don't want to introduce queuing in AX. Substrate eventually will handle queuing and AX will leverage it. We don't want to build anything AX that is not forward compatible with Substrate.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions