supervise

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMaxRestartsExhausted = errors.New("supervise: max restarts exhausted")

ErrMaxRestartsExhausted is returned when Run gives up.

Functions

func BuildAgentForTest

func BuildAgentForTest(t *testing.T) string

BuildAgentForTest compiles the cliwrap-agent binary once per test process and returns its path.

Types

type AgentHandle

type AgentHandle struct {
	Socket  *net.UnixConn
	Process *os.Process
	PID     int
	// contains filtered or unexported fields
}

AgentHandle is the result of spawning an agent: one half of a connected socket pair plus the OS process handle.

func (*AgentHandle) Close

func (h *AgentHandle) Close() error

Close shuts the host side of the socket, sends SIGTERM to the agent, waits briefly, then SIGKILL if still alive. It is idempotent.

type BackoffStrategy

type BackoffStrategy interface {
	Next(attempt int) time.Duration
}

BackoffStrategy computes the delay before the Nth restart attempt.

type ExponentialBackoff

type ExponentialBackoff struct {
	Initial    time.Duration
	Max        time.Duration
	Multiplier float64
	Jitter     float64 // 0..1, relative jitter range
	// contains filtered or unexported fields
}

ExponentialBackoff is an exponential backoff with optional jitter.

func (*ExponentialBackoff) Next

func (b *ExponentialBackoff) Next(attempt int) time.Duration

Next returns the delay before the (attempt)th retry. Attempt 0 returns Initial.

type RestartLoop

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

RestartLoop runs Starter.Start in a loop, honoring the configured policy.

func NewRestartLoop

func NewRestartLoop(opts RestartLoopOptions) *RestartLoop

NewRestartLoop returns a loop.

func (*RestartLoop) Run

func (r *RestartLoop) Run(ctx context.Context) error

Run executes Starter.Start until it succeeds (for OnFailure/Always) or MaxRestarts is exhausted. It returns nil on successful start, or the last observed error otherwise.

type RestartLoopOptions

type RestartLoopOptions struct {
	Starter     Starter
	Policy      RestartLoopPolicy
	MaxRestarts int // 0 = unlimited
	Backoff     BackoffStrategy
}

RestartLoopOptions configures a RestartLoop.

type RestartLoopPolicy

type RestartLoopPolicy int

RestartLoopPolicy controls whether Run retries on failure.

const (
	RestartLoopNever RestartLoopPolicy = iota
	RestartLoopOnFailure
	RestartLoopAlways
)

type Spawner

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

Spawner starts agent subprocesses.

func NewSpawner

func NewSpawner(opts SpawnerOptions) *Spawner

NewSpawner returns a Spawner.

func (*Spawner) Spawn

func (s *Spawner) Spawn(ctx context.Context, agentID string) (*AgentHandle, error)

Spawn creates a socket pair, execs the agent with one fd, and returns the host side of the socket wrapped in a net.UnixConn.

type SpawnerOptions

type SpawnerOptions struct {
	// AgentPath is the path to the cliwrap-agent binary. Required.
	AgentPath string

	// RuntimeDir is the parent directory for per-agent state.
	RuntimeDir string

	// ExtraEnv entries are appended to the agent's environment.
	ExtraEnv []string
}

SpawnerOptions configures a Spawner.

type Starter

type Starter interface {
	Start(ctx context.Context) error
}

Starter is any object that can attempt to start a process once.

type WatchResult

type WatchResult struct {
	PID      int
	ExitCode int
	Signal   int
}

WatchResult is the OS-level summary of a child's exit.

type Watcher

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

Watcher wraps os.Process.Wait in a context-aware API.

func NewWatcher

func NewWatcher(proc *os.Process) *Watcher

NewWatcher returns a Watcher for proc.

func (*Watcher) Wait

func (w *Watcher) Wait(ctx context.Context) (WatchResult, error)

Wait blocks until the process exits or ctx is canceled. On ctx cancel it returns ctx.Err() without killing the process — the caller must decide how to escalate.

Jump to

Keyboard shortcuts

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