checkpoint

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package checkpoint defines the Checkpoint entity for human-in-the-loop control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checkpoint

type Checkpoint struct {
	cortex.Entity
	ID        id.CheckpointID `json:"id"`
	RunID     id.AgentRunID   `json:"run_id"`
	AgentID   id.AgentID      `json:"agent_id"`
	Scope     cortex.Scope    `json:"scope"`
	Reason    string          `json:"reason"`
	StepIndex int             `json:"step_index"`
	State     string          `json:"state"`
	Decision  *Decision       `json:"decision,omitempty"`
	Metadata  map[string]any  `json:"metadata,omitempty"`
}

Checkpoint represents a point where a run pauses for approval.

func PublicList added in v1.10.0

func PublicList(cps []*Checkpoint) []*Checkpoint

PublicList applies Public to every checkpoint in cps.

func (*Checkpoint) Public added in v1.10.0

func (c *Checkpoint) Public() *Checkpoint

Public is a copy of c for a reader outside the engine, such as an API response or a dashboard. It drops Decision.DecidedByPrincipal: the store keeps the decider's codec bytes as the record of who decided, and they are the host's own, so no reader of the checkpoint gets them.

type Decision

type Decision struct {
	Approved  bool      `json:"approved"`
	DecidedBy string    `json:"decided_by,omitempty"`
	Reason    string    `json:"reason,omitempty"`
	DecidedAt time.Time `json:"decided_at"`
	// DecidedByPrincipal is the decider's principal, as the engine's
	// cortex.PrincipalCodec encoded it. ResolveCheckpoint fills it from
	// the context and overwrites whatever the caller supplied. It records
	// who decided; the run itself continues under its own principal.
	//
	// It is serialized because the SQL stores persist a decision as JSON.
	// Anything that serves a checkpoint to a reader goes through
	// Checkpoint.Public, which drops it.
	DecidedByPrincipal []byte `json:"decided_by_principal,omitempty"`
}

Decision represents the resolution of a checkpoint.

type ListFilter

type ListFilter struct {
	RunID  string
	Limit  int
	Offset int
}

ListFilter controls pagination for checkpoint listing.

type Store

type Store interface {
	CreateCheckpoint(ctx context.Context, cp *Checkpoint) error
	GetCheckpoint(ctx context.Context, cpID id.CheckpointID) (*Checkpoint, error)
	// Resolve records decision on a pending checkpoint at the caller's
	// exact scope. A checkpoint that is no longer pending keeps its first
	// decision and Resolve returns an error wrapping cortex.ErrInvalidState;
	// one that does not exist there is cortex.ErrCheckpointNotFound.
	Resolve(ctx context.Context, cpID id.CheckpointID, decision Decision) error
	ListPending(ctx context.Context, filter *ListFilter) ([]*Checkpoint, error)
	CountPending(ctx context.Context, filter *ListFilter) (int64, error)
}

Store defines persistence for checkpoints.

type SweepStore added in v1.10.0

type SweepStore interface {
	// ListPendingAcrossScopes lists pending checkpoints whose id sorts
	// after the given one, in id order, at most limit. A nil id starts
	// from the first. It deliberately bypasses scope, for the sweeper
	// only, which acts on each checkpoint under that checkpoint's own
	// scope.
	ListPendingAcrossScopes(ctx context.Context, after id.CheckpointID, limit int) ([]*Checkpoint, error)
}

SweepStore is an optional capability of checkpoint stores, for the engine sweeper. It finds pending checkpoints that no decision will ever reach, such as one whose run has ended or moved on to another pause.

Jump to

Keyboard shortcuts

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