Documentation
¶
Overview ¶
Package runtime mounts one immutable plugin plan with scoped services and reversible lifecycle effects.
Index ¶
- Constants
- Variables
- type CandidateContext
- type CandidateLifecycle
- type CandidateMount
- type CandidatePreMounter
- type CandidateStateMigrator
- type Config
- type ConfigValidator
- type EntryLive
- type EntryRetirement
- type EntryStateTransfer
- type EntryTransition
- type EntryUpdate
- type ExportLive
- type Factory
- type Lifecycle
- type Live
- type MountContext
- type Mounted
- func (mounted *Mounted) Activate(ctx context.Context, entryID string) error
- func (mounted *Mounted) Close(ctx context.Context) error
- func (mounted *Mounted) Export(name string) (value any, contract plugin.Contract, provider string, revision uint64, ...)
- func (mounted *Mounted) Live() Live
- func (mounted *Mounted) Plan() plugin.Plan
- func (mounted *Mounted) Reconcile(ctx context.Context, candidate ReconcileCandidate) (ReconcileReceipt, error)
- func (mounted *Mounted) Replace(ctx context.Context, entryID, implementation string) error
- func (mounted *Mounted) Unmount(ctx context.Context, entryID string) error
- type Permissions
- type Publisher
- type ReconcileCandidate
- type ReconcileReceipt
- type Registry
- type Services
- type StateLifecycle
- type StateMigration
- type StateQuiescer
- type StateResumer
- type StateSnapshotter
Constants ¶
const LiveFormatVersion = 1
const MaximumStateSnapshotBytes = 1 << 20
MaximumStateSnapshotBytes bounds both predecessor snapshots and migrated state. The bound is checked before and after canonicalization.
const ReconcileReceiptFormatVersion = 3
Variables ¶
var ( ErrReconcileStale = errors.New("plugin reconciliation candidate is stale") ErrReconcileNoChanges = errors.New("plugin reconciliation candidate has no changes") ErrCandidatePreMountUnsupported = errors.New("plugin reconciliation candidate cannot be pre-mounted") ErrStateMigrationNeeded = errors.New("plugin reconciliation requires explicit state migration") ErrReconcileLeakDetected = errors.New("plugin reconciliation detected retained ownership") )
var ( // ErrUnknownExport means a launcher requested a boundary not declared by // the frozen profile. ErrUnknownExport = errors.New("unknown plugin realm export") // currently active. ErrExportUnavailable = errors.New("plugin realm export unavailable") )
Functions ¶
This section is empty.
Types ¶
type CandidateContext ¶
type CandidateContext struct {
EntryID string
Identity plugin.Identity
Config json.RawMessage
Services Services
Lifecycle CandidateLifecycle
Permissions Permissions
Descriptor plugin.Descriptor
}
CandidateContext is the effect-restricted environment for a replacement pre-mount. Services are the exact currently bound dependencies and remain read-only. Publication and worker APIs are unavailable until Activate.
type CandidateLifecycle ¶
CandidateLifecycle owns resources acquired while a replacement is prepared. It deliberately omits Go: a candidate may acquire reversible resources, but it cannot start background work before the live dependency closure reaches its safe point.
type CandidateMount ¶
type CandidateMount interface {
Activate(context.Context, MountContext) error
}
CandidateMount is a successfully prepared replacement. Activate is called exactly once, after the affected live dependency closure has quiesced, with the ordinary publication and lifecycle capabilities. Resources acquired by PreMount remain runtime-owned through CandidateContext.Lifecycle.
type CandidatePreMounter ¶
type CandidatePreMounter interface {
PreMount(context.Context, CandidateContext) (CandidateMount, error)
}
CandidatePreMounter prepares a replacement without publishing services, starting workers, or changing externally visible state. Reconcile refuses a changed factory that lacks this contract before it tears down live work.
type CandidateStateMigrator ¶
type CandidateStateMigrator interface {
CandidateMount
MigrateState(context.Context, StateMigration) (json.RawMessage, error)
}
CandidateStateMigrator explicitly converts a predecessor snapshot for one changed stateful row. The returned strict-JSON object is validated and then supplied through MountContext.State when the prepared candidate activates.
type Config ¶
type Config struct {
Plan plugin.Plan
Registry *Registry
Implementations map[string]string
Values map[string]json.RawMessage
Permissions map[string][]plugin.Permission
ShutdownTimeout time.Duration
}
Config supplies the immutable plan and separate private deployment/value planes. A missing implementation entry selects the descriptor's symbolic name; production profiles normally pin every entry explicitly.
type ConfigValidator ¶
type ConfigValidator interface {
ValidateConfig(json.RawMessage) error
}
ConfigValidator proves one separate values document before any plugin is mounted. A descriptor with ConfigSchema requires this interface.
type EntryLive ¶
type EntryLive struct {
State string `json:"state"`
Desired bool `json:"desired"`
Identity plugin.Identity `json:"identity"`
Implementation string `json:"implementation"`
Runtime inspect.ArtifactIdentity `json:"runtime"`
Workers int `json:"workers"`
Effects int `json:"effects"`
Services []plugin.Contract `json:"services,omitempty"`
Error string `json:"error,omitempty"`
}
EntryLive is payload-free runtime evidence for one plugin row.
type EntryRetirement ¶
type EntryRetirement struct {
Entry string `json:"entry"`
RetiredScopes int `json:"retired_scopes"`
ClosedScopes int `json:"closed_scopes"`
RemainingWorkers int `json:"remaining_workers"`
RemainingEffects int `json:"remaining_effects"`
RemainingChildScopes int `json:"remaining_child_scopes"`
RemainingServices int `json:"remaining_services"`
}
EntryRetirement is payload-free evidence collected between teardown and replacement activation. A successful receipt always has every captured lifecycle closed and every remaining count at zero.
type EntryStateTransfer ¶
type EntryStateTransfer struct {
Entry string `json:"entry"`
Schema plugin.Contract `json:"schema"`
BeforeStateDigest string `json:"before_state_digest"`
AfterStateDigest string `json:"after_state_digest"`
MigratorImplementation string `json:"migrator_implementation,omitempty"`
}
EntryStateTransfer is payload-free evidence that one affected stateful row was restored. MigratorImplementation is present only for a changed row that ran an explicit candidate migrator; an unchanged dependent retains the same canonical snapshot digest without claiming a migration.
type EntryTransition ¶
type EntryTransition struct {
Entry string `json:"entry"`
BeforeImplementation string `json:"before_implementation"`
AfterImplementation string `json:"after_implementation"`
BeforeRuntime inspect.ArtifactIdentity `json:"before_runtime"`
AfterRuntime inspect.ArtifactIdentity `json:"after_runtime"`
BeforeConfigDigest string `json:"before_config_digest"`
AfterConfigDigest string `json:"after_config_digest"`
BeforePermissions []plugin.Permission `json:"before_permissions,omitempty"`
AfterPermissions []plugin.Permission `json:"after_permissions,omitempty"`
}
type EntryUpdate ¶
type EntryUpdate struct {
Entry string
SetImplementation bool
Implementation string
SetConfig bool
Config json.RawMessage
SetPermissions bool
Permissions []plugin.Permission
}
EntryUpdate is one explicit row replacement. Set fields distinguish an omitted plane from selecting its zero value (for example, the descriptor's default implementation or an empty permission set).
type ExportLive ¶
type ExportLive struct {
Provider string `json:"provider"`
Contract plugin.Contract `json:"contract"`
Available bool `json:"available"`
Revision uint64 `json:"revision,omitempty"`
}
ExportLive is a payload-free view of one declared application boundary.
type Factory ¶
type Factory interface {
Descriptor() plugin.Descriptor
Mount(context.Context, MountContext) error
}
Factory mounts one implementation of an immutable plugin descriptor. Mount may register services and scoped work, but it must not start untracked work.
type Lifecycle ¶
type Lifecycle interface {
Defer(name string, dispose func(context.Context) error) error
// Do executes caller-blocking work in the current goroutine while owning it
// as a cancellable lifecycle worker. Close waits for Do to return.
Do(name string, work func(context.Context) error) error
Go(name string, worker func(context.Context) error) error
}
Lifecycle owns every runtime effect started by a plugin.
type Live ¶
type Live struct {
FormatVersion uint64 `json:"format_version"`
Fingerprint string `json:"fingerprint"`
Realm plugin.Realm `json:"realm"`
Sequence uint64 `json:"sequence"`
ObservedAt time.Time `json:"observed_at"`
State string `json:"state"`
Entries map[string]EntryLive `json:"entries"`
Exports map[string]ExportLive `json:"exports,omitempty"`
}
Live identifies both the exact client/host/server plugin plan and its live implementation selections.
type MountContext ¶
type MountContext struct {
EntryID string
Identity plugin.Identity
Config json.RawMessage
Services Services
Publisher Publisher
Lifecycle Lifecycle
State StateLifecycle
Permissions Permissions
Descriptor plugin.Descriptor
}
MountContext is the complete scoped environment of one plugin instance.
type Mounted ¶
type Mounted struct {
// contains filtered or unexported fields
}
Mounted is one plugin realm. Mutating lifecycle operations serialize through its mutex; service lookups remain concurrent and do not take that mutex.
func Mount ¶
Mount validates the entire plan, deployment, and values before acquiring the first plugin resource, then mounts in deterministic dependency order.
func (*Mounted) Activate ¶
Activate enables one entry and then remounts every desired dependent whose required providers are active.
func (*Mounted) Close ¶
Close idempotently cancels all scoped work and disposes registrations in reverse dependency order.
func (*Mounted) Export ¶
func (mounted *Mounted) Export(name string) ( value any, contract plugin.Contract, provider string, revision uint64, err error, )
Export returns one service deliberately exposed by the compiled profile. The returned revision changes whenever the provider republishes the service, allowing application launchers to detect a replacement without depending on implementation details.
func (*Mounted) Reconcile ¶
func (mounted *Mounted) Reconcile( ctx context.Context, candidate ReconcileCandidate, ) (ReconcileReceipt, error)
Reconcile atomically applies implementation, values, and permission changes under the same immutable plan. It validates and effect-restricted pre-mounts every changed row before quiescing the affected dependency closure, rolls the complete set back on an activation failure, and transfers every affected stateful row only through its exact schema and explicit lifecycle contract. Topology/descriptor changes require a future plan-level reconciliation API and cannot be smuggled through this method.
type Permissions ¶
type Permissions interface {
Allows(kind, resource, operation string) bool
Snapshot() []plugin.Permission
}
Permissions is the deployment grant selected for one plugin instance. It is always a subset of the immutable descriptor ceiling. A plugin must check the grant at the effect boundary in addition to consuming any declared authority service.
type Publisher ¶
Publisher admits only services declared by the mounted plugin descriptor. Every publication is owned by the plugin lifecycle scope and is removed on unmount.
type ReconcileCandidate ¶
type ReconcileCandidate struct {
ExpectedPlanFingerprint string
ExpectedSequence uint64
Updates []EntryUpdate
}
ReconcileCandidate is bound to both the immutable plan and one observed lifecycle sequence. This prevents a UI or operator from applying a review made before a provider failure, replacement, or manual unmount.
type ReconcileReceipt ¶
type ReconcileReceipt struct {
FormatVersion uint64 `json:"format_version"`
PlanFingerprint string `json:"plan_fingerprint"`
BeforeSequence uint64 `json:"before_sequence"`
AfterSequence uint64 `json:"after_sequence"`
Transitions []EntryTransition `json:"transitions"`
Retirements []EntryRetirement `json:"retirements"`
StateTransfers []EntryStateTransfer `json:"state_transfers,omitempty"`
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry binds deployment implementation names to exact factories and code artifacts. Descriptor resolution remains in plugin.Catalog; this registry is the private deployment plane.
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) RegisterArtifact ¶
func (registry *Registry) RegisterArtifact( implementation string, artifact inspect.ArtifactIdentity, factory Factory, ) error
RegisterArtifact binds an implementation to exact executable/module bytes.
type Services ¶
type Services interface {
Lookup(name string) (
value any, contract plugin.Contract, provider string, revision uint64, found bool,
)
}
Services exposes only dependencies declared and bound by the compiled plan. Lookup remains live: an optional provider can appear after its consumer mounts, and a provider removed during reconciliation disappears immediately.
type StateLifecycle ¶
type StateLifecycle interface {
Restored() (snapshot json.RawMessage, available bool, err error)
Quiesce(StateQuiescer) error
Snapshot(StateSnapshotter) error
}
StateLifecycle is the state-transfer boundary available only to descriptors that declare a StateSchema. A restoring mount must consume Restored before it publishes services, and every snapshot-capable mount must register exactly one snapshot callback before Mount or Activate returns. Mutation-owning providers may additionally register one transactional quiescer.
type StateMigration ¶
type StateMigration struct {
EntryID string
Schema plugin.Contract
SourceImplementation string
Snapshot json.RawMessage
}
StateMigration is the exact predecessor state presented to an explicit candidate migrator after the affected live dependency closure has retired. Snapshot is independently cloned and remains private to the runtime and the selected migrator.
type StateQuiescer ¶
type StateQuiescer func(context.Context) (StateResumer, error)
StateQuiescer closes mutation admission and drains already-admitted mutations before a snapshot. The runtime invokes the returned resumer only when reconciliation is refused before lifecycle teardown. A successful transition closes the quiesced scope.
type StateResumer ¶
StateResumer reopens mutation admission after a refused pre-teardown state capture. It must be idempotent and honor its bounded context.
type StateSnapshotter ¶
type StateSnapshotter func(context.Context) (json.RawMessage, error)
StateSnapshotter returns one bounded strict-JSON object representing the complete restorable state of a mounted entry. The callback must take an internally consistent snapshot when invoked; payload bytes never leave the runtime reconciliation boundary.