session

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package session owns Peen's durable transport-neutral session transcript.

Index

Constants

View Source
const (
	// DefaultPageLimit is the API default for transcript pagination.
	DefaultPageLimit = 50
	// MaximumPageLimit bounds one transcript page at the storage boundary.
	MaximumPageLimit = 200
)

Variables

View Source
var (
	// ErrSessionBusy reports a concurrent turn attempt for one session.
	ErrSessionBusy = commerr.ErrLockHeld
	// ErrInvalidPage reports invalid transcript pagination arguments.
	ErrInvalidPage = commerr.ErrValidationFailed
)

Functions

This section is empty.

Types

type AgentRunCompactionInput added in v0.11.0

type AgentRunCompactionInput struct {
	ID                     uuid.UUID
	FromMessageID          uuid.UUID
	ToMessageID            uuid.UUID
	FromSequence           int64
	ToSequence             int64
	DirectFromSequence     int64
	DirectToSequence       int64
	Summary                string
	SourceMessageCount     int64
	InputTokenCount        int64
	SummaryTokenCount      int64
	ModelID                string
	PromptHash             string
	SupersedesCompactionID *uuid.UUID
}

AgentRunCompactionInput stores one immutable child replacement summary.

type AgentRunCompactionPage added in v0.11.0

type AgentRunCompactionPage struct {
	Items   []*models.AgentRunCompaction
	Limit   int
	Offset  int
	HasMore bool
}

AgentRunCompactionPage is one complete child compaction page, newest first.

type AgentRunEventInput added in v0.4.0

type AgentRunEventInput struct {
	ID          uuid.UUID
	EventType   string
	PayloadJSON string
	CreatedAt   time.Time
}

AgentRunEventInput is one immutable child-agent event.

type AgentRunEventPage added in v0.4.0

type AgentRunEventPage struct {
	Run        *models.AgentRun
	Items      []*models.AgentRunEvent
	NextCursor int64
	HasMore    bool
}

AgentRunEventPage is one complete ordered child-event window.

type AgentRunHistoryResult added in v0.11.0

type AgentRunHistoryResult struct {
	Compaction *models.AgentRunCompaction
	Messages   []*models.AgentRunMessage
}

AgentRunHistoryResult is a child's current summary plus the raw tail after it, which is what rebuilds the child conversation from SQLite.

type AgentRunMessageInput added in v0.11.0

type AgentRunMessageInput struct {
	ID            uuid.UUID
	Role          models.MessageRole
	Content       string
	ModelID       string
	Thinking      string
	ToolCallsJSON string
	ToolCallID    string
	IsError       bool
	Incomplete    bool
}

AgentRunMessageInput is one prompt-visible record in a child agent's own transcript. It carries no turn or workspace: a child belongs to its agent run, not to a session turn's message sequence.

type AgentRunMessagePage added in v0.11.0

type AgentRunMessagePage struct {
	Items   []*models.AgentRunMessage
	Limit   int
	Offset  int
	HasMore bool
}

AgentRunMessagePage is one complete child transcript page, oldest first.

type AgentRunPage added in v0.4.0

type AgentRunPage struct {
	Items   []*models.AgentRun
	Limit   int
	Offset  int
	HasMore bool
}

AgentRunPage is one complete child-run page.

type AppendJobOutputInput added in v0.4.0

type AppendJobOutputInput struct {
	ID        uuid.UUID
	Stream    models.JobOutputStream
	Content   string
	CreatedAt time.Time
}

AppendJobOutputInput is one immutable line in the combined process stream.

type CompactionInput

type CompactionInput struct {
	ID                     uuid.UUID
	FromMessageID          uuid.UUID
	ToMessageID            uuid.UUID
	FromSequence           int64
	ToSequence             int64
	DirectFromSequence     int64
	DirectToSequence       int64
	Summary                string
	SourceMessageCount     int64
	InputTokenCount        int64
	SummaryTokenCount      int64
	ModelID                string
	PromptHash             string
	SupersedesCompactionID *uuid.UUID
}

CompactionInput stores one immutable replacement summary.

type CompactionPage added in v0.4.0

type CompactionPage struct {
	Items   []*models.Compaction
	Limit   int
	Offset  int
	HasMore bool
}

CompactionPage is one complete session-local compaction page.

type CreateJobInput added in v0.4.0

type CreateJobInput struct {
	ID                 uuid.UUID
	TurnID             uuid.UUID
	WorkerGenerationID string
	ToolCallID         string
	PID                int64
	Purpose            string
	Command            string
	Directory          string
	StartedAt          time.Time
}

CreateJobInput records a supervised process before its output is observed.

type CreateModelCallInput added in v0.4.0

type CreateModelCallInput struct {
	ID                  uuid.UUID
	Round               int64
	RequestMessagesJSON string
	RequestToolsJSON    string
	StartedAt           time.Time
}

CreateModelCallInput describes one outbound provider round before bytes leave Peen.

type CreateModelRunInput added in v0.4.0

