execution

package
v0.0.0-...-8d0dba2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package execution reserves a worktree for one executor before it mutates runtime state or resources. A retained ownership record requires explicit reconciliation even after the OS has released a crashed process's lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLease

func ContextWithLease(ctx context.Context, lease *Lease) context.Context

Types

type ConflictError

type ConflictError struct {
	Worktree         string
	Owner            *Owner
	RecoveryRequired bool
	Cause            error
}

ConflictError reports an active owner or abandoned execution awaiting reconciliation. Owner can be nil during an owner's metadata publication.

func (*ConflictError) Code

func (*ConflictError) Code() string

func (*ConflictError) Error

func (e *ConflictError) Error() string

func (*ConflictError) Unwrap

func (e *ConflictError) Unwrap() error

type Lease

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

func Acquire

func Acquire(worktree string, owner Owner, opts ...Option) (*Lease, error)

Acquire immediately rejects a competing execution, including one in the same process. It never modifies the previous owner's marker on rejection.

func FromContext

func FromContext(ctx context.Context) *Lease

func (*Lease) Abandon

func (l *Lease) Abandon() error

Abandon unlocks the worktree while preserving the recovery record. It never grants another execution permission to proceed without reconciliation. Use RequireRecovery while the current owner still has finalization work to do.

func (*Lease) Owner

func (l *Lease) Owner() Owner

func (*Lease) Release

func (l *Lease) Release() error

Release clears the ownership record and unlocks the worktree. The caller must have confirmed resource cleanup first, or called RequireRecovery to preserve the record. A Release after Abandon leaves its recovery marker intact.

func (*Lease) RequireRecovery

func (l *Lease) RequireRecovery()

RequireRecovery marks cleanup incomplete without unlocking the worktree. Call this before writing final status or restoring an enclosing operation's temporary environment. It immediately prevents borrowing this lease for more execution; Release retains the recovery marker once finalization is complete.

func (*Lease) ValidFor

func (l *Lease) ValidFor(worktree string) bool

ValidFor permits an engine to reuse its caller's live lease. An absent, released, abandoned, recovery-required or different-worktree lease cannot grant admission.

type Option

type Option func(*options)

func WithRecovery

func WithRecovery(reconcile func(Owner) error) Option

WithRecovery permits replacing a retained owner only after reconcile returns nil. The callback runs while holding the worktree lock and must establish that resources left by the previous execution no longer conflict. A dead PID alone cannot establish this: children and external resources can outlive it.

type Owner

type Owner struct {
	Token      string    `json:"token"`
	PID        int       `json:"pid"`
	Worktree   string    `json:"worktree"`
	Target     string    `json:"target,omitempty"`
	Mode       string    `json:"mode,omitempty"`
	Kind       string    `json:"kind,omitempty"`
	AcquiredAt time.Time `json:"acquiredAt"`
}

Owner identifies the execution responsible for a worktree. Acquire supplies Token, PID, Worktree and AcquiredAt; callers describe Target, Mode and Kind. This record deliberately contains no runtime environment or credentials.

func ReadOwner

func ReadOwner(worktree string) (*Owner, error)

ReadOwner reads the diagnostic/recovery record without creating state. The presence of a record does not distinguish an active owner from an abandoned execution; only acquiring the OS lock can establish that distinction.

Jump to

Keyboard shortcuts

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