execution

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 34 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 execution delivers durable Turns through the existing daemon protocol.

Index

Constants

View Source
const DefaultExecutionConcurrency = 4

Variables

View Source
var (
	ErrEnvironmentInputExpired   = errors.New("environment input expired before admission")
	ErrEnvironmentInputCancelled = errors.New("environment input cancelled before admission")
	ErrExecutionUnavailable      = errors.New("execution ownership is unavailable")
)
View Source
var (
	ErrEnvironmentFileDirectory = fmt.Errorf("%w: environment file destination is a directory", sessions.ErrInvalidInput)
	ErrEnvironmentFileUnsafe    = fmt.Errorf("%w: environment file destination exists or traverses a link", sessions.ErrInvalidInput)
)

Known Files.create destination refusals reported by the Runtime installer. They wrap sessions.ErrInvalidInput; the rejected write installed nothing.

View Source
var ErrModelProviderRequired = errors.New("the Session has no model provider")

ErrModelProviderRequired reports a hosted or self-hosted Session that has no frozen model provider and therefore cannot run.

View Source
var ErrWhitespaceOnlyText = errors.New("whitespace-only message text is not supported by this harness")

ErrWhitespaceOnlyText is a declared native limitation reported before any write, reservation or promotion.

Functions

func LocalWorkspaceConfiguration

func LocalWorkspaceConfiguration(configuration json.RawMessage) bool

LocalWorkspaceConfiguration recognizes the qualified stored V1 profile. It does not provision a Runtime, validate live authority, or admit hosted creation.

Types

type Credentials

type Credentials interface {
	MCPBearerToken(context.Context, vaults.MCPBearerToken) (string, error)
}

Credentials opens the bearer token of a Session's frozen MCP credential binding.

type Dispatcher

type Dispatcher struct {
	Policy
	Store    *store.Store
	Registry *runtimegateway.Registry
	// Credentials opens the bearer tokens of authenticated MCP servers.
	Credentials Credentials
	// Observer records which deployment default model configurations committed
	// root Turns used. It is required.
	Observer modelconfiguration.Observer
	// Deployment reads the sandbox deployment and prepares a selection's setup.
	// It is required; deployment changes go through Owner.Deployment.
	Deployment *deployment.Service
	// DeploymentReader reads the deployment's pooled records, such as the
	// Sessions a reset still has to archive. It is required.
	DeploymentReader deployment.Reader
	// Sessions runs the pooled Session use cases, such as staging a Turn's
	// Artifacts. It is required.
	Sessions *sessions.Service
	// SessionsReader serves the plain Session reads. It is required.
	SessionsReader sessions.Reader
	// ManagedRuntimes is optional internal provisioning; it does not admit hosted API requests.
	ManagedRuntimes *RuntimeProvider
	// MaxConcurrentExecutions bounds work admitted by this Core execution owner.
	// Zero uses DefaultExecutionConcurrency. It is independent of sandbox capacity.
	MaxConcurrentExecutions int
	// contains filtered or unexported fields
}

func (*Dispatcher) Bind

func (d *Dispatcher) Bind(owner Owner) (*Dispatcher, error)

Bind returns a copy of d bound to owner's execution operations. StartWorker binds through it; a Dispatcher that runs Turns outside a Worker binds the same way.

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context, tenantID, sessionID, turnID string) (sessions.Turn, error)

Run claims once before subscribing or sending. Uncertain deliveries are not replayed.

func (*Dispatcher) RunEnvironmentInput

func (d *Dispatcher) RunEnvironmentInput(ctx context.Context, lease Ownership, tenantID, sessionID, reservationID string) (run EnvironmentRun, err error)

RunEnvironmentInput reserves a Turn on the Session-owned Runtime Executor. It checks lease, the lease d.Store was built on, before any Runtime preparation.

type EnvironmentRun

type EnvironmentRun struct {
	Reservation sessions.EnvironmentInputReservation
	Turn        sessions.Turn
}

type Owner

