Documentation
¶
Index ¶
- Variables
- type CreateRunCmd
- type CreateTaskCmd
- type QuotaChecker
- type RetryResult
- type RetryRunCmd
- type Service
- func (s *Service) AdmitWorkflowTask(ctx context.Context, cmd CreateTaskCmd) (*coretask.Task, error)
- func (s *Service) Admits(ctx context.Context, spaceID string) error
- func (s *Service) CreateRun(ctx context.Context, cmd CreateRunCmd) (*coretask.Run, error)
- func (s *Service) CreateTask(ctx context.Context, cmd CreateTaskCmd) (*coretask.Task, error)
- func (s *Service) GetTaskInConversation(ctx context.Context, conversationID, taskID string) (*coretask.Task, error)
- func (s *Service) RetryRun(ctx context.Context, cmd RetryRunCmd) (*RetryResult, error)
- func (s *Service) StartBackgroundTask(ctx context.Context, cmd CreateTaskCmd) (*StartBackgroundTaskResult, error)
- type StartBackgroundTaskResult
- type WorkflowStepLookup
Constants ¶
This section is empty.
Variables ¶
var ( ErrInputRequired = apierr.New(apierr.KindInvalid, "input required") ErrAgentsNotConfigured = apierr.New(apierr.KindNotConfigured, "agents not configured") ErrTasksNotConfigured = apierr.New(apierr.KindNotConfigured, "tasks not configured") ErrTaskRunsNotConfigured = apierr.New(apierr.KindNotConfigured, "task runs not configured") ErrAgentNotFound = apierr.New(apierr.KindInvalid, "agent not found") ErrTaskNotFound = apierr.New(apierr.KindNotFound, "task not found") // ErrAdmissionKeyRequired guards AdmitWorkflowTask: idempotent admission is // meaningless without a key, so an empty one is a caller error rather than a // silent fall-through to a plain create. ErrAdmissionKeyRequired = apierr.New(apierr.KindInvalid, "admission key required") // ErrNoRunToRetry means the task has no finished run to repeat: it has // never run, or its only run is still in flight. ErrNoRunToRetry = apierr.New(apierr.KindConflict, "this task has no finished run to retry") // ErrRetryOfWorkflowStep means the task belongs to a workflow step. The // workflow owns that task's lifecycle — it reacts to the step run's // outcome — so a run started behind its back would mark a settled step // succeeded and dispatch the next step of a workflow run that is already // over. ErrRetryOfWorkflowStep = apierr.New(apierr.KindConflict, "this run belongs to a workflow step and cannot be retried on its own") )
Functions ¶
This section is empty.
Types ¶
type CreateRunCmd ¶
type CreateRunCmd struct {
UserID string
TaskID string
Input string
CreatedByType string
TriggerSource string
// RetryOfTaskRunID names the run this one repeats, when it repeats one.
RetryOfTaskRunID *string
// SourceMessageID names the conversation message that asked for this run.
SourceMessageID *string
// IdempotencyKey is the caller's dedup key for this Continue request. A
// repeat with the same key on the same task returns the run the first call
// created instead of starting a second one.
IdempotencyKey *string
}
CreateRunCmd creates a new run on an existing task.
type CreateTaskCmd ¶
type CreateTaskCmd struct {
ConversationID string
UserID string
SpaceID string
Input string
AgentID *string
IssueID *string
// ScheduleID names the recurring time trigger that created this task, when a
// schedule dispatcher admitted it. An origin relation, never an owner.
ScheduleID *string
CreatedByType string
TriggerSource string
// SourceMessageID names the conversation message that asked for this task.
SourceMessageID *string
// AdmissionKey, when set, makes creation idempotent through AdmitWorkflowTask:
// a replayed or concurrent dispatch under the same key resolves to the one
// task instead of a duplicate. Empty for ordinary CreateTask callers.
AdmissionKey string
}
CreateTaskCmd creates a new task and its first run.
type QuotaChecker ¶
type QuotaChecker interface {
Check(ctx context.Context, spaceID string, runsToAdd, tokensToAdd int) (allowed bool, reason string, err error)
}
QuotaChecker is the narrow quota surface needed by task workflows.
type RetryResult ¶
RetryResult reports the new run and the one it repeats.
type RetryRunCmd ¶
RetryRunCmd repeats a task's most recent run.
type Service ¶
type Service struct {
Agents agentdef.Store
Tasks coretask.Store
TaskRuns coretask.RunStore
QuotaChecker QuotaChecker
TitleGenerator llm.TitleGenerator
// WorkflowSteps is only consulted by RetryRun. Callers that never retry
// leave it nil.
WorkflowSteps WorkflowStepLookup
}
Service owns task-related application workflows.
func (*Service) AdmitWorkflowTask ¶
AdmitWorkflowTask idempotently creates a Workflow node's task, keyed by cmd.AdmissionKey, so a coordinator that retries or races its dispatch — the crash window between admitting the task and recording the step link — resolves to the one task instead of a second execution. It is otherwise CreateTask: it resolves the same input, agent, and provenance and applies the same rules.
func (*Service) Admits ¶
Admits reports whether the space can start one more run right now, before a caller writes anything a refusal would strand.
CreateTask checks the same run allowance when it persists the task, but an orchestrator that opens a conversation first and asks afterwards leaves one behind on every refusal, and nothing deletes a conversation. Asking here keeps that refusal ahead of the first write.
The run allowance is the whole gate. A task is no longer refused for the tokens its generated title spent: those are already spent by the time the title exists, so refusing then only stranded a conversation. CreateTask records the title's tokens as usage instead of gating on them.
func (*Service) CreateRun ¶
CreateRun enforces basic run creation rules and delegates to TaskRunStore.
func (*Service) CreateTask ¶
CreateTask resolves input, applies title/quota rules, and persists a new task.
func (*Service) GetTaskInConversation ¶
func (s *Service) GetTaskInConversation(ctx context.Context, conversationID, taskID string) (*coretask.Task, error)
GetTaskInConversation reads a task and confirms it belongs to conversationID. A task in another conversation is reported as not found, because a conversation may only see its own tasks. This is the one place that scoping is decided, so a caller that already holds the Service does not reach past it into the store to re-check ConversationID.
func (*Service) RetryRun ¶
func (s *Service) RetryRun(ctx context.Context, cmd RetryRunCmd) (*RetryResult, error)
RetryRun repeats a task's most recent run with the same input.
The input comes from the run rather than the task because a task's later runs can carry follow-up instructions, and retrying means running that again — not running whatever the task was first asked to do.
A run still in flight is not retried: one task holds at most one active run, and the answer to "it is taking too long" is to stop it first.
func (*Service) StartBackgroundTask ¶
func (s *Service) StartBackgroundTask(ctx context.Context, cmd CreateTaskCmd) (*StartBackgroundTaskResult, error)
StartBackgroundTask creates a task and returns its task/run ids.
type StartBackgroundTaskResult ¶
StartBackgroundTaskResult is returned when a background task is created.
type WorkflowStepLookup ¶
type WorkflowStepLookup interface {
GetWorkflowStepRunByTaskID(ctx context.Context, taskID string) (*coreworkflow.StepRun, error)
}
WorkflowStepLookup answers whether a task is a workflow step's task. It is optional: a deployment with no workflow store has no workflow steps, so a nil lookup means nothing to protect rather than an unanswered question.