runtime

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 53 Imported by: 0

Documentation

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      = errors.New("engine admission identity conflict")
	ErrGenerationMismatch    = errors.New("engine generation mismatch")
	ErrBlockedDependency     = errors.New("execution blocked by missing dependency")
	ErrDurableDisposition    = errors.New("durable execution disposition failed")
)
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")
)
View Source
var ErrRulesetActive = errors.New("ruleset is active")
View Source
var ErrUnsupportedDeploymentStrategy = errors.New("unsupported deployment strategy")

Functions

func RegisterEngineExecutionServiceWithOptions

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

Types

type ActivationStore

type ActivationStore interface {
	GetActiveVersion(context.Context, string, string) (*RulesetVersion, error)
	SetActiveVersion(context.Context, string, string, string) error
	DeployRuleset(context.Context, string, string, string, *DeploymentConfig) error
	GetDeploymentStatus(context.Context, string, string) (*DeploymentStatus, error)
	RollbackDeployment(context.Context, string, string, string) error
}

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"`
}

Admission is the transport-neutral logical request for a new execution.

type ArtifactResolver

type ArtifactResolver interface {
	ResolveArtifact(context.Context, ledger.ExecutionArtifact, *ir.Checked) (*compiler.CompiledUnit, error)
}

ArtifactResolver reconstructs invocation-aware executor instances from an immutable artifact manifest. Callback-only implementations are not valid durable resolvers.

type ArtifactResolverFunc

type ArtifactResolverFunc func(context.Context, ledger.ExecutionArtifact, *ir.Checked) (*compiler.CompiledUnit, error)

func (ArtifactResolverFunc) ResolveArtifact

func (function ArtifactResolverFunc) ResolveArtifact(ctx context.Context, artifact ledger.ExecutionArtifact, checked *ir.Checked) (*compiler.CompiledUnit, error)

type AuditEntry

type AuditEntry struct {
	ID          string                 `json:"id"`
	Timestamp   time.Time              `json:"timestamp"`
	Action      string                 `json:"action"`
	Resource    string                 `json:"resource"`
	ResourceID  *uuid.UUID             `json:"resource_id,omitempty"`
	Version     string                 `json:"version"`
	Environment string                 `json:"environment"`
	UserID      string                 `json:"user_id"`
	UserEmail   string                 `json:"user_email"`
	IPAddress   string                 `json:"ip_address"`
	UserAgent   string                 `json:"user_agent"`
	SessionID   string                 `json:"session_id"`
	Details     map[string]interface{} `json:"details"`
	RequestID   string                 `json:"request_id"`
	TraceID     string                 `json:"trace_id"`
	Result      string                 `json:"result"`
	ErrorMsg    string                 `json:"error_msg,omitempty"`
	DurationMs  int                    `json:"duration_ms,omitempty"`
}

type AuditFilters

type AuditFilters struct {
	Actions   []string  `json:"actions"`
	Resources []string  `json:"resources"`
	UserIDs   []string  `json:"user_ids"`
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
	Result    string    `json:"result"`
	Limit     int       `json:"limit"`
	Offset    int       `json:"offset"`
}

type AuditStore