type Owner struct {
	Lease      Ownership
	Store      *store.Store                    // the remaining store execution operations, built by store.NewExecution(s, lease)
	Deployment *deployment.ExecutionOperations // sandbox deployment changes on the lease-bound deploymentpg storage
	Sessions   *sessions.ExecutionOperations   // Session execution operations on the lease-bound sessionpg storage
}

Owner is everything bound to one execution lease. Later cutovers add one explicit field per domain's execution operations and delete the matching store calls.

type Ownership

type Ownership interface {
	CheckOwnership(context.Context) error
	CancelOperations(context.Context, context.CancelFunc) error
	Close(context.Context) error
}

Ownership is the execution lease as the Worker uses it. *pgunit.Lease implements it.

type Policy

type Policy struct {
	Engines engine.Catalog
}

Policy supplies immutable service qualification to admission and dispatch. The zero value uses built-in profiles. Custom composition must supply the same policy to the HTTP handler and Dispatcher; Runtime claims never add profiles.

func (Policy) ValidateSessionConfiguration

func (p Policy) ValidateSessionConfiguration(engine string, configuration json.RawMessage) error

ValidateSessionConfiguration checks engine placement and configuration before persistence.

type PreparedRuntimeDeployment

type PreparedRuntimeDeployment struct {
	Config           *RuntimeProvider
	Publish          func(*RuntimeProvider)
	Selection        *sandbox.Selection
	VerifyCredential func(context.Context) error
	FenceCredential  func(context.Context) (func(), error)
}

PreparedRuntimeDeployment has completed provider validation without publishing a selection. Publish must only update in-memory state and must not fail. Selection is the resolved typed configuration returned by preparation.

type Result

type Result struct {
	EngineErrorCode  string            `json:"engine_error_code,omitempty"`
	EngineHTTPStatus *int              `json:"engine_http_status,omitempty"`
	Done             proto.DonePayload `json:"done"`
	ErrorCode        string            `json:"error_code,omitempty"`
	Error            string            `json:"error,omitempty"`
	AppliedThrough   int64             `json:"applied_through"`
}

type RuntimeProvider

type RuntimeProvider struct {
	// PublishUnconfigured updates the shared observation cache after reset commit.
	PublishUnconfigured func(uint64)
	Generation          uint64
	Mode                string

	ProviderKind                     string
	LocalNodeID                      string
	LocalCredentialSHA256            string
	LocalMaxActive, LocalMaxRetained int
	CoreURL                          string
	InstallationID                   string
	BackendFingerprint               string
	Provider                         sandbox.SandboxProvider
	AdmissionPaused                  bool
	Suspension                       *RuntimeSuspensionPolicy
	// contains filtered or unexported fields
}

RuntimeProvider binds one deployment to one sandbox installation. BackendFingerprint identifies its namespace independently of mutable sizing.

func NewDeferredRuntimeProvider

func NewDeferredRuntimeProvider(installationID string, load func(context.Context) (*RuntimeProvider, error), prepare ...RuntimeDeploymentPreparer) *RuntimeProvider

NewDeferredRuntimeProvider enables Web setup for one fixed installation. The loader returns nil until selection, then the committed immutable generation. Replacement is serialized by the deployment mutation gate and drain flow.

type RuntimeSuspensionPolicy

type RuntimeSuspensionPolicy struct {
	IdleTimeout time.Duration
	Retention   time.Duration
	MaxActive   int
	MaxRetained int
}

RuntimeSuspensionPolicy applies only to an explicitly qualified single-host provider. Fixed guest sizing plus MaxActive bounds reserved CPU and memory.

type Snapshot

type Snapshot struct {
	ModelProviderConfigured bool                          `json:"model_provider_configured,omitempty"`
	Agent                   v1.Agent                      `json:"agent"`
	Environment             *v1.Environment               `json:"environment"`
	VaultIDs                []string                      `json:"vault_ids,omitempty"`
	MCPCredentials          []vaults.MCPCredentialBinding `json:"mcp_credentials,omitempty"`
}

Snapshot is the Session configuration frozen at creation.

type Worker

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

Worker owns queued work; the database lease excludes a second execution service.

func StartWorker

