runstate

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("runstate: not found")
	ErrStaleSnapshot     = errors.New("runstate: snapshot version is stale")
	ErrInvalidStatus     = errors.New("runstate: invalid status")
	ErrInvalidTransition = errors.New("runstate: invalid status transition")
	ErrTokenSuperseded   = errors.New("humangate: token superseded by newer version")
)
View Source
var ErrInvalidToken = errors.New("runstate: invalid token")
View Source
var ErrTenantMismatch = errors.New("runstate: tenant mismatch")

Functions

func AuthorizeTenant added in v0.1.4

func AuthorizeTenant(ctx context.Context, snapshot RunSnapshot) error

AuthorizeTenant ensures an authenticated principal can access the snapshot tenant. Legacy snapshots without tenant_id remain accessible when no principal is present.

func CollectBlobRefs added in v0.1.4

func CollectBlobRefs(snapshot RunSnapshot) map[string]BlobRef

CollectBlobRefs returns blob references referenced by a snapshot's step outputs.

func CollectReferencedBlobIDs added in v0.1.4

func CollectReferencedBlobIDs(snapshots []RunSnapshot) map[string]struct{}

CollectReferencedBlobIDs returns blob IDs still referenced by the given snapshots.

func HydrateStepContext added in v0.1.3

func HydrateStepContext(ctx context.Context, blobs BlobStore, outputs map[string]StepOutputRef) (json.RawMessage, error)

HydrateStepContext loads inline and blob-backed step outputs into a JSON object shaped as {"steps":{"<node_id>":...}} suitable for hybrid run context.

func IndexedThreadID added in v0.2.0

func IndexedThreadID(snapshot RunSnapshot) string

IndexedThreadID returns the value stored in thread indexes for a snapshot.

func LoadStepOutput added in v0.1.3

func LoadStepOutput(ctx context.Context, blobs BlobStore, ref StepOutputRef) (json.RawMessage, error)

LoadStepOutput resolves a step output reference from inline or blob storage.

func PurgeOrphanBlobs added in v0.1.4

func PurgeOrphanBlobs(ctx context.Context, runs Repository, blobs BlobStore, filter ListFilter) (int, error)

PurgeOrphanBlobs deletes blobs that are not referenced by any listed run snapshot.

func ResolveThreadID added in v0.2.0

func ResolveThreadID(snapshot RunSnapshot) string

ResolveThreadID returns the thread group identifier for a snapshot.

func StampSnapshot added in v0.1.4

func StampSnapshot(snapshot *RunSnapshot, previous *RunSnapshot, now time.Time)

StampSnapshot preserves CreatedAt from a previous snapshot and refreshes UpdatedAt.

func StampTenant added in v0.1.4

func StampTenant(ctx context.Context, snapshot *RunSnapshot)

StampTenant assigns the principal tenant to new snapshots when present in ctx.

Types

type BlobAdmin added in v0.1.4

type BlobAdmin interface {
	BlobStore
	List(ctx context.Context) ([]BlobRef, error)
	Delete(ctx context.Context, ref BlobRef) error
}

BlobAdmin extends BlobStore with listing and deletion for retention workflows.

type BlobRef

type BlobRef struct {
	ID     string `json:"id"`
	Size   int64  `json:"size"`
	Sha256 string `json:"sha256"`
}

func NewBlobRef

func NewBlobRef(id string, data []byte) BlobRef

type BlobStore

type BlobStore interface {
	Put(ctx context.Context, data []byte) (BlobRef, error)
	Get(ctx context.Context, ref BlobRef) ([]byte, error)
}

type CheckpointHistory added in v0.2.0

type CheckpointHistory interface {
	Append(ctx context.Context, snapshot RunSnapshot) error
	List(ctx context.Context, runID string, limit int) ([]CheckpointSummary, error)
	Load(ctx context.Context, runID string, version int64) (RunSnapshot, error)
}

CheckpointHistory stores immutable run snapshot revisions for time-travel.

type CheckpointSummary added in v0.2.0

type CheckpointSummary struct {
	RunID         string    `json:"run_id"`
	Version       int64     `json:"version"`
	Status        RunStatus `json:"status"`
	CurrentNodeID string    `json:"current_node_id,omitempty"`
	StepCount     int       `json:"step_count"`
	RecordedAt    time.Time `json:"recorded_at"`
}

CheckpointSummary describes one append-only run snapshot revision.

type ListFilter added in v0.1.1

type ListFilter struct {
	// Status, when non-empty, restricts results to snapshots with this status.
	Status RunStatus
	// ScenarioName, when non-empty, restricts results to a specific scenario.
	ScenarioName string
	// TenantID, when non-empty, restricts results to a specific tenant.
	TenantID string
	// ParentRunID, when non-empty, restricts results to forks of a parent run.
	ParentRunID string
	// ThreadID, when non-empty, restricts results to a fork/thread group.
	ThreadID string
	// Limit is the maximum number of results to return. 0 means no limit.
	Limit int
}

ListFilter controls which snapshots are returned by Repository.List. Zero values are treated as "no filter" for the corresponding field.

type Repository

type Repository interface {
	Save(ctx context.Context, snapshot *RunSnapshot, expectedVersion int64) error
	Load(ctx context.Context, runID string) (RunSnapshot, error)
	Delete(ctx context.Context, runID string) error
	// List returns snapshots that match the filter. Implementations may
	// return results in any order. An empty filter matches all snapshots.
	List(ctx context.Context, filter ListFilter) ([]RunSnapshot, error)
}

type RunSnapshot

type RunSnapshot struct {
	RunID           string                     `json:"run_id"`
	Version         int64                      `json:"version"`
	ScenarioName    string                     `json:"scenario_name"`
	TenantID        string                     `json:"tenant_id,omitempty"`
	CurrentNodeID   string                     `json:"current_node_id,omitempty"`
	Status          RunStatus                  `json:"status"`
	Variables       map[string]json.RawMessage `json:"variables,omitempty"`
	StepOutputs     map[string]StepOutputRef   `json:"step_outputs,omitempty"`
	PendingGate     *core.CheckpointState      `json:"pending_gate,omitempty"`
	ParentRunID     string                     `json:"parent_run_id,omitempty"`
	ForkFromVersion int64                      `json:"fork_from_version,omitempty"`
	ThreadID        string                     `json:"thread_id,omitempty"`
	CreatedAt       time.Time                  `json:"created_at,omitempty"`
	UpdatedAt       time.Time                  `json:"updated_at,omitempty"`
}

func LoadAuthorized added in v0.1.4

func LoadAuthorized(ctx context.Context, repo Repository, runID string) (RunSnapshot, error)

LoadAuthorized loads a snapshot and enforces tenant access when a principal is present.

func (RunSnapshot) Validate

func (s RunSnapshot) Validate() error

type RunStatus

type RunStatus string
const (
	RunStatusRunning   RunStatus = "running"
	RunStatusPaused    RunStatus = "paused"
	RunStatusFailed    RunStatus = "failed"
	RunStatusCompleted RunStatus = "completed"
	RunStatusCancelled RunStatus = "cancelled"
)

func (RunStatus) CanTransitionTo

func (s RunStatus) CanTransitionTo(next RunStatus) bool

func (RunStatus) Valid

func (s RunStatus) Valid() bool

type StepOutputRef

type StepOutputRef struct {
	Inline json.RawMessage `json:"inline,omitempty"`
	Blob   *BlobRef        `json:"blob,omitempty"`
}

type TokenPayload

type TokenPayload struct {
	RunID     string    `json:"run_id"`
	Version   int64     `json:"version"`
	ExpiresAt time.Time `json:"expires_at,omitempty"`
}

type TokenSigner

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

func NewTokenSigner

func NewTokenSigner(secret []byte) (*TokenSigner, error)

func (*TokenSigner) Sign

func (s *TokenSigner) Sign(payload TokenPayload) (string, error)

func (*TokenSigner) Verify

func (s *TokenSigner) Verify(token string) (TokenPayload, error)

Jump to

Keyboard shortcuts

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