runtime

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 40 Imported by: 1 module, 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 runtime executes checked artifacts through immutable generations. Applications that need the default in-memory setup should start with package embedded.

Construction and ownership

CompileGeneration builds executable identity from a source bundle and descriptor resolvers. NewEngine takes generation ownership on success. ConfigureWorkflow and ConfigureLedger must run before execution when the application needs non-default stores. NewEngine does not start background recovery or transport servers.

Engine.Generation returns a borrowed generation. ArtifactResolver instead transfers ownership of each returned generation, including a generation returned with an error. Do not return another engine's borrowed generation from an artifact resolver.

Execution and errors

WaitAccepted acknowledges durable admission, not business completion. WaitTerminal returns unsuccessful terminal states through TerminalExecutionError. Use errors.As and errors.Is rather than parsing error text. Underlying causes can contain sensitive data and must not reach untrusted clients.

Shutdown

Stop admission and recovery workers before closing the engine. Engine.Close drains entered calls and closes owned generations. It leaves borrowed stores, database handles, and fencing providers open. Close those dependencies after the engine finishes. Cancellation is cooperative and cannot force a business operation to stop. Never call Engine.Close from an executor running on that engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidExecuteRequest = errors.New("invalid engine execute request")
	ErrExecutionNotFound     = errors.New("engine execution not found")
	// ErrIdentityConflict is the canonical identity-conflict sentinel. Durable
	// stores use the same sentinel so transports classify direct and raced
	// persistence conflicts consistently.
	ErrIdentityConflict   = schema.ErrIdentityConflict
	ErrGenerationMismatch = errors.New("engine generation mismatch")
	ErrBlockedDependency  = errors.New("execution blocked by missing dependency")
	ErrDurableDisposition = errors.New("durable execution disposition failed")
)
View Source
var (
	ErrTerminalExecution = errors.New("execution ended unsuccessfully")
	ErrExecutionBusy     = errors.New("execution has a recovery owner")
)
View Source
var (
	ErrGRPCInvalidInput      = errors.New("invalid gRPC execution input")
	ErrGRPCUnauthorized      = errors.New("gRPC authentication failed")
	ErrGRPCUnavailable       = errors.New("gRPC execution unavailable")
	ErrGRPCResourceExhausted = errors.New("gRPC execution resource exhausted")
)

Functions

func RegisterEngineExecutionServiceWithOptions

func RegisterEngineExecutionServiceWithOptions(registrar grpc.ServiceRegistrar, engine *Engine, options EngineExecutionServiceOptions) error

Types

type Admission

type Admission struct {
	ExecutionID              string         `json:"execution_id"`
	AdmissionID              string         `json:"admission_id,omitempty"`
	TenantNamespace          string         `json:"tenant_namespace"`
	Ruleset                  string         `json:"ruleset"`
	Version                  string         `json:"version"`
	Facts                    map[string]any `json:"facts"`
	MergePolicy              string         `json:"merge_policy,omitempty"`
	ExpectedGenerationDigest string         `json:"expected_generation_digest,omitempty"`
}

type ArtifactResolver

type ArtifactResolver interface {
	ResolveGeneration(context.Context, ledger.ExecutionArtifact) (*Generation, error)
}

ArtifactResolver reconstructs a callback-free Generation from one immutable durable artifact. It intentionally has no compiler or loader surface. A returned generation transfers ownership to the engine, including when an error is returned with it. Return a fresh owned instance, not one borrowed from another engine. The engine closes it after its final active use.

type ArtifactResolverFunc

type ArtifactResolverFunc func(context.Context, ledger.ExecutionArtifact) (*Generation, error)

func (ArtifactResolverFunc) ResolveGeneration added in v0.4.0

func (f ArtifactResolverFunc) ResolveGeneration(ctx context.Context, artifact ledger.ExecutionArtifact) (*Generation, error)

type BearerTokenAuthenticator

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

func NewBearerTokenAuthenticator

func NewBearerTokenAuthenticator(token string) (*BearerTokenAuthenticator, error)

func NewBearerTokenAuthenticatorSet

func NewBearerTokenAuthenticatorSet(tokens []string) (*BearerTokenAuthenticator, error)

func (*BearerTokenAuthenticator) Authenticate

func (authenticator *BearerTokenAuthenticator) Authenticate(ctx context.Context, _ string) (context.Context, error)

type Engine

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

Engine owns its active generation and historical generations returned by its resolver. Execute is concurrent-safe and always reads durable execution state. Only in-flight calls and resolutions are retained; idle cache retention is zero. Close stops admission and waits for active calls before closing owned resources.

func NewEngine

func NewEngine(generation *Generation) (*Engine, error)

NewEngine takes ownership of an open generation on success. It starts with an in-memory ledger and does not start recovery workers. Configure persistent storage before execution. Close the engine after its callers stop. On failure, the caller retains generation ownership.

func (*Engine) ActiveGenerationDigest

func (engine *Engine) ActiveGenerationDigest() string

func (*Engine) Close added in v0.4.0

func (engine *Engine) Close() error

Close waits for calls that already entered Execute, then closes resources. Do not call Close from an executor invoked by this engine. Repeated calls return the first resource-close error; borrowed stores are not closed.

func (*Engine) ConfigureLedger

func (engine *Engine) ConfigureLedger(durable ledger.ExecutionLedger, resolver ArtifactResolver) error

func (*Engine) ConfigureWorkflow added in v0.4.0

func (engine *Engine) ConfigureWorkflow(store workflow.OutboxStore, provider fencing.Provider, options schema.DispatcherOptions) error

func (*Engine) DryRun added in v0.4.0

func (engine *Engine) DryRun(ctx context.Context, facts map[string]any) ([]PlanEvaluation, error)

func (*Engine) Execute

func (engine *Engine) Execute(ctx context.Context, request ExecuteRequest) (result ExecuteResult, resultErr error)

func (*Engine) Generation added in v0.4.0

func (engine *Engine) Generation() *Generation

Generation returns a borrowed immutable reference. Do not close it separately or use its executor resources after Engine.Close.

func (*Engine) GenerationView added in v0.4.0

func (engine *Engine) GenerationView() *GenerationView

func (*Engine) SetObserver

func (engine *Engine) SetObserver(observer Observer)

type EngineExecutionService

type EngineExecutionService struct {
	effectusv1.UnimplementedRulesetExecutionServiceServer
	Engine *Engine
	// contains filtered or unexported fields
}

EngineExecutionService is the sole generated inbound gRPC facade. It has no mutable method registry and admits work only through Engine.Execute.

func (*EngineExecutionService) ExecuteRuleset

type EngineExecutionServiceOptions

type EngineExecutionServiceOptions struct {
	RulesetName string
	Version     string
}

type ExecuteRequest

type ExecuteRequest struct {
	Admission         *Admission
	ResumeExecutionID string
	WaitMode          WaitMode
	RecoveryLease     *schema.ExecutionLease
}

type ExecuteResult

type ExecuteResult struct {
	ExecutionID      string `json:"execution_id"`
	GenerationDigest string `json:"generation_digest"`
	State            string `json:"state"`
	DurablyAccepted  bool   `json:"durably_accepted"`
	Completed        bool   `json:"completed"`
}

type GRPCAuthenticator

type GRPCAuthenticator interface {
	Authenticate(context.Context, string) (context.Context, error)
}

type GRPCAuthenticatorFunc

type GRPCAuthenticatorFunc func(context.Context, string) (context.Context, error)

func (GRPCAuthenticatorFunc) Authenticate

func (function GRPCAuthenticatorFunc) Authenticate(ctx context.Context, method string) (context.Context, error)

type Generation

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

Generation is immutable after construction. Manager ownership and acquired handles are the only references counted for retirement.

func CompileGeneration added in v0.4.0

func CompileGeneration(ctx context.Context, config GenerationBuildConfig) (*Generation, error)

CompileGeneration compiles one source bundle exactly once, resolves every declared invocation descriptor, and freezes the resulting Generation.

