execution

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 39 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 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 a 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
	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 provisions hosted Environments on the sandbox deployment.
	// It is required.
	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 the Dispatcher's execution operations hold, before any Runtime preparation.

type EnvironmentRun

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

type Owner

type Owner struct {
	Workspaces *workspaces.ExecutionOperations
	Lease      Ownership
	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: one field per domain's execution operations.

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 {
	Declarations harnessconfig.Registry
}

Policy supplies the Harness declarations that admission and dispatch read. The zero value uses the built-in Harnesses. Custom composition must supply the same policy to the HTTP handler and Dispatcher; Runtime claims never add declarations.

func (Policy) Harnesses added in v0.0.12

func (p Policy) Harnesses() harnessconfig.Registry

Harnesses returns the declarations this policy admits against.

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
	CoreURL               string
	InstallationID        string
	BackendFingerprint    string
	Provider              sandbox.SandboxProvider
	Suspension            *RuntimeSuspensionPolicy
	Resources             sandbox.Resources
	WorkspaceRequirements *workspacefs.Requirements
	Workspace             *workspacefs.Declaration
	// 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; prepare validates each new selection before it is stored. Replacement is serialized by the deployment mutation gate and drain flow.

type RuntimeSuspensionPolicy

type RuntimeSuspensionPolicy struct {
	Retention time.Duration
}

RuntimeSuspensionPolicy supplies snapshot retention for a provider that suspends sandboxes. Deployment storage owns the mutable idle timeout.

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) 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) Configure added in v0.0.10

func (*Worker) CreateSession

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

CreateSession validates execution support before the pooled Session creation reserves or admits initial work, and wakes the scheduler once that creation commits.

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) Selection added in v0.0.10

func (w *Worker) Selection(ctx context.Context) (workspaces.Selection, error)

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    coremetrics.JobStatus
	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. A nil ExecutionOwner means the last ownership check failed.

Jump to

Keyboard shortcuts

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