This is an automated email from the ASF dual-hosted git repository. DImuthuUpe pushed a commit to branch pause-workflow-temp in repository https://gitbox.apache.org/repos/asf/airavata.git
commit 25e692a2be9a8de6758174d51ebc0682c5d942f3 Author: DImuthuUpe <[email protected]> AuthorDate: Tue Nov 3 08:09:31 2026 -0500 Support to pause workflow when interactive auth fails --- api/process/controller/pause.go | 67 ++++++++++++++++ api/process/dto/pause.go | 62 ++++++++++++++ api/process/model/pause.go | 69 ++++++++++++++++ api/process/model/process.go | 3 + api/process/repository/pause.go | 80 +++++++++++++++++++ api/process/service/launch.go | 12 ++- api/process/service/pause.go | 151 +++++++++++++++++++++++++++++++++++ go.mod | 2 +- internal/app/app.go | 8 +- internal/db/migrate.go | 3 + internal/orchestration/batch.go | 6 +- internal/orchestration/data.go | 6 +- internal/orchestration/engine.go | 16 ++-- internal/orchestration/pause.go | 134 +++++++++++++++++++++++++++++++ internal/orchestration/pause_test.go | 105 ++++++++++++++++++++++++ internal/server/server.go | 1 + internal/ssh/deferred.go | 56 +++++++++++++ internal/ssh/pool.go | 74 ++++++++++++++++- internal/ssh/pool_test.go | 54 +++++++++++++ internal/ssh/ssh.go | 1 + 20 files changed, 894 insertions(+), 16 deletions(-) diff --git a/api/process/controller/pause.go b/api/process/controller/pause.go new file mode 100644 index 0000000000..1cdef5099e --- /dev/null +++ b/api/process/controller/pause.go @@ -0,0 +1,67 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package controller + +import ( + "net/http" + + "github.com/apache/airavata/internal/httpx" + + "github.com/apache/airavata/api/process/service" +) + +// PauseController serves the pauses of a process's workflows, and the continue action +// that ends one, under /api/v1/processes/{processId}. +// +// Like launch, continue is a verb with no body: it wakes the workflow waiting on the +// process's open pause, after the owner has answered the interactive login it asked for. +type PauseController struct{ svc *service.PauseService } + +// NewPauseController returns a handler delegating to svc. +func NewPauseController(svc *service.PauseService) *PauseController { + return &PauseController{svc: svc} +} + +// Register mounts the pause routes. +func (h *PauseController) Register(mux *http.ServeMux) { + mux.HandleFunc("GET /api/v1/processes/{processId}/pauses", h.list) + mux.HandleFunc("POST /api/v1/processes/{processId}/continue", h.continueProcess) +} + +func (h *PauseController) list(w http.ResponseWriter, r *http.Request) { + pauses, err := h.svc.ListForProcess(r.Context(), r.PathValue("processId")) + if err != nil { + httpx.WriteError(w, r, err) + return + } + httpx.WriteJSON(w, http.StatusOK, pauses) +} + +// continueProcess answers 202, as launch does: the task runs again on the workflow's +// time, not the request's. The body is the pause it closed. +func (h *PauseController) continueProcess(w http.ResponseWriter, r *http.Request) { + pause, err := h.svc.Continue(r.Context(), r.PathValue("processId")) + if err != nil { + httpx.WriteError(w, r, err) + return + } + httpx.WriteJSON(w, http.StatusAccepted, pause) +} diff --git a/api/process/dto/pause.go b/api/process/dto/pause.go new file mode 100644 index 0000000000..0b15f4f778 --- /dev/null +++ b/api/process/dto/pause.go @@ -0,0 +1,62 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package dto + +import ( + model "github.com/apache/airavata/api/process/model" +) + +// TaskPauseResponse is the read model for one pause of a process's workflow. A pause +// is recorded by the workflow itself and closed by continuing the process, so there is +// no request DTO alongside it. +type TaskPauseResponse struct { + TaskPauseID string `json:"taskPauseId"` + ProcessID string `json:"processId"` + TaskID string `json:"taskId"` + TaskType model.PausedTaskType `json:"taskType"` + WorkflowInstanceID string `json:"workflowInstanceId"` + Reason *string `json:"reason"` + + // Both in milliseconds since the epoch. ContinuedAt is null while the pause is open. + PausedAt int64 `json:"pausedAt"` + ContinuedAt *int64 `json:"continuedAt"` +} + +func ToTaskPauseResponse(p *model.TaskPause) TaskPauseResponse { + return TaskPauseResponse{ + TaskPauseID: p.ID, + ProcessID: p.ProcessID, + TaskID: p.TaskID, + TaskType: p.TaskType, + WorkflowInstanceID: p.WorkflowInstanceID, + Reason: p.Reason, + PausedAt: p.PausedAt, + ContinuedAt: p.ContinuedAt, + } +} + +func ToTaskPauseResponses(in []model.TaskPause) []TaskPauseResponse { + out := make([]TaskPauseResponse, 0, len(in)) + for i := range in { + out = append(out, ToTaskPauseResponse(&in[i])) + } + return out +} diff --git a/api/process/model/pause.go b/api/process/model/pause.go new file mode 100644 index 0000000000..cb3167c2f1 --- /dev/null +++ b/api/process/model/pause.go @@ -0,0 +1,69 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package model + +import ( + "github.com/google/uuid" + "gorm.io/gorm" +) + +type PausedTaskType string + +const ( + PausedTaskTypeDataStaging PausedTaskType = "DATA_STAGING" + PausedTaskTypeJobSubmission PausedTaskType = "JOB_SUBMISSION" +) + +// TaskPause records a workflow parked on one of a process's tasks until its owner has +// completed an interactive SSH login and asked for the run to continue. +// +// A row is open while ContinuedAt is unset. The workflow it names is the one to signal +// to continue it: a process runs a submission and later a completion workflow, and +// either can be the one waiting. +type TaskPause struct { + ID string `gorm:"column:task_pause_id;primaryKey;type:varchar(36)" json:"taskPauseId"` + + ProcessID string `gorm:"column:process_id;type:varchar(36);index" json:"processId"` + Process *Process `gorm:"references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"-"` + + TaskID string `gorm:"column:task_id;type:varchar(36)" json:"taskId"` + TaskType PausedTaskType `gorm:"column:task_type;type:varchar(32)" json:"taskType"` + WorkflowInstanceID string `gorm:"column:workflow_instance_id;type:varchar(64)" json:"workflowInstanceId"` + + // Why the task stopped, as the SSH layer put it: the host, login user and the + // interactive auth the owner was asked to answer. + Reason *string `gorm:"column:reason;type:text" json:"reason,omitempty"` + + // Both in milliseconds since the epoch. + PausedAt int64 `gorm:"column:paused_at" json:"pausedAt"` + ContinuedAt *int64 `gorm:"column:continued_at" json:"continuedAt,omitempty"` +} + +// TableName returns the table backing TaskPause. +func (TaskPause) TableName() string { return "task_pauses" } + +// BeforeCreate assigns a UUID when none was supplied. +func (p *TaskPause) BeforeCreate(*gorm.DB) error { + if p.ID == "" { + p.ID = uuid.NewString() + } + return nil +} diff --git a/api/process/model/process.go b/api/process/model/process.go index bedd1f9f2b..ca2334265c 100644 --- a/api/process/model/process.go +++ b/api/process/model/process.go @@ -184,6 +184,9 @@ const ( ProcessStatusTypeCreated ProcessStatusType = "CREATED" ProcessStatusTypeSubmitted ProcessStatusType = "SUBMITTED" ProcessStatusTypeRunning ProcessStatusType = "RUNNING" + // A task is waiting for the owner to complete an interactive SSH login and then + // continue the process (see TaskPause). + ProcessStatusTypePaused ProcessStatusType = "PAUSED" ProcessStatusTypeCompleted ProcessStatusType = "COMPLETED" ProcessStatusTypeFailed ProcessStatusType = "FAILED" ) diff --git a/api/process/repository/pause.go b/api/process/repository/pause.go new file mode 100644 index 0000000000..15d962af0f --- /dev/null +++ b/api/process/repository/pause.go @@ -0,0 +1,80 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package repository + +import ( + "context" + + "gorm.io/gorm" + + model "github.com/apache/airavata/api/process/model" +) + +// TaskPauseRepository reads and writes the pauses of a process's workflows. +type TaskPauseRepository struct{ db *gorm.DB } + +// NewTaskPauseRepository returns a repository backed by db. +func NewTaskPauseRepository(db *gorm.DB) *TaskPauseRepository { return &TaskPauseRepository{db: db} } + +// WithTx returns a repository bound to tx. +func (r *TaskPauseRepository) WithTx(tx *gorm.DB) *TaskPauseRepository { + return &TaskPauseRepository{db: tx} +} + +// Create inserts a pause row. BeforeCreate assigns its id. +func (r *TaskPauseRepository) Create(ctx context.Context, p *model.TaskPause) error { + return r.db.WithContext(ctx).Create(p).Error +} + +// FindByProcessID returns every pause of one process, oldest first. +func (r *TaskPauseRepository) FindByProcessID(ctx context.Context, processID string) ([]model.TaskPause, error) { + var out []model.TaskPause + err := r.db.WithContext(ctx). + Where("process_id = ?", processID). + Order("paused_at"). + Find(&out).Error + return out, err +} + +// FindOpenByProcessID returns the latest pause of one process that has not been +// continued, or gorm.ErrRecordNotFound when its workflows are not waiting. +func (r *TaskPauseRepository) FindOpenByProcessID(ctx context.Context, processID string) (*model.TaskPause, error) { + var out model.TaskPause + err := r.db.WithContext(ctx). + Where("process_id = ? AND continued_at IS NULL", processID). + Order("paused_at DESC"). + First(&out).Error + if err != nil { + return nil, err + } + return &out, nil +} + +// MarkContinued stamps an open pause as continued at continuedAt, reporting false when +// it was not open. The condition is in the update itself, so of two requests racing to +// continue one pause exactly one wins, and the workflow is signalled once. +func (r *TaskPauseRepository) MarkContinued(ctx context.Context, id string, continuedAt int64) (bool, error) { + res := r.db.WithContext(ctx). + Model(&model.TaskPause{}). + Where("task_pause_id = ? AND continued_at IS NULL", id). + Update("continued_at", continuedAt) + return res.RowsAffected == 1, res.Error +} diff --git a/api/process/service/launch.go b/api/process/service/launch.go index 8d3dfaf065..8db83d38d1 100644 --- a/api/process/service/launch.go +++ b/api/process/service/launch.go @@ -142,16 +142,22 @@ func (s *LaunchService) LaunchProcess(ctx context.Context, processID string) (*d return proc, nil } -// requireOwnership allows the run's owner and platform admins. A process with no owner -// belongs to nobody, so it must not match the empty principal name. +// requireOwnership allows the run's owner and platform admins. func (s *LaunchService) requireOwnership(ctx context.Context, proc *dto.Response) error { + return requireOwner(ctx, proc, "Access denied: you may only launch your own processes") +} + +// requireOwner allows the run's owner and platform admins, refusing anyone else with +// denied. A process with no owner belongs to nobody, so it must not match the empty +// principal name. +func requireOwner(ctx context.Context, proc *dto.Response, denied string) error { principal, err := auth.RequireAuthenticated(ctx) if err != nil { return err } owned := proc.UserID != nil && *proc.UserID == principal.Name if !owned && !principal.IsAdmin() { - return httpx.Forbidden("Access denied: you may only launch your own processes") + return httpx.Forbidden("%s", denied) } return nil } diff --git a/api/process/service/pause.go b/api/process/service/pause.go new file mode 100644 index 0000000000..5b2a9b9c95 --- /dev/null +++ b/api/process/service/pause.go @@ -0,0 +1,151 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package service + +import ( + "context" + "errors" + "time" + + "gorm.io/gorm" + + "github.com/apache/airavata/internal/httpx" + "github.com/apache/airavata/internal/orchestration" + "github.com/apache/airavata/internal/ptr" + + dto "github.com/apache/airavata/api/process/dto" + model "github.com/apache/airavata/api/process/model" + "github.com/apache/airavata/api/process/repository" +) + +// PauseService lists the pauses of a process's workflows and continues a paused one. +// +// A workflow pauses when one of its tasks reaches a host that asks the owner for an +// interactive login (see orchestration.ExecutionEngine.runTask). The owner answers the +// login through the interactive auth API, then continues the process here; the paused +// task runs again from the start, logging in afresh if the connection has gone. +type PauseService struct { + db *gorm.DB + pauses *repository.TaskPauseRepository + statuses *repository.StatusRepository + processService *ProcessService + statusService *StatusService + + executionEngine *orchestration.ExecutionEngine +} + +// NewPauseService returns a pause service. +func NewPauseService(db *gorm.DB, pauses *repository.TaskPauseRepository, statuses *repository.StatusRepository, + processService *ProcessService, statusService *StatusService, executionEngine *orchestration.ExecutionEngine) *PauseService { + return &PauseService{ + db: db, + pauses: pauses, + statuses: statuses, + processService: processService, + statusService: statusService, + executionEngine: executionEngine, + } +} + +// ListForProcess returns every pause of a process, oldest first. Not owner-scoped, +// matching the other reads of this package. +func (s *PauseService) ListForProcess(ctx context.Context, processID string) ([]dto.TaskPauseResponse, error) { + if _, err := s.processService.Get(ctx, processID); err != nil { + return nil, err + } + found, err := s.pauses.FindByProcessID(ctx, processID) + if err != nil { + return nil, err + } + return dto.ToTaskPauseResponses(found), nil +} + +// Continue wakes the workflow waiting on a process's open pause, and returns the pause +// it closed. +// +// Owner-scoped like launching, and for the same reason: the task runs again against a +// host under the identity the run was submitted with. A process with nothing paused is +// a conflict. The pause is closed, the status recorded and the workflow signalled in one +// transaction, so a signal that cannot be delivered leaves the pause open to try again. +func (s *PauseService) Continue(ctx context.Context, processID string) (*dto.TaskPauseResponse, error) { + proc, err := s.processService.Get(ctx, processID) + if err != nil { + return nil, err + } + if err := requireOwner(ctx, proc, "Access denied: you may only continue your own processes"); err != nil { + return nil, err + } + + var out dto.TaskPauseResponse + err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { + pause, err := s.pauses.WithTx(tx).FindOpenByProcessID(ctx, processID) + if errors.Is(err, gorm.ErrRecordNotFound) { + return httpx.Conflict("Process %s is not paused", processID) + } + if err != nil { + return err + } + + now := time.Now().UnixMilli() + closed, err := s.pauses.WithTx(tx).MarkContinued(ctx, pause.ID, now) + if err != nil { + return err + } + if !closed { + return httpx.Conflict("Process %s has already been continued", processID) + } + pause.ContinuedAt = &now + + resumed, err := s.statusBeforePause(ctx, tx, processID) + if err != nil { + return err + } + if _, err := s.statusService.RecordTx(ctx, tx, processID, resumed, + ptr.To("Continued after an interactive SSH login")); err != nil { + return err + } + + if err := s.executionEngine.ContinueWorkflow(ctx, pause.WorkflowInstanceID, pause.ID); err != nil { + return err + } + out = dto.ToTaskPauseResponse(pause) + return nil + }) + if err != nil { + return nil, err + } + return &out, nil +} + +// statusBeforePause is the status the process had before its workflow last paused, +// which is what it returns to once continued. +func (s *PauseService) statusBeforePause(ctx context.Context, tx *gorm.DB, processID string) (model.ProcessStatusType, error) { + history, err := s.statuses.WithTx(tx).FindByProcessID(ctx, processID) + if err != nil { + return "", err + } + for i := len(history) - 1; i >= 0; i-- { + if st := history[i].Status; st != nil && *st != model.ProcessStatusTypePaused { + return *st, nil + } + } + return model.ProcessStatusTypeSubmitted, nil +} diff --git a/go.mod b/go.mod index db4c6e7489..722386d3d4 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/flosch/pongo2/v6 v6.1.0 github.com/glebarez/sqlite v1.11.0 github.com/google/uuid v1.6.0 + github.com/stretchr/testify v1.10.0 golang.org/x/crypto v0.52.0 gorm.io/driver/postgres v1.6.0 gorm.io/gorm v1.31.2 @@ -42,7 +43,6 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/go-internal v1.16.0 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/stretchr/testify v1.10.0 // indirect go.opentelemetry.io/otel v1.31.0 // indirect go.opentelemetry.io/otel/metric v1.31.0 // indirect go.opentelemetry.io/otel/sdk v1.31.0 // indirect diff --git a/internal/app/app.go b/internal/app/app.go index d7b88d1642..a81ce88f29 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -105,6 +105,8 @@ type Services struct { // Launch is a higher-level service that orchestrates the other services to submit // a process and its tasks, and to monitor the job until it completes. Launch *processsvc.LaunchService + // Pause continues a process whose workflow is waiting on an interactive login. + Pause *processsvc.PauseService ExecutionEngine *orchestration.ExecutionEngine } @@ -131,6 +133,7 @@ type Repositories struct { JobSubmissionTasks *processrepo.JobSubmissionTaskRepository JobMonitoringTasks *processrepo.JobMonitoringTaskRepository InteractiveCommandTasks *processrepo.InteractiveCommandTaskRepository + TaskPauses *processrepo.TaskPauseRepository } func NewRepositories(db *gorm.DB) *Repositories { @@ -156,6 +159,7 @@ func NewRepositories(db *gorm.DB) *Repositories { JobSubmissionTasks: processrepo.NewJobSubmissionTaskRepository(db), JobMonitoringTasks: processrepo.NewJobMonitoringTaskRepository(db), InteractiveCommandTasks: processrepo.NewInteractiveCommandTaskRepository(db), + TaskPauses: processrepo.NewTaskPauseRepository(db), } } @@ -186,6 +190,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos *Repositories, workflowBa monitoringTasks := repos.JobMonitoringTasks commandTasks := repos.InteractiveCommandTasks batchStatus := repos.BatchJobStatuses + taskPauses := repos.TaskPauses statusSvc := processsvc.NewStatusService(db, statuses, processes) configAccess := computesvc.NewConfigAccess(clusterConfigs, shares, groupMembers) @@ -211,7 +216,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos *Repositories, workflowBa sshCredentialSvc := credentialssvc.NewSSHCredentialService(sshCredentials, users, clusterConfigs, storages) executionEngine := orchestration.NewExecutionEngine(stagingTasks, submissionTasks, - monitoringTasks, storages, clusterConfigs, processes, deployments, templates, batchStatus, statuses, workflowBackend, sshContext) + monitoringTasks, storages, clusterConfigs, processes, deployments, templates, batchStatus, statuses, taskPauses, workflowBackend, sshContext) executionEngine.StartEngine() return &Services{ @@ -257,6 +262,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos *Repositories, workflowBa templateSvc, slurmClusterSvc, slurmClusterConfigSvc, sshCredentialSvc, scpDataStorageSvc, dataProductSvc, statusSvc, stagingTasks, submissionTasks, monitoringTasks, commandTasks, executionEngine), + Pause: processsvc.NewPauseService(db, taskPauses, statuses, processSvs, statusSvc, executionEngine), ExecutionEngine: executionEngine, } diff --git a/internal/db/migrate.go b/internal/db/migrate.go index 528b101e61..aaf02429ca 100644 --- a/internal/db/migrate.go +++ b/internal/db/migrate.go @@ -98,6 +98,9 @@ func Entities() []any { &processmodel.JobSubmissionTask{}, &processmodel.JobMonitoringTask{}, &processmodel.InteractiveCommandTask{}, + + // A workflow parked on one of the tasks above until its owner logs in. + &processmodel.TaskPause{}, } } diff --git a/internal/orchestration/batch.go b/internal/orchestration/batch.go index eb58a24b2c..e95e440a91 100644 --- a/internal/orchestration/batch.go +++ b/internal/orchestration/batch.go @@ -42,7 +42,11 @@ type SubmitBatchJobParameters struct { Environment map[string]string } -func (a *ExecutionEngine) submitBatchJob(ctx context.Context, executionContext *ExecutionContext, processID string, taskID string) (*ExecutionContext, error) { +func (a *ExecutionEngine) submitBatchJob(ctx context.Context, executionContext *ExecutionContext, processID string, taskID string) (_ *ExecutionContext, err error) { + // A host waiting for an interactive login parks the workflow rather than this + // activity: see runTask. + ctx = ssh.WithDeferredInteractiveAuth(ctx) + defer deferInteractiveAuth(&err) slog.Info("Starting to submit batch job", "taskId", taskID, "processId", processID) process, err := a.process(ctx, processID) diff --git a/internal/orchestration/data.go b/internal/orchestration/data.go index 8fc049d61d..0343b55a01 100644 --- a/internal/orchestration/data.go +++ b/internal/orchestration/data.go @@ -32,7 +32,11 @@ import ( ssh "github.com/apache/airavata/internal/ssh" ) -func (a *ExecutionEngine) copyData(ctx context.Context, executionContext *ExecutionContext, processId string, dataStagingTaskId string) (*ExecutionContext, error) { +func (a *ExecutionEngine) copyData(ctx context.Context, executionContext *ExecutionContext, processId string, dataStagingTaskId string) (_ *ExecutionContext, err error) { + // A host waiting for an interactive login parks the workflow rather than this + // activity: see runTask. + ctx = ssh.WithDeferredInteractiveAuth(ctx) + defer deferInteractiveAuth(&err) process, err := a.process(ctx, processId) if err != nil { diff --git a/internal/orchestration/engine.go b/internal/orchestration/engine.go index dcf2904cca..cb33f01cc4 100644 --- a/internal/orchestration/engine.go +++ b/internal/orchestration/engine.go @@ -56,6 +56,7 @@ type ExecutionEngine struct { orchestrator *worker.WorkflowOrchestrator batchStatus *processrepo.BatchJobStatusRepository processStatus *processrepo.StatusRepository + taskPauses *processrepo.TaskPauseRepository sshContext *ssh.GlobalSSHContext } @@ -92,6 +93,7 @@ func NewExecutionEngine(dataStagingTasks *processrepo.DataStagingTaskRepository, templates *applicationrepo.TemplateRepository, batchStatus *processrepo.BatchJobStatusRepository, processStatus *processrepo.StatusRepository, + taskPauses *processrepo.TaskPauseRepository, workflowBackend backend.Backend, sshContext *ssh.GlobalSSHContext, ) *ExecutionEngine { @@ -115,6 +117,7 @@ func NewExecutionEngine(dataStagingTasks *processrepo.DataStagingTaskRepository, orchestrator: orchestrator, batchStatus: batchStatus, processStatus: processStatus, + taskPauses: taskPauses, sshContext: sshContext, } } @@ -133,6 +136,7 @@ func (w *ExecutionEngine) StartEngine() { w.orchestrator.RegisterActivity(w.submitBatchJob) w.orchestrator.RegisterActivity(w.monitorBatchJob) w.orchestrator.RegisterActivity(w.completeProcess) + w.orchestrator.RegisterActivity(w.pauseTask) if err := w.orchestrator.Start(ctx); err != nil { slog.Error("Failed to start execution engine", "error", err) @@ -307,9 +311,9 @@ func (w *ExecutionEngine) handleBatchJobCompletion(ctx workflow.Context, process for _, dst := range dsts { // Attach output staging tasks if dst.TaskOrder != nil && *dst.TaskOrder > *jmt.TaskOrder { - executionContext, err = workflow.ExecuteActivity[*ExecutionContext]( + executionContext, err = w.runTask( ctx, workflow.ActivityOptions{RetryOptions: retryOptions(*dst.OnFailure, *dst.RetryCount)}, - w.copyData, executionContext, processID, dst.ID).Get(ctx) + w.copyData, model.PausedTaskTypeDataStaging, executionContext, processID, dst.ID) if err != nil { slog.Error("Failed processing data staging task", "processId", processID, "taskId", dst.ID, "error", err) return err @@ -373,9 +377,9 @@ func (w *ExecutionEngine) handleBatchJobSubmission(ctx workflow.Context, process for _, dst := range dsts { // tasks are already sorted by their task order. Attach input staging tasks if dst.TaskOrder != nil && *dst.TaskOrder < *jst.TaskOrder { - executionContext, err = workflow.ExecuteActivity[*ExecutionContext]( + executionContext, err = w.runTask( ctx, workflow.ActivityOptions{RetryOptions: retryOptions(*dst.OnFailure, *dst.RetryCount)}, - w.copyData, executionContext, processID, dst.ID).Get(ctx) + w.copyData, model.PausedTaskTypeDataStaging, executionContext, processID, dst.ID) if err != nil { slog.Error("Failed processing data staging task", "processId", processID, "taskId", dst.ID, "error", err) return err @@ -383,9 +387,9 @@ func (w *ExecutionEngine) handleBatchJobSubmission(ctx workflow.Context, process } } - executionContext, err = workflow.ExecuteActivity[*ExecutionContext]( + executionContext, err = w.runTask( ctx, workflow.ActivityOptions{RetryOptions: retryOptions(*jst.OnFailure, *jst.RetryCount)}, - w.submitBatchJob, executionContext, processID, jst.ID).Get(ctx) + w.submitBatchJob, model.PausedTaskTypeJobSubmission, executionContext, processID, jst.ID) if err != nil { slog.Error("Failed processing job submission task", "processId", processID, "taskId", jst.ID, "error", err) return err diff --git a/internal/orchestration/pause.go b/internal/orchestration/pause.go new file mode 100644 index 0000000000..f6858519d4 --- /dev/null +++ b/internal/orchestration/pause.go @@ -0,0 +1,134 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package orchestration + +import ( + "context" + "errors" + "log/slog" + "reflect" + "time" + + workflow "github.com/cschleiden/go-workflows/workflow" + + model "github.com/apache/airavata/api/process/model" + internalptr "github.com/apache/airavata/internal/ptr" + ssh "github.com/apache/airavata/internal/ssh" +) + +// continueSignal is the signal a paused workflow waits on. It carries the id of the +// pause being continued. +const continueSignal = "continue" + +// interactiveAuthErrorType is how an InteractiveAuthRequiredError is named once it has +// crossed the workflow backend, which keeps an error's type name but not its type. +var interactiveAuthErrorType = reflect.TypeOf(ssh.InteractiveAuthRequiredError{}).Name() + +// runTask executes one task activity, parking the workflow whenever the task stops for +// an interactive SSH login until the process is continued through the API. +// +// A continued task runs again from the start. If the login it asked for was answered +// in the meantime, its connection is waiting in the pool; if that connection has since +// been closed, the task dials afresh, which asks for a new login and parks it again. +func (w *ExecutionEngine) runTask(ctx workflow.Context, opts workflow.ActivityOptions, activity workflow.Activity, + taskType model.PausedTaskType, executionContext *ExecutionContext, processID, taskID string) (*ExecutionContext, error) { + resume := workflow.NewSignalChannel[string](ctx, continueSignal) + for { + out, err := workflow.ExecuteActivity[*ExecutionContext](ctx, opts, activity, executionContext, processID, taskID).Get(ctx) + if err == nil || !isInteractiveAuthRequired(err) { + return out, err + } + + instanceID := workflow.WorkflowInstance(ctx).InstanceID + if _, err := workflow.ExecuteActivity[any]( + ctx, workflow.ActivityOptions{RetryOptions: workflow.DefaultRetryOptions}, + w.pauseTask, processID, taskID, taskType, instanceID, err.Error()).Get(ctx); err != nil { + workflow.Logger(ctx).Error("Failed to pause task for interactive login", "processId", processID, "taskId", taskID, "error", err) + return nil, err + } + + pauseID, _ := resume.Receive(ctx) + workflow.Logger(ctx).Info("Continuing paused task", "processId", processID, "taskId", taskID, "pauseId", pauseID) + } +} + +// isInteractiveAuthRequired reports whether an activity failed because a host it dialed +// is waiting for its owner to log in, anywhere along the error's chain. +func isInteractiveAuthRequired(err error) bool { + for ; err != nil; err = errors.Unwrap(err) { + switch e := err.(type) { + case *workflow.Error: + if e.Type == interactiveAuthErrorType { + return true + } + case *ssh.InteractiveAuthRequiredError: + return true + } + } + return false +} + +// deferInteractiveAuth is deferred by a task activity over its named error. A login the +// task is waiting on is turned into a permanent error: retrying would only find the same +// login still unanswered, and runTask parks the workflow on it instead. +func deferInteractiveAuth(err *error) { + var authErr *ssh.InteractiveAuthRequiredError + if *err != nil && errors.As(*err, &authErr) { + *err = workflow.NewPermanentError(*err) + } +} + +// pauseTask records that a task is waiting for its owner to log in, both as an open +// pause the API can continue and as the process's current status. +func (a *ExecutionEngine) pauseTask(ctx context.Context, processID, taskID string, taskType model.PausedTaskType, workflowInstanceID, reason string) error { + now := time.Now().UnixMilli() + if err := a.taskPauses.Create(ctx, &model.TaskPause{ + ProcessID: processID, + TaskID: taskID, + TaskType: taskType, + WorkflowInstanceID: workflowInstanceID, + Reason: &reason, + PausedAt: now, + }); err != nil { + return err + } + + paused := model.ProcessStatusTypePaused + if err := a.processStatus.Create(ctx, &model.ProcessStatus{ + ProcessID: &processID, + Status: &paused, + Log: internalptr.To("Waiting for an interactive SSH login: " + reason), + Timestamp: &now, + }); err != nil { + return err + } + slog.Info("Paused task for interactive login", "processId", processID, "taskId", taskID, "reason", reason) + return nil +} + +// ContinueWorkflow wakes a workflow paused by runTask. The caller is responsible for +// having closed the pause first, so that one pause wakes the workflow once. +func (w *ExecutionEngine) ContinueWorkflow(ctx context.Context, workflowInstanceID, pauseID string) error { + if w.orchestrator == nil { + return ErrNoWorkflowBackend + } + return w.orchestrator.SignalWorkflow(ctx, workflowInstanceID, continueSignal, pauseID) +} diff --git a/internal/orchestration/pause_test.go b/internal/orchestration/pause_test.go new file mode 100644 index 0000000000..1f749c06cd --- /dev/null +++ b/internal/orchestration/pause_test.go @@ -0,0 +1,105 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package orchestration + +import ( + "context" + "fmt" + "sync/atomic" + "testing" + "time" + + "github.com/cschleiden/go-workflows/tester" + workflow "github.com/cschleiden/go-workflows/workflow" + "github.com/stretchr/testify/mock" + + model "github.com/apache/airavata/api/process/model" + ssh "github.com/apache/airavata/internal/ssh" +) + +// loginTaskRuns counts runs of loginTask, which asks for a login on its first run only, +// as a task does whose connection was answered while the workflow was parked. +var loginTaskRuns atomic.Int32 + +func loginTask(ctx context.Context, executionContext *ExecutionContext, processID, taskID string) (_ *ExecutionContext, err error) { + defer deferInteractiveAuth(&err) + if loginTaskRuns.Add(1) == 1 { + return nil, fmt.Errorf("ssh mkdir: %w", &ssh.InteractiveAuthRequiredError{Host: "delta", Port: 22, LoginUser: "alice", AuthID: "auth-1"}) + } + executionContext.SomeData = "done" + return executionContext, nil +} + +// A task that stops for a login parks the workflow, is not retried while parked, and +// runs again once the continue signal arrives. +func TestRunTaskPausesUntilContinued(t *testing.T) { + loginTaskRuns.Store(0) + engine := &ExecutionEngine{} + + wf := func(ctx workflow.Context) (*ExecutionContext, error) { + return engine.runTask(ctx, workflow.ActivityOptions{RetryOptions: retryOptions(model.OnFailureActionRetry, 3)}, + loginTask, model.PausedTaskTypeJobSubmission, &ExecutionContext{}, "proc-1", "task-1") + } + + wt := tester.NewWorkflowTester[*ExecutionContext](wf) + wt.Registry().RegisterActivity(loginTask) + var paused atomic.Bool + wt.OnActivity(engine.pauseTask, mock.Anything, "proc-1", "task-1", model.PausedTaskTypeJobSubmission, mock.Anything, mock.Anything). + Run(func(mock.Arguments) { paused.Store(true) }). + Return(nil).Once() + + wt.ScheduleCallback(time.Minute, func() { + if !paused.Load() { + t.Error("workflow was continued before it paused") + } + if n := loginTaskRuns.Load(); n != 1 { + t.Errorf("task ran %d times while parked, want 1", n) + } + wt.SignalWorkflow(continueSignal, "pause-1") + }) + + wt.Execute(context.Background()) + if !wt.WorkflowFinished() { + t.Fatal("workflow did not finish") + } + out, err := wt.WorkflowResult() + if err != nil { + t.Fatal(err) + } + if out == nil || out.SomeData != "done" || loginTaskRuns.Load() != 2 { + t.Fatalf("task was not run again after continuing: result %+v, runs %d", out, loginTaskRuns.Load()) + } + wt.AssertExpectations(t) +} + +// Only a login is a reason to park: any other failure still fails the task. +func TestIsInteractiveAuthRequired(t *testing.T) { + login := fmt.Errorf("ssh mkdir: %w", &ssh.InteractiveAuthRequiredError{AuthID: "auth-1"}) + if !isInteractiveAuthRequired(login) { + t.Error("a login was not recognised") + } + if !isInteractiveAuthRequired(workflow.NewPermanentError(login)) { + t.Error("a login was not recognised once wrapped for the workflow backend") + } + if isInteractiveAuthRequired(workflow.NewError(fmt.Errorf("ssh mkdir: connection refused"))) { + t.Error("an ordinary failure was taken for a login") + } +} diff --git a/internal/server/server.go b/internal/server/server.go index d7aadecc81..4a44e52358 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -71,6 +71,7 @@ func New(cfg config.Config, svcs *app.Services, introspector auth.Introspector) sharingctl.New(svcs.SlurmClusterConfigSharing, "/api/v1/slurm-cluster-configs", "slurmClusterConfigId").Register(mux) processctl.NewProcessController(svcs.Process).Register(mux) processctl.NewLaunchController(svcs.Launch).Register(mux) + processctl.NewPauseController(svcs.Pause).Register(mux) processctl.NewStatusController(svcs.ProcessStatus).Register(mux) processctl.NewDataStagingTaskController(svcs.DataStagingTask).Register(mux) processctl.NewJobSubmissionTaskController(svcs.JobSubmissionTask).Register(mux) diff --git a/internal/ssh/deferred.go b/internal/ssh/deferred.go new file mode 100644 index 0000000000..e447a31f07 --- /dev/null +++ b/internal/ssh/deferred.go @@ -0,0 +1,56 @@ +package ssh + +import ( + "context" + "fmt" + "time" +) + +// deferredDialTimeout bounds a login left running after its caller stopped waiting on +// it. The server's own LoginGraceTime usually ends an unanswered login well before +// this; the bound is for one that never does, so the dial cannot outlive it for good. +const deferredDialTimeout = 30 * time.Minute + +// InteractiveAuthRequiredError is what a dial under WithDeferredInteractiveAuth returns +// once the host asks for a password or OTP. The login carries on in the background, +// published to the dialing user as a pending interactive auth, so that once it is +// answered the connection is in the pool for the caller's next attempt. +type InteractiveAuthRequiredError struct { + Host string + Port int + LoginUser string + AuthID string +} + +func (e *InteractiveAuthRequiredError) Error() string { + return fmt.Sprintf("%s@%s:%d is waiting for an interactive login (auth %s)", e.LoginUser, e.Host, e.Port, e.AuthID) +} + +type deferredAuthKey struct{} + +// WithDeferredInteractiveAuth marks ctx so that a dial made under it does not wait for +// its owner to answer an interactive login, but returns InteractiveAuthRequiredError as +// soon as one is asked for. It is meant for workflow activities, which should hand the +// wait back to the workflow rather than hold a worker for as long as it takes. +func WithDeferredInteractiveAuth(ctx context.Context) context.Context { + return context.WithValue(ctx, deferredAuthKey{}, true) +} + +func defersInteractiveAuth(ctx context.Context) bool { + deferred, _ := ctx.Value(deferredAuthKey{}).(bool) + return deferred +} + +type authPromptKey struct{} + +// withAuthPromptHook has askUserInteractive call hook with the id of every auth it +// publishes under ctx, which is how the pool learns a dial is waiting on its owner. +func withAuthPromptHook(ctx context.Context, hook func(authID string)) context.Context { + return context.WithValue(ctx, authPromptKey{}, hook) +} + +func notifyAuthPrompt(ctx context.Context, authID string) { + if hook, ok := ctx.Value(authPromptKey{}).(func(string)); ok { + hook(authID) + } +} diff --git a/internal/ssh/pool.go b/internal/ssh/pool.go index 9f2d339dee..78d3373b07 100644 --- a/internal/ssh/pool.go +++ b/internal/ssh/pool.go @@ -49,6 +49,12 @@ type poolEntry struct { err error refs int idle *time.Timer + + // prompted is closed the first time the dial asks its owner for an interactive + // login, and authID names the auth asked most recently. authID is guarded by the + // pool lock. + prompted chan struct{} + authID string } // SSHConnectionPool shares one authenticated connection between every caller dialing @@ -81,13 +87,19 @@ func (c *pooledClient) Close() error { // acquire returns a live connection for dialConfig, dialing one if there is none. // Callers that arrive while a dial is in flight wait for it rather than starting their // own, so concurrent work against one host shares a single login. +// +// Under WithDeferredInteractiveAuth a caller stops waiting once the dial asks for an +// interactive login and gets InteractiveAuthRequiredError instead. A dial such a caller +// starts runs detached from its context, so the login can still be answered after it +// has returned. func (p *SSHConnectionPool) acquire(ctx context.Context, dialConfig SSHDialConfig, dial func(context.Context) (*gossh.Client, error)) (*pooledClient, error) { key := poolKeyFor(dialConfig) + deferred := defersInteractiveAuth(ctx) for { p.lock.Lock() entry, ok := p.entries[key] if !ok { - entry = &poolEntry{ready: make(chan struct{})} + entry = &poolEntry{ready: make(chan struct{}), prompted: make(chan struct{})} p.entries[key] = entry } entry.refs++ @@ -98,12 +110,44 @@ func (p *SSHConnectionPool) acquire(ctx context.Context, dialConfig SSHDialConfi p.lock.Unlock() if !ok { - client, err := dial(ctx) - p.settle(key, entry, client, err) + hook := func(authID string) { p.markPrompted(entry, authID) } + if deferred { + dialCtx, cancel := context.WithTimeout(withAuthPromptHook(context.WithoutCancel(ctx), hook), deferredDialTimeout) + go func() { + defer cancel() + client, err := dial(dialCtx) + p.settle(key, entry, client, err) + }() + } else { + client, err := dial(withAuthPromptHook(ctx, hook)) + p.settle(key, entry, client, err) + } + } + + // A nil channel never fires, so only a deferring caller hears the prompt. + var prompted <-chan struct{} + if deferred { + prompted = entry.prompted } select { case <-entry.ready: + case <-prompted: + // A login answered by now has nothing left to wait for, so ready wins a tie. + select { + case <-entry.ready: + default: + p.lock.Lock() + authID := entry.authID + p.lock.Unlock() + p.release(key, entry) + return nil, &InteractiveAuthRequiredError{ + Host: dialConfig.host, + Port: dialConfig.port, + LoginUser: dialConfig.sshUsername, + AuthID: authID, + } + } case <-ctx.Done(): p.release(key, entry) return nil, ctx.Err() @@ -129,6 +173,10 @@ func (p *SSHConnectionPool) settle(key poolKey, entry *poolEntry, client *gossh. if entry.err != nil { // A failed dial is not cached: the next caller should try again. p.evictLocked(key, entry) + } else if entry.refs == 0 { + // Everyone who wanted it stopped waiting during an interactive login. It is + // kept for whoever asks next, on the same clock as a connection handed back. + p.idleLocked(key, entry) } p.lock.Unlock() close(entry.ready) @@ -138,6 +186,20 @@ func (p *SSHConnectionPool) settle(key poolKey, entry *poolEntry, client *gossh. } } +// markPrompted records that entry's dial is waiting on its owner to answer authID, and +// wakes the callers deferring that wait. Only the first prompt wakes anyone; a later one +// in the same login, an OTP after a password say, just updates the id. +func (p *SSHConnectionPool) markPrompted(entry *poolEntry, authID string) { + p.lock.Lock() + defer p.lock.Unlock() + entry.authID = authID + select { + case <-entry.prompted: + default: + close(entry.prompted) + } +} + // watch drops the entry once its connection dies, whether the server closed it or the // keepalive gave up on it, so the next caller dials afresh instead of failing. func (p *SSHConnectionPool) watch(key poolKey, entry *poolEntry) { @@ -196,6 +258,12 @@ func (p *SSHConnectionPool) release(key poolKey, entry *poolEntry) { if entry.refs > 0 || entry.client == nil { return } + p.idleLocked(key, entry) +} + +// idleLocked closes entry's connection after poolIdleTimeout unless a caller takes it +// first. The caller holds the pool lock. +func (p *SSHConnectionPool) idleLocked(key poolKey, entry *poolEntry) { var timer *time.Timer timer = time.AfterFunc(poolIdleTimeout, func() { p.lock.Lock() diff --git a/internal/ssh/pool_test.go b/internal/ssh/pool_test.go index 57e35537df..cd786d0567 100644 --- a/internal/ssh/pool_test.go +++ b/internal/ssh/pool_test.go @@ -206,3 +206,57 @@ func TestPoolDoesNotCacheFailedDials(t *testing.T) { t.Fatal("failed dial was cached") } } + +func TestPoolDefersInteractiveLogin(t *testing.T) { + pool := newSSHConnectionPool() + defer pool.Close() + var dials atomic.Int32 + connect := pipeDialer(t, &dials) + + // Stands in for a login that asks its owner for an OTP: it waits for an answer + // that only arrives once the deferring caller has already returned. + answer := make(chan struct{}) + dial := func(ctx context.Context) (*gossh.Client, error) { + notifyAuthPrompt(ctx, "auth-1") + select { + case <-answer: + case <-ctx.Done(): + return nil, ctx.Err() + } + return connect(ctx) + } + + ctx, cancel := context.WithCancel(WithDeferredInteractiveAuth(t.Context())) + _, err := pool.acquire(ctx, testDialConfig(), dial) + var authErr *InteractiveAuthRequiredError + if !errors.As(err, &authErr) || authErr.AuthID != "auth-1" { + t.Fatalf("got %v, want an InteractiveAuthRequiredError for auth-1", err) + } + // The caller's context ending must not take the login with it. + cancel() + + // A second deferring caller joins the pending login rather than starting another. + if _, err := pool.acquire(WithDeferredInteractiveAuth(t.Context()), testDialConfig(), dial); !errors.As(err, &authErr) { + t.Fatalf("got %v, want an InteractiveAuthRequiredError", err) + } + + close(answer) + for range 100 { + pool.lock.Lock() + entry := pool.entries[poolKeyFor(testDialConfig())] + settled := entry != nil && entry.client != nil + pool.lock.Unlock() + if settled { + break + } + time.Sleep(10 * time.Millisecond) + } + + c, err := pool.acquire(WithDeferredInteractiveAuth(t.Context()), testDialConfig(), dial) + if err == nil { + defer c.Close() + } + if err != nil || dials.Load() != 1 { + t.Fatalf("answered login was not reused: err %v, dials %d", err, dials.Load()) + } +} diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go index 5882cd26ad..af9ba0a47a 100644 --- a/internal/ssh/ssh.go +++ b/internal/ssh/ssh.go @@ -531,5 +531,6 @@ func askUserInteractive(ctx context.Context, dialConfig SSHDialConfig, sshContex auth.name, auth.instruction, auth.prompts = name, instruction, prompts sshContext.InteractiveAuthStore.AddAuth(auth) defer sshContext.InteractiveAuthStore.RemoveAuth(dialConfig.userId, auth.AuthId) + notifyAuthPrompt(ctx, auth.AuthId) return auth.Challenge(ctx, name, instruction, prompts) }