type AuditStore interface {
	GetAuditLog(context.Context, *AuditFilters) ([]*AuditEntry, error)
	RecordActivity(context.Context, *AuditEntry) 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 CanaryConfig

type CanaryConfig struct {
	TrafficPercent   int           `json:"traffic_percent"`
	Duration         time.Duration `json:"duration"`
	SuccessThreshold float64       `json:"success_threshold"`
	ErrorThreshold   float64       `json:"error_threshold"`
	MetricsQueries   []string      `json:"metrics_queries"`
}

type CompileOptions

type CompileOptions struct {
	// DiscardInitialData retains inferred fact types but removes loader values
	// before publication. Use this for type samples that are not runtime defaults.
	DiscardInitialData bool
}

CompileOptions controls how a checked generation is published.

type CompiledEffect

type CompiledEffect struct {
	VerbName string
	Args     map[string]any
}

type CompiledPredicate

type CompiledPredicate struct {
	Path     string
	Operator string
	Value    any
}

type CompiledRule

type CompiledRule struct {
	Name        string
	Type        RuleType
	Predicates  []CompiledPredicate
	Effects     []CompiledEffect
	Priority    int
	Description string
}

type CompiledRuleset

type CompiledRuleset struct {
	Name          string
	Version       string
	Description   string
	FactSchema    *Schema
	EffectSchemas map[string]*Schema
	Rules         []CompiledRule
	Verbs         map[string]*compiler.CompiledVerbSpec
	Dependencies  []string
	Capabilities  []string
	Metadata      map[string]string
}

CompiledRuleset is retained as the storage representation used by legacy ruleset persistence. It is not a gRPC method-registration API.

type Deployment

type Deployment struct {
	Environment  string             `json:"environment"`
	Version      string             `json:"version"`
	DeployedAt   time.Time          `json:"deployed_at"`
	DeployedBy   string             `json:"deployed_by"`
	Status       DeploymentStatus   `json:"status"`
	Config       *DeploymentConfig  `json:"config"`
	HealthCheck  *HealthCheckResult `json:"health_check"`
	RollbackInfo *RollbackInfo      `json:"rollback_info,omitempty"`
	CanaryConfig *CanaryConfig      `json:"canary_config,omitempty"`
}

type DeploymentConfig

type DeploymentConfig struct {
	Strategy        string            `json:"strategy"`
	HealthCheckURL  string            `json:"health_check_url"`
	RollbackOnError bool              `json:"rollback_on_error"`
	MaxRollbackDays int               `json:"max_rollback_days"`
	Environments    []string          `json:"environments"`
	RequiredTests   []string          `json:"required_tests"`
	Approvers       []string          `json:"approvers"`
	Metadata        map[string]string `json:"metadata"`
}

type DeploymentStatus

type DeploymentStatus string
const (
	DeploymentStatusPending     DeploymentStatus = "pending"
	DeploymentStatusDeploying   DeploymentStatus = "deploying"
	DeploymentStatusActive      DeploymentStatus = "active"
	DeploymentStatusCanary      DeploymentStatus = "canary"
	DeploymentStatusRollingBack DeploymentStatus = "rolling_back"
	DeploymentStatusFailed      DeploymentStatus = "failed"
	DeploymentStatusInactive    DeploymentStatus = "inactive"
)

type Engine

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

Engine is the one workflow entry point used by compatibility runtime and transport adapters. It pins the active compiled unit for each admitted in-process execution. Durable deployments replace the in-memory admission index with the execution ledger without changing this API.

func NewEngine

func NewEngine(runtime *ExecutionRuntime) (*Engine, error)

NewEngine returns the shared engine owned by an ExecutionRuntime.

func (*Engine) ActiveGeneration

func (engine *Engine) ActiveGeneration() *ExecutionGeneration

ActiveGeneration returns a copy of the checked runtime publication currently used for new admissions, including its immutable bundle metadata.

func (*Engine) ActiveGenerationDigest

func (engine *Engine) ActiveGenerationDigest() string

ActiveGenerationDigest returns the checked engine generation currently used for new admissions.

func (*Engine) ConfigureLedger

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

ConfigureLedger replaces the development ledger. Configure the same PostgresOutboxStore as both workflow outbox and ledger to enable atomic admission.

func (*Engine) Execute

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

Execute enters the same state machine for new admissions and recovery.

func (*Engine) SetObserver

func (engine *Engine) SetObserver(observer Observer)

SetObserver installs an optional runtime 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 // Set only by RecoveryWorker.
}

ExecuteRequest admits a new execution or resumes an existing one. Exactly one of Admission and ResumeExecutionID must be set.

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"`
}

ExecuteResult reports the durable boundary reached by Execute.

type ExecutionGeneration

