Repository navigation
Description
Problem
When a Task's spec.command exits, the runner keeps the sandbox up so it can be inspected (runner.Run waits on ctx.Done() after reportExit). The actor stays Running and keeps its worker until someone calls ax suspend or ax delete.
For batch-style Tasks ("review this PR", "upgrade this dependency") this means a finished agent holds a worker indefinitely. On a pool with fewer workers than Tasks, new Tasks fail to resume with ResourceExhausted: no free workers available while finished Tasks sit idle. The density that suspend/resume is meant to deliver only appears if an external process watches every Task and suspends it.
We hit this while running several agents as Tasks on a small WorkerPool (kind, gVisor): each finished agent had to be suspended by hand before the next one could get a worker.
Existing pieces
- The roadmap lists "Idleness Detection and Automatic Suspension for Density" (
docs/roadmap.md). runner.Configalready has anOnCommandExit func(CommandExit)hook thatreportExitcalls with the exit code, but nothing sets it today.
Proposal
A small first step that covers command completion only, leaving general idleness detection for later:
- Runner reports completion. Set
OnCommandExitincmd/ax-task-runnerto record the exit, and expose it from the metadata server (for example/metadata/v1alpha1/ax/statusreturning{"exited": true, "exitCode": 0}). - Task API field. Add
spec.onCompletionwith valuesKeep(default, today's behavior),Suspend, andDelete. - Controller applies it. When the controller sees the command has exited, it applies the policy: for
Suspend, callSuspendActorand move the Task to aCompletedphase with the exit code in its status, soax get tasksshows the result and the worker is freed.
Keep as the default preserves current behavior. Suspend keeps /workspace in the snapshot, so results can still be inspected after ax resume.
Questions for maintainers
- Is this in line with how you plan to approach the roadmap item, or would you rather go straight to activity-based idle detection?
- Should the controller poll the runner's metadata endpoint, or should completion be reported another way?
- How should this relate to Substrate's worker-initiated suspend (
RequestActorSuspend/internal/ateomsuspend, recently added on Substratemain)? Is AX expected to use that path once it is wired up? - Would you accept a PR for steps 1–3 (with tests)? Happy to split it into one PR per step.
Activity
MushuEE commentedon Oct 18, 2026
The runner is executing within an untrusted scope. I am unsure if it can be relied upon to report anything with confidence. Maybe we need a heartbeat sidecar? When Substrate's idle probs put it in idle state, what lifecycle paths might trigger?
I think this needs to be part of the Task Lifecycle work 100%, unsure exactly what instrument(s) are needed to provide signal. Might need to support multiple plugins that can guide lifecycle on exit and resume. Regardless, lifecycle signals will need some backup state so dead probes etc don't leak resources and clog pools