Skip to content

Commit 25a0b88

Browse files
authored
Delete unused actor_template_ref from ActorAssigment sub-resource (agent-substrate#2322)
The field name doesn't follow the convention and ends with "ref", but more importantly, it's not really used. Part of agent-substrate#1378
1 parent 09af6d2 commit 25a0b88

9 files changed

Lines changed: 128 additions & 234 deletions

File tree

‎cmd/ateapi/internal/controlapi/actor_template.go‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,3 @@ func resolveActorTemplate(ctx context.Context, st actorTemplateGetter, actor *at
165165
}
166166
return template, nil
167167
}
168-
169-
// actorTemplateObjectRef returns a fresh copy of the actor's template
170-
// reference — fresh so records built from it never alias the actor message.
171-
func actorTemplateObjectRef(actor *ateapipb.Actor) *ateapipb.ObjectRef {
172-
ref := actor.GetActorTemplate()
173-
if ref == nil {
174-
return nil
175-
}
176-
return &ateapipb.ObjectRef{Atespace: ref.GetAtespace(), Name: ref.GetName()}
177-
}

‎cmd/ateapi/internal/controlapi/actor_template_test.go‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,3 @@ func TestUpdateActorTemplateMetadata(t *testing.T) {
469469
t.Errorf("uid after update = %q, want %q", got, want)
470470
}
471471
}
472-
473-
// TestActorTemplateObjectRef pins that snapshot and assignment records get a
474-
// fresh copy of the reference, never the actor's own message.
475-
func TestActorTemplateObjectRef(t *testing.T) {
476-
if got := actorTemplateObjectRef(&ateapipb.Actor{}); got != nil {
477-
t.Errorf("actorTemplateObjectRef(no ref) = %v, want nil", got)
478-
}
479-
actor := &ateapipb.Actor{ActorTemplate: &ateapipb.ObjectRef{Atespace: "team-a", Name: "tmpl1"}}
480-
got := actorTemplateObjectRef(actor)
481-
if got == actor.GetActorTemplate() {
482-
t.Error("actorTemplateObjectRef aliases the actor's reference")
483-
}
484-
if got.GetAtespace() != "team-a" || got.GetName() != "tmpl1" {
485-
t.Errorf("actorTemplateObjectRef = %v, want team-a/tmpl1", got)
486-
}
487-
}

‎cmd/ateapi/internal/controlapi/functionaltest/actor_test.go‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,9 +4279,8 @@ func TestResumeActor_CrashesIfAssignedWorkerIsDraining(t *testing.T) {
42794279
t.Fatalf("GetActor failed: %v", err)
42804280
}
42814281
if err := tc.persistence.BindActorToWorker(context.Background(), podA, &ateapipb.ActorAssignment{
4282-
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: id},
4283-
ActorUid: suspended.GetMetadata().GetUid(),
4284-
ActorTemplateRef: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "tmpl1"},
4282+
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: id},
4283+
ActorUid: suspended.GetMetadata().GetUid(),
42854284
}, nil); err != nil {
42864285
t.Fatalf("BindActorToWorker failed: %v", err)
42874286
}
@@ -4531,9 +4530,8 @@ func TestResumeActor_DanglingWorker(t *testing.T) {
45314530
t.Fatalf("GetActor failed: %v", err)
45324531
}
45334532
if err := tc.persistence.BindActorToWorker(context.Background(), podA, &ateapipb.ActorAssignment{
4534-
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: name},
4535-
ActorUid: suspended.GetMetadata().GetUid(),
4536-
ActorTemplateRef: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "tmpl1"},
4533+
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: name},
4534+
ActorUid: suspended.GetMetadata().GetUid(),
45374535
}, nil); err != nil {
45384536
t.Fatalf("BindActorToWorker failed: %v", err)
45394537
}
@@ -5133,9 +5131,8 @@ func TestDeleteActor_ReleasesAnAssignmentTheActorDoesNotReference(t *testing.T)
51335131
// Bind straight through the store, leaving the Actor's backlink unset:
51345132
// exactly the state a crash between the two writes leaves behind.
51355133
if err := tc.persistence.BindActorToWorker(ctx, podUID, &ateapipb.ActorAssignment{
5136-
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "orphaned"},
5137-
ActorUid: actorUID,
5138-
ActorTemplateRef: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "tmpl1"},
5134+
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "orphaned"},
5135+
ActorUid: actorUID,
51395136
}, nil); err != nil {
51405137
t.Fatalf("BindActorToWorker failed: %v", err)
51415138
}