type ExecutionGeneration struct {
	GenerationDigest string `json:"generation_digest"`
	IRDigest         string `json:"ir_digest"`
	GenerationMetadata
	PublishedAt time.Time `json:"published_at"`
	// contains filtered or unexported fields
}

ExecutionGeneration is the sole published production generation. Its unit and extension snapshot are immutable and are retired together.

type ExecutionRuntime

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

ExecutionRuntime orchestrates the complete flow from extension loading to execution

func NewExecutionRuntime

func NewExecutionRuntime() *ExecutionRuntime

NewExecutionRuntime creates a new execution runtime

func (*ExecutionRuntime) ActiveGeneration

func (er *ExecutionRuntime) ActiveGeneration() *ExecutionGeneration

ActiveGeneration returns a copy of the one production publication view.

func (*ExecutionRuntime) Close

func (er *ExecutionRuntime) Close() error

Close releases executor connection pools. It is safe to call more than once.

func (*ExecutionRuntime) CompileAndValidate

func (er *ExecutionRuntime) CompileAndValidate(ctx context.Context) error

CompileAndValidate loads extensions, compiles them, and validates everything.

func (*ExecutionRuntime) CompileAndValidateWithOptions

func (er *ExecutionRuntime) CompileAndValidateWithOptions(ctx context.Context, options CompileOptions) error

CompileAndValidateWithOptions loads, checks, and publishes one generation with the requested publication policy.

func (*ExecutionRuntime) ConfigureDurableWorkflowExecution

func (er *ExecutionRuntime) ConfigureDurableWorkflowExecution(store workflow.OutboxStore, provider fencing.Provider, options schema.DispatcherOptions) error

ConfigureDurableWorkflowExecution installs the mandatory outbox boundary for checked DURABLE_* workflows. Configure this before execution or hot reload.

func (*ExecutionRuntime) ConfigureExecutionLedger

func (er *ExecutionRuntime) ConfigureExecutionLedger(durableLedger ledger.ExecutionLedger, resolver ArtifactResolver) error

ConfigureExecutionLedger installs durable admission/recovery persistence and an immutable resolver for generations loaded after restart.

func (*ExecutionRuntime) ConfigureGenerationMetadata

func (er *ExecutionRuntime) ConfigureGenerationMetadata(metadata GenerationMetadata) error

ConfigureGenerationMetadata freezes bundle metadata into the next executable publication. Metadata cannot change independently after publication.

func (*ExecutionRuntime) EnableLegacyExecutionForCompatibility

func (er *ExecutionRuntime) EnableLegacyExecutionForCompatibility()

EnableLegacyExecutionForCompatibility permits unrestricted Go continuations. It must not be enabled by production deployments because callback-only executors cannot be reconstructed or guaranteed to preserve invocation metadata.

func (*ExecutionRuntime) Engine

func (er *ExecutionRuntime) Engine() *Engine

Engine returns the shared checked execution API.

func (*ExecutionRuntime) ExecuteVerb

func (er *ExecutionRuntime) ExecuteVerb(ctx context.Context, verbName string, args map[string]interface{}) (interface{}, error)

ExecuteVerb executes a specific verb with the given arguments

func (*ExecutionRuntime) ExecuteWorkflow

func (er *ExecutionRuntime) ExecuteWorkflow(ctx context.Context, facts map[string]interface{}) error

ExecuteWorkflow is retained as a fail-closed compatibility method. Durable recovery requires a caller-supplied stable execution identity.

func (*ExecutionRuntime) ExecuteWorkflowWithIdentity

func (er *ExecutionRuntime) ExecuteWorkflowWithIdentity(ctx context.Context, namespace, executionID string, facts map[string]interface{}) error

ExecuteWorkflowWithIdentity is a compatibility facade over Engine.Execute.

func (*ExecutionRuntime) GetRuntimeInfo

func (er *ExecutionRuntime) GetRuntimeInfo() *RuntimeInfo

