tasks

package
v0.1.90-dev.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tasks is the owner's scheduled tasks (mistgate.tasks.v1, design/adr/0017-agent-operable-fleet.md section 5): the TasksService, the scheduler that runs the tasks, and the two runners.

  • A check task runs its steps, MCP tools of the operator profile, in process through the same MCP server as an outside agent (scrubbed results, the panel's rate limits, the audit), with the hidden identity of the owner's scheduled tasks (store.ScheduledTokenID). No model is involved: each step's conditions are tested on the tool's JSON result.
  • An assistant task gives its prompt to the assistant (assistant.Service.RunScheduled), same identity and profile.

The same scheduler runs the assistant's follow-ups (follow_up.go): one-time continuations of a conversation, held under a lease of their own so each runs once.

The scheduler wakes every 20 seconds (and at once after a change), takes the due tasks, and starts a run of each that no run holds: a lease in the task's row means one run of a task at a time, and the run row is written with it. Runs are bounded (a check run 5 minutes, an assistant run assistant.ScheduledRunLimit) and at most two check runs and one assistant run go at a time. A run that ends gives the lease back with the next time from now, so a task the panel missed while it was down runs once on start, not once per missed time. A run a stopped panel left behind reads as interrupted when it starts again.

A run that found a problem, and a task that failed three runs in a row, are alert conditions the health evaluator reads (Conditions): SCHEDULED_CHECK and SCHEDULED_TASK_FAILING, which close themselves with a clean run.

The Cloudflare edition has none of it: the package is not linked into its Workers, and the app mounts a stub that answers UNIMPLEMENTED (internal/panel/app/tasks_wiring_js.go).

Index

Constants

View Source
const (
	AlertProblem = "scheduled_check"
	AlertFailing = "scheduled_task_failing"
)

Alert kinds the tasks raise through the health evaluator (health.AddConditionSource).

Variables

This section is empty.

Functions

func CheckToolName

func CheckToolName(name string) bool

CheckToolName reports whether a tool of the operator profile may be a step of a check: not a plan, not an apply, not a task tool.

func DefinitionOf

func DefinitionOf(in *tasksv1.TaskInput) spec.Definition

DefinitionOf is a TaskInput as the spec package checks it.

func InputOf

func InputOf(d spec.Definition) *tasksv1.TaskInput

InputOf is a definition as the API carries it.

func LooksSecret

func LooksSecret(text string) bool

LooksSecret rejects task text the scrubber would change or that carries a credential label.

func PromptAAD

func PromptAAD(id string) string

PromptAAD is the vault's associated data of a task's prompt.

func RunProto

RunProto is a run as the API carries it.

func ScheduleProto

func ScheduleProto(sc spec.Schedule) *tasksv1.Schedule

ScheduleProto is a schedule as the API carries it.

Types

type Assistant

Assistant runs a scheduled assistant task (assistant.Service.RunScheduled) and a follow-up the assistant set in a conversation (RunFollowUp).

type Config

type Config struct {
	Store *store.Store
	Vault *vault.Vault
	// Assistant runs the assistant tasks and the follow-ups; nil: the tasks are skipped (assistant_off), no follow-up runs.
	Assistant Assistant
	Now       func() time.Time
	Log       *slog.Logger
	// Tick is how often the scheduler looks for due tasks (20 s).
	Tick time.Duration
}

Config configures Service.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the TasksService and the scheduler.

func New

func New(cfg Config) *Service

New returns the service. Run starts the scheduler.

func (*Service) Conditions

func (s *Service) Conditions(ctx context.Context) []health.ExtCond

Conditions is the health condition source (health.Service.AddConditionSource): SCHEDULED_CHECK for an enabled task whose last finished run found a problem, SCHEDULED_TASK_FAILING for one that failed three runs in a row. Both close when the condition goes: a clean run, the task disabled or deleted.

func (*Service) Handler

func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)

Handler is the Connect handler, mounted at /api/mistgate.tasks.v1.TasksService/ behind the session middleware.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run is the scheduler: it ends the runs a stopped panel left, then starts the due tasks every tick until ctx ends, and waits for the runs in progress (they end as interrupted).

func (*Service) SetToolRuntime

func (s *Service) SetToolRuntime(r mcp.AssistantRuntime)

SetToolRuntime installs the in-process MCP server once the admin API is assembled (the assistant's, internal/panel/app).

Directories

Path Synopsis
Package spec is what a scheduled task is (mistgate.tasks.v1): its schedule and when it runs next, the steps of a check task and the conditions on their results, and the limits every definition is checked against.
Package spec is what a scheduled task is (mistgate.tasks.v1): its schedule and when it runs next, the steps of a check task and the conditions on their results, and the limits every definition is checked against.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL