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
- Variables
- type Checkpoint
- type Claim
- type ContextBinding
- type DeliveryPolicy
- type DeliveryReport
- type DeliverySink
- type EffectCertainty
- type EvidenceReader
- type MemoryStore
- func (s *MemoryStore) AckLeasedOutbox(ctx context.Context, owner execution.Identity, eventID, leaseID string, ...) (OutboxEvent, error)
- func (s *MemoryStore) AckOutbox(ctx context.Context, owner execution.Identity, eventID string, at time.Time) (OutboxEvent, error)
- func (s *MemoryStore) Claim(ctx context.Context, owner execution.Identity, id string, expected uint64, ...) (Record, error)
- func (s *MemoryStore) CommitResult(ctx context.Context, owner execution.Identity, id string, expected uint64, ...) (Record, error)
- func (s *MemoryStore) Create(ctx context.Context, checkpoint Checkpoint, at time.Time) (Record, bool, error)
- func (s *MemoryStore) ExpireClaim(ctx context.Context, owner execution.Identity, id string, expected uint64, ...) (Record, error)
- func (s *MemoryStore) Get(ctx context.Context, owner execution.Identity, id string) (Record, bool, error)
- func (s *MemoryStore) LeaseOutbox(ctx context.Context, owner execution.Identity, workerID, leaseID string, ...) ([]OutboxEvent, error)
- func (s *MemoryStore) Pending(ctx context.Context, owner execution.Identity, limit int) ([]Record, error)
- func (s *MemoryStore) PendingOutbox(ctx context.Context, owner execution.Identity, limit int) ([]OutboxEvent, error)
- func (s *MemoryStore) Reconcile(ctx context.Context, owner execution.Identity, id string, expected uint64, ...) (Record, error)
- func (s *MemoryStore) RetryOutbox(ctx context.Context, owner execution.Identity, eventID, leaseID string, ...) (OutboxEvent, error)
- func (s *MemoryStore) Settle(ctx context.Context, owner execution.Identity, id string, expected uint64, ...) (Record, error)
- type OutboxEvent
- type OutboxLease
- type OutboxStatus
- type ProjectionBinding
- type Record
- type RecoveryCoordinator
- type ResultReceipt
- type ResumeEvidence
- type ResumeProof
- type RuntimeBinding
- type State
- type Store
- type ToolBinding
Constants ¶
const ( CheckpointVersion = 1 ReceiptVersion = 1 )
Variables ¶
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") )
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 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 (*MemoryStore) AckOutbox ¶
func (s *MemoryStore) AckOutbox(ctx context.Context, owner execution.Identity, eventID string, at time.Time) (OutboxEvent, error)
func (*MemoryStore) CommitResult ¶
func (*MemoryStore) Create ¶
func (s *MemoryStore) Create(ctx context.Context, checkpoint Checkpoint, at time.Time) (Record, bool, error)
func (*MemoryStore) ExpireClaim ¶
func (*MemoryStore) LeaseOutbox ¶
func (*MemoryStore) PendingOutbox ¶
func (s *MemoryStore) PendingOutbox(ctx context.Context, owner execution.Identity, limit int) ([]OutboxEvent, error)
func (*MemoryStore) RetryOutbox ¶
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 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.
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 Store ¶
type Store interface {
Create(context.Context, Checkpoint, time.Time) (Record, bool, error)
CommitResult(context.Context, execution.Identity, string, uint64, ResultReceipt, string, time.Time) (Record, error)
Claim(context.Context, execution.Identity, string, uint64, ResumeProof, Claim, string, time.Time) (Record, error)
ExpireClaim(context.Context, execution.Identity, string, uint64, string, time.Time) (Record, error)
Settle(context.Context, execution.Identity, string, uint64, State, string, string, time.Time) (Record, error)
Reconcile(context.Context, execution.Identity, string, uint64, State, *ResultReceipt, string, string, time.Time) (Record, error)
Get(context.Context, execution.Identity, string) (Record, bool, error)
Pending(context.Context, execution.Identity, int) ([]Record, error)
PendingOutbox(context.Context, execution.Identity, int) ([]OutboxEvent, error)
LeaseOutbox(context.Context, execution.Identity, string, string, int, time.Time, time.Duration) ([]OutboxEvent, error)
RetryOutbox(context.Context, execution.Identity, string, string, uint64, string, time.Time, time.Time) (OutboxEvent, error)
AckLeasedOutbox(context.Context, execution.Identity, string, string, uint64, time.Time) (OutboxEvent, error)
AckOutbox(context.Context, execution.Identity, string, time.Time) (OutboxEvent, error)
}
Store is the durable continuation and transactional-outbox boundary. Mutation methods must update the record and append their event atomically.
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.