GetRuntimeInfo returns information about the current runtime state

func (*ExecutionRuntime) HotReload

func (er *ExecutionRuntime) HotReload(ctx context.Context) error

HotReload reloads and recompiles all extensions

func (*ExecutionRuntime) RegisterExecutorFactory

func (er *ExecutionRuntime) RegisterExecutorFactory(executorType compiler.ExecutorType, factory ExecutorFactory)

RegisterExecutorFactory registers a factory for creating executors. Deprecated: descriptor-backed checked execution is constructed by runtime publication.

func (*ExecutionRuntime) RegisterExtensionLoader

func (er *ExecutionRuntime) RegisterExtensionLoader(extensionLoader loader.Loader)

RegisterExtensionLoader adds an extension loader to the runtime.

type ExecutorDescriptor

type ExecutorDescriptor struct {
	Type       string            `json:"type"`
	ResolverID string            `json:"resolver_id"`
	Reference  string            `json:"reference,omitempty"`
	Config     map[string]string `json:"config,omitempty"`
}

ExecutorDescriptor is the immutable resolver input for one verb binding.

type ExecutorFactory

type ExecutorFactory interface {
	CreateExecutor(config compiler.ExecutorConfig) (VerbExecutor, error)
}

ExecutorFactory creates executors for different types

type FieldType

type FieldType struct {
	Type        string
	MessageType string
	Required    bool
	Description string
}

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 GRPCExecutor

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

func (*GRPCExecutor) Execute

func (ge *GRPCExecutor) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

type GRPCExecutorFactory

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

func (*GRPCExecutorFactory) Close

func (gef *GRPCExecutorFactory) Close() error

func (*GRPCExecutorFactory) CreateExecutor

func (gef *GRPCExecutorFactory) CreateExecutor(config compiler.ExecutorConfig) (VerbExecutor, 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 NewGeneration

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

func (*Generation) Checked

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

func (*Generation) Closed

func (generation *Generation) Closed() bool

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) Retired

func (generation *Generation) Retired() bool

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 GenerationConfig

