Skip to content

CreateTask: do not store a Task until its actor exists #698

Done

Description

@rakyll

A Task should not exist until its actor exists on Agent Substrate. Today CreateTask stores the Task first and creates the actor afterwards, so a failed create leaves a Task behind.

What happens today

CreateTask in internal/server/server.go:

  1. Stores the Task with state QUEUED.
  2. Calls TaskReconciler.Suspend, which creates the atespace, the ActorTemplate and the actor, suspends the actor, and binds the Gateway.
  3. On failure, recordFailure keeps the stored Task: QUEUED and Unavailable for a transient error, FAILED with PROVISIONING_FAILED otherwise.

The consequences:

  • A create that fails for good leaves a FAILED Task with no actor. Tasks are immutable, so the name cannot be applied again until the Task is deleted.
  • A create that fails transiently leaves a QUEUED Task. Nothing retries it: ax-server has no queue and no background work. The client has to apply the same manifest again, and CreateTask has a special case that allows this only for a stored QUEUED Task with no template and an identical spec.
  • QUEUED reads as "something will pick this up", which is not true.

Proposed change

  • Provision the actor first, and store the Task only once the actor exists.
  • A failed create returns the error and stores nothing. The client retries by applying again, as for any failed RPC.
  • Remove the stored QUEUED state for creation, the retry special case in CreateTask, and the provisioning use of recordFailure.

To decide

  • Orphaned actors. If storing the Task fails after the actor was created, or ax-server dies between the two steps, an actor exists with no Task. CreateTask can delete the actor when the store write fails. For a crash, a later create of the same name adopts the actor, because the actor is named after the Task and creation is an ensure; otherwise nothing removes it.
  • Server-assigned fields. metadata.uid, create_time and the default session_id are assigned before provisioning today. They can stay in memory until the Task is stored, as long as nothing in provisioning needs them to be durable.
  • Resume. ResumeTask also leaves a Task QUEUED after a transient failure. That Task already has an actor, so it is a separate question.

Related

Activity

  1. added this to the v1.0.0 milestone on Nov 21, 2026
  2. yongruilin commented on Nov 24, 2026

    @yongruilin
    Collaborator

    I can take this as the follow-up to #748.

    • CreateTask rejects a task that already exists, with no exception. The retry branch goes away.
    • The task is stored only after substrate related stuff provisioning succeeds.
    • A failed CreateTask returns the error, (deletes the actor it created?), and stores nothing. Running create again is a new create with the spec that is sent.
    • If an actor with the task's name exists but no task is stored (orphan actor), create deletes it first instead of adopting it, because it may come from another spec.

    Then:

    • A failed create leaves no QUEUED or Failed task, and a task is not visible until its create finishes.
    • ax suspend / ax resume no longer finish a failed create.

    Also:

    @rakyll Could this move to v0.4.0, so that it lands with #748?

  3. self-assigned this
    on Nov 24, 2026
  4. added a commit that references this issue on Nov 25, 2026
    da04c0d
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions