supervisor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 18 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

supervisor

github.com/webong/ext/res/graph/supervisor runs generic local component processes and projects their state, with recovery for unexpected exits.

CTX uses it when a selected backend does not already own its process lifecycle, for example local process plugins. Platform-specific process identity and signals live in the _unix and _windows files.

A state seen through Instance is already in the graph: the supervisor applies each lifecycle fact before it releases the instance, so a caller that waits for ready or stopped can read the matching graph fact straight away. The graph store is therefore written to while the instance lock is held and should not block for long.

See the graph runtime decision record for how supervision relates to process discovery.

Documentation

Overview

Package supervisor runs generic local component processes and projects their observed lifecycle into a graph. It does not decide why a process is trusted or whether a consumer is authorized to start it.

Index

Constants

View Source
const RuntimeNamespace = "ext.runtime"

Variables

View Source
var ErrRuntimeLeased = errors.New("runtime still has a live supervisor lease")

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	ID       string `json:"id"`
	Revision string `json:"revision"`
	Checksum string `json:"checksum"`
}

type Connection

type Connection struct {
	ID             string            `json:"id"`
	SourceEndpoint string            `json:"source_endpoint"`
	TargetEndpoint string            `json:"target_endpoint"`
	Metadata       map[string]string `json:"metadata,omitempty"`
}

type Endpoint

type Endpoint struct {
	ID        string `json:"id"`
	Address   string `json:"address"`
	Transport string `json:"transport"`
	Direction string `json:"direction,omitempty"`
}

type Instance

type Instance struct {
	ID              string       `json:"id"`
	Artifact        Artifact     `json:"artifact"`
	State           State        `json:"state"`
	PID             int          `json:"pid,omitempty"`
	ProcessIdentity string       `json:"process_identity,omitempty"`
	StartedAt       time.Time    `json:"started_at,omitempty"`
	UpdatedAt       time.Time    `json:"updated_at"`
	ExitCode        *int         `json:"exit_code,omitempty"`
	CrashCount      int          `json:"crash_count"`
	Health          string       `json:"health,omitempty"`
	LastError       string       `json:"last_error,omitempty"`
	Endpoints       []Endpoint   `json:"endpoints,omitempty"`
	Connections     []Connection `json:"connections,omitempty"`
	Dependencies    []string     `json:"dependencies,omitempty"`
}

type Options

type Options struct {
	Graph           store.Store
	SecretResolver  func(context.Context, SecretReference) (string, error)
	LogLimit        int
	RuntimeID       string
	RequireChecksum bool
	OrphanPolicy    OrphanPolicy
	LeaseDuration   time.Duration
	RetainTerminal  int
	// ProcessPolicyFactory installs optional platform resource or sandbox
	// controls for each launch attempt. CTX still controls the process tree.
	ProcessPolicyFactory func(Spec) (ProcessPolicy, error)
}

type Orphan

type Orphan struct {
	ID              string
	PID             int
	ProcessIdentity string
	Alive           bool
}

type OrphanPolicy

type OrphanPolicy string
const (
	// OrphanMark records an expired process lease and blocks new starts until
	// the caller explicitly resolves that process.
	OrphanMark OrphanPolicy = "mark"
	// OrphanTerminate terminates identity-matched process trees on recovery.
	OrphanTerminate OrphanPolicy = "terminate"
)

type ProcessPolicy

type ProcessPolicy interface {
	Configure(*exec.Cmd) error
	Attach(*os.Process) error
	Close() error
}

ProcessPolicy is an optional platform control supplied by an embedding service. Configure runs before checksum verification and secret resolution; Attach runs immediately after the child starts.

type RestartPolicy

type RestartPolicy struct {
	MaxAttempts  int
	InitialDelay time.Duration
	MaxDelay     time.Duration
}

type SecretReference

type SecretReference struct {
	Scope string `json:"scope"`
	ID    string `json:"id"`
}

type Spec

type Spec struct {
	Artifact         Artifact
	Command          string
	Args             []string
	Dir              string
	Environment      map[string]string
	SecretReferences map[string]SecretReference
	Endpoints        []Endpoint
	Connections      []Connection
	Dependencies     []string
	Restart          RestartPolicy
	HealthCheck      func(context.Context) error
	// EndpointReady checks that the declared endpoints can accept connections.
	// ProtocolHandshake verifies the consumer's protocol after endpoint readiness.
	// Neither hook receives resolved secret values.
	EndpointReady     func(context.Context, Instance) error
	ProtocolHandshake func(context.Context, Instance) error
	ReadinessTimeout  time.Duration
}

type State

type State string
const (
	StateStarting   State = "starting"
	StateRunning    State = "running"
	StateReady      State = "ready"
	StateStopping   State = "stopping"
	StateStopped    State = "stopped"
	StateCrashed    State = "crashed"
	StateRestarting State = "restarting"
	StateOrphaned   State = "orphaned"
)

type Supervisor

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

func New

func New(opts Options) (*Supervisor, error)

func (*Supervisor) Close

func (s *Supervisor) Close(ctx context.Context) error

func (*Supervisor) Health

func (s *Supervisor) Health(ctx context.Context, id string) (bool, error)

func (*Supervisor) Instance

func (s *Supervisor) Instance(id string) (Instance, error)

func (*Supervisor) Instances

func (s *Supervisor) Instances() []Instance

func (*Supervisor) Logs

func (s *Supervisor) Logs(id string) (string, error)

func (*Supervisor) Orphans

func (s *Supervisor) Orphans() []Orphan

Orphans returns processes left by an expired supervisor lease. While any live orphan remains unresolved, Start refuses to create another process.

func (*Supervisor) ResolveOrphan

func (s *Supervisor) ResolveOrphan(ctx context.Context, id string) error

ResolveOrphan terminates an identity-matched orphan process tree and clears its durable orphan state. It never targets a reused PID.

func (*Supervisor) Start

func (s *Supervisor) Start(ctx context.Context, spec Spec) (Instance, error)

func (*Supervisor) Stop

func (s *Supervisor) Stop(ctx context.Context, id string) error

Jump to

Keyboard shortcuts

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