type CreateModelRunInput struct {
	ID                  uuid.UUID
	TurnID              uuid.UUID
	AgentRunID          *uuid.UUID
	Stage               models.ModelRunStage
	ModelReference      string
	ConnectionName      string
	RequestedModelID    string
	RequestSettingsJSON string
	StartedAt           time.Time
}

CreateModelRunInput describes one logical provider invocation before its first outbound round starts.

type CreateSessionNoticeInput added in v0.4.0

type CreateSessionNoticeInput struct {
	ID        uuid.UUID
	Type      string
	Source    string
	Summary   string
	DataJSON  string
	Delivery  models.NoticeDelivery
	CreatedAt time.Time
}

CreateSessionNoticeInput describes an external or worker report before it is delivered to a model.

type CreateWorkerGenerationInput added in v0.8.0

type CreateWorkerGenerationInput struct {
	ID              uuid.UUID
	Kind            string
	Profile         string
	ProfileRevision int64
	State           string
	Workspace       string
	SocketPath      string

	// CredentialHash verifies the worker's launch credential. The raw
	// credential is never stored.
	CredentialHash string
}

CreateWorkerGenerationInput records one worker before it launches, so a controller that dies mid-launch still leaves a row an operator can reconcile.

type EventInput

type EventInput struct {
	ID                 uuid.UUID
	RequestID          uuid.UUID
	WorkerGenerationID string
	EventType          string
	PayloadJSON        string
	ParentToolCallID   string
}

EventInput describes one exact internal or protocol event.

type EventPage added in v0.4.0

type EventPage struct {
	Items   []*models.Event
	Limit   int
	Offset  int
	HasMore bool
}

EventPage is one complete session-local protocol event page.

type FinalizeAgentRunInput added in v0.4.0

type FinalizeAgentRunInput struct {
	State                 models.AgentRunState
	ResponseText          string
	ResponseThinking      string
	ResponseMessagesJSON  string
	FinishReason          string
	PromptTokenCount      int64
	CompletionTokenCount  int64
	FailureClassification string
	FailureDetail         string
}

FinalizeAgentRunInput describes the durable terminal outcome of a child.

type FinalizeJobInput added in v0.4.0

type FinalizeJobInput struct {
	State         models.JobState
	ExitCode      int64
	FailureDetail string
}

FinalizeJobInput stores a job's terminal outcome exactly once.

type FinalizeModelCallInput added in v0.4.0

type FinalizeModelCallInput struct {
	State                   models.ModelCallState
	ResponseMessageJSON     string
	ResponseUsageJSON       string
	RetryAttemptsJSON       string
	RetryAttemptCount       int64
	PromptTokens            int64
	CompletionTokens        int64
	TotalTokens             int64
	ReasoningTokens         int64
	CacheReadTokens         int64
	CacheWriteTokens        int64
	CacheWriteLongTTLTokens int64
	WastedPromptTokens      int64
	WastedCompletionTokens  int64
	WastedTotalTokens       int64
	TotalAttempts           int64
	ResponseModelID         string
	FinishReason            string
	ResponseCostAmount      string
	RetryCostAmount         string
	BilledCostAmount        string
	CostKnown               bool
	FailureClassification   string
	FailureDetail           string
}

FinalizeModelCallInput records the complete result of one provider round.

type FinalizeModelRunInput added in v0.4.0

type FinalizeModelRunInput struct {
	State                  models.ModelRunState
	ResponseModelID        string
	ResponseText           string
	ResponseThinking       string
	ResponseMessagesJSON   string
	ResponseInjectionsJSON string
	ResponseUsageJSON      string
	ResponseCostAmount     string
	RetryCostAmount        string
	BilledCostAmount       string
	CostKnown              bool
	FinishReason           string
	FailureClassification  string
	FailureDetail          string
}

FinalizeModelRunInput stores every non-secret result of one logical model invocation, including aggregate usage across its provider rounds.

type FinalizeTurnInput

type FinalizeTurnInput struct {
	State                 models.TurnState
	FailureClassification string
	ContextSnapshotHash   *string
	PromptSnapshotHash    *string
	Messages              []MessageInput
	Events                []EventInput
}

FinalizeTurnInput describes terminal turn state and durable references.

type History

type History struct {
	Compaction *models.Compaction
	Messages   []*models.Message
}

History is the active compaction followed by its uncovered completed tail.

type JobOutputPage added in v0.4.0

type JobOutputPage struct {
	Job        *models.Job
	Items      []*models.JobOutputLine
	NextCursor int64
	HasMore    bool
}

JobOutputPage is one complete ordered output replay page.

type JobPage added in v0.4.0

type JobPage struct {
	Items   []*models.Job
	Limit   int
	Offset  int
	HasMore bool
}

JobPage is one complete process-job page.

type JobSignalRequestPage added in v0.4.0

type JobSignalRequestPage struct {
	Job     *models.Job
	Items   []*models.JobSignalRequest
	Limit   int
	Offset  int
	HasMore bool
}

JobSignalRequestPage is one complete signal-request history page.

type Lease

type Lease struct {
	SessionID uuid.UUID
	TurnID    uuid.UUID
}

Lease uniquely identifies one active turn in a session.

type ListAgentRunCompactionsOptions added in v0.11.0

type ListAgentRunCompactionsOptions struct {
	Limit  int
	Offset int
}

ListAgentRunCompactionsOptions bounds one child compaction page.

type ListAgentRunEventsOptions added in v0.4.0

type ListAgentRunEventsOptions struct {
	Cursor int64
	Limit  int
}

ListAgentRunEventsOptions controls one replay window. Cursor is the next sequence number the caller has not seen yet, beginning at zero.

type ListAgentRunMessagesOptions added in v0.11.0

type ListAgentRunMessagesOptions struct {
	Limit  int
	Offset int
}

ListAgentRunMessagesOptions bounds one child transcript page.

type ListAgentRunsOptions added in v0.4.0

type ListAgentRunsOptions struct {
	Limit  int
	Offset int
	State  *models.AgentRunState
}

ListAgentRunsOptions controls a bounded child-run page.

type ListCompactionsOptions added in v0.4.0

type ListCompactionsOptions struct {
	Limit  int
	Offset int
}

ListCompactionsOptions controls a bounded page of compaction records.

type ListEventsOptions added in v0.4.0

type ListEventsOptions struct {
	Limit  int
	Offset int
	Order  PageOrder
}

ListEventsOptions controls a bounded page of durable protocol events.

type ListJobOutputOptions added in v0.4.0

type ListJobOutputOptions struct {
	Cursor int64
	Limit  int
	Stream *models.JobOutputStream
}

ListJobOutputOptions controls one ordered process-output replay window.

type ListJobSignalRequestsOptions added in v0.4.0

type ListJobSignalRequestsOptions struct {
	Limit  int
	Offset int
}

ListJobSignalRequestsOptions controls a bounded signal-request history page.

type ListJobsOptions added in v0.4.0

type ListJobsOptions struct {
	Limit  int
	Offset int
	State  *models.JobState
}

ListJobsOptions controls a bounded session-local process-job page.

type ListMessagesOptions

type ListMessagesOptions struct {
	Limit  int
	Offset int
	Order  PageOrder
}

ListMessagesOptions controls a bounded session-local message page.

type ListModelCallsOptions added in v0.4.0

type ListModelCallsOptions struct {
	Limit  int
	Offset int
}

ListModelCallsOptions controls one ordered provider-round page.

type ListModelRunsOptions added in v0.4.0

type ListModelRunsOptions struct {
	Limit  int
	Offset int
	Stage  *models.ModelRunStage
	State  *models.ModelRunState
}

ListModelRunsOptions controls a bounded session-local model-run page.

type ListProfileDecisionsOptions added in v0.8.0

type ListProfileDecisionsOptions struct {
	Limit  int
	Offset int
}

ListProfileDecisionsOptions controls a bounded page of one session's execution profile decisions.

type ListSessionNoticesOptions added in v0.4.0

type ListSessionNoticesOptions struct {
	Limit  int
	Offset int
}

ListSessionNoticesOptions controls a bounded page of notice history.

type ListSessionsOptions added in v0.8.0

type ListSessionsOptions struct {
	Limit  int
	Offset int
}

ListSessionsOptions controls a bounded page of the control surface's durable sessions.

type ListTurnsOptions added in v0.4.0

type ListTurnsOptions struct {
	Limit  int
	Offset int
}

ListTurnsOptions controls a bounded page of durable session turns.

type ListWorkerGenerationsOptions added in v0.8.0

type ListWorkerGenerationsOptions struct {
	Limit  int
	Offset int
}

ListWorkerGenerationsOptions controls a bounded page of one session's worker generations.

type MessageInput

type MessageInput struct {
	ID            uuid.UUID
	Workspace     string
	Role          models.MessageRole
	Content       string
	ModelID       string
	Thinking      string
	ToolCallsJSON string
	ToolCallID    string
	IsError       bool
	Incomplete    bool
}

MessageInput describes a durable transcript record.

type MessagePage

type MessagePage struct {
	Items   []*models.Message
	Limit   int
	Offset  int
	HasMore bool
}

MessagePage is one complete limit-offset transcript page.

type ModelCallPage added in v0.4.0

type ModelCallPage struct {
	Run     *models.ModelRun
	Items   []*models.ModelCall
	Limit   int
	Offset  int
	HasMore bool
}

ModelCallPage is one complete provider-round page for a model run.

type ModelRunPage added in v0.4.0

type ModelRunPage struct {
	Items   []*models.ModelRun
	Limit   int
	Offset  int
	HasMore bool
}

ModelRunPage is one complete model-run page.

type NoticePage added in v0.5.0

type NoticePage struct {
	Items   []*models.SessionNotice
	Limit   int
	Offset  int
	HasMore bool
}

NoticePage is one complete session-local notice page.

type OpenSessionOptions

