Documentation
¶
Overview ¶
Package run executes deterministic Programs against an append-only tree log. Store.Append acknowledges every Effect intent before dispatch and every settlement before another Step can consume it. A Checkpoint materializes its prefix: recovery starts from the newest one, re-executes only the Steps after it, and rejects code whose replayed Transition differs from the log. The Checkpoint is the authority for its prefix: recovery never re-executes the Steps it covers, so nondeterministic code is detected only in Steps after the newest Checkpoint. Retained inputs, successful outputs and unaddressed Signals must satisfy their bound Program's Descriptor before recovery acquires a writer Epoch. Wait answers belong to their Wait's schema; Definition.Restore owns only the opaque execution state.
A Runtime owns the host Build identity. Its Compiler capability lets strategy packages freeze declarations into Program references without exposing the Runtime's execution authority. Bind is the atomic construction API for custom Definitions. Revision identifies opaque callbacks and clients; changing Build, Revision, a declaration, or a child reference changes the Program reference.
Start is durable and detached from the request context after admission. Reuse the same StartID to retry submission; a conflicting declaration is rejected. Recover explicitly acquires a new writer Epoch. A duplicate Start never takes over another writer. Run instead attaches the foreground operation to its context and joins and releases its anonymous local writer before returning. An interrupted Run returns RuntimeError with the durable recovery identity. Await checks its observation context before reading and before returning a result, so concurrent completion cannot conceal caller cancellation. A later observation can still read the committed outcome. Close cancels and joins local work without declaring an uncertain external operation stopped; unresolved Effects remain in the durable log. ReleaseTree joins an exited root's local writer before relinquishing it; a writer already stopped by Close can be released even without a root Exit.
Process paths own ancestry. A child key cannot be reused within its parent's lifetime because that would also reuse Effect identities, so each parent keeps every key it has started with the LSN of that child's Started record. The set grows with every child started and is bounded only when TreeLimits.MaxChildren is. A child's state leaves the tree once its Exit is consumed and Reaped is appended; Runtime.Answered then reads only the history of that child's subtree, from its Started record to its Reaped record.
Completion carries a definite Effect outcome. An Unknown outcome stays pending until explicit resolution or a permitted replay under the same EffectID. Exit and Result are published only after all descendants and uncertain operations have drained, including after cancellation or failure. Yield declares local Wait values directly; the inbox never contains a wait-opening handshake. A WaitKey permanently identifies its first question, answer schema and byte limit. Withdrawal stops answer admission but retains that contract in the process and its Checkpoints; reintroduction must repeat it exactly. An answered key cannot reopen, so a new question requires a new key. Retained contracts grow with the process's distinct WaitKeys until reaping.
Store.Load serves recovery and Store.Read serves history, so the cost of each is bounded by what it returns rather than by the age of the tree. Observe reads history after an LSN and remains valid across recovery; a tree this Runtime writes wakes its observers on commit. Runtime.History reads the complete log for projections that need facts a Checkpoint no longer carries. Observation of an already exited tree ends at the head confirmed on its first pull, including recovery activations committed after the root's Exit. Hosts own log retention. Config.Deltas is the separate best-effort stream: channel saturation may drop increments but cannot change committed usage or outcomes. Keep the channel open until Close returns.
Index ¶
- Constants
- Variables
- func NormalizeDiagnostic(message string) string
- func RequireContext(ctx context.Context) context.Context
- func UsageFromRecord(record Record) (ProcessID, Usage)
- func ValidDescription(description string) bool
- func ValidDiagnostic(message string) bool
- func ValidQualifiedName(name string) bool
- type Activated
- type Batch
- type BindingConfig
- type Budget
- type CallbackPanicError
- type Capability
- type CapabilitySet
- func (c CapabilitySet) Allows(requested CapabilitySet) bool
- func (c CapabilitySet) Contains(capability Capability) bool
- func (CapabilitySet) JSONSchemaModel() any
- func (c CapabilitySet) MarshalJSON() ([]byte, error)
- func (c *CapabilitySet) UnmarshalJSON(data []byte) error
- func (c CapabilitySet) Values() []Capability
- type Checkpoint
- type ChildBinding
- type ChildKey
- type ChildSpec
- type ClassifiedError
- type Compiler
- type Completion
- type Config
- type ControlKind
- type ControlOrigin
- type ControlRequested
- type Definition
- type Delta
- type DeltaEmitter
- type Descriptor
- func (d Descriptor) DecodeOutput[T any](output Payload) (T, error)
- func (d Descriptor) Description() string
- func (d Descriptor) Digest() Digest
- func (d Descriptor) EncodeInput[T any](value T) (Payload, error)
- func (d Descriptor) InputSchema() jsonschema.Schema
- func (Descriptor) JSONSchemaModel() any
- func (d Descriptor) MarshalJSON() ([]byte, error)
- func (d Descriptor) Name() string
- func (d Descriptor) OutputSchema() jsonschema.Schema
- func (d Descriptor) SignalSchema() jsonschema.Schema
- func (d *Descriptor) UnmarshalJSON(data []byte) error
- func (d Descriptor) Valid() bool
- func (d Descriptor) ValidateInput(input Payload) error
- func (d Descriptor) ValidateOutput(output Payload) error
- func (d Descriptor) ValidateSignal(input Payload) error
- type DescriptorConfig
- type Digest
- type Dispatcher
- type Effect
- type EffectID
- type EffectIntent
- type EffectPolicy
- type EffectRequest
- type EffectSettled
- type EffectTarget
- type Entry
- type Epoch
- type Execution
- type ExecutionFailed
- type ExecutionState
- type Exit
- type Exited
- type Failure
- func (f Failure) Classification() FailureClassification
- func (f Failure) Code() string
- func (Failure) JSONSchemaModel() any
- func (f Failure) Kind() FailureKind
- func (f Failure) MarshalJSON() ([]byte, error)
- func (f Failure) Message() string
- func (f *Failure) UnmarshalJSON(data []byte) error
- func (f Failure) Valid() bool
- type FailureClassification
- type FailureKind
- type Handle
- func (h *Handle[O]) Answer[A any](ctx context.Context, wait WaitKey, value A) error
- func (h *Handle[O]) Await(ctx context.Context) (Result[O], error)
- func (h *Handle[O]) Cancel(ctx context.Context, reason string) error
- func (h *Handle[O]) DeliverSignals(ctx context.Context, signals ...Signal) (bool, error)
- func (h *Handle[O]) Epoch() Epoch
- func (h *Handle[O]) ID() ProcessID
- func (h *Handle[O]) Inspect(ctx context.Context) (TreeInspection, error)
- func (h *Handle[O]) Kill(ctx context.Context, reason string) error
- func (h *Handle[O]) Observe(ctx context.Context, after LSN) iter.Seq2[Entry, error]
- func (h *Handle[O]) Pause(ctx context.Context, reason string) error
- func (h *Handle[O]) ProgramRef() ProgramRef
- func (h *Handle[O]) ReplayUnknownEffect(ctx context.Context, id EffectID) error
- func (h *Handle[O]) ResolveUnknownEffect(ctx context.Context, id EffectID, outcome Settlement) error
- func (h *Handle[O]) Resume(ctx context.Context) error
- type Inbox
- type LSN
- type Log
- type MemoryStore
- type Message
- type Payload
- func (p Payload) Decode[T any]() (T, error)
- func (p Payload) Equal(other Payload) bool
- func (p Payload) IsZero() bool
- func (p Payload) JSON() json.RawMessage
- func (Payload) JSONSchemaModel() any
- func (p Payload) MarshalJSON() ([]byte, error)
- func (p *Payload) UnmarshalJSON(data []byte) error
- func (p Payload) Valid() bool
- type PendingCheckpoint
- type PendingEffect
- type ProcessAdmission
- func (p ProcessAdmission) Budget() Budget
- func (p ProcessAdmission) Capabilities() CapabilitySet
- func (p ProcessAdmission) Descriptor() Descriptor
- func (p ProcessAdmission) ProcessID() ProcessID
- func (p ProcessAdmission) ProgramRef() ProgramRef
- func (p ProcessAdmission) StartID() (StartID, bool)
- func (p ProcessAdmission) Valid() bool
- type ProcessAdmitter
- type ProcessAdmitterFunc
- type ProcessCheckpoint
- type ProcessID
- func (p ProcessID) Child(key ChildKey) (ProcessID, error)
- func (p ProcessID) Contains(other ProcessID) bool
- func (p ProcessID) Depth() uint32
- func (p ProcessID) IsZero() bool
- func (ProcessID) JSONSchemaModel() any
- func (p ProcessID) Key() (ChildKey, bool)
- func (p ProcessID) MarshalText() ([]byte, error)
- func (p ProcessID) Parent() (ProcessID, bool)
- func (p ProcessID) Root() ProcessID
- func (p ProcessID) String() string
- func (p *ProcessID) UnmarshalText(data []byte) error
- func (p ProcessID) Valid() bool
- type ProcessInspection
- type Program
- type ProgramRef
- func (p ProgramRef) Build() string
- func (p ProgramRef) Digest() Digest
- func (ProgramRef) JSONSchemaModel() any
- func (p ProgramRef) MarshalJSON() ([]byte, error)
- func (p ProgramRef) Name() string
- func (p ProgramRef) String() string
- func (p *ProgramRef) UnmarshalJSON(data []byte) error
- func (p ProgramRef) Valid() bool
- type ProgramResolver
- type QualifiedName
- type Quota
- type Reaped
- type Record
- type RecordKind
- type ReplayPolicy
- type Result
- type Runtime
- func (r *Runtime) Answered(ctx context.Context, process ProcessID, wait WaitKey, answer Payload) (bool, error)
- func (r *Runtime) Close(ctx context.Context) error
- func (r *Runtime) Compiler() *Compiler
- func (r *Runtime) History(ctx context.Context, root ProcessID) (Log, error)
- func (r *Runtime) Inspect(ctx context.Context, root ProcessID) (TreeInspection, error)
- func (r *Runtime) Process(id ProcessID) (*Handle[Payload], bool)
- func (r *Runtime) Recover[I, O any](ctx context.Context, program Program[I, O], root ProcessID) (*Handle[O], error)
- func (r *Runtime) ReleaseTree(ctx context.Context, root ProcessID) error
- func (r *Runtime) Run[I, O any](ctx context.Context, program Program[I, O], input I) (O, error)
- func (r *Runtime) Start[I, O any](ctx context.Context, program Program[I, O], request StartRequest[I]) (*Handle[O], error)
- type RuntimeError
- type Settlement
- func (s Settlement) Failure() (Failure, bool)
- func (Settlement) JSONSchemaModel() any
- func (s Settlement) MarshalJSON() ([]byte, error)
- func (s Settlement) Payload() Payload
- func (s Settlement) SpawnResult() (ProcessID, Failure, error)
- func (s Settlement) Status() SettlementStatus
- func (s *Settlement) UnmarshalJSON(data []byte) error
- func (s Settlement) Valid() bool
- type SettlementStatus
- type Signal
- type SignalAdmitted
- type SignalID
- type SignalReceipt
- type StartConflictError
- type StartID
- type StartRequest
- type Started
- type StartedChild
- type Status
- type Stepped
- type Store
- type Termination
- func (t Termination) Cause() TerminationCause
- func (t Termination) Failure() (Failure, bool)
- func (Termination) JSONSchemaModel() any
- func (t Termination) MarshalJSON() ([]byte, error)
- func (t Termination) Output() (Payload, bool)
- func (t Termination) Reason() string
- func (t Termination) Status() Status
- func (t *Termination) UnmarshalJSON(data []byte) error
- func (t Termination) Valid() bool
- type TerminationCause
- type TerminationError
- type Transition
- func (t Transition) Consumed() uint32
- func (t Transition) Effects() []Effect
- func (t Transition) Failure() (Failure, bool)
- func (t Transition) Kind() TransitionKind
- func (t Transition) MarshalJSON() ([]byte, error)
- func (t Transition) Output() (Payload, bool)
- func (t *Transition) UnmarshalJSON(data []byte) error
- func (t Transition) Valid() bool
- func (t Transition) Waits() []Wait
- type TransitionKind
- type TreeInspection
- type TreeLimits
- type Turn
- type Usage
- type Wait
- type WaitCheckpoint
- type WaitKey
Examples ¶
Constants ¶
const MaxDescriptionBytes = 4096
const MaxDiagnosticBytes = 4096
const MaxPayloadBytes = 64 << 20
MaxPayloadBytes is the maximum encoded JSON size of an individual Agent input, output, Effect, Signal, or settlement payload. Both the supplied bytes and the canonical encoding must fit. Canonical payloads use RFC 7493 JSON, omit whitespace, sort object names by UTF-16 code units (RFC 8785 section 3.2.3), preserve number literals verbatim, and escape <, >, &, U+2028 and U+2029. Strings otherwise use their shortest JSON encoding. Digests over payloads and persisted payload bytes use this form; this is not RFC 8785 number canonicalization.
Variables ¶
var ( ErrInvalidChildStart = errors.New("run: invalid child process start") ErrInvalidChildControl = errors.New("run: invalid child control") )
var ( ErrInvalidLog = errors.New("run: invalid log") ErrCommitConflict = errors.New("run: log position conflict") ErrEpochConflict = errors.New("run: writer epoch conflict") ErrNondeterministicStep = errors.New("run: replayed step differs from committed transition") )
var ( ErrInvalidMessage = errors.New("run: invalid message") ErrSignalRejected = errors.New("run: signal rejected") ErrSignalConflict = errors.New("run: signal identity conflict") )
var ( ErrInvalidConfig = errors.New("run: invalid runtime configuration") ErrClosed = errors.New("run: runtime is closed") // ErrWriterStopped is the work context's cancellation cause when its local // writer ends. It does not declare cancellation of the durable Process. ErrWriterStopped = errors.New("run: local writer stopped") ErrProcessNotFound = errors.New("run: process not found") ErrProcessNotActive = errors.New("run: process has no active local writer") ErrProcessFinished = errors.New("run: process has finished") ErrActiveProcesses = errors.New("run: runtime has active processes") ErrTreeNotFound = errors.New("run: tree not found") ErrEffectNotPending = errors.New("run: effect does not require resolution") ErrEffectReplayForbidden = errors.New("run: effect cannot be replayed under the same identity") ErrEffectOutcomeUnknown = errors.New("run: effect outcome remains unknown") ErrInvalidProcessControl = errors.New("run: invalid process control") ErrNilContext = errors.New("run: nil context") )
var ErrCounterExhausted = NewClassifiedError( FailureKindExecution, failureCodeRuntimeCounterExhausted, "run: counter exhausted", )
ErrCounterExhausted reports exhausted numeric identity or accounting space, independently of the Host's quota policy. Work stops before a counter wraps. Strategies exhausting their own counters report this same sentinel.
var ErrInvalidCapability = errors.New("run: invalid capability")
var ErrInvalidDescriptor = errors.New("run: invalid descriptor")
var ErrInvalidDigest = errors.New("run: invalid digest")
var ErrInvalidEffect = errors.New("run: invalid effect")
var ErrInvalidExecutionState = errors.New("run: invalid execution state")
var ErrInvalidFailure = errors.New("run: invalid failure")
var ErrInvalidIdentity = errors.New("run: invalid identity")
var ErrInvalidPayload = errors.New("run: invalid payload")
var ErrInvalidProgram = errors.New("run: invalid program")
var ErrInvalidProgramRef = errors.New("run: invalid program reference")
var ErrInvalidSettlement = errors.New("run: invalid effect settlement")
var ErrInvalidStart = errors.New("run: invalid start identity")
var ErrInvalidStatus = errors.New("run: invalid status")
var ErrInvalidTransition = errors.New("run: invalid transition")
var ErrPayloadTooLarge = errors.New("run: payload exceeds the maximum encoded size")
ErrPayloadTooLarge reports an encoding over MaxPayloadBytes, letting a caller that reuses this encoding as an admission bound tell an undeliverable payload from an otherwise invalid one.
var ErrProcessAdmissionRejected = errors.New("run: process admission rejected")
var ErrResourceLimitExceeded = NewClassifiedError(FailureKindExecution, failureCodeRuntimeResourceLimitExceeded, "run: resource limit exceeded")
ErrResourceLimitExceeded reports a designed execution bound, not a Runtime defect.
Functions ¶
func NormalizeDiagnostic ¶
NormalizeDiagnostic makes arbitrary external text non-empty, trimmed UTF-8 within MaxDiagnosticBytes. Callers remain responsible for excluding secrets.
func UsageFromRecord ¶ added in v0.61.0
UsageFromRecord projects the contribution owned by one committed record. Live folding, historical totals, and observers use this same rule, including child exits that contribute to their parent after the child is reaped.
func ValidDescription ¶
func ValidDiagnostic ¶
func ValidQualifiedName ¶
Types ¶
type Batch ¶ added in v0.60.0
Batch is the unit a Store appends atomically: Records placed after After by the writer holding Epoch. Entries derives each record's coordinates, so a Store never assigns positions itself.
func (Batch) Admit ¶ added in v0.60.0
Admit is the one append decision every Store makes against its current Epoch and head, given the stored entries the batch would occupy. It returns the Epoch after the batch, or retry=true when an identical batch is already stored and the append must be acknowledged without writing.
func (Batch) MarshalJSON ¶ added in v0.60.0
func (*Batch) UnmarshalJSON ¶ added in v0.60.0
type BindingConfig ¶
type BindingConfig struct {
Definition Definition
Dispatcher Dispatcher
Revision string
Configuration any
}
Bind hashes the declaration after freezing its canonical JSON. Opaque collaborators must be identified by Revision in their declaring configuration.
type Budget ¶
type Budget struct {
Steps Quota `json:"steps" jsonwire:"required"`
Effects Quota `json:"effects" jsonwire:"required"`
Messages Quota `json:"messages" jsonwire:"required"`
}
Budget grants cumulative work authority. Zero quotas are unlimited. A finite parent permanently charges child grants, including unused child work. An unlimited parent grants either kind without a finite debit. Each dimension is independent; a finite parent cannot grant an unlimited child quota.
func (*Budget) UnmarshalJSON ¶
type CallbackPanicError ¶
CallbackPanicError identifies a panic contained at a Host callback boundary. Operation names the callback; Value is the recovered value, which Unwrap exposes when it is an error. The boundary still owns the outcome: execution failures use FailureKindPanic, uncertain dispatch remains unknown, and storage errors stop the writer through RuntimeError. It is an in-memory diagnostic and must not be serialized as a result.
func (*CallbackPanicError) Error ¶
func (c *CallbackPanicError) Error() string
func (*CallbackPanicError) Unwrap ¶
func (c *CallbackPanicError) Unwrap() error
type Capability ¶
type Capability struct {
// contains filtered or unexported fields
}
Capability is one stable qualified authority name understood by a Program's dispatcher or another external boundary. The Framework only enforces possession and attenuation; it does not assign product meaning.
func ParseCapability ¶
func ParseCapability(name string) (Capability, error)
func (Capability) JSONSchemaModel ¶
func (Capability) JSONSchemaModel() any
func (Capability) MarshalText ¶
func (c Capability) MarshalText() ([]byte, error)
func (Capability) String ¶
func (c Capability) String() string
func (*Capability) UnmarshalText ¶
func (c *Capability) UnmarshalText(text []byte) error
func (Capability) Valid ¶
func (c Capability) Valid() bool
type CapabilitySet ¶
type CapabilitySet struct {
// contains filtered or unexported fields
}
CapabilitySet is an immutable, sorted set of authority names. Its zero value is the valid empty set, encoded as an empty JSON array. JSON null is invalid.
func NewCapabilitySet ¶
func NewCapabilitySet(capabilities ...Capability) (CapabilitySet, error)
func (CapabilitySet) Allows ¶
func (c CapabilitySet) Allows(requested CapabilitySet) bool
func (CapabilitySet) Contains ¶
func (c CapabilitySet) Contains(capability Capability) bool
func (CapabilitySet) JSONSchemaModel ¶
func (CapabilitySet) JSONSchemaModel() any
func (CapabilitySet) MarshalJSON ¶
func (c CapabilitySet) MarshalJSON() ([]byte, error)
Construction and decode already guarantee valid, sorted, unique grants, and a nil slice encodes as the empty-set array the contract requires.
func (*CapabilitySet) UnmarshalJSON ¶
func (c *CapabilitySet) UnmarshalJSON(data []byte) error
UnmarshalJSON rejects duplicate grants and null; ordering is normalized. Construction accepts duplicates because its arguments describe a set.
func (CapabilitySet) Values ¶
func (c CapabilitySet) Values() []Capability
Values returns an independently owned, sorted capability slice.
type Checkpoint ¶
type Checkpoint struct {
Processes []ProcessCheckpoint `json:"processes"`
StartedProcesses uint64 `json:"started_processes"`
}
Checkpoint materializes every acknowledged record before it. Recovery starts from the newest one without reading its prefix, so it is the authority for that prefix rather than a cache to be checked against it; it can only be written by the fenced writer that folded the prefix. Only this record carries opaque ExecutionState.
type ChildBinding ¶ added in v0.60.0
type ChildBinding struct {
Program Program[Payload, Payload]
Budget Budget
Capabilities CapabilitySet
}
ChildBinding fixes the program and delegated resources before a strategy chooses a particular child identity and input.
func (ChildBinding) Spec ¶ added in v0.60.0
func (c ChildBinding) Spec(key ChildKey, input Payload) (ChildSpec, error)
func (ChildBinding) Valid ¶ added in v0.60.0
func (c ChildBinding) Valid() bool
type ChildKey ¶
type ChildKey struct {
// contains filtered or unexported fields
}
func ParseChildKey ¶
func (ChildKey) JSONSchemaModel ¶
func (ChildKey) JSONSchemaModel() any
func (ChildKey) MarshalText ¶
func (*ChildKey) UnmarshalText ¶
type ChildSpec ¶
type ChildSpec struct {
Key ChildKey `json:"key"`
ProgramRef ProgramRef `json:"program_ref"`
Input Payload `json:"input"`
Budget Budget `json:"budget" jsonwire:"required"`
Capabilities CapabilitySet `json:"capabilities" jsonwire:"required"`
}
func (*ChildSpec) UnmarshalJSON ¶
type ClassifiedError ¶
type ClassifiedError struct {
// contains filtered or unexported fields
}
ClassifiedError is a sentinel that owns the Failure kind and code persisted when an error wrapping it leaves Execution.Step, so no separate mapping can disagree with the declaration.
func NewClassifiedError ¶
func NewClassifiedError(kind FailureKind, code, message string) *ClassifiedError
NewClassifiedError declares one sentinel together with the Failure the Runtime persists when Execution.Step returns an error wrapping it; the persisted message is the complete wrapped diagnostic. An invalid kind, code, or message is a programming error and panics.
func (*ClassifiedError) Error ¶
func (c *ClassifiedError) Error() string
type Completion ¶ added in v0.60.0
type Completion struct {
Effect EffectID `json:"effect"`
Outcome Settlement `json:"outcome"`
}
func (Completion) Valid ¶ added in v0.60.0
func (c Completion) Valid() bool
type Config ¶
type Config struct {
Store Store
Build string
ProgramResolver ProgramResolver
ProcessAdmitter ProcessAdmitter
Deltas chan<- Delta
Budget Budget
TreeLimits TreeLimits
Capabilities CapabilitySet
// Tree-wide snapshots cannot read an Execution during its Step. At this
// interval, new Steps wait for existing Steps to drain; controls and
// settlements stay live.
CheckpointInterval uint64
StoreTimeout time.Duration
}
type ControlKind ¶ added in v0.60.0
type ControlKind string
const ( ControlPause ControlKind = "pause" ControlResume ControlKind = "resume" ControlCancel ControlKind = "cancel" ControlKill ControlKind = "kill" ControlDeadline ControlKind = "deadline" )
func (ControlKind) Valid ¶ added in v0.60.0
func (c ControlKind) Valid() bool
type ControlOrigin ¶ added in v0.60.0
type ControlOrigin string
ControlOrigin records who requested a control independently of its target. A parent's direct child request must retain its cause across replay.
const ( ControlOriginHost ControlOrigin = "host" ControlOriginParent ControlOrigin = "parent" )
func (ControlOrigin) Valid ¶ added in v0.60.0
func (c ControlOrigin) Valid() bool
type ControlRequested ¶ added in v0.60.0
type ControlRequested struct {
Process ProcessID `json:"process"`
Kind ControlKind `json:"kind"`
Origin ControlOrigin `json:"origin"`
Reason string `json:"reason"`
At time.Time `json:"at"`
}
type Definition ¶
type Definition interface {
Descriptor() Descriptor
ChildPrograms() []Program[Payload, Payload]
Start(input Payload) (Execution, error)
Restore(ctx context.Context, state ExecutionState) (Execution, error)
}
Definition and Execution perform no external I/O. Their inputs contain every fact needed to replay a Step; clocks, randomness and Host context values must not influence a transition. Each restored transition is checked against its log.
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
func (Delta) EffectSequence ¶
func (Delta) Payload ¶
func (d Delta) Payload() json.RawMessage
type DeltaEmitter ¶
type DeltaEmitter func(json.RawMessage)
type Descriptor ¶
type Descriptor struct {
// contains filtered or unexported fields
}
Descriptor is an immutable Definition contract. It contains no executable behavior or Program configuration.
func NewDescriptor ¶
func NewDescriptor(config DescriptorConfig) (Descriptor, error)
func (Descriptor) DecodeOutput ¶
func (d Descriptor) DecodeOutput[T any](output Payload) (T, error)
func (Descriptor) Description ¶
func (d Descriptor) Description() string
func (Descriptor) Digest ¶
func (d Descriptor) Digest() Digest
func (Descriptor) EncodeInput ¶
func (d Descriptor) EncodeInput[T any](value T) (Payload, error)
func (Descriptor) InputSchema ¶
func (d Descriptor) InputSchema() jsonschema.Schema
func (Descriptor) JSONSchemaModel ¶
func (Descriptor) JSONSchemaModel() any
func (Descriptor) MarshalJSON ¶
func (d Descriptor) MarshalJSON() ([]byte, error)
func (Descriptor) Name ¶
func (d Descriptor) Name() string
func (Descriptor) OutputSchema ¶
func (d Descriptor) OutputSchema() jsonschema.Schema
func (Descriptor) SignalSchema ¶
func (d Descriptor) SignalSchema() jsonschema.Schema
SignalSchema returns the unaddressed input contract; false rejects all input.
func (*Descriptor) UnmarshalJSON ¶
func (d *Descriptor) UnmarshalJSON(data []byte) error
func (Descriptor) Valid ¶
func (d Descriptor) Valid() bool
func (Descriptor) ValidateInput ¶
func (d Descriptor) ValidateInput(input Payload) error
func (Descriptor) ValidateOutput ¶
func (d Descriptor) ValidateOutput(output Payload) error
func (Descriptor) ValidateSignal ¶
func (d Descriptor) ValidateSignal(input Payload) error
type DescriptorConfig ¶
type DescriptorConfig struct {
Name string
Description string
InputSchema jsonschema.Schema
OutputSchema jsonschema.Schema
// SignalSchema declares unaddressed Host input. The zero value rejects all
// unaddressed Signals. Addressed replies belong to their external wait;
// Runtime-owned protocol frames never pass through this schema.
SignalSchema jsonschema.Schema
}
DescriptorConfig contains the complete static contract of a Definition. Executable implementation and frozen configuration identity belong to a Program, not this contract.
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is a canonical SHA-256 content identity. Its zero value is invalid.
func ComputeDigest ¶
Hashes identify canonical bytes. Protocol owners must normalize equivalent JSON before hashing so representation details cannot create another identity.
func ParseDigest ¶
func (Digest) JSONSchemaModel ¶
func (Digest) JSONSchemaModel() any
func (Digest) MarshalText ¶
func (*Digest) UnmarshalText ¶
type Dispatcher ¶
type Dispatcher interface {
Dispatch(context.Context, EffectRequest, DeltaEmitter) (Settlement, error)
Policy(Effect) EffectPolicy
}
Policy is captured in EffectIntent before dispatch. Recovery uses that acknowledged declaration, never a newly queried replay decision. Dispatch must distinguish a definite result from interruption: an error leaves the outcome unknown. A work context canceled by local writer shutdown has ErrWriterStopped as its cause; this is not a durable business failure.
type Effect ¶
type Effect struct {
// contains filtered or unexported fields
}
Each variant owns its operation; a payload is never inspected to guess a framework operation or to distinguish a completion from external input.
func NewChildCancelEffect ¶
func NewChildSignalEffect ¶
func NewChildStartEffect ¶
func NewDispatcherEffect ¶
func NewDispatcherEffect(payload json.RawMessage) (Effect, error)
func (Effect) ChildStart ¶ added in v0.60.0
ChildStart reports the child a framework Effect starts.
func (Effect) MarshalJSON ¶
func (Effect) Target ¶
func (e Effect) Target() EffectTarget
func (*Effect) UnmarshalJSON ¶
type EffectID ¶
type EffectID struct {
Process ProcessID `json:"process"`
Step uint64 `json:"step"`
Index uint32 `json:"index" jsonwire:"required"`
}
func ParseEffectID ¶
func (EffectID) JSONSchemaModel ¶
func (EffectID) MarshalJSON ¶ added in v0.60.0
func (EffectID) Precedes ¶ added in v0.60.0
Precedes reports whether e was declared before other by the same process. Effects of different processes have no declaration order.
func (*EffectID) UnmarshalJSON ¶ added in v0.60.0
type EffectIntent ¶ added in v0.60.0
type EffectIntent struct {
ID EffectID `json:"id"`
Effect Effect `json:"effect"`
Policy EffectPolicy `json:"policy"`
At time.Time `json:"at"`
}
type EffectPolicy ¶
type EffectPolicy struct {
Replay ReplayPolicy `json:"replay"`
RequiredCapabilities CapabilitySet `json:"required_capabilities" jsonwire:"required"`
}
func (*EffectPolicy) UnmarshalJSON ¶ added in v0.60.0
func (e *EffectPolicy) UnmarshalJSON(data []byte) error
func (EffectPolicy) Valid ¶
func (e EffectPolicy) Valid() bool
type EffectRequest ¶
type EffectRequest struct {
// contains filtered or unexported fields
}
func (EffectRequest) Effect ¶
func (e EffectRequest) Effect() Effect
func (EffectRequest) Epoch ¶ added in v0.60.0
func (e EffectRequest) Epoch() Epoch
func (EffectRequest) ID ¶
func (e EffectRequest) ID() EffectID
func (EffectRequest) ProgramRef ¶
func (e EffectRequest) ProgramRef() ProgramRef
func (EffectRequest) Valid ¶
func (e EffectRequest) Valid() bool
type EffectSettled ¶ added in v0.60.0
type EffectSettled struct {
ID EffectID `json:"id"`
Outcome Settlement `json:"outcome"`
Failure *Failure `json:"failure,omitzero"`
At time.Time `json:"at"`
}
type EffectTarget ¶
type EffectTarget string
const ( EffectTargetInvalid EffectTarget = "" EffectTargetFramework EffectTarget = "framework" EffectTargetDispatcher EffectTarget = "dispatcher" )
func (EffectTarget) String ¶
func (e EffectTarget) String() string
func (EffectTarget) Valid ¶
func (e EffectTarget) Valid() bool
type Entry ¶ added in v0.60.0
func (Entry) MarshalJSON ¶ added in v0.60.0
func (*Entry) UnmarshalJSON ¶ added in v0.60.0
func (Entry) ValidateFor ¶ added in v0.61.0
ValidateFor admits one entry's structure and tree membership. A nonzero LSN is required, but the root's first Started legitimately has Epoch zero. Continuity, epoch progression, and replay consistency require the owning Log.
type Epoch ¶ added in v0.60.0
type Epoch uint64
Epoch fences writers: each Activated advances it, and a Store rejects any batch appended under an older one.
type Execution ¶
type Execution interface {
Step(ctx context.Context, turn Turn) (Transition, error)
Snapshot() (ExecutionState, error)
}
type ExecutionFailed ¶ added in v0.60.0
type ExecutionState ¶
type ExecutionState struct {
// contains filtered or unexported fields
}
ExecutionState is an immutable envelope owned by one Execution Strategy. The Runtime persists and returns Payload without interpreting it. Its zero value is invalid.
func EncodeExecutionState ¶
func EncodeExecutionState[T any](kind string, value T) (ExecutionState, error)
EncodeExecutionState strictly encodes a typed strategy state and seals it with ParseExecutionState. Invalid UTF-8 and duplicate JSON names are rejected.
func ParseExecutionState ¶
func ParseExecutionState(kind string, payload json.RawMessage) (ExecutionState, error)
ParseExecutionState freezes an opaque payload under its owning Strategy kind.
func (ExecutionState) Decode ¶
func (e ExecutionState) Decode[T any](kind string) (T, error)
Decode checks the Strategy kind before decoding its payload into T. Unknown object members are rejected; the Strategy still validates its domain state.
func (ExecutionState) Kind ¶
func (e ExecutionState) Kind() string
func (ExecutionState) MarshalJSON ¶
func (e ExecutionState) MarshalJSON() ([]byte, error)
func (ExecutionState) Payload ¶
func (e ExecutionState) Payload() json.RawMessage
Payload returns an independently owned copy of the opaque Strategy state.
func (*ExecutionState) UnmarshalJSON ¶
func (e *ExecutionState) UnmarshalJSON(data []byte) error
func (ExecutionState) Valid ¶
func (e ExecutionState) Valid() bool
type Exit ¶ added in v0.60.0
type Exit struct {
Child ProcessID `json:"child"`
Termination Termination `json:"termination"`
}
type Exited ¶ added in v0.60.0
type Exited struct {
Process ProcessID `json:"process"`
Termination Termination `json:"termination"`
At time.Time `json:"at"`
}
type Failure ¶
type Failure struct {
// contains filtered or unexported fields
}
Failure separates stable codes from diagnostic text so wording changes cannot alter control flow. Its bounded UTF-8 message must survive snapshot JSON and must exclude secrets.
func NewFailure ¶
func NewFailure(kind FailureKind, code, message string) (Failure, error)
NewFailure requires a trimmed UTF-8 message within MaxDiagnosticBytes.
func StepFailure ¶
StepFailure reports the Failure the Runtime persists when Execution.Step returns an error wrapping a ClassifiedError. Its message includes the complete wrapped diagnostic. It reports false for an error the Runtime records as execution.step.failed, and for cancellation and contained panics, whose classifications the Runtime owns.
func (Failure) Classification ¶
func (f Failure) Classification() FailureClassification
func (Failure) JSONSchemaModel ¶
func (Failure) Kind ¶
func (f Failure) Kind() FailureKind
func (Failure) MarshalJSON ¶
func (*Failure) UnmarshalJSON ¶
type FailureClassification ¶
type FailureClassification struct {
// contains filtered or unexported fields
}
FailureClassification is the stable, diagnostic-free part of a Failure. Observations carry only this part, so they can be recorded and aggregated without exposing diagnostic text.
func (FailureClassification) Code ¶
func (f FailureClassification) Code() string
func (FailureClassification) Kind ¶
func (f FailureClassification) Kind() FailureKind
func (FailureClassification) Valid ¶
func (f FailureClassification) Valid() bool
type FailureKind ¶
type FailureKind string
FailureKind stays independent of retryability so classifying a failure cannot silently select a recovery or business policy.
const ( FailureKindInvalid FailureKind = "" // FailureKindExecution reports a Strategy error or an exhausted execution bound. FailureKindExecution FailureKind = "execution" // FailureKindContract reports an invalid protocol value or authority violation. FailureKindContract FailureKind = "contract" // FailureKindExternal reports a Host boundary error without a contained panic. FailureKindExternal FailureKind = "external" // FailureKindPanic reports a contained callback panic when that boundary produces // a Failure. Storage and API errors retain CallbackPanicError instead. This kind // does not establish an external operation's outcome or authorize replay. FailureKindPanic FailureKind = "panic" )
func (FailureKind) String ¶
func (f FailureKind) String() string
func (FailureKind) Valid ¶
func (f FailureKind) Valid() bool
type Handle ¶
type Handle[O any] struct { // contains filtered or unexported fields }
func (*Handle[O]) DeliverSignals ¶
func (*Handle[O]) Inspect ¶ added in v0.60.0
func (h *Handle[O]) Inspect(ctx context.Context) (TreeInspection, error)
func (*Handle[O]) Observe ¶
A terminal tree may acquire later writer epochs without another Exit. The first pull fixes its committed head as this observation's endpoint; further recovery cannot extend it. An active observation ends after the snapshot containing the root's exit. Local commits wake readers; other writers are polled, with each read starting after the last delivered position.
func (*Handle[O]) ProgramRef ¶
func (h *Handle[O]) ProgramRef() ProgramRef
func (*Handle[O]) ReplayUnknownEffect ¶
func (*Handle[O]) ResolveUnknownEffect ¶
type Inbox ¶ added in v0.60.0
type Inbox []Message
func (Inbox) MarshalJSON ¶ added in v0.60.0
func (*Inbox) UnmarshalJSON ¶ added in v0.60.0
type LSN ¶ added in v0.60.0
type LSN uint64
LSN is a record's 1-based position in its tree's log, and therefore also a resumable observation cursor.
type Log ¶ added in v0.60.0
Log is a contiguous segment of one tree's log that begins at the tree's Start or at a Checkpoint, so it can be folded without what precedes it.
func (Log) Complete ¶ added in v0.60.0
Complete reports whether the log begins at the tree's Start rather than at a Checkpoint, which history projections require.
func (Log) Inspect ¶ added in v0.60.0
func (l Log) Inspect() (TreeInspection, error)
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore keeps each tree's log for the lifetime of the store value. It implements the complete Store contract, so it is a faithful stand-in for a durable backend in tests and single-process hosts.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) Append ¶ added in v0.60.0
func (m *MemoryStore) Append(ctx context.Context, batch Batch) error
type Message ¶ added in v0.60.0
type Message interface {
// contains filtered or unexported methods
}
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
Payload is an immutable canonical JSON value. Its zero value is invalid. ParsePayload and EncodePayload copy and normalize their input. Descriptor schemas define its role as Process input or final output; streamed Deltas never become final output implicitly.
func EncodePayload ¶
EncodePayload strictly encodes a typed value into an independently owned Payload. Invalid UTF-8 and duplicate JSON names are rejected, including custom codec output. Custom codecs are responsible for preserving their source values.
func ParsePayload ¶
func ParsePayload(data json.RawMessage) (Payload, error)
func (Payload) Decode ¶
Decode strictly decodes p into a typed value. Unknown object fields are rejected when T is a struct.
func (Payload) Equal ¶ added in v0.61.0
Equal reports whether both payloads hold the same canonical JSON. Every constructor normalizes its input, so equal values have identical bytes; two absent payloads are equal.
func (Payload) JSON ¶
func (p Payload) JSON() json.RawMessage
JSON returns an independently owned JSON representation.
func (Payload) JSONSchemaModel ¶
func (Payload) MarshalJSON ¶
func (*Payload) UnmarshalJSON ¶
type PendingCheckpoint ¶ added in v0.60.0
type PendingCheckpoint struct {
Intent EffectIntent `json:"intent"`
Outcome *Settlement `json:"outcome,omitzero"`
Failure *Failure `json:"failure,omitzero"`
}
type PendingEffect ¶ added in v0.60.0
type PendingEffect struct {
Request EffectRequest
Policy EffectPolicy
Outcome Settlement
Failure *Failure
}
type ProcessAdmission ¶
type ProcessAdmission struct {
// contains filtered or unexported fields
}
func (ProcessAdmission) Budget ¶
func (p ProcessAdmission) Budget() Budget
func (ProcessAdmission) Capabilities ¶
func (p ProcessAdmission) Capabilities() CapabilitySet
func (ProcessAdmission) Descriptor ¶
func (p ProcessAdmission) Descriptor() Descriptor
func (ProcessAdmission) ProcessID ¶ added in v0.60.0
func (p ProcessAdmission) ProcessID() ProcessID
func (ProcessAdmission) ProgramRef ¶
func (p ProcessAdmission) ProgramRef() ProgramRef
func (ProcessAdmission) StartID ¶
func (p ProcessAdmission) StartID() (StartID, bool)
func (ProcessAdmission) Valid ¶
func (p ProcessAdmission) Valid() bool
type ProcessAdmitter ¶
type ProcessAdmitter interface {
Admit(context.Context, ProcessAdmission) error
}
type ProcessAdmitterFunc ¶
type ProcessAdmitterFunc func(context.Context, ProcessAdmission) error
func (ProcessAdmitterFunc) Admit ¶
func (p ProcessAdmitterFunc) Admit(ctx context.Context, admission ProcessAdmission) error
type ProcessCheckpoint ¶ added in v0.60.0
type ProcessCheckpoint struct {
Started Started `json:"started"`
State ExecutionState `json:"state,omitzero"`
Inbox Inbox `json:"inbox"`
Receipts []SignalReceipt `json:"receipts"`
Children []StartedChild `json:"children"`
Waits []WaitCheckpoint `json:"waits"`
Pending []PendingCheckpoint `json:"pending"`
Usage Usage `json:"usage"`
Allocated resourceAmounts `json:"allocated"`
Paused bool `json:"paused"`
Yielded bool `json:"yielded"`
Terminal *Termination `json:"terminal,omitzero"`
Exited *Exited `json:"exited,omitzero"`
}
type ProcessID ¶
type ProcessID struct {
// contains filtered or unexported fields
}
func ParseProcessID ¶
func (ProcessID) JSONSchemaModel ¶
func (ProcessID) MarshalText ¶
func (*ProcessID) UnmarshalText ¶
type ProcessInspection ¶
type ProcessInspection struct {
ID ProcessID
Program ProgramRef
Status Status
Termination Termination
Usage Usage
StartedAt time.Time
FinishedAt time.Time
Waits []Wait
PendingEffects []PendingEffect
}
type Program ¶
type Program[I, O any] struct { // contains filtered or unexported fields }
Program is an immutable binding of one Definition, its optional external Dispatcher, and an exact value reference used by Process logs.
func Bind ¶
func Bind[I, O any](compiler *Compiler, config BindingConfig) (Program[I, O], error)
Example ¶
package main
import (
"context"
"fmt"
"github.com/Tangerg/scope/agent/run"
"github.com/Tangerg/scope/core/jsonschema"
)
func main() {
ctx := context.Background()
runtime := exampleValue(run.New(ctx, run.Config{Build: "example", Store: run.NewMemoryStore()}))
defer func() {
if err := runtime.Close(ctx); err != nil {
panic(err)
}
}()
schema := exampleValue(jsonschema.For[string]())
descriptor := exampleValue(run.NewDescriptor(run.DescriptorConfig{
Name: "example.echo", Description: "Return the admitted input.", InputSchema: schema, OutputSchema: schema,
}))
program := exampleValue(run.Bind[string, string](runtime.Compiler(), run.BindingConfig{
Definition: echoDefinition{descriptor: descriptor},
}))
output := exampleValue(runtime.Run(ctx, program, "hello"))
fmt.Println(output)
}
func exampleValue[T any](value T, err error) T {
if err != nil {
panic(err)
}
return value
}
const echoStateKind = "example.echo"
type echoDefinition struct{ descriptor run.Descriptor }
func (e echoDefinition) Descriptor() run.Descriptor { return e.descriptor }
func (echoDefinition) ChildPrograms() []run.Program[run.Payload, run.Payload] { return nil }
func (echoDefinition) Start(input run.Payload) (run.Execution, error) {
return echoExecution{input: input}, nil
}
func (echoDefinition) Restore(_ context.Context, state run.ExecutionState) (run.Execution, error) {
input, err := state.Decode[string](echoStateKind)
if err != nil {
return nil, err
}
payload, err := run.EncodePayload(input)
if err != nil {
return nil, err
}
return echoExecution{input: payload}, nil
}
type echoExecution struct{ input run.Payload }
func (e echoExecution) Snapshot() (run.ExecutionState, error) {
return run.ParseExecutionState(echoStateKind, e.input.JSON())
}
func (e echoExecution) Step(_ context.Context, turn run.Turn) (run.Transition, error) {
return run.Complete(uint32(len(turn.Messages)), e.input)
}
Output: hello
func (Program[I, O]) Definition ¶
func (p Program[I, O]) Definition() Definition
func (Program[I, O]) Descriptor ¶
func (p Program[I, O]) Descriptor() Descriptor
func (Program[I, O]) Erase ¶
Erase preserves the same frozen binding for heterogeneous child graphs.
func (Program[I, O]) ProgramRef ¶
func (p Program[I, O]) ProgramRef() ProgramRef
type ProgramRef ¶
type ProgramRef struct {
// contains filtered or unexported fields
}
func (ProgramRef) Build ¶ added in v0.60.0
func (p ProgramRef) Build() string
func (ProgramRef) Digest ¶
func (p ProgramRef) Digest() Digest
func (ProgramRef) JSONSchemaModel ¶
func (ProgramRef) JSONSchemaModel() any
func (ProgramRef) MarshalJSON ¶
func (p ProgramRef) MarshalJSON() ([]byte, error)
func (ProgramRef) Name ¶
func (p ProgramRef) Name() string
func (ProgramRef) String ¶
func (p ProgramRef) String() string
func (*ProgramRef) UnmarshalJSON ¶
func (p *ProgramRef) UnmarshalJSON(data []byte) error
func (ProgramRef) Valid ¶
func (p ProgramRef) Valid() bool
type ProgramResolver ¶
type ProgramResolver interface {
Resolve(ProgramRef) (Program[Payload, Payload], error)
}
type QualifiedName ¶
type QualifiedName string
QualifiedName is a lowercase dotted identifier carried on the wire. Its value is validated by ValidQualifiedName; JSONSchemaPattern projects that same rule for schema generation from the same compiled grammar.
func (QualifiedName) JSONSchemaPattern ¶
func (QualifiedName) JSONSchemaPattern() string
type Quota ¶
type Quota struct {
// contains filtered or unexported fields
}
Quota is an immutable optional upper bound. Its zero value is unlimited; NewQuota constructs a finite bound, including zero. A Quota is policy, never a usage counter or a reservation. Its JSON object preserves this distinction: {"maximum":null} is unlimited and {"maximum":0} permits no work.
Example ¶
unlimited := Quota{}
finite := NewQuota(3)
zero := NewQuota(0)
fmt.Println(unlimited.Allows(10001), finite.Allows(2, 1), finite.Allows(3, 1), zero.Allows(1))
Output: true true false false
func (Quota) Allows ¶
Allows reports whether all quantities fit together, without unsigned overflow. Unlimited quotas impose no bound; callers still own counter and identity overflow.
func (Quota) JSONSchemaModel ¶
func (Quota) MarshalJSON ¶
func (*Quota) UnmarshalJSON ¶
type Record ¶ added in v0.60.0
type Record interface {
// contains filtered or unexported methods
}
Record is the closed set of facts a tree's log holds. Only this package implements it, so a Store can rely on EncodeRecord and DecodeRecord alone.
func DecodeRecord ¶ added in v0.60.0
func DecodeRecord(kind RecordKind, data []byte) (Record, error)
type RecordKind ¶ added in v0.60.0
type RecordKind string
RecordKind is the storage discriminator of a Record; a Store persists it beside the encoded body so DecodeRecord can restore the exact variant.
const ( RecordKindStarted RecordKind = "started" RecordKindActivated RecordKind = "activated" RecordKindSignalAdmitted RecordKind = "signal_admitted" RecordKindStepped RecordKind = "stepped" RecordKindEffectIntent RecordKind = "effect_intent" RecordKindEffectSettled RecordKind = "effect_settled" RecordKindExited RecordKind = "exited" RecordKindReaped RecordKind = "reaped" RecordKindCheckpoint RecordKind = "checkpoint" RecordKindControlRequested RecordKind = "control_requested" RecordKindExecutionFailed RecordKind = "execution_failed" )
func EncodeRecord ¶ added in v0.60.0
func EncodeRecord(record Record) (RecordKind, []byte, error)
type ReplayPolicy ¶
type ReplayPolicy string
const ( ReplayPolicyInvalid ReplayPolicy = "" ReplayPolicyNever ReplayPolicy = "never" ReplayPolicySameIdentity ReplayPolicy = "same_identity" )
func (ReplayPolicy) String ¶
func (r ReplayPolicy) String() string
func (ReplayPolicy) Valid ¶
func (r ReplayPolicy) Valid() bool
type Result ¶
type Result[O any] struct { // contains filtered or unexported fields }
func (Result[O]) FinishedAt ¶
func (Result[O]) Termination ¶
func (r Result[O]) Termination() Termination
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func (*Runtime) Answered ¶ added in v0.60.0
func (r *Runtime) Answered(ctx context.Context, process ProcessID, wait WaitKey, answer Payload) (bool, error)
Answered reports whether wait already admitted exactly this answer, so a caller can confirm a delivery whose acknowledgment was lost without sending it twice. A different answer to the same wait is ErrSignalConflict.
func (*Runtime) History ¶ added in v0.60.0
History reads the complete log of root's tree, for projections that need facts a checkpoint no longer carries, such as settled tool rounds.
func (*Runtime) ReleaseTree ¶
type RuntimeError ¶
type RuntimeError struct {
// contains filtered or unexported fields
}
func (*RuntimeError) After ¶ added in v0.60.0
func (r *RuntimeError) After() LSN
func (*RuntimeError) Epoch ¶ added in v0.60.0
func (r *RuntimeError) Epoch() Epoch
func (*RuntimeError) Error ¶
func (r *RuntimeError) Error() string
func (*RuntimeError) ProcessID ¶
func (r *RuntimeError) ProcessID() ProcessID
func (*RuntimeError) UnresolvedEffectIDs ¶
func (r *RuntimeError) UnresolvedEffectIDs() []EffectID
func (*RuntimeError) Unwrap ¶
func (r *RuntimeError) Unwrap() error
type Settlement ¶
type Settlement struct {
// contains filtered or unexported fields
}
Settlement is the immutable final fact for one Effect. The Effect it answers owns the EffectID, so a Settlement is addressed by where it is returned or recorded rather than by a copy of that identity. Status owns whether the Effect definitely succeeded, definitely failed, or remains unknown. Failure owns the diagnostic of a definite failure. Payload carries optional domain evidence independently, including work completed before a rejection. The Runtime delivers a definite settlement as a Completion message.
func NewFailedSettlement ¶ added in v0.60.0
func NewFailedSettlement(failure Failure, details Payload) (Settlement, error)
func NewSettlement ¶
func NewSettlement(status SettlementStatus, payload json.RawMessage) (Settlement, error)
func (Settlement) Failure ¶ added in v0.60.0
func (s Settlement) Failure() (Failure, bool)
func (Settlement) JSONSchemaModel ¶ added in v0.60.0
func (Settlement) JSONSchemaModel() any
func (Settlement) MarshalJSON ¶
func (s Settlement) MarshalJSON() ([]byte, error)
func (Settlement) Payload ¶
func (s Settlement) Payload() Payload
Payload is domain evidence. A failed settlement may omit it; its diagnostic remains available through Failure without interpreting the domain's schema.
func (Settlement) SpawnResult ¶ added in v0.60.0
func (s Settlement) SpawnResult() (ProcessID, Failure, error)
SpawnResult reads the outcome of a Spawn: the started child, or the Failure that rejected the start. Exactly one of them is valid.
func (Settlement) Status ¶
func (s Settlement) Status() SettlementStatus
func (*Settlement) UnmarshalJSON ¶
func (s *Settlement) UnmarshalJSON(data []byte) error
func (Settlement) Valid ¶
func (s Settlement) Valid() bool
type SettlementStatus ¶
type SettlementStatus string
SettlementStatus records whether an Effect definitely succeeded, definitely failed, or has an unknown external result. Unknown never implies safe retry.
const ( SettlementStatusInvalid SettlementStatus = "" SettlementStatusSucceeded SettlementStatus = "succeeded" SettlementStatusFailed SettlementStatus = "failed" SettlementStatusUnknown SettlementStatus = "unknown" )
func (SettlementStatus) String ¶
func (s SettlementStatus) String() string
func (SettlementStatus) Valid ¶
func (s SettlementStatus) Valid() bool
type Signal ¶
type SignalAdmitted ¶ added in v0.60.0
type SignalID ¶
type SignalID struct {
// contains filtered or unexported fields
}
func ParseSignalID ¶
func (SignalID) JSONSchemaModel ¶
func (SignalID) JSONSchemaModel() any
func (SignalID) MarshalText ¶
func (*SignalID) UnmarshalText ¶
type SignalReceipt ¶
type StartConflictError ¶
func (*StartConflictError) Error ¶
func (s *StartConflictError) Error() string
type StartRequest ¶
type Started ¶ added in v0.60.0
type Started struct {
Process ProcessID `json:"process"`
Program ProgramRef `json:"program"`
Input Payload `json:"input"`
Budget Budget `json:"budget" jsonwire:"required"`
Capabilities CapabilitySet `json:"capabilities" jsonwire:"required"`
Limits TreeLimits `json:"limits,omitzero"`
At time.Time `json:"at"`
}
func (Started) IntentDigest ¶ added in v0.60.0
IntentDigest is derived from the accepted declaration. Persisting a separately writable digest would let a stale cache accept a conflicting idempotent Start.
type StartedChild ¶ added in v0.60.0
type Status ¶
type Status string
Status is the complete common lifecycle state of a Process. Strategy-specific conditions such as a Planning no-plan result do not add common statuses.
const ( StatusInvalid Status = "" StatusRunning Status = "running" StatusWaiting Status = "waiting" StatusPaused Status = "paused" StatusDraining Status = "draining" StatusCompleted Status = "completed" StatusFailed Status = "failed" StatusCanceled Status = "canceled" StatusTimedOut Status = "timed_out" StatusKilled Status = "killed" )
func (Status) JSONSchemaEnum ¶ added in v0.60.0
func (Status) MarshalText ¶
func (*Status) UnmarshalText ¶
type Stepped ¶ added in v0.60.0
type Stepped struct {
Process ProcessID `json:"process"`
Step uint64 `json:"step"`
Delivered uint32 `json:"delivered" jsonwire:"required"`
Transition Transition `json:"transition"`
}
type Store ¶
type Store interface {
// Append is the only operation that advances a tree. It must atomically
// compare the writer Epoch and the head position before extending the log,
// and acknowledge a byte-identical retry of an applied batch.
Append(ctx context.Context, batch Batch) error
// Load returns the recovery segment: the newest Checkpoint entry and every
// entry after it, or the whole log when it holds no Checkpoint.
Load(ctx context.Context, root ProcessID) (Log, bool, error)
// Read yields the committed entries after position in order. It reads one
// consistent snapshot and ends at that snapshot's head.
Read(ctx context.Context, root ProcessID, after LSN) iter.Seq2[Entry, error]
}
Store owns one append-only log per root tree. Recovery and history are separate reads so neither pays for the other's range: Load skips the prefix covered by the newest checkpoint, and Read is incremental.
type Termination ¶
type Termination struct {
// contains filtered or unexported fields
}
Termination is the immutable result of applying the terminal priority matrix. Only the Runtime creates terminal facts from validated control intents and Step outcomes; callers obtain this observation from Result or decode it. Failure owns failed causes and diagnostics, Output owns completion, and the remaining control causes own their reason. Status is always derived from the cause.
func (Termination) Cause ¶
func (t Termination) Cause() TerminationCause
func (Termination) Failure ¶
func (t Termination) Failure() (Failure, bool)
func (Termination) JSONSchemaModel ¶
func (Termination) JSONSchemaModel() any
func (Termination) MarshalJSON ¶
func (t Termination) MarshalJSON() ([]byte, error)
func (Termination) Output ¶
func (t Termination) Output() (Payload, bool)
Output returns the final semantic result only for StatusCompleted. A present JSON null is a completed output.
func (Termination) Reason ¶
func (t Termination) Reason() string
Reason returns a bounded diagnostic reason. Completion has an empty reason.
func (Termination) Status ¶
func (t Termination) Status() Status
func (*Termination) UnmarshalJSON ¶
func (t *Termination) UnmarshalJSON(data []byte) error
func (Termination) Valid ¶
func (t Termination) Valid() bool
type TerminationCause ¶
type TerminationCause string
const ( TerminationCauseInvalid TerminationCause = "" TerminationCauseCompletion TerminationCause = "completion" TerminationCauseRuntimeKill TerminationCause = "runtime_kill" TerminationCauseParentDeadline TerminationCause = "parent_deadline" TerminationCauseHostDeadline TerminationCause = "host_deadline" TerminationCauseParentCancellation TerminationCause = "parent_cancellation" TerminationCauseHostCancellation TerminationCause = "host_cancellation" TerminationCauseExecutionFailure TerminationCause = "execution_failure" TerminationCauseContractFailure TerminationCause = "contract_failure" TerminationCauseExternalFailure TerminationCause = "external_failure" TerminationCausePanic TerminationCause = "panic" )
func (TerminationCause) String ¶
func (t TerminationCause) String() string
func (TerminationCause) Valid ¶
func (t TerminationCause) Valid() bool
type TerminationError ¶
type TerminationError struct {
ID ProcessID
Termination Termination
}
func (*TerminationError) Error ¶
func (t *TerminationError) Error() string
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
func Yield ¶ added in v0.60.0
func Yield(consumed uint32, effects []Effect, waits ...Wait) (Transition, error)
func (Transition) Consumed ¶ added in v0.60.0
func (t Transition) Consumed() uint32
func (Transition) Effects ¶
func (t Transition) Effects() []Effect
func (Transition) Failure ¶
func (t Transition) Failure() (Failure, bool)
func (Transition) Kind ¶
func (t Transition) Kind() TransitionKind
func (Transition) MarshalJSON ¶
func (t Transition) MarshalJSON() ([]byte, error)
func (Transition) Output ¶
func (t Transition) Output() (Payload, bool)
func (*Transition) UnmarshalJSON ¶
func (t *Transition) UnmarshalJSON(data []byte) error
func (Transition) Valid ¶
func (t Transition) Valid() bool
func (Transition) Waits ¶ added in v0.60.0
func (t Transition) Waits() []Wait
type TransitionKind ¶
type TransitionKind string
const ( TransitionKindInvalid TransitionKind = "" TransitionKindContinue TransitionKind = "continue" TransitionKindYield TransitionKind = "yield" TransitionKindComplete TransitionKind = "complete" TransitionKindFail TransitionKind = "fail" )
func (TransitionKind) String ¶
func (t TransitionKind) String() string
func (TransitionKind) Valid ¶
func (t TransitionKind) Valid() bool
type TreeInspection ¶
type TreeInspection struct {
Root ProcessID
Head LSN
Epoch Epoch
Processes []ProcessInspection
}
func (TreeInspection) Process ¶
func (t TreeInspection) Process(id ProcessID) (ProcessInspection, bool)
type TreeLimits ¶
type TreeLimits struct {
MaxRecordBytes Quota `json:"max_record_bytes" jsonwire:"required"`
MaxCheckpointBytes Quota `json:"max_checkpoint_bytes" jsonwire:"required"`
MaxPendingMessages uint64 `json:"max_pending_messages" jsonwire:"required"`
MaxDepth uint32 `json:"max_depth" jsonwire:"required"`
MaxChildren Quota `json:"max_children" jsonwire:"required"`
MaxActiveChildren uint32 `json:"max_active_children" jsonwire:"required"`
MaxTreeProcesses Quota `json:"max_tree_processes" jsonwire:"required"`
}
Root Started owns the resolved policy. Child records never repeat these limits. Message capacity reserves Completions and child Exits before dispatch, so admitted work can finish even while external Signals arrive.
func DefaultTreeLimits ¶
func DefaultTreeLimits() TreeLimits
DefaultTreeLimits returns conservative structured-concurrency and mailbox bounds; cumulative counts and record bytes remain unlimited.
func (*TreeLimits) UnmarshalJSON ¶
func (t *TreeLimits) UnmarshalJSON(data []byte) error
func (TreeLimits) Valid ¶
func (t TreeLimits) Valid() bool
type Usage ¶
type Usage struct {
CommittedSteps uint64 `json:"committed_steps" jsonwire:"required"`
PreparedEffects uint64 `json:"prepared_effects" jsonwire:"required"`
AcceptedMessages uint64 `json:"accepted_messages" jsonwire:"required"`
}
Counters are projections of committed records; transient delta delivery cannot change durable usage. Each decoded counter must be present, including zero.
func (*Usage) UnmarshalJSON ¶
type Wait ¶
type Wait struct {
Key WaitKey `json:"key"`
Question Payload `json:"question,omitzero"`
AnswerSchema jsonschema.Schema `json:"answer_schema,omitzero"`
MaxAnswerBytes int `json:"max_answer_bytes"`
}
type WaitCheckpoint ¶ added in v0.61.0
Retaining the first contract after withdrawal keeps a WaitKey immutable even when recovery starts after its original declaration.
type WaitKey ¶
type WaitKey struct {
// contains filtered or unexported fields
}
func ParseWaitKey ¶
func (WaitKey) JSONSchemaModel ¶
func (WaitKey) JSONSchemaModel() any
func (WaitKey) MarshalText ¶
func (*WaitKey) UnmarshalText ¶
Source Files
¶
- batch.go
- callback_error.go
- callback_panic.go
- capability.go
- checkpoint.go
- child.go
- definition.go
- delta.go
- descriptor.go
- diagnostic.go
- digest.go
- dispatcher.go
- doc.go
- effect.go
- entry.go
- execution_boundary.go
- execution_state.go
- failure.go
- handle.go
- identity.go
- inspection.go
- log.go
- memory_store.go
- message.go
- name.go
- process_admission.go
- process_state.go
- program.go
- program_ref.go
- quota.go
- record.go
- resource.go
- restore_context.go
- runtime.go
- runtime_error.go
- settlement.go
- start.go
- status.go
- step_error.go
- termination.go
- transition.go
- tree_runtime.go
- tree_state.go
- wait.go
- wire.go