func NewGeneration

func NewGeneration(config GenerationConfig) (*Generation, error)

func (*Generation) Checked

func (generation *Generation) Checked() *ir.Checked

func (*Generation) Close added in v0.4.0

func (generation *Generation) Close() error

Close retires all generation-owned resources exactly once in reverse acquisition order. A changed generation requires replacing the process.

func (*Generation) Closed

func (generation *Generation) Closed() bool

Closed reports whether generation-owned executor resources are retired.

func (*Generation) Digest

func (generation *Generation) Digest() string

func (*Generation) Environment

func (generation *Generation) Environment() ir.Environment

func (*Generation) Executor

func (generation *Generation) Executor(verb string) (invocation.Executor, bool)

func (*Generation) ExecutorDescriptors added in v0.4.0

func (generation *Generation) ExecutorDescriptors() map[string]invocation.Descriptor

ExecutorDescriptors returns the immutable resolver manifest.

func (*Generation) FunctionIDs added in v0.4.0

func (generation *Generation) FunctionIDs() map[string]string

FunctionIDs returns the immutable function resolver identities.

func (*Generation) Ruleset

func (generation *Generation) Ruleset() string

func (*Generation) SourceDigest

func (generation *Generation) SourceDigest() string

func (*Generation) Version

func (generation *Generation) Version() string

type GenerationBuildConfig added in v0.4.0

type GenerationBuildConfig struct {
	Bundle         *bundle.SourceBundle
	CompileOptions compiler.CompileOptions
	Resolvers      *invocation.Registry
	FunctionIDs    map[string]string
	Production     bool
}

GenerationBuildConfig is the single source-bundle to generation startup input.

type GenerationConfig

type GenerationConfig struct {
	Checked             *ir.Checked
	Environment         ir.Environment
	Ruleset             string
	Version             string
	ExecutorDescriptors map[string]invocation.Descriptor
	FunctionIDs         map[string]string
	SourceDigest        string
	Executors           map[string]invocation.Executor
	Closers             []io.Closer
	Production          bool
}

GenerationConfig contains every value covered by a generation digest.

type GenerationView added in v0.4.0

type GenerationView struct {
	Ruleset          string
	Version          string
	GenerationDigest string
	IRDigest         string
	SourceDigest     string
	Environment      ir.Environment
	Plans            []PlanView
}

type ManifestArtifactResolver

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

ManifestArtifactResolver rebuilds a generation only from the descriptor manifest durably pinned with an execution. No extension loader or callback implementation participates in recovery.

func NewManifestArtifactResolver

func NewManifestArtifactResolver(registries ...*invocation.Registry) *ManifestArtifactResolver

func (*ManifestArtifactResolver) ResolveGeneration added in v0.4.0

func (resolver *ManifestArtifactResolver) ResolveGeneration(ctx context.Context, artifact ledger.ExecutionArtifact) (*Generation, error)

type Observer

type Observer interface {
	ObserveExecution(ExecuteResult, error)
	ObserveRecovery(RecoveryObservation)
}

type PlanEvaluation added in v0.4.0

type PlanEvaluation struct {
	Plan    PlanView
	Matched bool
}

type PlanView added in v0.4.0

type PlanView struct {
	ID        string
	Dialect   effectusv1.SourceDialect
	Priority  int32
	Predicate string
	Verbs     []string
}

type RecoveryObservation

type RecoveryObservation struct {
	BacklogMeasured                     bool
	Backlog, Blocked                    int64
	OldestExecutionAge, OldestOutboxAge time.Duration
	ExecutionID, State                  string
	Err                                 error
}

type RecoveryWorker

type RecoveryWorker struct {
	Engine        *Engine
	Store         ledger.ExecutionLedger
	Owner         string
	BatchSize     int
	LeaseDuration time.Duration
	PollInterval  time.Duration
	Observer      Observer
}

