store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package store holds the shared in-memory state machine behind the memory and filesystem reference Repository implementations. It centralizes the contract logic (Rev CAS, Guards, uniqueness, atomic ChangeSet application, and ClaimNextProcess) so both implementations satisfy an identical contract and pass repository/repotest. The package is internal: the boundary genuinely spans two sibling packages, which is why it is a package rather than unexported helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

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

State is an immutable-by-convention snapshot of the whole Repository. Writes never mutate an existing State: After and ClaimNext build and return a fresh State (copy-on-write on the touched keys), so the caller can persist it before swapping it in. Reads deep-copy on the way out so a caller mutating a returned value cannot reach into stored state.

func Load

func Load(data []byte) (*State, error)

Load reconstructs a State from a JSON snapshot and rebuilds its indexes.

func NewState

func NewState() *State

NewState returns an empty State.

func (*State) After

func (s *State) After(cs agentkit.ChangeSet) (*State, error)

After validates cs against the current state and, on success, returns a fresh next State with the ChangeSet applied (Processes' Rev +1'd, Awaits upserted, Events appended). On any precondition or uniqueness failure it returns ErrConflict and no State (the caller writes nothing).

func (*State) ClaimNext

func (s *State) ClaimNext(workerID string, leaseUntil, now time.Time) (*agentkit.Process, *State, error)

ClaimNext atomically claims the runnable Process with the smallest CreatedAt. It returns a deep copy of the claimed Process and the next State to persist, or (nil, nil, nil) when there is no target.

func (*State) FindByIdempotencyKey

func (s *State) FindByIdempotencyKey(key string) (*agentkit.Process, error)

FindByIdempotencyKey returns the Process with the given idempotency key, or ErrProcessNotFound.

func (*State) FindOpenBySubject

func (s *State) FindOpenBySubject(subject agentkit.SubjectRef) (*agentkit.Process, error)

FindOpenBySubject returns the open (pending/running/waiting) Process holding the subject, or ErrProcessNotFound.

func (*State) GetProcess

func (s *State) GetProcess(pid agentkit.ProcessID) (*agentkit.Process, error)

GetProcess returns a deep copy of the Process, or ErrProcessNotFound.

func (*State) ListAwaits

func (s *State) ListAwaits(pid agentkit.ProcessID) []*agentkit.Await

ListAwaits returns deep copies of all awaits of a Process.

func (*State) ListEvents

func (s *State) ListEvents(pid agentkit.ProcessID, q agentkit.EventQuery) ([]*agentkit.Event, error)

ListEvents returns deep copies of a Process's events in append order, starting after the cursor and capped at limit. See the Repository contract for the cursor semantics; an unknown after is agentkit.ErrEventNotFound.

func (*State) Marshal

func (s *State) Marshal() ([]byte, error)

Marshal serializes the full state to JSON.

Jump to

Keyboard shortcuts

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