type OpenSessionOptions struct {
	RootAgent string
	ModelID   string

	// ExecutionProfile is the operator-defined profile a newly created session
	// runs under. Opening an existing session never changes its profile, so
	// this only applies to creation.
	ExecutionProfile string
}

OpenSessionOptions supplies immutable session attribution on creation.

type OpenSessionResult

type OpenSessionResult struct {
	Session *models.Session
	Created bool
}

OpenSessionResult is a resolved session and whether this call created it.

type Options

type Options struct {
	Clock func() time.Time
	NewID func() uuid.UUID

	// MaxStoredMessageBytes bounds one message row of any role. An assistant
	// or tool message has no caller-facing size limit, so without this a
	// single tool result could grow the transcript without bound. Zero takes
	// the package default.
	MaxStoredMessageBytes int
}

Options supplies deterministic seams for the transport-neutral store.

type PageOrder

type PageOrder string

PageOrder controls transcript pagination direction.

const (
	PageOrderAscending  PageOrder = "asc"
	PageOrderDescending PageOrder = "desc"
)

type ProfileDecisionPage added in v0.8.0

type ProfileDecisionPage struct {
	Items   []*models.SessionProfileDecision
	Limit   int
	Offset  int
	HasMore bool
}

ProfileDecisionPage is one complete page of profile decisions.

type RecordJobSignalInput added in v0.4.0

type RecordJobSignalInput struct {
	ID          uuid.UUID
	Signal      models.JobSignal
	Accepted    bool
	RequestedAt time.Time
}

RecordJobSignalInput records one accepted or no-op request to stop a job.

type RecordModelCallRetriesInput added in v0.4.0

type RecordModelCallRetriesInput struct {
	RetryAttemptsJSON string
	RetryAttemptCount int64
}

RecordModelCallRetriesInput persists every retry that Elelem reports while a provider round remains active.

type StartAgentRunInput added in v0.4.0

type StartAgentRunInput struct {
	ID                 uuid.UUID
	ParentTurnID       uuid.UUID
	WorkerGenerationID string
	ParentAgentRunID   *uuid.UUID
	ParentToolCallID   string
	RequestID          uuid.UUID
	Name               string
	Definition         models.AgentRunDefinition
	Depth              int64
	Workspace          string
	ModelReference     string
	ModelID            string
	Task               string
	Instructions       string
	AllowedToolsJSON   string
	SystemPrompt       string
	StartedAt          time.Time
}

StartAgentRunInput describes the immutable child-agent launch record.

type StartTurnInput

type StartTurnInput struct {
	RequestID uuid.UUID
	Workspace string
	Messages  []MessageInput
	Events    []EventInput
}

StartTurnInput describes the durable beginning of an agent turn.

type Storage added in v0.8.0

type Storage interface {
	// contains filtered or unexported methods
}

Storage is the durable surface one session's runtime needs.

It exists because the same runtime runs in two places. Inside the control plane it is backed by *Store, which owns SQLite. Inside a worker it is backed by the private worker protocol, which forwards each operation to the controller. A worker therefore gets the same transcript semantics without ever opening the controller's database.

The interface is deliberately the whole set rather than a convenient subset. A worker-side implementation must answer every method, and refusing one it has no business performing is a decision that shows up in the code rather than a method that silently does not exist.

type Store

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

Store persists sessions and protects each active session turn in-process.

func NewStore

func NewStore(handle *db.Handle, options Options) (*Store, error)

NewStore builds a store over an already-open migrated database handle.

func (*Store) AcquireTurn

func (s *Store) AcquireTurn(
	ctx context.Context,
	sessionID uuid.UUID,
	input StartTurnInput,
) (Lease, error)

AcquireTurn starts one durable turn and records its initial transcript data.

func (*Store) AgentRunHistory added in v0.11.0

func (s *Store) AgentRunHistory(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
) (*AgentRunHistoryResult, error)

AgentRunHistory returns the child's current summary and the raw tail that follows it, which is what rebuilds a child conversation after a restart.

func (*Store) AppendAgentRunEvent added in v0.4.0

func (s *Store) AppendAgentRunEvent(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	input AgentRunEventInput,
) (*models.AgentRunEvent, error)

AppendAgentRunEvent records a child event before it reaches a live client.

func (*Store) AppendAgentRunMessages added in v0.11.0

func (s *Store) AppendAgentRunMessages(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	inputs []AgentRunMessageInput,
) ([]*models.AgentRunMessage, error)

AppendAgentRunMessages stores prompt-visible child records in one transaction, so a child loop never continues past a message the durable transcript does not hold.

Sequences are allocated per agent run, independent of the session transcript. A child agent is a separate model context, so its messages never enter the session transcript and a parent-session compaction can never absorb them.

func (*Store) AppendCheckpoint

func (s *Store) AppendCheckpoint(
	ctx context.Context,
	lease Lease,
	messages []MessageInput,
	events []EventInput,
) error

AppendCheckpoint records visible messages and events without ending a turn.

