Documentation
¶
Overview ¶
Package sessionpg stores Sessions in PostgreSQL and decides nothing. WithSession runs a Session transaction: it locks the Session, runs the operation and prunes the journal. Inside a Session transaction, on its queries, the participants load the facts the sessions and items decisions read and apply what they decide: they lock the Session, allocate event sequence positions, event IDs, Item positions and output indexes, and write the public change journal, a Turn's execution journal and its counters, Items, Turn usage, Subagent bindings, child Turns and child Items, Artifact settlement, Environment state, input reservations and devices. SessionTx binds a Session to its caller's transaction for the sessions procedures. Store is the pooled adapter: it stores the sessions.Service use cases and serves the Session reads. Execution is the lease-bound adapter: it runs the sessions.ExecutionOperations transactions on the execution lease.
Index ¶
- func AppendChanges(ctx context.Context, q *sqlc.Queries, session pgtype.UUID, ...) error
- func ApplyTurnEnd(ctx context.Context, q *sqlc.Queries, session, turn pgtype.UUID, ...) error
- func LoadEnding(ctx context.Context, q *sqlc.Queries, session, turn pgtype.UUID) (sessions.Ending, error)
- func LoadEnvironment(ctx context.Context, q *sqlc.Queries, tenant, environment string) (sessions.Environment, error)
- func LoadEnvironmentInput(ctx context.Context, q *sqlc.Queries, session pgtype.UUID) (*sessions.EnvironmentInputState, error)
- func LoadRequiredActions(ctx context.Context, q *sqlc.Queries, session pgtype.UUID, turn sessions.Turn) ([]v1.FunctionCallAction, error)
- func LoadUsage(ctx context.Context, q *sqlc.Queries, session pgtype.UUID) (json.RawMessage, error)
- func LockSession(ctx context.Context, q *sqlc.Queries, tenant, session pgtype.UUID) (sessions.LockedSession, error)
- func PruneChanges(ctx context.Context, q *sqlc.Queries, session pgtype.UUID) error
- func ResourceLookup(tenantID, id string) (sqlc.GetDeviceParams, error)
- func TurnFromRow(row sqlc.Turn) sessions.Turn
- func TurnLookup(tenantID, sessionID, turnID string) (sqlc.GetTurnParams, error)
- func WithEnvironment(ctx context.Context, runner pgunit.Transactor, tenant, environment pgtype.UUID, ...) error
- func WithSession(ctx context.Context, runner pgunit.Transactor, tenant, session pgtype.UUID, ...) error
- type Execution
- func (e *Execution) ListEnvironmentConnections(ctx context.Context, after string) ([]sessions.EnvironmentKey, error)
- func (e *Execution) WithConnection(ctx context.Context, tenant, environment string, ...) error
- func (e *Execution) WithDeviceBinding(ctx context.Context, tenant, session string, ...) error
- func (e *Execution) WithDueInputReservations(ctx context.Context, ...) error
- func (e *Execution) WithFileWriteReservation(ctx context.Context, tenant, environment string, ...) error
- func (e *Execution) WithFileWriteSettlement(ctx context.Context, tenant, environment, write string, ...) error
- func (e *Execution) WithFunctionTurn(ctx context.Context, tenant, session, turn string, ...) error
- func (e *Execution) WithInitialization(ctx context.Context, tenant, environment string, ...) error
- func (e *Execution) WithInputs(ctx context.Context, tenant, session string, ...) error
- func (e *Execution) WithTurns(ctx context.Context, tenantID, sessionID string, ...) error
- type SessionTx
- func (t *SessionTx) AdmitInputReservation(ctx context.Context, reservation string) (time.Time, error)
- func (t *SessionTx) AppendChanges(ctx context.Context, changes ...sessions.SessionChange) error
- func (t *SessionTx) ApplyFunctionResult(ctx context.Context, turn, call string) error
- func (t *SessionTx) ApplySubagentLifecycle(ctx context.Context, subagent string, lifecycle sessions.SubagentLifecycle) error
- func (t *SessionTx) ApplyTurnEnd(ctx context.Context, turn string, end sessions.TurnEnd) error
- func (t *SessionTx) ApplyTurnStatus(ctx context.Context, turn string, change sessions.TurnStatusChange) (sessions.Turn, error)
- func (t *SessionTx) BeginArtifactCapture(ctx context.Context, turn string) error
- func (t *SessionTx) BindDevice(ctx context.Context, device string) error
- func (t *SessionTx) CancelPendingInput(ctx context.Context) error
- func (t *SessionTx) CountEvents(ctx context.Context, turn string, count int32, size int64) error
- func (t *SessionTx) CreateFunctionCall(ctx context.Context, turn string, call sessions.FunctionCall) error
- func (t *SessionTx) CreateInputReservation(ctx context.Context, key string, batch json.RawMessage, initial bool, ...) (sessions.EnvironmentInputReservation, error)
- func (t *SessionTx) CreateTurn(ctx context.Context, settings sessions.TurnSettings) (sessions.Turn, error)
- func (t *SessionTx) CreateTurnInput(ctx context.Context, turn, key string, position int32, input sessions.Input) (int64, error)
- func (t *SessionTx) ExpireEnvironment(ctx context.Context, environment string) error
- func (t *SessionTx) ExpireInputReservation(ctx context.Context, reservation string) error
- func (t *SessionTx) FailInputReservation(ctx context.Context, reservation, code string) error
- func (t *SessionTx) FailPendingInput(ctx context.Context) error
- func (t *SessionTx) FindCallTurn(ctx context.Context, call string) (sessions.Turn, string, bool, error)
- func (t *SessionTx) FindInputReservation(ctx context.Context, key string, batch json.RawMessage) (*sessions.EnvironmentInputReservation, bool, error)
- func (t *SessionTx) FindResultTurn(ctx context.Context, turn string) (sessions.Turn, bool, error)
- func (t *SessionTx) HasFunctionCall(ctx context.Context, call string) (bool, error)
- func (t *SessionTx) HasUnappliedInputs(ctx context.Context, turn string, appliedThrough int64) (bool, error)
- func (t *SessionTx) InsertEnvironmentDevice(ctx context.Context, device sessions.ExecutionDevice, credentialHash string) error
- func (t *SessionTx) InsertEvent(ctx context.Context, turn string, ordinal int32, event sessions.ExecutionEvent) error
- func (t *SessionTx) InsertEvents(ctx context.Context, turn string, first int32, ...) error
- func (t *SessionTx) LoadActiveTurn(ctx context.Context) (sessions.Turn, bool, error)
- func (t *SessionTx) LoadArchive(ctx context.Context) (sessions.ManagedArchive, error)
- func (t *SessionTx) LoadBoundDevice(ctx context.Context) (bool, error)
- func (t *SessionTx) LoadChildItem(ctx context.Context, subagent, item string, candidate json.RawMessage) (sessions.StoredChildItem, bool, error)
- func (t *SessionTx) LoadChildTurn(ctx context.Context, subagent, id string) (sessions.ChildTurn, bool, error)
- func (t *SessionTx) LoadComputeSuspension(ctx context.Context) (bool, error)
- func (t *SessionTx) LoadDevice(ctx context.Context, device string) (bool, error)
- func (t *SessionTx) LoadEnding(ctx context.Context, turn string) (sessions.Ending, error)
- func (t *SessionTx) LoadEnvironment(ctx context.Context) (sessions.Environment, error)
- func (t *SessionTx) LoadEnvironmentInput(ctx context.Context) (*sessions.EnvironmentInputState, error)
- func (t *SessionTx) LoadEventSources(ctx context.Context, turn string, first int32) ([]sessions.Source, error)
- func (t *SessionTx) LoadFunctionCall(ctx context.Context, turn, call string) (sessions.FunctionCall, bool, error)
- func (t *SessionTx) LoadInputBatch(ctx context.Context, key string, batch json.RawMessage) ([]sessions.InputReceipt, bool, error)
- func (t *SessionTx) LoadInputGate(ctx context.Context, key string, batch json.RawMessage) (sessions.InputGate, error)
- func (t *SessionTx) LoadInputReservation(ctx context.Context, reservation string) (sessions.EnvironmentInputReservation, error)
- func (t *SessionTx) LoadInputSource(ctx context.Context, sequence int64) (sessions.Source, error)
- func (t *SessionTx) LoadItem(ctx context.Context, turnID string, update items.Update) (items.Stored, error)
- func (t *SessionTx) LoadJournalTurn(ctx context.Context, turn string) (sessions.JournalTurn, bool, error)
- func (t *SessionTx) LoadNativeSubagent(ctx context.Context, native string) (sessions.NativeSubagent, bool, error)
- func (t *SessionTx) LoadPendingFileWrite(ctx context.Context) (bool, error)
- func (t *SessionTx) LoadPendingFunctionCalls(ctx context.Context, turn string) ([]sessions.FunctionCall, error)
- func (t *SessionTx) LoadPublicSubagent(ctx context.Context, id string) (v1.Subagent, error)
- func (t *SessionTx) LoadRootAgent(ctx context.Context) (string, error)
- func (t *SessionTx) LoadTurn(ctx context.Context, turn string) (sessions.Turn, error)
- func (t *SessionTx) LoadTurnSettings(ctx context.Context) (sessions.TurnSettings, error)
- func (t *SessionTx) LoadUsage(ctx context.Context) (json.RawMessage, error)
- func (t *SessionTx) MatchEvents(ctx context.Context, turn string, first int32, ...) (bool, error)
- func (t *SessionTx) MatchFunctionCall(ctx context.Context, turn string, call sessions.FunctionCall) (sessions.FunctionCallMatch, error)
- func (t *SessionTx) MatchFunctionResult(ctx context.Context, turn, call string, result json.RawMessage) (sessions.FunctionResultMatch, error)
- func (t *SessionTx) PublishSubagent(ctx context.Context, subagent string, name, instructions *string) error
- func (t *SessionTx) PutChildItem(ctx context.Context, item sessions.ChildItem) error
- func (t *SessionTx) PutChildTurn(ctx context.Context, turn sessions.ChildTurn) error
- func (t *SessionTx) PutItem(ctx context.Context, turnID string, created time.Time, change items.Change) (*int32, error)
- func (t *SessionTx) PutSubagentEffect(ctx context.Context, effect string, payload json.RawMessage) (bool, error)
- func (t *SessionTx) PutSubagentIdentity(ctx context.Context, identity sessions.SubagentIdentity) (string, error)
- func (t *SessionTx) PutTurnUsage(ctx context.Context, turnID string, usage v1.TokenUsage) error
- func (t *SessionTx) RecordEnvironmentFailure(ctx context.Context, environment, reason string, ...) (time.Time, error)
- func (t *SessionTx) RecordInputAudit(ctx context.Context) error
- func (t *SessionTx) RecordTerminalActivity(ctx context.Context) error
- func (t *SessionTx) RememberNativeSession(ctx context.Context, native string) error
- func (t *SessionTx) RequestTurnCancel(ctx context.Context, turn string) error
- func (t *SessionTx) SubmitFunctionResult(ctx context.Context, turn, call string, result json.RawMessage) error
- func (t *SessionTx) WithdrawFunctionCall(ctx context.Context, turn, call string) error
- type Store
- func (s *Store) ArchivedCancellationReceipt(ctx context.Context, device, credentialHash string, runIDs []string) (runtimedevice.ArchivedCancellationReceipt, error)
- func (s *Store) AuditSessionOperation(ctx context.Context, tenantID, sessionID, action string) error
- func (s *Store) AuthenticateEnvironmentExecutor(ctx context.Context, environment, digest string) (string, error)
- func (s *Store) CreateDevice(ctx context.Context, tenant string, registration sessions.DeviceRegistration) (sessions.ExecutionDevice, error)
- func (s *Store) DeleteSessionArtifact(ctx context.Context, tenantID, sessionID, artifactID string) error
- func (s *Store) ExecutorProjectExists(ctx context.Context, scope identity.ProjectScope) (bool, error)
- func (s *Store) FindCreation(ctx context.Context, tenantID, key string) (sessions.CreationRecord, error)
- func (s *Store) FingerprintProviderKey(secret string) (string, error)
- func (s *Store) GetDeviceCredential(ctx context.Context, device string) (runtimedevice.Credential, bool, error)
- func (s *Store) GetEnvironment(ctx context.Context, tenant, environment string) (sessions.Environment, error)
- func (s *Store) GetEnvironmentInputReservation(ctx context.Context, tenantID, sessionID, reservationID string) (sessions.EnvironmentInputReservation, error)
- func (s *Store) GetManagedSessionArchive(ctx context.Context, tenantID, sessionID string) (sessions.ManagedArchive, error)
- func (s *Store) GetSession(ctx context.Context, tenantID, sessionID string) (sessions.Session, error)
- func (s *Store) GetSessionArtifact(ctx context.Context, tenantID, sessionID, artifactID string) (sessions.Artifact, error)
- func (s *Store) GetSessionDevice(ctx context.Context, tenant, session string) (sessions.ExecutionDevice, error)
- func (s *Store) GetSessionEnvironment(ctx context.Context, tenant, session string) (sessions.Environment, error)
- func (s *Store) GetSessionExecutionBinding(ctx context.Context, tenant, session string) (sessions.ExecutionBinding, error)
- func (s *Store) GetSessionExecutionConfiguration(ctx context.Context, tenantID, sessionID string) (v1.SessionExecutionConfiguration, error)
- func (s *Store) GetSessionRuntimeDevice(ctx context.Context, tenant, session string) (sessions.ExecutionDevice, error)
- func (s *Store) GetSubagent(ctx context.Context, tenantID, sessionID, subagentID string) (v1.Subagent, error)
- func (s *Store) GetSubagentTurn(ctx context.Context, tenantID, sessionID, subagentID, turnID string) (v1.Turn, error)
- func (s *Store) GetTurn(ctx context.Context, tenant, session, turn string) (sessions.Turn, error)
- func (s *Store) GetTurnDiagnosticsSnapshot(ctx context.Context, tenantID, sessionID, turnID string) (sessions.TurnDiagnosticsSnapshot, error)
- func (s *Store) ListAdminRuntimeTargets(ctx context.Context, tenantIDs []string, after string, limit int, ...) (sessions.AdminRuntimeTargetPage, error)
- func (s *Store) ListEnrolledRuntimeBindings(ctx context.Context) ([]sessions.EnrolledRuntimeBinding, error)
- func (s *Store) ListEnvironmentInitializations(ctx context.Context, after string) ([]sessions.EnvironmentInitialization, error)
- func (s *Store) ListEnvironmentInputWork(ctx context.Context, after string, connectedDevices []string) ([]sessions.EnvironmentInputWork, error)
- func (s *Store) ListEnvironments(ctx context.Context, tenantID string, creator identity.Subject, cursor string, ...) ([]sessions.Environment, bool, error)
- func (s *Store) ListExecutionDevices(ctx context.Context, tenant string) ([]sessions.ExecutionDevice, error)
- func (s *Store) ListExecutionWork(ctx context.Context, after string, statuses, connectedDevices []string) ([]sessions.ExecutionWork, error)
- func (s *Store) ListItems(ctx context.Context, tenantID, sessionID, cursor string, limit int, ...) (sessions.ItemPage, error)
- func (s *Store) ListSessionArtifacts(ctx context.Context, tenantID, sessionID, environmentID, cursor string, ...) (sessions.ArtifactPage, error)
- func (s *Store) ListSessionEvents(ctx context.Context, tenantID, sessionID string, after int64) ([]sessions.SessionChange, error)
- func (s *Store) ListSessions(ctx context.Context, tenantID, cursor string, limit int, ascending bool, ...) (sessions.Page, error)
- func (s *Store) ListSubagentItems(ctx context.Context, tenantID, sessionID, subagentID, cursor string, limit int, ...) (v1.ItemList, error)
- func (s *Store) ListSubagentTurnItems(ctx context.Context, tenantID, sessionID, subagentID, turnID, cursor string, ...) (v1.ItemList, error)
- func (s *Store) ListSubagentTurns(ctx context.Context, tenantID, sessionID, subagentID, cursor string, limit int, ...) (v1.TurnList, error)
- func (s *Store) ListSubagents(ctx context.Context, tenantID, sessionID, cursor string, limit int, ...) (v1.SubagentList, error)
- func (s *Store) ListTurnInputs(ctx context.Context, tenant, session, turn string, after int64, limit int) ([]sessions.TurnInput, error)
- func (s *Store) ListTurnItems(ctx context.Context, tenantID, sessionID, turnID, cursor string, limit int, ...) (sessions.ItemPage, error)
- func (s *Store) ListTurns(ctx context.Context, tenant, session, cursor string, limit int, ascending bool) (sessions.TurnPage, error)
- func (s *Store) LoadExecutorCredentialRestriction(ctx context.Context, principal identity.Principal, key string) (string, error)
- func (s *Store) LoadProjectArchived(ctx context.Context, tenant string) (bool, error)
- func (s *Store) MeasuredSessionUsage(ctx context.Context, tenantID, sessionID string) (json.RawMessage, error)
- func (s *Store) ProjectExecutorCredentialState(ctx context.Context, project identity.Principal, environment string) (sessions.ExecutorCredentialState, error)
- func (s *Store) ReadAdminSummary(ctx context.Context, tenantID string, filter sessions.AdminSummaryFilter, ...) (sessions.AdminAssetCounts, error)
- func (s *Store) ReadEnvironmentSetup(ctx context.Context, tenant, environment string) (environmentconfig.Setup, error)
- func (s *Store) ReadInitialEnvironmentFile(ctx context.Context, tenant, environment string, position int) (environmentconfig.InitialFileMetadata, []byte, error)
- func (s *Store) ReadSessionArtifact(ctx context.Context, tenantID, sessionID, artifactID string, ...) error
- func (s *Store) RevokeDevice(ctx context.Context, tenant, device string) error
- func (s *Store) SessionEventCursor(ctx context.Context, tenantID, sessionID string) (int64, error)
- func (s *Store) SessionModelExecution(ctx context.Context, tenant, session string) (*v1.ModelProviderInput, error)
- func (s *Store) SessionStreamSnapshot(ctx context.Context, tenantID, sessionID string) (sessions.Session, int64, error)
- func (s *Store) SignInstallation(_ context.Context, payload string) (string, error)
- func (s *Store) TouchAuthenticatedDevice(ctx context.Context, device, credentialHash string, ...) (bool, error)
- func (s *Store) TouchDevice(ctx context.Context, device string) (bool, error)
- func (s *Store) UpdateSession(ctx context.Context, tenantID, sessionID string, encoded []byte, ...) (sessions.Session, error)
- func (s *Store) VerifyInstallation(_ context.Context, payload, signature string) error
- func (s *Store) WithArtifactStaging(ctx context.Context, key sessions.ArtifactStagingKey, ...) error
- func (s *Store) WithCreation(ctx context.Context, tenantID string, ...) error
- func (s *Store) WithEnrollment(ctx context.Context, environment, credentialHash string, ...) error
- func (s *Store) WithEnvironmentCreation(ctx context.Context, tenantID string, ident sessions.EnvironmentIdentity, ...) error
- func (s *Store) WithEnvironmentExecutorCredentials(ctx context.Context, tenant, environment string, ...) error
- func (s *Store) WithExecutorCredentials(ctx context.Context, tenant string, ...) error
- func (s *Store) WithInputs(ctx context.Context, tenant, session string, ...) error
- func (s *Store) WithSessionDeletion(ctx context.Context, tenantID, sessionID string, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendChanges ¶
func AppendChanges(ctx context.Context, q *sqlc.Queries, session pgtype.UUID, changes ...sessions.SessionChange) error
AppendChanges journals public changes in order. Each gets a new event ID and the Session's next sequence position, and commits with the caller's state. Text PostgreSQL cannot store is textvalue.ErrUnstorable.
func ApplyTurnEnd ¶
func ApplyTurnEnd(ctx context.Context, q *sqlc.Queries, session, turn pgtype.UUID, end sessions.TurnEnd) error
ApplyTurnEnd writes what a Turn that ended settles, in the order sessions.TurnEnd lists: terminal activity, Artifacts, finished Items and then the public changes.
func LoadEnding ¶
func LoadEnding(ctx context.Context, q *sqlc.Queries, session, turn pgtype.UUID) (sessions.Ending, error)
LoadEnding reads the facts sessions.EndTurn settles a Turn that ended with: its Items still in progress and the Session's public usage.
func LoadEnvironment ¶
func LoadEnvironment(ctx context.Context, q *sqlc.Queries, tenant, environment string) (sessions.Environment, error)
LoadEnvironment reads, on q, the tenant's Environment of a Session that was not publicly deleted. A malformed tenant is sessions.ErrInvalidInput, and a malformed Environment ID a missing Environment, sessions.ErrNotFound. Other adapters read the Environment of their operation with it.
func LoadEnvironmentInput ¶
func LoadEnvironmentInput(ctx context.Context, q *sqlc.Queries, session pgtype.UUID) (*sessions.EnvironmentInputState, error)
LoadEnvironmentInput reads the Session's latest Environment input reservation that no Turn has admitted or superseded, with the facts of its Environment, and nil when there is none. sessions.InputActivity projects it.
func LoadRequiredActions ¶
func LoadRequiredActions(ctx context.Context, q *sqlc.Queries, session pgtype.UUID, turn sessions.Turn) ([]v1.FunctionCallAction, error)
LoadRequiredActions reads the required actions of the Session's Turn within the caller's snapshot, as sessions.LoadRequiredActions selects them.
func LoadUsage ¶
LoadUsage reads the Session's public usage: the sum of its root Turns once every one has ended with recorded usage, and null otherwise.
func LockSession ¶
func LockSession(ctx context.Context, q *sqlc.Queries, tenant, session pgtype.UUID) (sessions.LockedSession, error)
LockSession locks the tenant's Session row, including a publicly deleted one, and returns what the lock shows. Every Session write takes this lock first, which orders input admission against completion and cancellation across service processes. A missing Session is sessions.ErrNotFound.
func PruneChanges ¶
PruneChanges drops the Session's journaled changes beyond the sessions retention bounds. Callers run it after the transaction's last change.
func ResourceLookup ¶ added in v0.0.10
func ResourceLookup(tenantID, id string) (sqlc.GetDeviceParams, error)
ResourceLookup parses a tenant and the internal identifier of one of its resources, such as a device, Session or Environment; a malformed one is sessions.ErrInvalidInput.
func TurnLookup ¶
func TurnLookup(tenantID, sessionID, turnID string) (sqlc.GetTurnParams, error)
TurnLookup parses the internal identifiers of a tenant's Turn; a malformed one is sessions.ErrInvalidInput.
func WithEnvironment ¶ added in v0.0.14
func WithEnvironment(ctx context.Context, runner pgunit.Transactor, tenant, environment pgtype.UUID, apply func(context.Context, *sqlc.Queries, sessions.LockedSession, pgtype.UUID) error) error
WithEnvironment runs one Environment transaction on runner. It reads the attached Session, locks that Session if there is one, then locks the Environment and checks that the attachment did not move; it retries once when it did. The lock order is always Session, then Environment. apply gets what the locks show, with Deleted true for a Session-owned Environment whose Session was deleted and Engine the attached Session's, and the attached Session, which is invalid when none is attached. The attached Session's journal is pruned afterwards.
func WithSession ¶
func WithSession(ctx context.Context, runner pgunit.Transactor, tenant, session pgtype.UUID, apply func(context.Context, *sqlc.Queries, sessions.LockedSession) error) error
WithSession runs one Session transaction on runner: it locks the tenant's Session, runs apply on the transaction's queries with what the lock shows, then prunes the Session's journal, and commits only when all of them succeed. apply applies the public view itself, with sessions.LockedSession.Public. It is the transaction runner of Session operations; other adapters lock the Session inside their own transaction with LockSession.
Types ¶
type Execution ¶
type Execution struct {
// contains filtered or unexported fields
}
Execution is the Session storage of the execution owner. Every transaction runs on the connection that holds the execution lease, which the owner acquired and closes; losing or closing the lease fails the operation and never falls back to the pool.
func NewExecution ¶
NewExecution builds the Session execution storage on a lease it borrows.
func (*Execution) ListEnvironmentConnections ¶
func (*Execution) WithConnection ¶
func (e *Execution) WithConnection(ctx context.Context, tenant, environment string, apply func(context.Context, sessions.ConnectionTx, sessions.LockedSession) error) error
WithConnection runs apply in the transaction of the tenant's Environment.
func (*Execution) WithDeviceBinding ¶
func (*Execution) WithDueInputReservations ¶ added in v0.0.10
func (e *Execution) WithDueInputReservations(ctx context.Context, apply func(context.Context, sessions.InputTx, string) error) error
WithDueInputReservations locks each due reservation's Session with the scan itself, skipping Sessions another transaction holds, and prunes each Session's change journal after apply.
func (*Execution) WithFileWriteReservation ¶
func (e *Execution) WithFileWriteReservation(ctx context.Context, tenant, environment string, apply func(context.Context, sessions.FileWriteReservationTx, sessions.Environment, sessions.LockedSession) error) error
WithFileWriteReservation runs apply in the transaction of the tenant's Environment, with the Environment it reads under the locks.
func (*Execution) WithFileWriteSettlement ¶
func (e *Execution) WithFileWriteSettlement(ctx context.Context, tenant, environment, write string, apply func(context.Context, sessions.FileWriteSettlementTx) error) error
WithFileWriteSettlement runs apply in the transaction of the write's Environment, whether or not its Session was publicly deleted. A malformed ID is sessions.ErrInvalidInput and an unknown write sessions.ErrNotFound.
func (*Execution) WithFunctionTurn ¶
func (*Execution) WithInitialization ¶
func (e *Execution) WithInitialization(ctx context.Context, tenant, environment string, apply func(context.Context, sessions.InitializationTx, sessions.LockedSession) error) error
WithInitialization runs apply in the transaction of the tenant's Environment. A malformed Environment ID is a missing Environment.
func (*Execution) WithInputs ¶ added in v0.0.10
type SessionTx ¶
type SessionTx struct {
// contains filtered or unexported fields
}
SessionTx is one Session inside its caller's transaction. It implements the transaction interfaces of the sessions procedures by loading the facts they read and applying what they decide, and decides nothing itself.
The caller guarantees what the procedures assume: the queries are bound to the caller's open transaction, the tenant owns the Session, the transaction already holds the Session lock (LockSession), and the operation that owns the transaction supplies its authority, such as the execution lease. A SessionTx never begins or commits a transaction, never chooses a pool or the lease, and is not used after the transaction callback it was bound in returns.
func BindSession ¶
BindSession binds the tenant's Session to the caller's transaction-bound queries.
func (*SessionTx) AdmitInputReservation ¶ added in v0.0.10
func (*SessionTx) AppendChanges ¶
func (*SessionTx) ApplyFunctionResult ¶
func (*SessionTx) ApplySubagentLifecycle ¶
func (*SessionTx) ApplyTurnEnd ¶
func (*SessionTx) ApplyTurnStatus ¶ added in v0.0.10
func (*SessionTx) BeginArtifactCapture ¶ added in v0.0.10
func (*SessionTx) BindDevice ¶
BindDevice binds the device to the Session; a Session bound to another device is sessions.ErrDeviceBindingConflict.
func (*SessionTx) CancelPendingInput ¶
func (*SessionTx) CountEvents ¶
CountEvents adds entries to the Turn's journal counters.
func (*SessionTx) CreateFunctionCall ¶
func (*SessionTx) CreateInputReservation ¶ added in v0.0.10
func (t *SessionTx) CreateInputReservation(ctx context.Context, key string, batch json.RawMessage, initial bool, settings sessions.TurnSettings) (sessions.EnvironmentInputReservation, error)
func (*SessionTx) CreateTurn ¶ added in v0.0.10
func (*SessionTx) CreateTurnInput ¶ added in v0.0.10
func (*SessionTx) ExpireEnvironment ¶
ExpireEnvironment expires the tenant's Environment; another one is sessions.ErrNotFound and changes nothing.
func (*SessionTx) ExpireInputReservation ¶ added in v0.0.10
func (*SessionTx) FailInputReservation ¶ added in v0.0.10
func (*SessionTx) FailPendingInput ¶
func (*SessionTx) FindCallTurn ¶ added in v0.0.13
func (*SessionTx) FindInputReservation ¶ added in v0.0.10
func (t *SessionTx) FindInputReservation(ctx context.Context, key string, batch json.RawMessage) (*sessions.EnvironmentInputReservation, bool, error)
func (*SessionTx) FindResultTurn ¶
func (*SessionTx) HasFunctionCall ¶
func (*SessionTx) HasUnappliedInputs ¶ added in v0.0.10
func (*SessionTx) InsertEnvironmentDevice ¶
func (t *SessionTx) InsertEnvironmentDevice(ctx context.Context, device sessions.ExecutionDevice, credentialHash string) error
InsertEnvironmentDevice inserts the device only for a hosted Environment, bound to the attached Session if there is one. The insert takes no row when the Environment already has a device, including one a concurrent transaction inserted first, or cannot take one: that is sessions.ErrDeviceBindingConflict.
func (*SessionTx) InsertEvent ¶
func (t *SessionTx) InsertEvent(ctx context.Context, turn string, ordinal int32, event sessions.ExecutionEvent) error
InsertEvent records event at the Turn's journal position ordinal.
func (*SessionTx) InsertEvents ¶
func (t *SessionTx) InsertEvents(ctx context.Context, turn string, first int32, events []sessions.ExecutionEvent) error
InsertEvents records events at the Turn's journal positions from first. The database stamps each entry.
func (*SessionTx) LoadActiveTurn ¶
func (*SessionTx) LoadArchive ¶ added in v0.0.10
LoadArchive reads the resource disposal of the Session's hosted Environment, as GetManagedSessionArchive does.
func (*SessionTx) LoadBoundDevice ¶
func (*SessionTx) LoadChildItem ¶
func (t *SessionTx) LoadChildItem(ctx context.Context, subagent, item string, candidate json.RawMessage) (sessions.StoredChildItem, bool, error)
func (*SessionTx) LoadChildTurn ¶
func (*SessionTx) LoadComputeSuspension ¶
func (*SessionTx) LoadDevice ¶
func (*SessionTx) LoadEnding ¶
func (*SessionTx) LoadEnvironment ¶
func (*SessionTx) LoadEnvironmentInput ¶
func (*SessionTx) LoadEventSources ¶
func (t *SessionTx) LoadEventSources(ctx context.Context, turn string, first int32) ([]sessions.Source, error)
LoadEventSources reads the Turn's journal entries from first, in order.
func (*SessionTx) LoadFunctionCall ¶
func (*SessionTx) LoadInputBatch ¶ added in v0.0.10
func (t *SessionTx) LoadInputBatch(ctx context.Context, key string, batch json.RawMessage) ([]sessions.InputReceipt, bool, error)
func (*SessionTx) LoadInputGate ¶ added in v0.0.10
func (*SessionTx) LoadInputReservation ¶ added in v0.0.10
func (*SessionTx) LoadInputSource ¶
LoadInputSource reads the Session's admitted input at sequence.
func (*SessionTx) LoadItem ¶
func (t *SessionTx) LoadItem(ctx context.Context, turnID string, update items.Update) (items.Stored, error)
LoadItem reads what the Session holds for update's Item: the stored Item and, when update asks for them, whether the Turn has another assistant message and the result the application saved for the call.
func (*SessionTx) LoadJournalTurn ¶
func (t *SessionTx) LoadJournalTurn(ctx context.Context, turn string) (sessions.JournalTurn, bool, error)
LoadJournalTurn reads the tenant's Turn in the Session.
func (*SessionTx) LoadNativeSubagent ¶
func (*SessionTx) LoadPendingFileWrite ¶
func (*SessionTx) LoadPendingFunctionCalls ¶
func (*SessionTx) LoadPublicSubagent ¶
func (*SessionTx) LoadRootAgent ¶
func (*SessionTx) LoadTurnSettings ¶ added in v0.0.14
func (*SessionTx) MatchEvents ¶
func (t *SessionTx) MatchEvents(ctx context.Context, turn string, first int32, events []sessions.ExecutionEvent) (bool, error)
MatchEvents compares the Turn's journal entries from first with events.
func (*SessionTx) MatchFunctionCall ¶
func (t *SessionTx) MatchFunctionCall(ctx context.Context, turn string, call sessions.FunctionCall) (sessions.FunctionCallMatch, error)
func (*SessionTx) MatchFunctionResult ¶
func (t *SessionTx) MatchFunctionResult(ctx context.Context, turn, call string, result json.RawMessage) (sessions.FunctionResultMatch, error)
func (*SessionTx) PublishSubagent ¶
func (*SessionTx) PutChildItem ¶
PutChildItem stores a Subagent Item; a new output Item takes its Turn's next output index.
func (*SessionTx) PutChildTurn ¶
func (*SessionTx) PutItem ¶
func (t *SessionTx) PutItem(ctx context.Context, turnID string, created time.Time, change items.Change) (*int32, error)
PutItem stores a decided Item change. A new Item takes the Session's next position and, when it is output, the Turn's next output index; an update keeps both, and its first terminal status records when it settled. PutItem returns the Item's output index, nil when it has none, and textvalue.ErrUnstorable for text PostgreSQL cannot store.
func (*SessionTx) PutSubagentEffect ¶
func (*SessionTx) PutSubagentIdentity ¶
func (t *SessionTx) PutSubagentIdentity(ctx context.Context, identity sessions.SubagentIdentity) (string, error)
PutSubagentIdentity allocates the Subagent ID of a new binding.
func (*SessionTx) PutTurnUsage ¶
PutTurnUsage replaces a root Turn's recorded usage with a measurement.
func (*SessionTx) RecordEnvironmentFailure ¶
func (t *SessionTx) RecordEnvironmentFailure(ctx context.Context, environment, reason string, detail *sessions.ProvisioningFailureDetail) (time.Time, error)
RecordEnvironmentFailure fails the tenant's Environment only while it is still live; otherwise it changes nothing and returns pgx.ErrNoRows.
func (*SessionTx) RecordInputAudit ¶ added in v0.0.10
func (*SessionTx) RecordTerminalActivity ¶
RecordTerminalActivity marks the Session's running managed compute active at the database's commit clock.
func (*SessionTx) RememberNativeSession ¶ added in v0.0.10
func (*SessionTx) RequestTurnCancel ¶
func (*SessionTx) SubmitFunctionResult ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the pooled Session adapter: the storage of the Session use cases and the Session reads. cipher opens the Session data frozen at creation and signs installation authorizations; it is nil on a service without a credential key.
func New ¶
func New(units *pgunit.Pool, cipher *credentialcrypto.Cipher) *Store
New builds the pooled Session adapter on units, opening frozen Session data and signing installation authorizations with cipher.
func (*Store) ArchivedCancellationReceipt ¶ added in v0.0.10
func (s *Store) ArchivedCancellationReceipt(ctx context.Context, device, credentialHash string, runIDs []string) (runtimedevice.ArchivedCancellationReceipt, error)
ArchivedCancellationReceipt is a read-only exception for the exact already authenticated delivery. The ordinary credential view remains revoked; this cannot authorize bootstrap, reconnect, dispatch, workspace access or renewal. A marker records that archive caused the first revocation; timestamps alone cannot distinguish an earlier ordinary cancel/revoke followed by archive.
func (*Store) AuditSessionOperation ¶ added in v0.0.10
func (*Store) AuthenticateEnvironmentExecutor ¶
func (*Store) CreateDevice ¶
func (s *Store) CreateDevice(ctx context.Context, tenant string, registration sessions.DeviceRegistration) (sessions.ExecutionDevice, error)
func (*Store) DeleteSessionArtifact ¶
func (*Store) ExecutorProjectExists ¶
func (*Store) FindCreation ¶ added in v0.0.10
func (*Store) FingerprintProviderKey ¶ added in v0.0.10
func (*Store) GetDeviceCredential ¶
func (s *Store) GetDeviceCredential(ctx context.Context, device string) (runtimedevice.Credential, bool, error)
GetDeviceCredential reads a device's credential for the Runtime gateway. A malformed or unknown device has no credential.
func (*Store) GetEnvironment ¶
func (*Store) GetEnvironmentInputReservation ¶ added in v0.0.10
func (*Store) GetManagedSessionArchive ¶ added in v0.0.10
func (*Store) GetSession ¶ added in v0.0.10
func (*Store) GetSessionArtifact ¶
func (*Store) GetSessionDevice ¶
func (*Store) GetSessionEnvironment ¶
func (*Store) GetSessionExecutionBinding ¶ added in v0.0.10
func (*Store) GetSessionExecutionConfiguration ¶ added in v0.0.10
func (*Store) GetSessionRuntimeDevice ¶
func (*Store) GetSubagent ¶
func (*Store) GetSubagentTurn ¶
func (*Store) GetTurnDiagnosticsSnapshot ¶ added in v0.0.10
func (*Store) ListAdminRuntimeTargets ¶ added in v0.0.10
func (*Store) ListEnrolledRuntimeBindings ¶
func (*Store) ListEnvironmentInitializations ¶
func (*Store) ListEnvironmentInputWork ¶ added in v0.0.10
func (*Store) ListEnvironments ¶ added in v0.0.14
func (s *Store) ListEnvironments(ctx context.Context, tenantID string, creator identity.Subject, cursor string, limit int, ascending bool) ([]sessions.Environment, bool, error)
ListEnvironments reads a page of the standalone Environments the creator made in the tenant, whatever their status, after the cursor Environment in (created, ID) order. It reports whether more follow. A missing cursor is sessions.ErrNotFound.
func (*Store) ListExecutionDevices ¶ added in v0.0.10
func (*Store) ListExecutionWork ¶ added in v0.0.10
func (*Store) ListSessionArtifacts ¶
func (*Store) ListSessionEvents ¶ added in v0.0.10
func (*Store) ListSessions ¶ added in v0.0.10
func (*Store) ListSubagentItems ¶
func (*Store) ListSubagentTurnItems ¶
func (*Store) ListSubagentTurns ¶
func (*Store) ListSubagents ¶
func (*Store) ListTurnInputs ¶ added in v0.0.10
func (*Store) ListTurnItems ¶ added in v0.0.14
func (s *Store) ListTurnItems(ctx context.Context, tenantID, sessionID, turnID, cursor string, limit int, ascending bool) (sessions.ItemPage, error)
ListTurnItems lists the Items of one root Turn with the Session Item cursor rules.
func (*Store) LoadExecutorCredentialRestriction ¶
func (*Store) LoadProjectArchived ¶
func (*Store) MeasuredSessionUsage ¶ added in v0.0.10
func (*Store) ProjectExecutorCredentialState ¶
func (*Store) ReadAdminSummary ¶ added in v0.0.10
func (*Store) ReadEnvironmentSetup ¶
func (s *Store) ReadEnvironmentSetup(ctx context.Context, tenant, environment string) (environmentconfig.Setup, error)
ReadEnvironmentSetup opens the setup frozen for the Environment. An ended Environment is sessions.ErrNotFound. Frozen data that does not open, decode or validate is corrupt stored data, never the caller's input, so it is an internal error.
func (*Store) ReadInitialEnvironmentFile ¶
func (s *Store) ReadInitialEnvironmentFile(ctx context.Context, tenant, environment string, position int) (environmentconfig.InitialFileMetadata, []byte, error)
ReadInitialEnvironmentFile opens the initial file frozen for the Environment at position. A file that does not open or match its recorded size is corrupt stored data, so it is an internal error.
func (*Store) ReadSessionArtifact ¶
func (s *Store) ReadSessionArtifact(ctx context.Context, tenantID, sessionID, artifactID string, consume func(sessions.Artifact, io.Reader) error) error
ReadSessionArtifact keeps an admitted snapshot available across concurrent deletion.
func (*Store) RevokeDevice ¶
func (*Store) SessionEventCursor ¶ added in v0.0.10
func (*Store) SessionModelExecution ¶ added in v0.0.10
func (*Store) SessionStreamSnapshot ¶ added in v0.0.10
func (*Store) SignInstallation ¶
func (*Store) TouchAuthenticatedDevice ¶
func (*Store) TouchDevice ¶
func (*Store) UpdateSession ¶ added in v0.0.14
func (*Store) VerifyInstallation ¶
func (*Store) WithArtifactStaging ¶
func (s *Store) WithArtifactStaging(ctx context.Context, key sessions.ArtifactStagingKey, stage func(context.Context, sessions.ArtifactStagingTx) error) error
WithArtifactStaging runs the staging in one pooled transaction, not on the execution lease: the transfer can outlast a lease transaction, and staged Artifacts stay private until the lease-bound completion publishes or discards them. Large objects the staging created are removed with the rolled-back transaction.
func (*Store) WithCreation ¶ added in v0.0.10
func (*Store) WithEnrollment ¶
func (s *Store) WithEnrollment(ctx context.Context, environment, credentialHash string, apply func(context.Context, sessions.EnrollmentTx, sessions.Environment, sessions.LockedSession) error) error
WithEnrollment authenticates the credential and reads the Environment on the pool; the enrollment transaction rechecks that authority under the Environment locks.
func (*Store) WithEnvironmentCreation ¶ added in v0.0.14
func (*Store) WithEnvironmentExecutorCredentials ¶
func (s *Store) WithEnvironmentExecutorCredentials(ctx context.Context, tenant, environment string, apply func(context.Context, sessions.EnvironmentExecutorCredentialTx, sessions.LockedSession) error) error
WithEnvironmentExecutorCredentials runs apply in the transaction of the tenant's Environment.
func (*Store) WithExecutorCredentials ¶
func (*Store) WithInputs ¶ added in v0.0.10
func (*Store) WithSessionDeletion ¶ added in v0.0.10
Source Files
¶
- admin.go
- artifacts.go
- binding.go
- changes.go
- creation.go
- devices.go
- doc.go
- environment.go
- environment_creation.go
- environment_lock.go
- execution.go
- execution_environment.go
- execution_file_writes.go
- execution_functions.go
- execution_inputs.go
- execution_turns.go
- executor_credentials.go
- frozen.go
- functions.go
- inputs.go
- item_reads.go
- items.go
- journal.go
- model_execution.go
- public_session.go
- rows.go
- session.go
- session_reads.go
- session_writes.go
- store.go
- subagent_reads.go
- subagents.go
- turn_end.go
- turn_reads.go
- usage.go