MCPcopy Create free account
hub / github.com/compozy/agh / SetExecutionProfile

Method SetExecutionProfile

internal/task/manager_profile.go:46–106  ·  view source on GitHub ↗

SetExecutionProfile validates and persists one task-owned execution profile.

(
	ctx context.Context,
	taskID string,
	profile *ExecutionProfile,
	actor ActorContext,
)

Source from the content-addressed store, hash-verified

44
45// SetExecutionProfile validates and persists one task-owned execution profile.
46func (m *Service) SetExecutionProfile(
47 ctx context.Context,
48 taskID string,
49 profile *ExecutionProfile,
50 actor ActorContext,
51) (ExecutionProfile, error) {
52 if err := requireWriteAuthority(actor); err != nil {
53 return ExecutionProfile{}, err
54 }
55 trimmedID := strings.TrimSpace(taskID)
56 if trimmedID == "" {
57 return ExecutionProfile{}, fmt.Errorf("%w: task id is required", ErrValidation)
58 }
59 if profile == nil {
60 return ExecutionProfile{}, fmt.Errorf("%w: task_execution_profile is required", ErrValidation)
61 }
62 if strings.TrimSpace(profile.TaskID) != "" && strings.TrimSpace(profile.TaskID) != trimmedID {
63 return ExecutionProfile{}, fmt.Errorf(
64 "%w: task_execution_profile.task_id must match task id %q",
65 ErrValidation,
66 trimmedID,
67 )
68 }
69
70 record, err := m.store.GetTask(ctx, trimmedID)
71 if err != nil {
72 return ExecutionProfile{}, err
73 }
74 if strings.TrimSpace(record.CurrentRunID) != "" {
75 return ExecutionProfile{}, fmt.Errorf(
76 "%w: task %q execution profile cannot change while run %q is active",
77 ErrInvalidStatusTransition,
78 record.ID,
79 record.CurrentRunID,
80 )
81 }
82
83 profile.TaskID = trimmedID
84 normalized, err := profile.Normalize(m.profileValidation)
85 if err != nil {
86 return ExecutionProfile{}, err
87 }
88 normalized.UpdatedAt = m.now().UTC()
89 if normalized.CreatedAt.IsZero() {
90 normalized.CreatedAt = normalized.UpdatedAt
91 }
92
93 stored, err := m.store.UpsertExecutionProfile(ctx, &normalized)
94 if err != nil {
95 return ExecutionProfile{}, err
96 }
97 if err := m.recordTaskEvent(ctx, trimmedID, "", taskEventProfileUpdated, actor, profileMutationEventPayload{
98 TaskID: trimmedID,
99 CoordinatorMode: stored.Coordinator.Mode,
100 WorkerMode: stored.Worker.Mode,
101 SandboxMode: stored.Sandbox.Mode,
102 }); err != nil {
103 return ExecutionProfile{}, err

Callers

nothing calls this directly

Calls 7

recordTaskEventMethod · 0.95
requireWriteAuthorityFunction · 0.85
GetTaskMethod · 0.65
NormalizeMethod · 0.45
nowMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected