continuation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 9 Imported by: ? 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 continuation defines crash-safe, exact resume contracts for parked agent work. Durable implementations must commit each state transition and its outbox event in one storage transaction.

Index

Constants

View Source
const (
	CheckpointVersion = 1
	ReceiptVersion    = 1
)

Variables

View Source
var (
	ErrConflict         = errors.New("continuation identity reused with different checkpoint")
	ErrRevisionConflict = errors.New("continuation revision conflict")
	ErrOwnerMismatch    = errors.New("continuation owner mismatch")
	ErrNotResumable     = errors.New("continuation is not resumable")
	ErrProofMismatch    = errors.New("continuation resume proof mismatch")
)
View Source
var (
	ErrOutboxLeaseConflict = errors.New("continuation outbox lease conflict")
	ErrOutboxAttempt       = errors.New("continuation outbox attempt conflict")
)

Functions

This section is empty.

Types

type Checkpoint

type Checkpoint struct {
	Version               int                `json:"version"`
	ID                    string             `json:"id"`
	Identity              execution.Identity `json:"identity"`
	InputID               string             `json:"input_id"`
	Runtime               RuntimeBinding     `json:"runtime"`
	Context               ContextBinding     `json:"context"`
	Tool                  ToolBinding        `json:"tool"`
	DelegationLeaseDigest string             `json:"delegation_lease_digest,omitempty"`
	TrajectoryCursor      uint64             `json:"trajectory_cursor"`
	ResumeTokenHash       string             `json:"resume_token_hash,omitempty"`
	ContentHash           string             `json:"content_hash"`
}

Checkpoint is immutable resume intent. ResumeTokenHash binds a secret token without requiring the continuation store to retain the token itself.

func SealCheckpoint

func SealCheckpoint(in Checkpoint) (Checkpoint, error)

type Claim

type Claim struct {
	ID        string    `json:"id"`
	WorkerID  string    `json:"worker_id"`
	ExpiresAt time.Time `json:"expires_at"`
}

type ContextBinding

type ContextBinding struct {
	ID       string `json:"id"`
	Revision uint64 `json:"revision"`
	Digest   string `json:"digest"`
	Epoch    uint64 `json:"epoch"`
}

ContextBinding identifies one immutable context projection head.

type DeliveryPolicy

type DeliveryPolicy struct {
	BatchSize   int
	LeaseTTL    time.Duration
	BaseBackoff time.Duration
	MaxBackoff  time.Duration
	Now         func() time.Time
}

DeliveryPolicy controls at-least-once outbox delivery. Receivers must deduplicate by OutboxEvent.ID because a sink may succeed before ACK persists.

type DeliveryReport

type DeliveryReport struct {
	Leased    int `json:"leased"`
	Delivered int `json:"delivered"`
	Deferred  int `json:"deferred"`
	Recovered int `json:"recovered"`
}

func DrainOutbox

func DrainOutbox(ctx context.Context, store Store, owner execution.Identity, workerID, leaseID string, policy DeliveryPolicy, sink DeliverySink) (DeliveryReport, error)

DrainOutbox leases one page, delivers it, and records ACK or retry state. Delivery is at-least-once; the stable event ID is the receiver's dedupe key.

type DeliverySink

type DeliverySink func(context.Context, OutboxEvent) error

type EffectCertainty

type EffectCertainty string
const (
	EffectNoEffect EffectCertainty = "no_effect"
	EffectApplied  EffectCertainty = "effect_applied"
	EffectUnknown  EffectCertainty = "effect_unknown"
)

type EvidenceReader

type EvidenceReader interface {
	ObserveResume(context.Context, Checkpoint, ResultReceipt) (ResumeEvidence, error)
}

EvidenceReader joins the host's runtime, context, archive, and trajectory stores into one observation. Implementations must not trust model or client fields when constructing evidence.

type MemoryStore

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

MemoryStore is a concurrency-safe reference implementation. It models the atomicity durable SQL/KV implementations must provide, but is not durable.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) AckLeasedOutbox

func (s *MemoryStore) AckLeasedOutbox(ctx context.Context, owner execution.Identity, eventID, leaseID string, expectedAttempt uint64, at time.Time) (OutboxEvent, error)

func (*MemoryStore) AckOutbox

func (s *MemoryStore) AckOutbox(ctx context.Context, owner execution.Identity, eventID string, at time.Time) (OutboxEvent, error)

func (*MemoryStore) Claim

func (s *MemoryStore) Claim(ctx context.Context, owner execution.Identity, id string, expected uint64, proof ResumeProof, claim Claim, eventID string, at time.Time) (Record, error)

func (*MemoryStore) CommitResult

func (s *MemoryStore) CommitResult(ctx context.Context, owner execution.Identity, id string, expected uint64, receipt ResultReceipt, eventID string, at time.Time) (Record, error)

func (*MemoryStore) Create

func (s *MemoryStore) Create(ctx context.Context, checkpoint Checkpoint, at time.Time) (Record, bool, error)

func (*MemoryStore) ExpireClaim

func (s *MemoryStore) ExpireClaim(ctx context.Context, owner execution.Identity, id string, expected uint64, eventID string, at time.Time) (Record, error)

func (*MemoryStore) Get

func (s *MemoryStore) Get(ctx context.Context, owner execution.Identity, id string) (Record, bool, error)

func (*MemoryStore) LeaseOutbox

func (s *MemoryStore) LeaseOutbox(ctx context.Context, owner execution.Identity, workerID, leaseID string, limit int, now time.Time, ttl time.Duration) ([]OutboxEvent, error)

func (*MemoryStore) Pending

func (s *MemoryStore) Pending(ctx context.Context, owner execution.Identity, limit int) ([]Record, error)

func (*MemoryStore) PendingOutbox

func (s *MemoryStore) PendingOutbox(ctx context.Context, owner execution.Identity, limit int) ([]OutboxEvent, error)

func (*MemoryStore) Reconcile

func (s *MemoryStore) Reconcile(ctx context.Context, owner execution.Identity, id string, expected uint64, next State, receipt *ResultReceipt, reason, eventID string, at time.Time) (Record, error)

func (*MemoryStore) RetryOutbox

func (s *MemoryStore) RetryOutbox(ctx context.Context, owner execution.Identity, eventID, leaseID string, expectedAttempt uint64, reason string, next, at time.Time) (OutboxEvent, error)

func (*MemoryStore) Settle

func (s *MemoryStore) Settle(ctx context.Context, owner execution.Identity, id string, expected uint64, next State, reason, eventID string, at time.Time) (Record, error)

type OutboxEvent

type OutboxEvent struct {
	ID                  string             `json:"id"`
	Kind                string             `json:"kind"`
	Identity            execution.Identity `json:"identity"`
	ContinuationID      string             `json:"continuation_id"`
	CheckpointHash      string             `json:"checkpoint_hash"`
	ExpectedState       State              `json:"expected_state"`
	ExpectedRevision    uint64             `json:"expected_revision"`
	OperationKey        string             `json:"operation_key"`
	ReceiptHash         string             `json:"receipt_hash,omitempty"`
	ClaimID             string             `json:"claim_id,omitempty"`
	ReasonCode          string             `json:"reason_code,omitempty"`
	ContentHash         string             `json:"content_hash"`
	OriginalContentHash string             `json:"original_content_hash,omitempty"`
	CorruptContentHash  string             `json:"corrupt_content_hash,omitempty"`
	Status              OutboxStatus       `json:"status"`
	Recovery            bool               `json:"recovery,omitempty"`
	Attempts            uint64             `json:"attempts"`
	NextAttemptAt       time.Time          `json:"next_attempt_at,omitempty"`
	Lease               *OutboxLease       `json:"lease,omitempty"`
	LastError           string             `json:"last_error,omitempty"`
	At                  time.Time          `json:"at"`
	DeliveredAt         time.Time          `json:"delivered_at,omitempty"`
}

OutboxEvent is intentionally metadata-only. Prompts, credentials, resume tokens, and raw tool output never belong in the transactional outbox.

type OutboxLease

type OutboxLease struct {
	ID        string    `json:"id"`
	WorkerID  string    `json:"worker_id"`
	ExpiresAt time.Time `json:"expires_at"`
}

type OutboxStatus

type OutboxStatus string
const (
	OutboxPending   OutboxStatus = "pending"
	OutboxLeased    OutboxStatus = "leased"
	OutboxDelivered OutboxStatus = "delivered"
)

type ProjectionBinding

type ProjectionBinding struct {
	ID            string `json:"id"`
	LogicalCallID string `json:"logical_call_id"`
	ToolName      string `json:"tool_name"`
}

ProjectionBinding proves where the exact tool exchange was incorporated.

type Record

type Record struct {
	Checkpoint Checkpoint     `json:"checkpoint"`
	State      State          `json:"state"`
	Receipt    *ResultReceipt `json:"receipt,omitempty"`
	Proof      *ResumeProof   `json:"proof,omitempty"`
	Claim      *Claim         `json:"claim,omitempty"`
	ReasonCode string         `json:"reason_code,omitempty"`
	Revision   uint64         `json:"revision"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
}

type RecoveryCoordinator

type RecoveryCoordinator struct {
	Store    Store
	Evidence EvidenceReader
}

RecoveryCoordinator is the preferred claim boundary. It reconstructs proof from authoritative evidence immediately before the store's CAS transition.

func (RecoveryCoordinator) Claim

func (c RecoveryCoordinator) Claim(ctx context.Context, owner execution.Identity, continuationID string, expected uint64, claim Claim, eventID string, at time.Time) (Record, error)

type ResultReceipt

type ResultReceipt struct {
	Version              int               `json:"version"`
	ContinuationID       string            `json:"continuation_id"`
	CheckpointHash       string            `json:"checkpoint_hash"`
	AttemptID            string            `json:"attempt_id"`
	RoundID              string            `json:"round_id"`
	CallID               string            `json:"call_id"`
	ToolName             string            `json:"tool_name"`
	ResultEventID        string            `json:"result_event_id"`
	ResultEventHash      string            `json:"result_event_hash"`
	SemanticResultHash   string            `json:"semantic_result_hash"`
	ObservableResultHash string            `json:"observable_result_hash"`
	IsError              bool              `json:"is_error"`
	EffectCertainty      EffectCertainty   `json:"effect_certainty"`
	Projection           ProjectionBinding `json:"projection"`
	ReceiptHash          string            `json:"receipt_hash"`
}

ResultReceipt couples the semantic tool outcome to its exact durable event and the context projection that must cover it before inference resumes.

func SealResultReceipt

func SealResultReceipt(checkpoint Checkpoint, in ResultReceipt) (ResultReceipt, error)

type ResumeEvidence

type ResumeEvidence struct {
	Runtime          RuntimeBinding    `json:"runtime"`
	Context          ContextBinding    `json:"context"`
	Projection       ProjectionBinding `json:"projection"`
	ResultEventID    string            `json:"result_event_id"`
	ResultEventHash  string            `json:"result_event_hash"`
	TrajectoryCursor uint64            `json:"trajectory_cursor"`
}

ResumeEvidence is loaded from authoritative host stores. It deliberately excludes caller-authored checkpoint and receipt hashes.

type ResumeProof

type ResumeProof struct {
	CheckpointHash   string            `json:"checkpoint_hash"`
	ReceiptHash      string            `json:"receipt_hash"`
	Runtime          RuntimeBinding    `json:"runtime"`
	Context          ContextBinding    `json:"context"`
	Projection       ProjectionBinding `json:"projection"`
	ResultEventID    string            `json:"result_event_id"`
	ResultEventHash  string            `json:"result_event_hash"`
	TrajectoryCursor uint64            `json:"trajectory_cursor"`
}

ResumeProof is reconstructed from authoritative stores immediately before a claim. The context revision must be newer than the parked baseline.

type RuntimeBinding

type RuntimeBinding struct {
	Harness             string `json:"harness"`
	HarnessVersion      string `json:"harness_version"`
	HarnessConfigDigest string `json:"harness_config_digest"`
	ResumeCapability    string `json:"resume_capability"`
	Model               string `json:"model"`
	EnvironmentDigest   string `json:"environment_digest"`
	PolicyVersion       string `json:"policy_version"`
	CatalogVersion      string `json:"catalog_version"`
}

RuntimeBinding prevents a continuation from silently changing the harness, model, environment, policy, or tool catalog that created its checkpoint.

type State

type State string
const (
	StateParked            State = "parked"
	StateResultCommitted   State = "result_committed"
	StateClaimed           State = "claimed"
	StateCompleted         State = "completed"
	StateFailed            State = "failed"
	StateEffectUnknown     State = "effect_unknown"
	StateReconcileRequired State = "reconcile_required"
)

type ToolBinding

type ToolBinding struct {
	Name           string `json:"name"`
	Version        string `json:"version"`
	RoundID        string `json:"round_id"`
	CallID         string `json:"call_id"`
	AttemptID      string `json:"attempt_id"`
	ApprovalID     string `json:"approval_id"`
	EnvelopeHash   string `json:"envelope_hash"`
	TargetHash     string `json:"target_hash"`
	IdempotencyKey string `json:"idempotency_key"`
}

ToolBinding identifies the exact approved operation parked by a checkpoint.

Jump to

Keyboard shortcuts

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