func (*Store) AppendJobOutput added in v0.4.0

func (s *Store) AppendJobOutput(
	ctx context.Context,
	sessionID uuid.UUID,
	jobID uuid.UUID,
	input AppendJobOutputInput,
) (*models.JobOutputLine, error)

AppendJobOutput stores one process line in sequence before any live reader can see it. stdout and stderr share the same sequence so replay preserves observed ordering across both streams.

func (*Store) Cancel

func (s *Store) Cancel(ctx context.Context, sessionID uuid.UUID) (bool, error)

Cancel requests cancellation for the active turn without waiting for it.

func (*Store) CompletedHistory

func (s *Store) CompletedHistory(
	ctx context.Context,
	sessionID uuid.UUID,
) (*History, error)

CompletedHistory returns the current summary and the raw completed tail.

func (*Store) CreateAgentRun added in v0.4.0

func (s *Store) CreateAgentRun(
	ctx context.Context,
	sessionID uuid.UUID,
	input StartAgentRunInput,
) (*models.AgentRun, error)

CreateAgentRun records a child before any provider work or visible stream event can begin.

func (*Store) CreateAgentRunCompaction added in v0.11.0

func (s *Store) CreateAgentRunCompaction(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	input AgentRunCompactionInput,
) (*models.AgentRunCompaction, error)

CreateAgentRunCompaction stores one immutable child summary and assigns the direct messages it covered.

Only rows this compaction covered itself are assigned, so an earlier child compaction keeps the direct membership it already recorded.

func (*Store) CreateCompaction

func (s *Store) CreateCompaction(
	ctx context.Context,
	sessionID uuid.UUID,
	input CompactionInput,
) (*models.Compaction, error)

CreateCompaction stores an immutable completed-history replacement summary.

func (*Store) CreateJob added in v0.4.0

func (s *Store) CreateJob(
	ctx context.Context,
	sessionID uuid.UUID,
	input CreateJobInput,
) (*models.Job, error)

CreateJob records a supervised process before its output reaches memory or any connected client.

func (*Store) CreateModelCall added in v0.4.0

func (s *Store) CreateModelCall(
	ctx context.Context,
	sessionID uuid.UUID,
	modelRunID uuid.UUID,
	input CreateModelCallInput,
) (*models.ModelCall, error)

CreateModelCall writes one exact outbound provider request before Elelem gives its driver permission to execute it.

func (*Store) CreateModelRun added in v0.4.0

func (s *Store) CreateModelRun(
	ctx context.Context,
	sessionID uuid.UUID,
	input CreateModelRunInput,
) (*models.ModelRun, error)

CreateModelRun records a logical model invocation before any provider work begins. No live event is permitted to outrun this row.

func (*Store) CreateOrResume

func (s *Store) CreateOrResume(
	ctx context.Context,
	requestedSessionID *uuid.UUID,
	options OpenSessionOptions,
) (*OpenSessionResult, error)

CreateOrResume creates a session or resumes its requested durable ID.

func (*Store) CreateSessionNotice added in v0.4.0

func (s *Store) CreateSessionNotice(
	ctx context.Context,
	sessionID uuid.UUID,
	input CreateSessionNoticeInput,
) (*models.SessionNotice, error)

CreateSessionNotice writes a notice before it reaches an in-process bus or a model. It is the durable source of the session's outside event history.

func (*Store) CreateWorkerGeneration added in v0.8.0

func (s *Store) CreateWorkerGeneration(
	ctx context.Context,
	sessionID uuid.UUID,
	input CreateWorkerGenerationInput,
) (*models.WorkerGeneration, error)

CreateWorkerGeneration stores a new generation for one existing session.

func (*Store) CurrentWorkerGeneration added in v0.8.0

func (s *Store) CurrentWorkerGeneration(
	ctx context.Context,
	sessionID uuid.UUID,
) (*models.WorkerGeneration, error)

CurrentWorkerGeneration returns the session's newest generation.

func (*Store) DrainSessionNotices added in v0.4.0

func (s *Store) DrainSessionNotices(
	ctx context.Context,
	sessionID uuid.UUID,
) ([]*models.SessionNotice, error)

DrainSessionNotices marks every pending notice delivered and returns the exact immutable records for the next model context.

func (*Store) FinalizeAgentRun added in v0.4.0

func (s *Store) FinalizeAgentRun(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	input FinalizeAgentRunInput,
) (*models.AgentRun, error)

FinalizeAgentRun writes the terminal response or failure exactly once.

func (*Store) FinalizeJob added in v0.4.0

func (s *Store) FinalizeJob(
	ctx context.Context,
	sessionID uuid.UUID,
	jobID uuid.UUID,
	input FinalizeJobInput,
) (*models.Job, error)

FinalizeJob records a terminal process result exactly once.

func (*Store) FinalizeModelCall added in v0.4.0

func (s *Store) FinalizeModelCall(
	ctx context.Context,
	sessionID uuid.UUID,
	modelRunID uuid.UUID,
	modelCallID uuid.UUID,
	input FinalizeModelCallInput,
) (*models.ModelCall, error)

FinalizeModelCall writes one provider round's output and accounting exactly once. The request snapshot is immutable from CreateModelCall.

func (*Store) FinalizeModelRun added in v0.4.0

func (s *Store) FinalizeModelRun(
	ctx context.Context,
	sessionID uuid.UUID,
	modelRunID uuid.UUID,
	input FinalizeModelRunInput,
) (*models.ModelRun, error)

FinalizeModelRun writes the logical invocation outcome after every round has either finished or been marked terminal.

func (*Store) FinalizeTurn

func (s *Store) FinalizeTurn(
	ctx context.Context,
	lease Lease,
	input FinalizeTurnInput,
) error

FinalizeTurn atomically writes terminal transcript data and state.

func (*Store) Get

func (s *Store) Get(
	ctx context.Context,
	sessionID uuid.UUID,
) (*models.Session, error)

Get returns durable metadata for one existing session.

func (*Store) GetAgentRun added in v0.4.0

func (s *Store) GetAgentRun(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
) (*models.AgentRun, error)

GetAgentRun returns one session-scoped durable child run.

func (*Store) GetAgentRunCompaction added in v0.11.0

func (s *Store) GetAgentRunCompaction(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	compactionID uuid.UUID,
) (*models.AgentRunCompaction, error)

GetAgentRunCompaction returns one immutable child compaction owned by both the session and the agent run.

func (*Store) GetCompaction added in v0.4.0

func (s *Store) GetCompaction(
	ctx context.Context,
	sessionID uuid.UUID,
	compactionID uuid.UUID,
) (*models.Compaction, error)

GetCompaction returns one immutable compaction record owned by a session.

func (*Store) GetContextSnapshot added in v0.4.0

func (s *Store) GetContextSnapshot(
	ctx context.Context,
	sessionID uuid.UUID,
	hash string,
) (*models.ContextSnapshot, error)

GetContextSnapshot returns a snapshot only when this session references it.

func (*Store) GetJob added in v0.4.0

func (s *Store) GetJob(
	ctx context.Context,
	sessionID uuid.UUID,
	jobID uuid.UUID,
) (*models.Job, error)

GetJob reads a single durable process job scoped to its session.

func (*Store) GetModelRun added in v0.4.0

func (s *Store) GetModelRun(
	ctx context.Context,
	sessionID uuid.UUID,
	modelRunID uuid.UUID,
) (*models.ModelRun, error)

GetModelRun returns one session-scoped logical model invocation.

func (*Store) GetPromptSnapshot added in v0.4.0

func (s *Store) GetPromptSnapshot(
	ctx context.Context,
	sessionID uuid.UUID,
	hash string,
) (*models.PromptSnapshot, error)

GetPromptSnapshot returns a snapshot only when this session references it.

func (*Store) GetWorkerGeneration added in v0.8.0

func (s *Store) GetWorkerGeneration(
	ctx context.Context,
	sessionID uuid.UUID,
	generationID uuid.UUID,
) (*models.WorkerGeneration, error)

GetWorkerGeneration reads one generation by ID, scoped to its session so a caller cannot read another session's worker record by guessing an ID.

func (*Store) IsActive

func (s *Store) IsActive(sessionID uuid.UUID) bool

IsActive reports whether the process currently owns a running turn.

func (*Store) LatestAgentRunCompaction added in v0.11.0

func (s *Store) LatestAgentRunCompaction(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
) (*models.AgentRunCompaction, error)

LatestAgentRunCompaction returns the child's current chain head, never a superseded row.

func (*Store) LatestCompaction

func (s *Store) LatestCompaction(
	ctx context.Context,
	sessionID uuid.UUID,
) (*models.Compaction, error)

LatestCompaction returns the current chain head, not a superseded row.

func (*Store) ListAgentRunCompactions added in v0.11.0

func (s *Store) ListAgentRunCompactions(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	options ListAgentRunCompactionsOptions,
) (*AgentRunCompactionPage, error)

ListAgentRunCompactions returns one bounded page of a child's compaction lineage, newest first, scoped to the owning session.

func (*Store) ListAgentRunEvents added in v0.4.0

func (s *Store) ListAgentRunEvents(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	options ListAgentRunEventsOptions,
) (*AgentRunEventPage, error)

ListAgentRunEvents returns ordered durable replay data for one child run.

func (*Store) ListAgentRunMessages added in v0.11.0

func (s *Store) ListAgentRunMessages(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
	options ListAgentRunMessagesOptions,
) (*AgentRunMessagePage, error)

ListAgentRunMessages returns one bounded page of a child's own transcript, oldest first, scoped to the owning session.

func (*Store) ListAgentRuns added in v0.4.0

func (s *Store) ListAgentRuns(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListAgentRunsOptions,
) (*AgentRunPage, error)

ListAgentRuns returns a stable newest-first session-scoped child-run page.

func (*Store) ListCompactions added in v0.4.0

func (s *Store) ListCompactions(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListCompactionsOptions,
) (*CompactionPage, error)

ListCompactions returns a stable newest-first page of durable summaries.

func (*Store) ListEvents added in v0.4.0

func (s *Store) ListEvents(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListEventsOptions,
) (*EventPage, error)

ListEvents returns a stable bounded page of durable protocol events.

func (*Store) ListJobOutput added in v0.4.0

func (s *Store) ListJobOutput(
	ctx context.Context,
	sessionID uuid.UUID,
	jobID uuid.UUID,
	options ListJobOutputOptions,
) (*JobOutputPage, error)

ListJobOutput replays the one persisted combined process stream.

func (*Store) ListJobSignalRequests added in v0.4.0

func (s *Store) ListJobSignalRequests(
	ctx context.Context,
	sessionID uuid.UUID,
	jobID uuid.UUID,
	options ListJobSignalRequestsOptions,
) (*JobSignalRequestPage, error)

ListJobSignalRequests returns every durable request to signal one job.

func (*Store) ListJobs added in v0.4.0

func (s *Store) ListJobs(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListJobsOptions,
) (*JobPage, error)

ListJobs returns a stable newest-first session-local process-job page.

func (*Store) ListLiveWorkerGenerations added in v0.8.0

func (s *Store) ListLiveWorkerGenerations(
	ctx context.Context,
) ([]*models.WorkerGeneration, error)

ListLiveWorkerGenerations returns every generation a restarted controller may still own, newest first.

A controller reconnects to these before replacing anything, so a worker that outlived its controller is adopted rather than abandoned.

func (*Store) ListMessages

func (s *Store) ListMessages(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListMessagesOptions,
) (*MessagePage, error)

ListMessages returns a stable bounded page of one session's transcript.

func (*Store) ListModelCalls added in v0.4.0

func (s *Store) ListModelCalls(
	ctx context.Context,
	sessionID uuid.UUID,
	modelRunID uuid.UUID,
	options ListModelCallsOptions,
) (*ModelCallPage, error)

ListModelCalls returns the ordered provider rounds for one durable model invocation, including each exact request and retry trail.

func (*Store) ListModelRuns added in v0.4.0

func (s *Store) ListModelRuns(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListModelRunsOptions,
) (*ModelRunPage, error)

ListModelRuns returns a stable newest-first session-local model run page.

func (*Store) ListSessionNotices added in v0.4.0

func (s *Store) ListSessionNotices(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListSessionNoticesOptions,
) (*NoticePage, error)

ListSessionNotices returns all notice history, pending and delivered, in durable sequence order.

func (*Store) ListSessionProfileDecisions added in v0.8.0

func (s *Store) ListSessionProfileDecisions(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListProfileDecisionsOptions,
) (*ProfileDecisionPage, error)

ListSessionProfileDecisions returns one session's profile decision history, newest first.

func (*Store) ListSessions added in v0.8.0

func (s *Store) ListSessions(
	ctx context.Context,
	options ListSessionsOptions,
) (*WorkspaceSessionPage, error)

ListSessions returns a stable bounded page of every durable session.

Unlike the other durable reads it takes no session ID, because it is how a client discovers which sessions exist. Ordering is newest-updated first so a client that pages sees the sessions it is most likely to want first.

func (*Store) ListTurns added in v0.4.0

func (s *Store) ListTurns(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListTurnsOptions,
) (*TurnPage, error)

ListTurns returns a stable newest-first page of durable session turns.

func (*Store) ListWorkerGenerations added in v0.8.0

func (s *Store) ListWorkerGenerations(
	ctx context.Context,
	sessionID uuid.UUID,
	options ListWorkerGenerationsOptions,
) (*WorkerGenerationPage, error)

ListWorkerGenerations returns a stable newest-first page of one session's worker generations.

func (*Store) OpenWorkspace added in v0.7.0

func (s *Store) OpenWorkspace(
	ctx context.Context,
	workspace string,
	options OpenSessionOptions,
) (*OpenSessionResult, error)

OpenWorkspace returns the one durable session belonging to workspace.

func (*Store) ReconfigureExecutionProfile added in v0.8.0

func (s *Store) ReconfigureExecutionProfile(
	ctx context.Context,
	sessionID uuid.UUID,
	toProfile string,
	reason string,
) (*models.SessionProfileDecision, error)

ReconfigureExecutionProfile moves one idle session to a different execution profile and records why.

It refuses a session with a turn in flight, because changing the environment under running work would leave that turn's tool calls attributed to a profile that did not run them. The caller stops the session's worker afterwards so the next turn starts a new generation under the new profile.

func (*Store) RecordJobSignal added in v0.4.0

func (s *Store) RecordJobSignal(
	ctx context.Context,
	sessionID uuid.UUID,
	jobID uuid.UUID,
	input RecordJobSignalInput,
) (*models.JobSignalRequest, error)

RecordJobSignal stores every accepted and no-op signal request.

