run

package
v0.24.0 Latest Latest
Warning

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

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

Documentation

Overview

Package run is the execution-bound reversible-run wrap: it composes the runtime's scope and settlement primitives around an execution so a run is reversible by default — an isolated fork whose work is merged on success and discarded on failure.

It is the Go port of Python Shepherd's `_run_execution_bound` (PD2, _vcscore_runtime.py): fork isolated → mint the execution capability only after the fork succeeded → dispatch → merge (default) / seal / discard. The heavy machinery already lives in the runtime (Scope, ScopeManager, Seal, Settle, the merge gate); this package is the composition.

Merge semantics: an isolated run (the default) propagates physically through settlement, not Scope.Merge — `Seal` then `SettleSelect` (fast-forward) or `SettleApply` (three-way). A reviewer or authority decision runs against the child via `ProposeMerge`; the proposal is recorded before review, and the decision is recorded when the outcome is known (after settlement for an approval, before discard for a denial) via `RecordMergeProposal` / `RecordMergeDecision`. Shared-sandbox children are integrated with Scope.Merge by their own host; this package does not use the removed CommitMerge gate.

Index

Constants

View Source
const SchemaRunExecuted = "goatherd.run.executed.v1"

SchemaRunExecuted is the runtime record the wrap appends for each run — the durable trail of isolation, disposition, authority evidence, and outcome.

Variables

View Source
var ErrReviewDecisionUnrecorded = errors.New("run: work integrated but review decision was not recorded")

ErrReviewDecisionUnrecorded reports that the run's work integrated but its approval decision could not be appended. The work is on the parent; the failure is a provenance gap, not a failed integration.

Functions

func VerifyHandler

func VerifyHandler(ctx context.Context, probe *RunContext, h Handler) error

VerifyHandler is the negotiation conformance probe for a host-supplied handler, mirroring verify_execution_negotiation. A handler is execution-bound by receiving a RunContext; conformance means it refuses real execution when handed a capability with no backend, rather than succeeding unconfined.

probe is a RunContext the caller supplies (typically a throwaway scope carrying a backend-less capability); it is passed to the handler. A handler that attempts execution through the capability refuses with ErrExecutionAuthorityRequired or ErrPaddockNotEstablished — VerifyHandler requires exactly that. A handler that returns nil ran without authority and fails. This is a deliberate, opt-in probe for handlers that should be execution-bound; a pure-data path never receives a RunContext at all.

Types

type DecisionProvider

type DecisionProvider func(ctx context.Context, proposal goatherd.MergeProposal) error

DecisionProvider judges a run's proposed changes before integration, mirroring merge_with_authority's data-only decision provider. Approve by returning nil; deny by returning an error (the run is discarded).

type Disposition

type Disposition string

Disposition is what a successful reversible run does with its isolated work.

const (
	// DispositionMerge integrates the run's changes into the parent. It is the
	// default and, for an isolated run, is a physical propagation: Seal then
	// SettleSelect, falling back to SettleApply when the parent has moved.
	DispositionMerge Disposition = "merge"
	// DispositionSeal freezes the run's changes into a RetainedOutput and leaves
	// integration to the caller (fork-and-choose).
	DispositionSeal Disposition = "seal"
	// DispositionAuthorityMerge is the authority-aware merge: the run's sealed
	// changes are judged by Options.Decision before integration, and a denial
	// discards them.
	DispositionAuthorityMerge Disposition = "authority_merge"
)

type Handler

type Handler func(ctx context.Context, rc *RunContext) (Result, error)

Handler runs the run's work in RunContext. It is the structural analogue of a driver's prepare_bound: a handler receives execution authority per call and never stores it.

type Options

type Options struct {
	// OwnerID names the run's child scope. Required.
	OwnerID string
	// NonReversible runs against the parent scope with isolation "ground",
	// recorded as such — the loud opt-out. It cannot be combined with a
	// non-merge disposition.
	NonReversible bool
	// Disposition defaults to DispositionMerge.
	Disposition Disposition
	// Placement defaults to PlacementAuto.
	Placement containment.Placement
	// Confinement is the caller's authority lowering; nil asks the backend for
	// its default. Plan 1's confinement lowerers produce it. Mutually exclusive
	// with Plan.
	Confinement *confinement.ConfinementSpec
	// Plan is the compiled permission plan (confinement.Install) driving this
	// run: it supplies the confinement spec (the jail monitor's) and the plan
	// digest / descriptor recorded as authority evidence. Mutually exclusive
	// with Confinement.
	Plan *confinement.PermissionPlan
	// Reviewer, when set, gates a merge disposition: a denial discards the run
	// and returns *goatherd.SupervisorDeniedError.
	Reviewer goatherd.MergeReviewer
	// Decision, required for DispositionAuthorityMerge, judges the run's proposed
	// changes before integration; a denial discards the run.
	Decision DecisionProvider
	// Backend is the paddock backend the capability carries (e.g.
	// landlock.Detect()). It may be nil on an advisory host.
	Backend containment.Backend
	// NewSandbox constructs the run's isolated sandbox. Required for a
	// reversible run; Reversible calls Create on it. It is not used for a
	// NonReversible run.
	NewSandbox func(runID string) (sandbox.Sandbox, error)
	// Snapshot is the opaque caller snapshot recorded at fork (typically
	// conversation history).
	Snapshot any
	// MaxDiffLines bounds a reviewer proposal's diff; <= 0 is unbounded.
	MaxDiffLines int
}

Options configures one reversible run. The zero value plus OwnerID runs a merge-disposition, auto-placement, isolated run with a Permissive default confinement.

type Outcome

type Outcome struct {
	// Scope is the run scope (the child, or the parent for a NonReversible run).
	Scope *goatherd.Scope
	// Output is the sealed output for a seal disposition or a merge that sealed
	// on the way (nil otherwise).
	Output *goatherd.RetainedOutput
	// Result is the handler's outcome.
	Result Result
	// Isolation is "isolated" or "ground".
	Isolation string
	// Disposition is the disposition that ran.
	Disposition Disposition
}

Outcome is the wrap's result.

func Reversible

func Reversible(ctx context.Context, mgr *goatherd.ScopeManager, parent *goatherd.Scope, opts Options, handler Handler) (Outcome, error)

Reversible runs handler as a reversible transaction.

  1. Resolve placement and backend availability before forking, so a paddock that cannot be established never allocates a scope.
  2. A reversible run creates an isolated child scope (ForkIsolated); a NonReversible run uses the parent scope.
  3. The capability is minted only after the fork succeeded, and a confined run is guarded by RequireExecutionAuthority.
  4. The handler runs; on error the child is discarded, never half-merged.
  5. On success the disposition integrates (merge), seals, or refuses.

type Result

type Result struct {
	Value    map[string]any
	Evidence string
	ExitCode int
	Denied   bool
}

Result is a handler's outcome: its value, the authority-evidence digest (the paddock monitor's permission-plan digest, when a confined run recorded one), and the run's primary execution status.

type RunContext

type RunContext struct {
	Scope       *goatherd.Scope
	Capability  containment.Capability
	Confinement confinement.ConfinementSpec
}

RunContext is what a Handler receives: the run's scope, the execution capability that proves authority, and the resolved confinement spec. The handler runs confined commands through RunContext.Exec (capability-first, paddock-or-refuse) or the scope's sandbox (sandbox-first), and never needs to know about forks or settlement.

func (*RunContext) Exec

Exec runs a command confined by the capability: resolve → profile → probe → launch. It is the handler's first-class execution path and refuses without a paddock backend (ErrPaddockNotEstablished) rather than running unconfined — the structural guarantee that real execution implies authority.

Jump to

Keyboard shortcuts

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