state

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 12 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.

README

Inventory publication and admission

Coordinator implements ports.StateSource and ports.ExecutionGate over immutable, complete connection snapshots. It is host-owned; runtimes borrow it. Close runtimes before closing the coordinator and persistence resources.

An update follows this sequence:

  1. Prepare a complete candidate with a new revision and the same publication domain. Shared jump snapshots must agree across all dependent plans, including hops that have no standalone entry in the target map.
  2. Call BeginUpdate(ctx, expectedRevision, candidate) before writing storage. Affected nodes are blocked; unrelated operations can still be admitted.
  3. Call BeginPersistence() before attempting the external transaction.
  4. On a known commit, call ConfirmCommit(). On a proven rollback, call ConfirmRollback(). On an unknown outcome, retain the update and reload the authoritative store before choosing either conclusion. Abort() only works before persistence has been attempted.
  5. Call Publish(ctx, backend.RetirePlans). Publication, admission comparison, and operation registration are ordered under one in-memory lock. Retirement runs outside that lock while the affected barrier remains in place.

If publication fails after commit, Pending() stays true. The host must not repeat the transaction or claim activation succeeded. After confirming the committed candidate from storage, retry Publish with a fresh deadline and an idempotent retirement callback. Snapshot() is an administrative view and can show the committed revision while activation is pending.

Ordinary endpoint edits preserve already-admitted operations. Credential/trust changes, disablement, deletion, and policy changes cancel affected noncommitting permits. A commit permit admitted before the update remains valid until its own deadline or explicit close. This does not promise rollback of remote work.

For an upload's TransferStart-to-Commit transition, pass its live permit in Admission.Previous with the same OperationID and Binding. The coordinator revalidates the snapshot and atomically replaces the registration in its existing capacity slot. No extra slot is required at MaxActive. A foreign, closed, replayed, or mismatched permit cannot transfer capacity. Rejection leaves the original registration intact; after success, closing the old permit cannot release the new slot. Runtime retains the original SSH/SFTP transport through this change and releases finished stream admission before temporary cleanup. Host gates with their own capacity accounting must implement the same handoff; ports.NewPermit alone does not implement a quota ledger.

Display-only changes do not alter execution bindings or retire SSH connections. Hosts must change execution versions when displayed attributes affect policy. Deleted node IDs cannot be reused during a coordinator's lifetime; the host database must preserve that identity rule across process restarts. Every hop in an active candidate is checked against tombstones, including jumps absent from the current target map. Disabled records may retain old plans but cannot be re-enabled until those references are removed.

Connection retirement also covers work that was admitted before an edit but has not acquired its transport yet. Those old plans use uncached leases rather than recreating a retired pool. Retirement history is bounded; once full, new generations remain uncached for that connector's lifetime.

This component does not persist tasks or inventory. Deferred transfer binding, journal format migration, and database/Web adapters are separate integration work; a coordinator alone is not a complete dynamic MCP deployment.

Documentation

Overview

Package state coordinates immutable inventory publication and MCP operation admission. Persistence belongs to the host; no network or database I/O is performed while the publication lock is held.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUpdating           = errors.New("affected inventory is being published")
	ErrConflict           = errors.New("inventory revision conflict")
	ErrClosed             = errors.New("inventory coordinator is closed")
	ErrPersistenceUnknown = errors.New("persistence may have committed; reload before releasing admission")
	ErrUpdateState        = errors.New("inventory update state does not permit this operation")
	ErrIdentityReuse      = errors.New("deleted node identity cannot be reused")
	ErrCapacity           = errors.New("operation admission capacity exhausted")
)

Functions

This section is empty.

Types

type Change

type Change struct {
	Affected map[string]struct{}
	Revoke   map[string]struct{}
	Removed  []string
	Retired  []ssh.ConnectionPlan
	Policy   bool
}

type Coordinator

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

func New

func New(initial ports.OperationSnapshot, options Options) (*Coordinator, error)

func (*Coordinator) BeginUpdate

func (c *Coordinator) BeginUpdate(ctx context.Context, expected string, next ports.OperationSnapshot) (*Update, error)

BeginUpdate reserves the complete candidate before external persistence. Only one update can persist at a time; unrelated node operations continue.

func (*Coordinator) Close

func (c *Coordinator) Close() error

func (*Coordinator) DomainID

func (c *Coordinator) DomainID() string

func (*Coordinator) Enter

func (c *Coordinator) Enter(ctx context.Context, admission ports.Admission) (ports.Permit, error)

func (*Coordinator) List

func (*Coordinator) Pending

func (c *Coordinator) Pending() bool

func (*Coordinator) Resolve

func (*Coordinator) Snapshot

func (c *Coordinator) Snapshot() ports.OperationSnapshot

Snapshot is an administrative view. It can include a committed publication whose activation is still blocked; Pending reports that distinction.

type Options

type Options struct{ MaxActive int }

type Retire

type Retire func(context.Context, []ssh.ConnectionPlan) error

Retire must stop reuse of the supplied old connection generations. It runs outside the publication lock while affected admission remains blocked. Implementations must honor ctx; retry after a failure must be idempotent.

type Update

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

func (*Update) Abort

func (u *Update) Abort() error

Abort releases a reservation only before any persistence was attempted.

func (*Update) BeginPersistence

func (u *Update) BeginPersistence() error

BeginPersistence marks the point after which an error may mean a committed write. Call it before sending a database commit; Abort then fails closed.

func (*Update) ConfirmCommit

func (u *Update) ConfirmCommit() error

ConfirmCommit records an authoritative successful transaction (or a host's explicit in-memory publication). It does not release admission.

func (*Update) ConfirmRollback

func (u *Update) ConfirmRollback() error

ConfirmRollback is used only after the host has proved the write did not apply. It cannot undo a known commit or a partially activated publication.

func (*Update) Publish

func (u *Update) Publish(ctx context.Context, retire Retire) error

Publish activates the already committed candidate and retires old pools. If activation/retirement fails, the reservation remains blocked and Publish can be retried with a fresh deadline. Do not repeat the external transaction.

Jump to

Keyboard shortcuts

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