func StartWorker(ctx context.Context, dispatcher *Dispatcher, owner Owner) (_ *Worker, err error)

StartWorker takes over owner.Lease from the moment it is called: a failed start closes the lease before returning, and a started Worker closes it after Run drains.

func (*Worker) ArchiveManagedSession

func (w *Worker) ArchiveManagedSession(ctx context.Context, tenant, session string, generation uint64) (sessions.ManagedArchive, error)

ArchiveManagedSession records administrative cleanup intent through the same execution owner that settles resources. Provider work remains in the lifecycle.

func (*Worker) CancelSandboxReset

func (w *Worker) CancelSandboxReset(ctx context.Context, generation uint64) (deployment.View, error)

func (*Worker) CheckOwnership

func (w *Worker) CheckOwnership(ctx context.Context) error

CheckOwnership checks the same database lease used for execution writes.

func (*Worker) CreateSession

func (w *Worker) CreateSession(ctx context.Context, tenant string, input sessions.CreateSession) (sessions.Session, error)

CreateSession validates execution support before reserving or admitting initial work.

func (*Worker) CreateSessionStream

func (w *Worker) CreateSessionStream(ctx context.Context, tenant string, input sessions.CreateSession) (sessions.Creation, error)

CreateSessionStream applies the same execution admission before creating a stream.

func (*Worker) InitializeSandboxDeployment

func (w *Worker) InitializeSandboxDeployment(ctx context.Context, input sandbox.Selection) (deployment.View, error)

func (*Worker) MetricsSnapshot

func (w *Worker) MetricsSnapshot() WorkerMetrics

MetricsSnapshot copies bounded in-process observations without querying storage.

func (*Worker) ProvisionEnvironment

func (w *Worker) ProvisionEnvironment(ctx context.Context, tenant, environment, providerKey string) (deployment.Allocation, error)

ProvisionEnvironment is an internal bootstrap operation for an already authorized hosted Environment. It does not enable public hosted admission.

func (*Worker) ReadEnvironmentDirectory

func (w *Worker) ReadEnvironmentDirectory(ctx context.Context, environment sessions.Environment, path string) (proto.WorkspaceDirectoryResult, error)

ReadEnvironmentDirectory observes a Worker-owned read without admitting model input.

func (*Worker) ReconcileManagedRuntimes

func (w *Worker) ReconcileManagedRuntimes(ctx context.Context) error

ReconcileManagedRuntimes is also callable before serving admission. One scan observes existing allocations and bootstraps committed resources without an allocation. It never retries an existing Create or native work.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) (runErr error)

Run retains queued work across restarts, but never replays an uncertain claim.

func (*Worker) StartSandboxReset

func (w *Worker) StartSandboxReset(ctx context.Context, input deployment.ResetRequest) (deployment.View, error)

func (*Worker) SubmitInputs

func (w *Worker) SubmitInputs(ctx context.Context, tenant, session, key string, inputs []sessions.Input) ([]sessions.InputReceipt, error)

func (*Worker) UpdateSandboxDeployment

func (w *Worker) UpdateSandboxDeployment(ctx context.Context, input sandbox.Selection) (deployment.View, error)

func (*Worker) WriteEnvironmentFile

func (w *Worker) WriteEnvironmentFile(ctx context.Context, environment sessions.Environment, path string, data []byte) (int64, error)

WriteEnvironmentFile observes a Worker-owned mutation. Caller detachment never clears the durable write intent or starts a replacement operation.

type WorkerJobMetrics

type WorkerJobMetrics struct {
	Status    string
	LastRunAt *time.Time
	Processed *int64
	Failed    *int64
}

WorkerJobMetrics describes the last completed scheduling poll. Failed counts failed polls, not failed Turns; Processed is unknown when a poll fails.

type WorkerMetrics

type WorkerMetrics struct {
	SlotsInUse     *int64
	SlotsTotal     *int64
	ExecutionOwner *bool
	Scheduler      WorkerJobMetrics
}

WorkerMetrics contains only observations from this worker's existing operations. Missing pointers mean the corresponding operation has not established a value.

Jump to

Keyboard shortcuts

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