Documentation
¶
Overview ¶
Package session owns Peen's durable transport-neutral session transcript.
Index ¶
- Constants
- Variables
- type AdmissionGate
- type AdmissionTicket
- type AgentRunCompactionInput
- type AgentRunCompactionPage
- type AgentRunEventInput
- type AgentRunEventPage
- type AgentRunHistoryResult
- type AgentRunMessageInput
- type AgentRunMessagePage
- type AgentRunPage
- type AppendJobOutputInput
- type CompactionInput
- type CompactionPage
- type CreateJobInput
- type CreateModelCallInput
- type CreateModelRunInput
- type CreateSessionNoticeInput
- type CreateWorkerGenerationInput
- type EventInput
- type EventPage
- type FinalizeAgentRunInput
- type FinalizeJobInput
- type FinalizeModelCallInput
- type FinalizeModelRunInput
- type FinalizeTurnInput
- type History
- type JobOutputPage
- type JobPage
- type JobSignalRequestPage
- type Lease
- type ListAgentRunCompactionsOptions
- type ListAgentRunEventsOptions
- type ListAgentRunMessagesOptions
- type ListAgentRunsOptions
- type ListCompactionsOptions
- type ListEventsOptions
- type ListJobOutputOptions
- type ListJobSignalRequestsOptions
- type ListJobsOptions
- type ListMessagesOptions
- type ListModelCallsOptions
- type ListModelRunsOptions
- type ListProfileDecisionsOptions
- type ListSessionNoticesOptions
- type ListSessionsOptions
- type ListTurnsOptions
- type ListWorkerGenerationsOptions
- type MessageInput
- type MessagePage
- type ModelCallPage
- type ModelRunPage
- type NoticePage
- type OpenSessionOptions
- type OpenSessionResult
- type Options
- type PageOrder
- type ProfileDecisionPage
- type RecordJobSignalInput
- type RecordModelCallRetriesInput
- type StartAgentRunInput
- type StartTurnInput
- type Storage
- type Store
- func (s *Store) AcquireTurn(ctx context.Context, sessionID uuid.UUID, input StartTurnInput) (Lease, error)
- func (s *Store) AgentRunHistory(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID) (*AgentRunHistoryResult, error)
- func (s *Store) AppendAgentRunEvent(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*models.AgentRunEvent, error)
- func (s *Store) AppendAgentRunMessages(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) ([]*models.AgentRunMessage, error)
- func (s *Store) AppendCheckpoint(ctx context.Context, lease Lease, messages []MessageInput, events []EventInput) error
- func (s *Store) AppendJobOutput(ctx context.Context, sessionID uuid.UUID, jobID uuid.UUID, ...) (*models.JobOutputLine, error)
- func (s *Store) Cancel(ctx context.Context, sessionID uuid.UUID) (bool, error)
- func (s *Store) CompletedHistory(ctx context.Context, sessionID uuid.UUID) (*History, error)
- func (s *Store) CreateAgentRun(ctx context.Context, sessionID uuid.UUID, input StartAgentRunInput) (*models.AgentRun, error)
- func (s *Store) CreateAgentRunCompaction(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*models.AgentRunCompaction, error)
- func (s *Store) CreateCompaction(ctx context.Context, sessionID uuid.UUID, input CompactionInput) (*models.Compaction, error)
- func (s *Store) CreateJob(ctx context.Context, sessionID uuid.UUID, input CreateJobInput) (*models.Job, error)
- func (s *Store) CreateModelCall(ctx context.Context, sessionID uuid.UUID, modelRunID uuid.UUID, ...) (*models.ModelCall, error)
- func (s *Store) CreateModelRun(ctx context.Context, sessionID uuid.UUID, input CreateModelRunInput) (*models.ModelRun, error)
- func (s *Store) CreateOrResume(ctx context.Context, requestedSessionID *uuid.UUID, options OpenSessionOptions) (*OpenSessionResult, error)
- func (s *Store) CreateSessionNotice(ctx context.Context, sessionID uuid.UUID, input CreateSessionNoticeInput) (*models.SessionNotice, error)
- func (s *Store) CreateWorkerGeneration(ctx context.Context, sessionID uuid.UUID, input CreateWorkerGenerationInput) (*models.WorkerGeneration, error)
- func (s *Store) CurrentWorkerGeneration(ctx context.Context, sessionID uuid.UUID) (*models.WorkerGeneration, error)
- func (s *Store) DrainSessionNotices(ctx context.Context, sessionID uuid.UUID) ([]*models.SessionNotice, error)
- func (s *Store) FinalizeAgentRun(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*models.AgentRun, error)
- func (s *Store) FinalizeJob(ctx context.Context, sessionID uuid.UUID, jobID uuid.UUID, ...) (*models.Job, error)
- func (s *Store) FinalizeModelCall(ctx context.Context, sessionID uuid.UUID, modelRunID uuid.UUID, ...) (*models.ModelCall, error)
- func (s *Store) FinalizeModelRun(ctx context.Context, sessionID uuid.UUID, modelRunID uuid.UUID, ...) (*models.ModelRun, error)
- func (s *Store) FinalizeTurn(ctx context.Context, lease Lease, input FinalizeTurnInput) error
- func (s *Store) Get(ctx context.Context, sessionID uuid.UUID) (*models.Session, error)
- func (s *Store) GetAgentRun(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID) (*models.AgentRun, error)
- func (s *Store) GetAgentRunCompaction(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*models.AgentRunCompaction, error)
- func (s *Store) GetCompaction(ctx context.Context, sessionID uuid.UUID, compactionID uuid.UUID) (*models.Compaction, error)
- func (s *Store) GetContextSnapshot(ctx context.Context, sessionID uuid.UUID, hash string) (*models.ContextSnapshot, error)
- func (s *Store) GetJob(ctx context.Context, sessionID uuid.UUID, jobID uuid.UUID) (*models.Job, error)
- func (s *Store) GetModelRun(ctx context.Context, sessionID uuid.UUID, modelRunID uuid.UUID) (*models.ModelRun, error)
- func (s *Store) GetPromptSnapshot(ctx context.Context, sessionID uuid.UUID, hash string) (*models.PromptSnapshot, error)
- func (s *Store) GetWorkerGeneration(ctx context.Context, sessionID uuid.UUID, generationID uuid.UUID) (*models.WorkerGeneration, error)
- func (s *Store) IsActive(sessionID uuid.UUID) bool
- func (s *Store) LatestAgentRunCompaction(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID) (*models.AgentRunCompaction, error)
- func (s *Store) LatestCompaction(ctx context.Context, sessionID uuid.UUID) (*models.Compaction, error)
- func (s *Store) ListAgentRunCompactions(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*AgentRunCompactionPage, error)
- func (s *Store) ListAgentRunEvents(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*AgentRunEventPage, error)
- func (s *Store) ListAgentRunMessages(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID, ...) (*AgentRunMessagePage, error)
- func (s *Store) ListAgentRuns(ctx context.Context, sessionID uuid.UUID, options ListAgentRunsOptions) (*AgentRunPage, error)
- func (s *Store) ListCompactions(ctx context.Context, sessionID uuid.UUID, options ListCompactionsOptions) (*CompactionPage, error)
- func (s *Store) ListEvents(ctx context.Context, sessionID uuid.UUID, options ListEventsOptions) (*EventPage, error)
- func (s *Store) ListJobOutput(ctx context.Context, sessionID uuid.UUID, jobID uuid.UUID, ...) (*JobOutputPage, error)
- func (s *Store) ListJobSignalRequests(ctx context.Context, sessionID uuid.UUID, jobID uuid.UUID, ...) (*JobSignalRequestPage, error)
- func (s *Store) ListJobs(ctx context.Context, sessionID uuid.UUID, options ListJobsOptions) (*JobPage, error)
- func (s *Store) ListLiveWorkerGenerations(ctx context.Context) ([]*models.WorkerGeneration, error)
- func (s *Store) ListMessages(ctx context.Context, sessionID uuid.UUID, options ListMessagesOptions) (*MessagePage, error)
- func (s *Store) ListModelCalls(ctx context.Context, sessionID uuid.UUID, modelRunID uuid.UUID, ...) (*ModelCallPage, error)
- func (s *Store) ListModelRuns(ctx context.Context, sessionID uuid.UUID, options ListModelRunsOptions) (*ModelRunPage, error)
- func (s *Store) ListSessionNotices(ctx context.Context, sessionID uuid.UUID, options ListSessionNoticesOptions) (*NoticePage, error)
- func (s *Store) ListSessionProfileDecisions(ctx context.Context, sessionID uuid.UUID, options ListProfileDecisionsOptions) (*ProfileDecisionPage, error)
- func (s *Store) ListSessions(ctx context.Context, options ListSessionsOptions) (*WorkspaceSessionPage, error)
- func (s *Store) ListTurns(ctx context.Context, sessionID uuid.UUID, options ListTurnsOptions) (*TurnPage, error)
- func (s *Store) ListWorkerGenerations(ctx context.Context, sessionID uuid.UUID, options ListWorkerGenerationsOptions) (*WorkerGenerationPage, error)
- func (s *Store) OpenWorkspace(ctx context.Context, workspace string, options OpenSessionOptions) (*OpenSessionResult, error)
- func (s *Store) ReconfigureExecutionProfile(ctx context.Context, sessionID uuid.UUID, toProfile string, reason string) (*models.SessionProfileDecision, error)
- func (s *Store) RecordJobSignal(ctx context.Context, sessionID uuid.UUID, jobID uuid.UUID, ...) (*models.JobSignalRequest, error)
- func (s *Store) RecordModelCallRetries(ctx context.Context, sessionID uuid.UUID, modelRunID uuid.UUID, ...) error
- func (s *Store) RecordTurnWorkerGeneration(ctx context.Context, lease Lease, generationID uuid.UUID) error
- func (s *Store) RecordWorkerContainer(ctx context.Context, generationID uuid.UUID, containerID string, ...) error
- func (s *Store) RecordWorkerExit(ctx context.Context, generationID uuid.UUID, exitCode int) error
- func (s *Store) RecordWorkerProcess(ctx context.Context, generationID uuid.UUID, processID int) error
- func (s *Store) RecoverInterrupted(ctx context.Context) (int, error)
- func (s *Store) RecoverInterruptedAgentRuns(ctx context.Context) (int, error)
- func (s *Store) RecoverInterruptedJobs(ctx context.Context) (int, error)
- func (s *Store) RecoverInterruptedModelRuns(ctx context.Context) (int, error)
- func (s *Store) RegisterCancellation(lease Lease, cancel context.CancelFunc)
- func (s *Store) ReleaseTurn(lease Lease)
- func (s *Store) RequestAgentRunCancellation(ctx context.Context, sessionID uuid.UUID, agentRunID uuid.UUID) (*models.AgentRun, bool, error)
- func (s *Store) SaveContextSnapshot(ctx context.Context, snapshot *models.ContextSnapshot) error
- func (s *Store) SavePromptSnapshot(ctx context.Context, snapshot *models.PromptSnapshot) error
- func (s *Store) UpdateWorkerGenerationState(ctx context.Context, generationID uuid.UUID, state string, ...) error
- type TurnPage
- type WorkerGenerationPage
- type WorkspaceSessionPage
Constants ¶
const ( // DefaultPageLimit is the API default for transcript pagination. DefaultPageLimit = 50 // MaximumPageLimit bounds one transcript page at the storage boundary. MaximumPageLimit = 200 )
Variables ¶
var ( // ErrSessionBusy reports a concurrent turn attempt for one session. ErrSessionBusy = commerr.ErrLockHeld // ErrInvalidPage reports invalid transcript pagination arguments. ErrInvalidPage = commerr.ErrValidationFailed // ErrRunningTurnSettingsChange reports a message sent while a turn runs // that asks for another model, reasoning level, or system prompt. A // queued message joins the running turn, so it cannot change how that // turn runs. It is always joined with commerr.ErrValidationFailed, and // its text is written for the person who sent the message. ErrRunningTurnSettingsChange = errors.New( "a message sent during a running turn cannot change its model, reasoning, or system prompt", ) // ErrRunningTurnSkillActivation reports a message sent while a turn runs // that explicitly names a skill. Skills are resolved when a turn starts, // so a queued message cannot add one. It is always joined with // commerr.ErrValidationFailed. ErrRunningTurnSkillActivation = errors.New( "a message sent during a running turn cannot explicitly activate a skill", ) )
Functions ¶
This section is empty.
Types ¶
type AdmissionGate ¶ added in v0.17.0
type AdmissionGate struct {
// contains filtered or unexported fields
}
AdmissionGate admits messages to each session one at a time, in the order their places were reserved.
Admitting a message means deciding whether it starts a turn or joins the running turn's queue, and making that decision take effect. Two messages for one session admitted at once can both see an idle session and race for its lease, so the loser is refused as busy even though it only had to queue, and the one sent second can start the turn. Holding the gate across the decision and its effect removes both races.
Sessions do not share a line, so a slow admission in one never delays another. A session's line exists only while a ticket is in it.
func NewAdmissionGate ¶ added in v0.17.0
func NewAdmissionGate() *AdmissionGate
NewAdmissionGate builds a gate with every session's line empty.
func (*AdmissionGate) Acquire ¶ added in v0.17.0
Acquire reserves a place and waits for it. It returns the ticket's release function, which is safe to call more than once, so a caller can release as soon as its message is admitted and still defer the call for every failure path.
func (*AdmissionGate) Reserve ¶ added in v0.17.0
func (g *AdmissionGate) Reserve(sessionID uuid.UUID) *AdmissionTicket
Reserve takes the next place in the session's line without waiting.
A caller that hands the message to another goroutine reserves before doing so, which fixes the admission order to the order the messages were received rather than the order those goroutines happen to run in. The ticket must be released on every path, admitted or not.
type AdmissionTicket ¶ added in v0.17.0
type AdmissionTicket struct {
// contains filtered or unexported fields
}
AdmissionTicket is one message's place in its session's admission line.
func (*AdmissionTicket) Release ¶ added in v0.17.0
func (t *AdmissionTicket) Release()
Release leaves the line. When the ticket was at the front, the next one is admitted. Releasing again does nothing.
func (*AdmissionTicket) SessionID ¶ added in v0.17.0
func (t *AdmissionTicket) SessionID() uuid.UUID
SessionID is the session whose line the ticket is in.
func (*AdmissionTicket) Wait ¶ added in v0.17.0
func (t *AdmissionTicket) Wait(ctx context.Context) error
Wait blocks until every ticket reserved before this one is released. A caller that stops waiting cancels ctx, which returns the context error; the ticket still holds its place until it is released.
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
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 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
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 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 ListAgentRunCompactionsOptions ¶ added in v0.11.0
ListAgentRunCompactionsOptions bounds one child compaction page.
type ListAgentRunEventsOptions ¶ added in v0.4.0
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
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
ListCompactionsOptions controls a bounded page of compaction records.
type ListEventsOptions ¶ added in v0.4.0
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
ListJobSignalRequestsOptions controls a bounded signal-request history page.
type ListJobsOptions ¶ added in v0.4.0
ListJobsOptions controls a bounded session-local process-job page.
type ListMessagesOptions ¶
ListMessagesOptions controls a bounded session-local message page.
type ListModelCallsOptions ¶ added in v0.4.0
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
ListProfileDecisionsOptions controls a bounded page of one session's execution profile decisions.
type ListSessionNoticesOptions ¶ added in v0.4.0
ListSessionNoticesOptions controls a bounded page of notice history.
type ListSessionsOptions ¶ added in v0.8.0
ListSessionsOptions controls a bounded page of the control surface's durable sessions.
type ListTurnsOptions ¶ added in v0.4.0
ListTurnsOptions controls a bounded page of durable session turns.
type ListWorkerGenerationsOptions ¶ added in v0.8.0
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
Injected bool
}
MessageInput describes a durable transcript record.
type MessagePage ¶
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
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 ¶
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 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
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 (*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) CompletedHistory ¶
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 ¶
FinalizeTurn atomically writes terminal transcript data and state.
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) 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 ¶
RecoverInterrupted marks active turns and their messages incomplete.
func (*Store) RecoverInterruptedAgentRuns ¶ added in v0.4.0
RecoverInterruptedAgentRuns marks stale child runs terminal during startup.
func (*Store) RecoverInterruptedJobs ¶ added in v0.4.0
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
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 ¶
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 ¶
SaveContextSnapshot stores an immutable resolved harness context.
func (*Store) SavePromptSnapshot ¶
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 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
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.