‎cmd/ateapi/internal/controlapi/worker_test.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ func validWorker(name string, mods ...func(*ateapipb.Worker)) *ateapipb.Worker {
5757

5858
func newAPIAssignment(actorUID string) *ateapipb.ActorAssignment {
5959
return &ateapipb.ActorAssignment{
60-
ActorTemplateRef: &ateapipb.ObjectRef{Atespace: "ate-system", Name: "tmpl"},
61-
Actor: &ateapipb.ObjectRef{Atespace: "team-a", Name: "actor-1"},
62-
ActorUid: actorUID,
60+
Actor: &ateapipb.ObjectRef{Atespace: "team-a", Name: "actor-1"},
61+
ActorUid: actorUID,
6362
}
6463
}
6564

‎cmd/ateapi/internal/controlapi/workflow_resume.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ func (w *ActorWorkflow) assignWorkerAttempt(ctx context.Context, actorRef resour
510510
// Record what this claim reserves so release returns the same amount.
511511
Resources: admittedResources(constraints),
512512
}
513-
assignment.ActorTemplateRef = actorTemplateObjectRef(actor)
514513

515514
// The candidate came from a watch-fed cache, so it may already be full or no
516515
// longer eligible. The store re-asks under the Worker's row lock, where the

‎cmd/ateapi/internal/controlapi/workflow_resume_test.go‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -178,58 +178,6 @@ func TestEnsureWorkerAssigned_ConflictExhaustionIsRetryable(t *testing.T) {
178178
}
179179
}
180180

181-
// TestAssignWorkerAttempt_StampsSubstrateTemplateRef verifies a ref-mode
182-
// actor's worker claim names the substrate template via actor_template_ref
183-
// and leaves the legacy kube reference unset.
184-
func TestAssignWorkerAttempt_StampsSubstrateTemplateRef(t *testing.T) {
185-
ctx := context.Background()
186-
persistence := newTestPersistence(t)
187-
188-
worker := &ateapipb.Worker{
189-
Metadata: &ateapipb.ResourceMetadata{Name: testWorkerUID("pod-free")},
190-
WorkerNamespace: "worker-ns",
191-
WorkerPool: "pool",
192-
WorkerPod: "pod-free",
193-
WorkerPodUid: testWorkerUID("pod-free"),
194-
SandboxClass: "gvisor",
195-
Status: &ateapipb.WorkerStatus{State: ateapipb.WorkerState_WORKER_STATE_ACTIVE, Capacity: &ateapipb.WorkerResources{Actors: 1}},
196-
}
197-
if _, err := persistence.CreateWorker(ctx, worker); err != nil {
198-
t.Fatalf("CreateWorker: %v", err)
199-
}
200-
201-
actor := storetest.MustCreateActor(t, ctx, persistence, &ateapipb.Actor{
202-
Metadata: &ateapipb.ResourceMetadata{Atespace: "team-a", Name: "id1"},
203-
ActorTemplate: &ateapipb.ObjectRef{Atespace: "team-a", Name: "sub-tmpl"},
204-
Status: &ateapipb.ActorStatus{State: ateapipb.ActorState_ACTOR_STATE_SUSPENDED},
205-
})
206-
207-
cacheCtx, cancel := context.WithCancel(ctx)
208-
defer cancel()
209-
wc := workercache.New(persistence, time.Minute)
210-
if err := wc.Start(cacheCtx); err != nil {
211-
t.Fatalf("workercache.Start: %v", err)
212-
}
213-
214-
w := &ActorWorkflow{store: persistence, workerCache: wc, scheduler: scheduling.New(wc)}
215-
tmpl := &ateapipb.ActorTemplate{
216-
Metadata: &ateapipb.ResourceMetadata{Atespace: "team-a", Name: "sub-tmpl"},
217-
SandboxConfig: &ateapipb.SandboxConfig{SandboxClass: ateapipb.SandboxClass_SANDBOX_CLASS_GVISOR},
218-
}
219-
_, assigned, err := w.assignWorkerAttempt(ctx, resources.ActorRef{Atespace: "team-a", Name: "id1"}, actor, tmpl)
220-
if err != nil {
221-
t.Fatalf("assignWorkerAttempt: %v", err)
222-
}
223-
224-
assignment, err := persistence.GetWorkerAssignment(ctx, assigned.GetMetadata().GetName(), actor.GetMetadata().GetUid())
225-
if err != nil {
226-
t.Fatalf("GetWorkerAssignment: %v", err)
227-
}
228-
if assignment.GetActorTemplateRef().GetAtespace() != "team-a" || assignment.GetActorTemplateRef().GetName() != "sub-tmpl" {
229-
t.Errorf("assignment ActorTemplateRef = %v, want team-a/sub-tmpl", assignment.GetActorTemplateRef())
230-
}
231-
}
232-
233181
func TestAssignWorkerAttempt_SkipsWorkerAssignedInOtherAtespace(t *testing.T) {
234182
ctx := context.Background()
235183
persistence := newTestPersistence(t)

‎cmd/ateapi/internal/store/storecontract/contract.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,10 +2077,9 @@ func runWorkerAssignmentContractTests(t *testing.T, setup func(t *testing.T) sto
20772077
// over several of them is unambiguous about which were counted.
20782078
newTestAssignment := func(actorUID string, cpuMilli, memoryBytes int64) *ateapipb.ActorAssignment {
20792079
return &ateapipb.ActorAssignment{
2080-
ActorTemplateRef: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "test-template"},
2081-
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "actor-" + actorUID},
2082-
ActorUid: actorUID,
2083-
Resources: resources.CPUMemory(cpuMilli, memoryBytes),
2080+
Actor: &ateapipb.ObjectRef{Atespace: testAtespace, Name: "actor-" + actorUID},
2081+
ActorUid: actorUID,
2082+
Resources: resources.CPUMemory(cpuMilli, memoryBytes),
20842083
}
20852084
}
20862085

0 commit comments

Comments
 (0)