RecoveryWorker resumes durable executions serially. BatchSize bounds work per poll, not the number of leases held at once. Configure fields before Run. Built-in stores renew live leases. Custom stores without renewal support must finish each execution within the original lease's safe window. Zero BatchSize, LeaseDuration, and PollInterval select 32, 30s, and 1s. Negative settings are invalid; leases must be at least one microsecond.

func (*RecoveryWorker) Run

func (worker *RecoveryWorker) Run(ctx context.Context) error

Run polls until cancellation. Each poll is bounded by BatchSize.

func (*RecoveryWorker) RunOnce

func (worker *RecoveryWorker) RunOnce(ctx context.Context) (int, error)

RunOnce acquires a lease only when it can start that execution. It resumes work through Engine.Execute and leaves terminal persistence to the engine.

type RulesetExecutionServer

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

func NewRulesetExecutionServer

func NewRulesetExecutionServer(engine *Engine, addr string) (*RulesetExecutionServer, error)

NewRulesetExecutionServer is retained for source compatibility but cannot infer authentication or TLS policy. It returns an actionable configuration error without binding. Use NewRulesetExecutionServerWithOptions instead.

func NewRulesetExecutionServerOnListener

func NewRulesetExecutionServerOnListener(engine *Engine, listener net.Listener, options RulesetExecutionServerOptions) (*RulesetExecutionServer, error)

NewRulesetExecutionServerOnListener transfers listener ownership on success. The caller retains the listener on configuration failure. Stop the server before closing its engine.

func NewRulesetExecutionServerWithOptions

func NewRulesetExecutionServerWithOptions(engine *Engine, addr string, options RulesetExecutionServerOptions) (*RulesetExecutionServer, error)

NewRulesetExecutionServerWithOptions validates configuration before binding. RulesetName and Version must match engine.Generation(). Configure Authenticator and TLSConfig. Insecure or unauthenticated operation requires explicit opt-in. Zero message limits use 4 MiB. Zero duration uses 30 seconds. Zero concurrency uses 128 RPCs. Negative limits fail. Start once, then Stop before engine.Close.

func (*RulesetExecutionServer) Address

func (server *RulesetExecutionServer) Address() net.Addr

func (*RulesetExecutionServer) Ready

func (server *RulesetExecutionServer) Ready() error

func (*RulesetExecutionServer) Start

func (server *RulesetExecutionServer) Start() error

func (*RulesetExecutionServer) Stop

func (server *RulesetExecutionServer) Stop()

Stop drains the server and joins concurrent Stop calls. After the configured execution duration it cancels active RPCs, then waits for their handlers. Handlers must honor cancellation. Do not call Stop from this server's handler.

type RulesetExecutionServerOptions

type RulesetExecutionServerOptions struct {
	MaxReceiveBytes        int
	MaxSendBytes           int
	MaxExecutionDuration   time.Duration
	MaxConcurrentRPCs      int
	Authenticator          GRPCAuthenticator
	AllowUnauthenticated   bool
	TLSConfig              *tls.Config
	AllowInsecureTransport bool
	RulesetName            string
	Version                string
}

RulesetExecutionServerOptions defines the immutable service registration and transport policy. The generated service is registered in the constructor, before Serve can be called.

type TerminalExecutionError added in v0.5.0

type TerminalExecutionError struct {
	State schema.ExecutionState
	Cause error
}

TerminalExecutionError preserves a durable failed or blocked disposition. Inspect State with errors.As and Cause with errors.Is/Unwrap. Cause may contain executor or storage details; transports must not expose it without sanitizing.

func (*TerminalExecutionError) Error added in v0.5.0

func (err *TerminalExecutionError) Error() string

func (*TerminalExecutionError) Is added in v0.5.0

func (err *TerminalExecutionError) Is(target error) bool

func (*TerminalExecutionError) Unwrap added in v0.5.0

func (err *TerminalExecutionError) Unwrap() error

type WaitMode

type WaitMode string
const (
	WaitAccepted WaitMode = "accepted"
	WaitTerminal WaitMode = "terminal"
)

Directories

Path Synopsis
internal
db

Jump to

Keyboard shortcuts

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