Documentation
¶
Overview ¶
Package tooltask implements admission and execution of typed background tool tasks.
Index ¶
- func Eligible(name tool.Name) bool
- type Completion
- type CompletionHook
- type Invocation
- type Service
- func (service *Service) AttachRuntime(runtime *taskruntime.Service)
- func (service *Service) Cancel(ctx context.Context, owner, taskID string) (*database.ToolTaskEntity, bool, error)
- func (service *Service) Get(ctx context.Context, owner, id string) (*database.ToolTaskEntity, bool, error)
- func (service *Service) Kind() string
- func (service *Service) List(ctx context.Context, owner string, states []database.TaskState, limit int) ([]database.ToolTaskEntity, error)
- func (service *Service) RecoverExpired(ctx context.Context, expiresBefore time.Time) error
- func (service *Service) ReleaseAdmission(taskID string)
- func (service *Service) Run(ctx context.Context, task *database.TaskEntity, _ taskruntime.EventSink) (taskruntime.Outcome, error)
- func (service *Service) SetCompletionHook(hook CompletionHook)
- func (service *Service) Settle(ctx context.Context, finish *database.TaskFinish, outcome taskruntime.Outcome) (bool, error)
- func (service *Service) Start(ctx context.Context, request *StartRequest) (*database.ToolTaskEntity, error)
- func (service *Service) SubscribeCompletions() (events <-chan Completion, cancel func())
- func (service *Service) TryAdmit(ctx context.Context, task *database.TaskEntity) (bool, error)
- func (service *Service) Wait(ctx context.Context, owner, taskID string) (*database.ToolTaskEntity, error)
- type StartRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Completion ¶
type Completion struct {
Err error
Arguments tool.Arguments
TaskID string
InvocationID string
WrapperCallID string
ParentCallID string
OwnerSessionID string
Target string
ArgumentsJSON string
Result tool.Result
SourceSequence int
}
Completion is the canonical target outcome presented to lifecycle hooks.
type CompletionHook ¶
type CompletionHook func(context.Context, *Completion) error
CompletionHook applies assistant lifecycle semantics in the surviving worker.
type Invocation ¶
type Invocation struct {
ID string
WrapperCallID string
ParentCallID string
OwnerSessionID string
CWD string
InitiatingEntryID string
SourceSequence int
}
Invocation is immutable assistant metadata used for idempotent durable acceptance.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service admits tasks and reconstructs built-in executors in workers.
func New ¶
func New( repository *database.ToolTaskRepository, coordinator *tool.Coordinator, defaultTimeout time.Duration, maxTimeout time.Duration, maxOutcomeBytes int, ) *Service
New constructs a background tool task service.
func (*Service) AttachRuntime ¶
func (service *Service) AttachRuntime(runtime *taskruntime.Service)
AttachRuntime connects the scheduler used to wake and cancel task execution.
func (*Service) Cancel ¶
func (service *Service) Cancel(ctx context.Context, owner, taskID string) (*database.ToolTaskEntity, bool, error)
Cancel requests cancellation of an owner-scoped task.
func (*Service) Get ¶
func (service *Service) Get(ctx context.Context, owner, id string) (*database.ToolTaskEntity, bool, error)
Get returns an owner-scoped task snapshot.
func (*Service) List ¶
func (service *Service) List( ctx context.Context, owner string, states []database.TaskState, limit int, ) ([]database.ToolTaskEntity, error)
List returns an owner's tasks, optionally filtered by state.
func (*Service) RecoverExpired ¶
RecoverExpired interrupts tasks whose worker leases have expired.
func (*Service) ReleaseAdmission ¶
ReleaseAdmission abandons any pre-claim reservation that was not consumed.
func (*Service) Run ¶
func (service *Service) Run( ctx context.Context, task *database.TaskEntity, _ taskruntime.EventSink, ) (taskruntime.Outcome, error)
Run reconstructs and executes a durably admitted tool invocation.
func (*Service) SetCompletionHook ¶
func (service *Service) SetCompletionHook(hook CompletionHook)
SetCompletionHook installs the process lifecycle bridge before workers start.
func (*Service) Settle ¶
func (service *Service) Settle( ctx context.Context, finish *database.TaskFinish, outcome taskruntime.Outcome, ) (bool, error)
Settle atomically persists the canonical outcome and terminal transition.
func (*Service) Start ¶
func (service *Service) Start(ctx context.Context, request *StartRequest) (*database.ToolTaskEntity, error)
Start validates and durably admits a background tool invocation.
func (*Service) SubscribeCompletions ¶
func (service *Service) SubscribeCompletions() (events <-chan Completion, cancel func())
SubscribeCompletions follows canonical outcomes after their terminal state is durably committed. Delivery is best effort and never blocks workers; Get remains the authoritative repair path.
func (*Service) TryAdmit ¶
TryAdmit reserves mutation resources before the authoritative task claim. Saturated resources leave the durable task queued rather than occupying a worker. A true result may accompany an error: admission succeeded, and the caller must continue dispatch so Run can durably settle the reported definition drift.
type StartRequest ¶
type StartRequest struct {
Admit func(context.Context, *StartRequest) error
Arguments tool.Arguments
Target string
Invocation Invocation
Timeout time.Duration
}
StartRequest requests asynchronous execution of an ordinary built-in tool.