func (*Store) RecordModelCallRetries added in v0.4.0

func (s *Store) RecordModelCallRetries(
	ctx context.Context,
	sessionID uuid.UUID,
	modelRunID uuid.UUID,
	modelCallID uuid.UUID,
	input RecordModelCallRetriesInput,
) error

RecordModelCallRetries checkpoints failed attempts while the provider round remains in progress, preserving them even if the process exits mid-backoff.

func (*Store) RecordTurnWorkerGeneration added in v0.8.0

func (s *Store) RecordTurnWorkerGeneration(
	ctx context.Context,
	lease Lease,
	generationID uuid.UUID,
) error

RecordTurnWorkerGeneration names the worker that ran one turn. It updates only the lease's own turn, so a concurrent turn cannot be relabelled.

func (*Store) RecordWorkerContainer added in v0.8.0

func (s *Store) RecordWorkerContainer(
	ctx context.Context,
	generationID uuid.UUID,
	containerID string,
	imageDigest string,
) error

RecordWorkerContainer stores the container a Docker worker created. It is separate from the state transition because a container ID only exists once the daemon has accepted the create call.

func (*Store) RecordWorkerExit added in v0.8.0

func (s *Store) RecordWorkerExit(
	ctx context.Context,
	generationID uuid.UUID,
	exitCode int,
) error

RecordWorkerExit stores how a worker ended.

func (*Store) RecordWorkerProcess added in v0.8.0

func (s *Store) RecordWorkerProcess(
	ctx context.Context,
	generationID uuid.UUID,
	processID int,
) error

RecordWorkerProcess stores the operating system identity of a native worker.

func (*Store) RecoverInterrupted

func (s *Store) RecoverInterrupted(ctx context.Context) (int, error)

RecoverInterrupted marks active turns and their messages incomplete.

func (*Store) RecoverInterruptedAgentRuns added in v0.4.0

func (s *Store) RecoverInterruptedAgentRuns(ctx context.Context) (int, error)

RecoverInterruptedAgentRuns marks stale child runs terminal during startup.

func (*Store) RecoverInterruptedJobs added in v0.4.0

func (s *Store) RecoverInterruptedJobs(ctx context.Context) (int, error)

RecoverInterruptedJobs marks process rows left running by a prior process terminal. The original child process cannot be safely reattached.

func (*Store) RecoverInterruptedModelRuns added in v0.4.0

func (s *Store) RecoverInterruptedModelRuns(ctx context.Context) (int, error)

RecoverInterruptedModelRuns marks durable work left running by a prior Peen process terminal. No provider connection can be safely resumed in place.

func (*Store) RegisterCancellation

func (s *Store) RegisterCancellation(lease Lease, cancel context.CancelFunc)

RegisterCancellation associates cancellation with one exact active lease.

func (*Store) ReleaseTurn

func (s *Store) ReleaseTurn(lease Lease)

ReleaseTurn removes a lease only when it is still the registered turn.

func (*Store) RequestAgentRunCancellation added in v0.4.0

func (s *Store) RequestAgentRunCancellation(
	ctx context.Context,
	sessionID uuid.UUID,
	agentRunID uuid.UUID,
) (*models.AgentRun, bool, error)

RequestAgentRunCancellation records cancellation before signalling an active in-process child. It is idempotent for terminal and already-requested rows.

func (*Store) SaveContextSnapshot

func (s *Store) SaveContextSnapshot(
	ctx context.Context,
	snapshot *models.ContextSnapshot,
) error

SaveContextSnapshot stores an immutable resolved harness context.

func (*Store) SavePromptSnapshot

func (s *Store) SavePromptSnapshot(
	ctx context.Context,
	snapshot *models.PromptSnapshot,
) error

SavePromptSnapshot stores an immutable effective prompt.

func (*Store) UpdateWorkerGenerationState added in v0.8.0

func (s *Store) UpdateWorkerGenerationState(
	ctx context.Context,
	generationID uuid.UUID,
	state string,
	failureDetail string,
) error

UpdateWorkerGenerationState advances one generation's lifecycle.

Reaching ready stamps the start time and reaching a terminal state stamps the end time, so a durable record carries how long a worker actually ran.

type TurnPage added in v0.4.0

type TurnPage struct {
	Items   []*models.Turn
	Limit   int
	Offset  int
	HasMore bool
}

TurnPage is one complete session-local turn page.

type WorkerGenerationPage added in v0.8.0

type WorkerGenerationPage struct {
	Items   []*models.WorkerGeneration
	Limit   int
	Offset  int
	HasMore bool
}

WorkerGenerationPage is one complete page of worker generations.

type WorkspaceSessionPage added in v0.8.0

type WorkspaceSessionPage struct {
	Items   []*models.Session
	Limit   int
	Offset  int
	HasMore bool
}

WorkspaceSessionPage is one complete page of durable sessions. Every session is bound to a canonical workspace, so the name says which sessions it holds without stuttering as session.SessionPage.

Jump to

Keyboard shortcuts

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