Skip to content

feat: allow creating a task from an actor template - #552

Closed
siyuanfoundation wants to merge 1 commit into
google:mainfrom
siyuanfoundation:actor-template
Closed

siyuanfoundation wants to merge 1 commit into
google:mainfrom
siyuanfoundation:actor-template

Conversation

@siyuanfoundation

@siyuanfoundation siyuanfoundation commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Add optional spec.template field to TaskSpec referencing a Substrate ActorTemplate, allowing tasks to run directly from an existing template.

  • Add template (ObjectRef) to TaskSpec in ax.proto and regenerate protos.
  • Validate mutual exclusivity of spec.image and spec.template, reject command with template, and require template name.
  • Check that the referenced ActorTemplate exists in Substrate at CreateTask time before saving or provisioning, returning FailedPrecondition if not found.
  • Reconcile directly against the referenced template without provisioning a per-task ActorTemplate.
  • On task deletion, delete only the Actor and skip template cleanup when spec.template is set.
  • Update ax describe task to display template name and atespace.
  • Add unit tests across types, reconciler, server, and an E2E test exercising the full lifecycle against Substrate.

Refs #491

In the current implementation, a task is rejected at creation time if the referenced ActorTemplate does not exist in Substrate. This is because currently there is no self-healing loop in ax, users would need to delete and recreate the task after the template is created. We will revisit this after reconciliation loop is introduced in the future.

@siyuanfoundation

Copy link
Copy Markdown
Collaborator Author

/cc @rakyll @mayawang

@mayawang

mayawang commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Nice, this matches #491 closely. One question before approving: with spec.template set, AX skips the per-task template, so the task's workspace, env, resources and config never reach the actor. #491's own example binds a workspace. @rakyll should those be rejected with template, or passed some other way? Either works, I'd just rather they aren't silently ignored.

Add optional spec.template field to TaskSpec referencing a Substrate
ActorTemplate, allowing tasks to run directly from an existing template.

- Add template (ObjectRef) to TaskSpec in ax.proto and regenerate protos.
- Validate mutual exclusivity of spec.image and spec.template, reject command with template, and require template name.
- Check that the referenced ActorTemplate exists in Substrate at CreateTask time before saving or provisioning, returning FailedPrecondition if not found.
- Reconcile directly against the referenced template without provisioning a per-task ActorTemplate.
- On task deletion, delete only the Actor and skip template cleanup when spec.template is set.
- Update ax describe task to display template name and atespace.
- Add unit tests across types, reconciler, server, and an E2E test exercising the full lifecycle against Substrate.

Refs google#491
if len(spec.GetCommand()) > 0 {
return errors.New("spec: command cannot be set with template")
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also validate the template.GetName() and template.GetAtespace() as Substrate also does that.


// 3. Ensure Actor exists on Substrate
var templateAtespace, templateName string
if tmpl := task.Spec.Template; tmpl != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env, resources, workspace, config and debug only reach the actor through ensureTaskTemplate, so they're silently dropped here. Until they can be passed through, should ValidateTask reject them with template, like command?

if err := r.client.DeleteActor(ctx, atespace, taskName); err != nil {
return err
}
if skipTemplates {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only covers this task's own delete. Deleting an unrelated image task user still sweeps a referenced "user-tmpl-1a2b3c4d" (the naming the e2e uses), and Substrate doesn't stop you deleting a template that's in use. Could the sweep only match templates AX created? Then skipTemplates and DeleteTask aren't needed.


// 3. Ensure Actor exists on Substrate
var templateAtespace, templateName string
if tmpl := task.Spec.Template; tmpl != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the template is not valid, do we need to Ensure the template before the following call "EnsureActor"?

@YoyinZyc

YoyinZyc commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

I feel not quite right to expose the substrate-level primitive into the ax level. As we are working on the API proto, the API change in the pr may not be valid. I think we need to consolidate the API change, the apply the shortcut.

@siyuanfoundation

Copy link
Copy Markdown
Collaborator Author

/hold

@mayawang

Copy link
Copy Markdown
Collaborator

@siyuanfoundation any update here? Happy to re-review once the template-deletion and ignored-fields questions are sorted

@siyuanfoundation

Copy link
Copy Markdown
Collaborator Author

@mayawang We will add the actor template option along with the new Profile field based on the new design. How about we just close this PR?

@mayawang

Copy link
Copy Markdown
Collaborator

Sounds good, closing makes sense since Profile will cover it. Thanks for picking this up!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants