Documentation
¶
Overview ¶
Package taskrun provides task-run execution.
RunTask executes a single run in-process: materialize workspace, optionally restore session from the previous run, run the agent runtime, persist outputs, and update run state via TaskRunUpdater.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunTask ¶
func RunTask(ctx context.Context, input RunTaskInput) error
RunTask runs a single task run: materialize workspace, optionally restore session from previous run, execute agent in-process, upload run state to blob, update run and task via updater. If input.StreamSender is non-nil, stdout is streamed to the server as deltas; full output is still accumulated for persist and PATCH.
The cause on a dead ctx says which of three things happened. ErrRunCanceled means someone asked this run to stop: it is recorded as CANCELED, keeps the output and artifacts it had produced, and RunTask returns ErrRunCanceled. ErrRunInterrupted means the process was asked to stop while the run was working: it keeps the same evidence but is recorded as FAILED, because nothing chose to stop it and it did not finish. Any other end of ctx is the process going away without warning, which is not this run's outcome to report — the stale-run reaper closes those.
Types ¶
type ManagedInference ¶
type ManagedInference struct {
// ServerURL is the BuildMax server that minted RunToken. A managed entry
// naming any other server is refused rather than sent this credential.
ServerURL string
// RunToken authorizes this one run's inference calls.
RunToken string
}
ManagedInference is what a run needs to reach the managed LLM gateway instead of a provider.
It is separate from Model because it is a credential, not configuration: the model entry says which alias to call, and this says what authorizes the call. The zero value means the run uses a direct model and holds a provider key.
Mirrors the design in docs/design/worker-run-token.md.
func (ManagedInference) Enabled ¶
func (m ManagedInference) Enabled() bool
Enabled reports whether this run can reach the gateway.
type RunTaskInput ¶
type RunTaskInput struct {
Task *coretask.Task
// AdditionalSystemPrompt is the instruction text of the agent this task names, resolved by
// the server for this run. It becomes the last layer of the system prompt, where it is
// re-sent whole on every call, instead of riding in the task input where compaction
// eventually drops it.
AdditionalSystemPrompt string
SpaceAgentInstructions string
Run *coretask.Run
SessionID string
Paths RuntimePaths
Persist blob.PersistStorage
RunOutputStorage blob.RunOutputStorage
Updater TaskRunUpdater
StreamSender workerclient.StreamSender
Model config.ModelEntry
Managed ManagedInference
// ManagedHTTPClient carries the worker's server trust to managed inference,
// which reaches the gateway on the same internal listener as every other
// worker call. Nil uses http.DefaultClient, which is correct only for a
// plain-HTTP development server. See
// docs/design/worker-api-network-boundary.md §6.
ManagedHTTPClient *http.Client
// WorkerAPI is how this run reaches the server it was dispatched by. Its
// zero value leaves the run without the artifact capability, so the agent
// gets no artifact tool rather than one that always fails.
WorkerAPI workerclient.WorkerAPIClientConfig
// Plugins are the releases the server resolved for this run. They are
// materialized into the run's BUILDMAX_HOME before the runtime is
// assembled; a pin that cannot be materialized fails the run.
Plugins []coreplugin.Pin
// SandboxNetworkTier and SandboxFilesystemTier are this run's agent-
// declared sandbox tiers, resolved by the server when the worker claimed
// the run. Empty means the strictest tier on that axis. See
// docs/design/agent-sandbox-policy.md.
SandboxNetworkTier config.SandboxNetworkTier
SandboxFilesystemTier config.SandboxFilesystemTier
// SecretEnvGrants are this run's resolved Space Secret grants, variable name
// to value, computed by the server from the agent's consumption config.
// They are set in the run's environment and their names are allow-listed
// past env scrubbing. Empty when the agent consumes no Secret. See
// docs/design/space-secrets.md §8.2.
SecretEnvGrants map[string]string
// InterruptGrace is how long this run may spend reporting after its process
// is asked to stop. Zero uses interruptReportTimeout. A dispatcher that will
// kill the worker on its own deadline passes that deadline here, so the run
// stops reporting before it is killed mid-upload rather than after.
InterruptGrace time.Duration
}
RunTaskInput holds all inputs for RunTask. Callers build this struct and pass it to RunTask.
type RuntimePaths ¶
type RuntimePaths interface {
RuntimeTaskRunDir(spaceID, taskID, taskRunID string) string
RuntimeTaskRunWorkspaceDir(spaceID, taskID, taskRunID string) string
RuntimeTaskRunGlobalDir(spaceID, taskID, taskRunID string) string
}
RuntimePaths provides the space-owned filesystem layout for tasks and runs. It is injected for testability and to avoid hard dependency on internal/config.
func NewRuntimePathsFromRoot ¶
func NewRuntimePathsFromRoot(root string) RuntimePaths
NewRuntimePathsFromRoot returns a RuntimePaths that uses root as the parent of all space dirs.
type TaskRunUpdater ¶
type TaskRunUpdater interface {
UpdateRunStatus(ctx context.Context, taskRunID string, req *workerclient.PatchTaskRunRequest) error
}
TaskRunUpdater is used by the worker to update run status and register artifacts via HTTP. When status is SUCCEEDED with artifact, server creates artifact and syncs task denormalized fields. When status is FAILED, server syncs task denormalized from run.