type GenerationConfig struct {
	Checked             *ir.Checked
	Environment         ir.Environment
	Ruleset             string
	Version             string
	ExecutorDescriptors map[string]ExecutorDescriptor
	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 GenerationHandle

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

GenerationHandle pins a generation until Release.

func (*GenerationHandle) Generation

func (handle *GenerationHandle) Generation() *Generation

func (*GenerationHandle) Release

func (handle *GenerationHandle) Release() error

type GenerationManager

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

GenerationManager is retained for embedded compatibility tests. Deprecated: ExecutionRuntime owns the production generation publication.

func (*GenerationManager) Acquire

func (manager *GenerationManager) Acquire() (*GenerationHandle, error)

func (*GenerationManager) ActiveDigest

func (manager *GenerationManager) ActiveDigest() string

func (*GenerationManager) Publish

func (manager *GenerationManager) Publish(generation *Generation) error

type GenerationMetadata

type GenerationMetadata struct {
	Ruleset      string `json:"ruleset"`
	Version      string `json:"version"`
	BundleDigest string `json:"bundle_digest,omitempty"`
}

GenerationMetadata is presentation metadata published with executable state.

type HTTPExecutor

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

func (*HTTPExecutor) Execute

func (he *HTTPExecutor) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

type HTTPExecutorFactory

type HTTPExecutorFactory struct{}

func (*HTTPExecutorFactory) CreateExecutor

func (hef *HTTPExecutorFactory) CreateExecutor(config compiler.ExecutorConfig) (VerbExecutor, error)

type HealthCheckResult

type HealthCheckResult struct {
	Status      string            `json:"status"`
	LastChecked time.Time         `json:"last_checked"`
	Details     map[string]string `json:"details"`
	Errors      []string          `json:"errors"`
}

type InMemoryRuleStorage

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

InMemoryRuleStorage implements RuleStorageBackend in memory Useful for testing and local development

func NewInMemoryRuleStorage

func NewInMemoryRuleStorage() *InMemoryRuleStorage

NewInMemoryRuleStorage creates a new in-memory rule storage backend

func (*InMemoryRuleStorage) Cleanup

func (m *InMemoryRuleStorage) Cleanup(ctx context.Context, olderThan time.Time) error

Cleanup removes old entries

func (*InMemoryRuleStorage) DeleteRuleset

func (m *InMemoryRuleStorage) DeleteRuleset(ctx context.Context, name, version string) error

DeleteRuleset removes a ruleset from memory

func (*InMemoryRuleStorage) DeployRuleset

func (m *InMemoryRuleStorage) DeployRuleset(ctx context.Context, name, version, environment string, config *DeploymentConfig) error

DeployRuleset atomically replaces the active version for an environment.

func (*InMemoryRuleStorage) GetActiveVersion

func (m *InMemoryRuleStorage) GetActiveVersion(ctx context.Context, name, environment string) (*RulesetVersion, error)

GetActiveVersion returns the active version for an environment

func (*InMemoryRuleStorage) GetAuditLog

func (m *InMemoryRuleStorage) GetAuditLog(ctx context.Context, filters *AuditFilters) ([]*AuditEntry, error)

GetAuditLog returns audit logs with filters

func (*InMemoryRuleStorage) GetDeploymentStatus

func (m *InMemoryRuleStorage) GetDeploymentStatus(ctx context.Context, name, environment string) (*DeploymentStatus, error)

GetDeploymentStatus returns deployment status

func (*InMemoryRuleStorage) GetRuleset

func (m *InMemoryRuleStorage) GetRuleset(ctx context.Context, name, version string) (*StoredRuleset, error)

GetRuleset retrieves a ruleset from memory

func (*InMemoryRuleStorage) GetRulesetVersions

func (m *InMemoryRuleStorage) GetRulesetVersions(ctx context.Context, name string) ([]*RulesetVersion, error)

GetRulesetVersions returns versions of a ruleset

func (*InMemoryRuleStorage) HealthCheck

func (m *InMemoryRuleStorage) HealthCheck(ctx context.Context) error

HealthCheck always returns healthy for in-memory storage

func (*InMemoryRuleStorage) ListRulesets

func (m *InMemoryRuleStorage) ListRulesets(ctx context.Context, filters *RulesetFilters) ([]*RulesetMetadata, error)

ListRulesets lists rulesets from memory with filters

func (*InMemoryRuleStorage) RecordActivity

func (m *InMemoryRuleStorage) RecordActivity(ctx context.Context, entry *AuditEntry) error

RecordActivity records an audit entry

func (*InMemoryRuleStorage) RollbackDeployment

func (m *InMemoryRuleStorage) RollbackDeployment(ctx context.Context, name, environment, targetVersion string) error

RollbackDeployment rolls back a deployment

func (*InMemoryRuleStorage) SetActiveVersion

func (m *InMemoryRuleStorage) SetActiveVersion(ctx context.Context, name, environment, version string) error

SetActiveVersion atomically replaces the active version for an environment. Deprecated: use DeployRuleset with the atomic strategy.

func (*InMemoryRuleStorage) StoreRuleset

func (m *InMemoryRuleStorage) StoreRuleset(ctx context.Context, ruleset *StoredRuleset) error

StoreRuleset stores a ruleset in memory

type LocalExecutorAdapter

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

Executor implementations

func (*LocalExecutorAdapter) Execute

func (lea *LocalExecutorAdapter) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

type LocalExecutorFactory

type LocalExecutorFactory struct{}

Executor factory implementations

func (*LocalExecutorFactory) CreateExecutor

func (lef *LocalExecutorFactory) CreateExecutor(config compiler.ExecutorConfig) (VerbExecutor, error)

type ManifestArtifactResolver

type ManifestArtifactResolver struct{}

ManifestArtifactResolver reconstructs invocation-aware adapters only from immutable descriptors stored in the execution artifact.

func NewManifestArtifactResolver

func NewManifestArtifactResolver() *ManifestArtifactResolver

func (*ManifestArtifactResolver) ResolveArtifact

type MessageExecutor

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

func (*MessageExecutor) Execute

func (me *MessageExecutor) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

type MessageExecutorFactory

type MessageExecutorFactory struct{}

func (*MessageExecutorFactory) CreateExecutor

func (mef *MessageExecutorFactory) CreateExecutor(config compiler.ExecutorConfig) (VerbExecutor, error)

type MockExecutor

type MockExecutor struct{}

func (*MockExecutor) Execute

func (me *MockExecutor) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

type MockExecutorFactory

type MockExecutorFactory struct{}

func (*MockExecutorFactory) CreateExecutor

func (mef *MockExecutorFactory) CreateExecutor(config compiler.ExecutorConfig) (VerbExecutor, error)

type Observer

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

Observer receives checked-runtime events without coupling the runtime to a metrics implementation. Implementations must not block execution.

type PostgresStorage

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

PostgresStorage implements RuleStorageBackend using sqlc and goose

func NewPostgresStorage

func NewPostgresStorage(config *PostgresStorageConfig) (*PostgresStorage, error)

NewPostgresStorage creates a new PostgreSQL storage backend with modern tooling

func (*PostgresStorage) Cleanup

func (p *PostgresStorage) Cleanup(ctx context.Context, olderThan time.Time) error

Cleanup removes old data based on retention policies

func (*PostgresStorage) Close

func (p *PostgresStorage) Close()

Close closes the database connection pool

func (*PostgresStorage) DeleteRuleset

func (p *PostgresStorage) DeleteRuleset(ctx context.Context, name, version string) error

func (*PostgresStorage) DeployRuleset

func (p *PostgresStorage) DeployRuleset(ctx context.Context, name, version, environment string, config *DeploymentConfig) error

func (*PostgresStorage) GetActiveVersion

func (p *PostgresStorage) GetActiveVersion(ctx context.Context, name, environment string) (*RulesetVersion, error)

func (*PostgresStorage) GetAuditLog

func (p *PostgresStorage) GetAuditLog(ctx context.Context, filters *AuditFilters) ([]*AuditEntry, error)

GetAuditLog retrieves audit logs using sqlc-generated queries

func (*PostgresStorage) GetDeploymentStatus

func (p *PostgresStorage) GetDeploymentStatus(ctx context.Context, name, environment string) (*DeploymentStatus, error)

func (*PostgresStorage) GetRuleset

func (p *PostgresStorage) GetRuleset(ctx context.Context, name, version string) (*StoredRuleset, error)

GetRuleset retrieves a ruleset using sqlc-generated queries

func (*PostgresStorage) GetRulesetVersions

func (p *PostgresStorage) GetRulesetVersions(ctx context.Context, name string) ([]*RulesetVersion, error)

func (*PostgresStorage) HealthCheck

func (p *PostgresStorage) HealthCheck(ctx context.Context) error

HealthCheck checks the database connection

func (*PostgresStorage) ListRulesets

func (p *PostgresStorage) ListRulesets(ctx context.Context, filters *RulesetFilters) ([]*RulesetMetadata, error)

ListRulesets lists rulesets with filtering using sqlc-generated queries

func (*PostgresStorage) RecordActivity

func (p *PostgresStorage) RecordActivity(ctx context.Context, entry *AuditEntry) error

RecordActivity records an audit entry using sqlc-generated queries

func (*PostgresStorage) RollbackDeployment

func (p *PostgresStorage) RollbackDeployment(ctx context.Context, name, environment, targetVersion string) error

func (*PostgresStorage) SetActiveVersion

func (p *PostgresStorage) SetActiveVersion(ctx context.Context, name, environment, version string) error

func (*PostgresStorage) StoreRuleset

func (p *PostgresStorage) StoreRuleset(ctx context.Context, ruleset *StoredRuleset) error

StoreRuleset stores a compiled ruleset using sqlc-generated queries

type PostgresStorageConfig

type PostgresStorageConfig struct {
	// Database connection
	DSN             string        `yaml:"dsn"`
	MaxConnections  int           `yaml:"max_connections"`
	ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime"`
	ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time"`

	// Migration settings
	MigrationsPath string `yaml:"migrations_path"`
	AutoMigrate    bool   `yaml:"auto_migrate"`
}

PostgresStorageConfig configures PostgreSQL storage with modern tooling

type RecoveryObservation

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

RecoveryObservation describes one bounded recovery poll or disposition.

type RecoveryWorker

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

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 leases a bounded set of nonterminal executions and resumes each only through Engine.Execute. Lease completion is a CAS performed by the engine.

type RollbackInfo

type RollbackInfo struct {
	PreviousVersion string    `json:"previous_version"`
	RollbackReason  string    `json:"rollback_reason"`
	RolledBackAt    time.Time `json:"rolled_back_at"`
	RolledBackBy    string    `json:"rolled_back_by"`
	AutoRollback    bool      `json:"auto_rollback"`
}

type RuleStorageBackend

type RuleStorageBackend interface {
	RulesetStore
	ActivationStore
	AuditStore
	StorageMaintenance
}

RuleStorageBackend composes the storage roles for compatibility.

type RuleType

type RuleType string
const (
	RuleTypeList RuleType = "list"
	RuleTypeFlow RuleType = "flow"
)

type RulesetExecutionServer

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

func NewRulesetExecutionServer

func NewRulesetExecutionServer(runtime *ExecutionRuntime, addr string) (*RulesetExecutionServer, error)

func NewRulesetExecutionServerOnListener

func NewRulesetExecutionServerOnListener(runtime *ExecutionRuntime, listener net.Listener, options RulesetExecutionServerOptions) (*RulesetExecutionServer, error)

func NewRulesetExecutionServerWithOptions

func NewRulesetExecutionServerWithOptions(runtime *ExecutionRuntime, addr string, options RulesetExecutionServerOptions) (*RulesetExecutionServer, error)

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()

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 RulesetFilters

type RulesetFilters struct {
	Names        []string          `json:"names"`
	Versions     []string          `json:"versions"`
	Environments []string          `json:"environments"`
	Status       []RulesetStatus   `json:"status"`
	Tags         []string          `json:"tags"`
	Owner        string            `json:"owner"`
	Team         string            `json:"team"`
	CreatedAfter *time.Time        `json:"created_after"`
	CreatedBy    string            `json:"created_by"`
	GitCommit    string            `json:"git_commit"`
	Metadata     map[string]string `json:"metadata"`
	Limit        int               `json:"limit"`
	Offset       int               `json:"offset"`
}

type RulesetMetadata

type RulesetMetadata struct {
	ID              string        `json:"id"`
	Name            string        `json:"name"`
	Version         string        `json:"version"`
	Environment     string        `json:"environment"`
	Status          RulesetStatus `json:"status"`
	RuleCount       int           `json:"rule_count"`
	CreatedAt       time.Time     `json:"created_at"`
	UpdatedAt       time.Time     `json:"updated_at"`
	CreatedBy       string        `json:"created_by"`
	Tags            []string      `json:"tags"`
	Description     string        `json:"description"`
	Owner           string        `json:"owner"`
	Team            string        `json:"team"`
	SchemaVersion   string        `json:"schema_version"`
	ValidationHash  string        `json:"validation_hash"`
	DeploymentCount int           `json:"deployment_count"`
}

type RulesetStatus

type RulesetStatus string
const (
	RulesetStatusDraft      RulesetStatus = "draft"
	RulesetStatusValidating RulesetStatus = "validating"
	RulesetStatusReady      RulesetStatus = "ready"
	RulesetStatusDeployed   RulesetStatus = "deployed"
	RulesetStatusDeprecated RulesetStatus = "deprecated"
	RulesetStatusFailed     RulesetStatus = "failed"
)

type RulesetStore

type RulesetStore interface {
	StoreRuleset(context.Context, *StoredRuleset) error
	GetRuleset(context.Context, string, string) (*StoredRuleset, error)
	ListRulesets(context.Context, *RulesetFilters) ([]*RulesetMetadata, error)
	DeleteRuleset(context.Context, string, string) error
	GetRulesetVersions(context.Context, string) ([]*RulesetVersion, error)
}

type RulesetVersion

type RulesetVersion struct {
	Version       string    `json:"version"`
	CreatedAt     time.Time `json:"created_at"`
	CreatedBy     string    `json:"created_by"`
	GitCommit     string    `json:"git_commit"`
	IsActive      bool      `json:"is_active"`
	DeployedEnvs  []string  `json:"deployed_envs"`
	ChangeMessage string    `json:"change_message"`
}

type RuntimeInfo

type RuntimeInfo struct {
	State            RuntimeState `json:"state"`
	GenerationDigest string       `json:"generationDigest,omitempty"`
	IRDigest         string       `json:"irDigest,omitempty"`
	Ruleset          string       `json:"ruleset,omitempty"`
	Version          string       `json:"version,omitempty"`
	BundleDigest     string       `json:"bundleDigest,omitempty"`
	PublishedAt      time.Time    `json:"publishedAt,omitempty"`
	LoaderCount      int          `json:"loaderCount"`
	VerbCount        int          `json:"verbCount"`
	FunctionCount    int          `json:"functionCount"`
	PlanCount        int          `json:"planCount"`
	Dependencies     []string     `json:"dependencies"`
	Capabilities     []string     `json:"capabilities"`
}

RuntimeInfo provides information about the runtime state

type RuntimeState

type RuntimeState string

RuntimeState represents the current state of the runtime

const (
	StateInitializing RuntimeState = "initializing"
	StateLoading      RuntimeState = "loading"
	StateCompiling    RuntimeState = "compiling"
	StateReady        RuntimeState = "ready"
	StateExecuting    RuntimeState = "executing"
	StateFailed       RuntimeState = "failed"
	StateClosing      RuntimeState = "closing"
	StateClosed       RuntimeState = "closed"
)

type Schema

type Schema struct {
	Name        string
	Fields      map[string]*FieldType
	Required    []string
	Description string
}

type StorageMaintenance

type StorageMaintenance interface {
	HealthCheck(context.Context) error
	Cleanup(context.Context, time.Time) error
}

type StoredRuleset

type StoredRuleset struct {
	Ruleset *CompiledRuleset

	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Version     string    `json:"version"`
	Environment string    `json:"environment"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	CreatedBy   string    `json:"created_by"`
	UpdatedBy   string    `json:"updated_by"`

	GitCommit   string `json:"git_commit,omitempty"`
	GitBranch   string `json:"git_branch,omitempty"`
	GitTag      string `json:"git_tag,omitempty"`
	GitAuthor   string `json:"git_author,omitempty"`
	PullRequest string `json:"pull_request,omitempty"`

	CompiledAt      time.Time `json:"compiled_at"`
	CompilerVersion string    `json:"compiler_version"`
	SchemaVersion   string    `json:"schema_version"`
	ValidationHash  string    `json:"validation_hash"`

	Status      RulesetStatus          `json:"status"`
	Deployments map[string]*Deployment `json:"deployments"`

	Tags        []string          `json:"tags"`
	Description string            `json:"description"`
	Owner       string            `json:"owner"`
	Team        string            `json:"team"`
	Metadata    map[string]string `json:"metadata"`
}

type VerbExecutor

type VerbExecutor interface {
	Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)
}

VerbExecutor defines the interface for executing verbs

type WaitMode

type WaitMode string

WaitMode controls how far Execute drives the shared state machine.

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