Agent Executor (AX) is Google's open agentic orchestration runtime
Go
fix(controller): keep task templates stable across lifecycle changes (#390)
Alex Jonese6211f84a9e3
diff --git a/docs/runner.md b/docs/runner.mdindex 92c6e99..d9bfff4 100644--- a/docs/runner.md+++ b/docs/runner.md@@ -14,7 +14,7 @@ The controller does not run `spec.command` as the container entrypoint. It alway|---|---|| Container image | `spec.image`, or the default `ax-task-runner` image when unset || Container command | `/usr/local/bin/ax-task-runner`, always |-| `AX_TASK_YAML` | The full `Task` resource as YAML, including status |+| `AX_TASK_YAML` | The `Task` launch configuration as YAML, excluding status and the suspend flag || `AX_WORKSPACES_YAML` | Every bound `Workspace` resource as a multi-document YAML stream, in the task's binding order || `spec.env` entries | Each one set directly in the container environment || `GEMINI_API_KEY` | Set when the atespace has a Gemini credential configured |diff --git a/docs/sandbox.md b/docs/sandbox.mdindex b6fff77..f582278 100644--- a/docs/sandbox.md+++ b/docs/sandbox.md@@ -17,7 +17,7 @@ The daemon speaks HTTP/1.1 and `h2c` on the same port. Your agent can introspect|---|---|---|---|| `/healthz` | `GET` | `text/plain` | Liveness. Always `200 OK`. || `/readyz` | `GET` | `text/plain` | Readiness. `503` while the workspace is initializing, `200` once clones, MCP config, and skills are in place. |-| `/metadata/v1alpha1/ax/task` | `GET` | `application/yaml` | Full spec and status of the current `Task`. |+| `/metadata/v1alpha1/ax/task` | `GET` | `application/yaml` | Task launch configuration, excluding status and the suspend flag. || `/metadata/v1alpha1/ax/workspaces` | `GET` | `application/yaml` | Every bound `Workspace`, as a multi-document stream in binding order. |```bashdiff --git a/internal/controller/reconciler.go b/internal/controller/reconciler.goindex 31c399b..b9b0c17 100644--- a/internal/controller/reconciler.go+++ b/internal/controller/reconciler.go@@ -33,6 +33,7 @@ import ("github.com/google/ax/pkg/apis/v1alpha1""google.golang.org/grpc/codes""google.golang.org/grpc/status"+ "google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/timestamppb""gopkg.in/yaml.v3")@@ -153,8 +154,12 @@ func (r *TaskReconciler) Reconcile(ctx context.Context, task *v1alpha1.Task, gatextraEnv[geminiSecretKey] = geminiKey}- // Inject Task YAML specification into container environment- if taskYAML, err := yaml.Marshal(task); err == nil {+ // Only launch configuration belongs in the template; status and suspend+ // changes must not create new golden snapshots.+ launchTask := proto.Clone(task).(*v1alpha1.Task)+ launchTask.Status = nil+ launchTask.Spec.Suspend = false+ if taskYAML, err := yaml.Marshal(launchTask); err == nil {extraEnv["AX_TASK_YAML"] = string(taskYAML)}diff --git a/internal/controller/reconciler_test.go b/internal/controller/reconciler_test.goindex e699ee0..67febcd 100644--- a/internal/controller/reconciler_test.go+++ b/internal/controller/reconciler_test.go@@ -26,7 +26,9 @@ import ("github.com/google/ax/internal/substrate""github.com/google/ax/pkg/apis/v1alpha1""google.golang.org/grpc"+ "google.golang.org/grpc/codes""google.golang.org/grpc/credentials/insecure"+ "google.golang.org/grpc/status")type mockControlServer struct {@@ -47,6 +49,23 @@ func noSecrets(context.Context, string, string, string) (string, error) {return "", nil}+func (m *mockControlServer) GetActorTemplate(_ context.Context, req *ateapipb.GetActorTemplateRequest) (*ateapipb.ActorTemplate, error) {+ ref := req.GetActorTemplate()+ if !m.actorTemplates[ref.GetName()] {+ return nil, status.Error(codes.NotFound, "template not found")+ }+ return &ateapipb.ActorTemplate{Metadata: &ateapipb.ResourceMetadata{Name: ref.GetName(), Atespace: ref.GetAtespace()}}, nil+}++func (m *mockControlServer) CreateActorTemplate(_ context.Context, req *ateapipb.CreateActorTemplateRequest) (*ateapipb.ActorTemplate, error) {+ if m.actorTemplates == nil {+ m.actorTemplates = make(map[string]bool)+ }+ tmpl := req.GetActorTemplate()+ m.actorTemplates[tmpl.GetMetadata().GetName()] = true+ return tmpl, nil+}+func (m *mockControlServer) CreateAtespace(ctx context.Context, req *ateapipb.CreateAtespaceRequest) (*ateapipb.Atespace, error) {name := ""if req.Atespace != nil && req.Atespace.Metadata != nil {@@ -382,6 +401,18 @@ func TestTaskReconciler_WorkspaceReady(t *testing.T) {}assertCondition(t, reconciledResumed, "WorkspaceReady", "True", "SetupComplete")assertCondition(t, reconciledResumed, "Ready", "True", "TaskRunning")+ if got := len(mockSrv.actorTemplates); got != 1 {+ t.Fatalf("readiness updates and suspend/resume created %d templates, want 1", got)+ }++ // A launch configuration change must still get a distinct template.+ task.Spec.Command = []string{"python3", "agent.py"}+ if _, err := reconciler.Reconcile(ctx, task, nil); err != nil {+ t.Fatalf("Reconcile with changed command failed: %v", err)+ }+ if got := len(mockSrv.actorTemplates); got != 2 {+ t.Errorf("command change left %d templates, want 2", got)+ }}// assertCondition fails the test unless the task has a condition of the given type with