checkpoint

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package checkpoint keeps the history checkpoints of a session: what stands in a request for the history at or before a position, so that only the rows after it load raw.

A checkpoint holds, in order, the rows it keeps by reference and the summaries that fold the rest; it always holds a summary. A request renders the items in their order, and then the session's context rows after the checkpoint's position: its visible rows of complete turns, other than legacy passive_sync rows. Compaction folds onto the active checkpoint and makes the result active; a fork takes a copy of its source's. Every checkpoint names its parent: hiding, replacing or deleting rows at or before the active one's position moves the session back, in the same statement, to the newest one on its chain before them.

Index

Constants

This section is empty.

Variables

View Source
var ErrMoved = errors.New("history checkpoint moved since it was read")

ErrMoved reports a fold whose parent is no longer the session's active checkpoint: the history moved on since the fold read it.

Functions

func CopyToFork

func CopyToFork(ctx context.Context, q dbstore.Queries, c Copy) error

CopyToFork gives a fork the newest checkpoint on its source's active chain that accounts for no history past the copy, in the transaction q runs in: its summaries become the fork's own, naming the copies of the rows they cite (renameRows), the rows it keeps are named by their copies, and its position becomes the copy's place for it. The fork's checkpoint has no parent: nothing before it exists in the fork. The fork copied every visible row through the turn, so it copied every row such a checkpoint keeps or its summaries cite.

Types

type Checkpoint

type Checkpoint struct {
	ID       string
	ParentID string
	// Position is the last place in the history the checkpoint accounts for.
	Position messagepkg.HistoryPosition
	Items    []Item
}

Checkpoint is one history checkpoint of a session. The zero Checkpoint stands for nothing: every context row of the session renders raw.

func (Checkpoint) RowIDs

func (c Checkpoint) RowIDs() []string

RowIDs names the rows the checkpoint keeps by reference, in item order.

func (Checkpoint) RowUUIDs

func (c Checkpoint) RowUUIDs() []pgtype.UUID

RowUUIDs names the rows the checkpoint keeps by reference as the queries that take them do.

func (Checkpoint) SummaryIDs

func (c Checkpoint) SummaryIDs() []string

SummaryIDs names the summaries the checkpoint holds, in item order.

type Copy

type Copy struct {
	SourceSessionID string
	ForkSessionID   string
	// SourceMessageIDs and ForkMessageIDs pair each copied source row with
	// its copy.
	SourceMessageIDs []pgtype.UUID
	ForkMessageIDs   []pgtype.UUID
	// ThroughTurnPosition is the source position of the last turn the fork
	// copied.
	ThroughTurnPosition int64
}

Copy is the history a fork copied from its source session, under the source's share lock (LockSessionForFork).

type Fold

type Fold struct {
	SessionID string
	// Parent is the checkpoint the pass folded onto: the session's active one
	// when it read its candidates.
	Parent Checkpoint
	// SummaryID names the pass's compaction log and Summary is its text.
	SummaryID string
	Summary   string
	// Folded are the rows the summary folds.
	Folded []Row
	// Read names every row the pass read, folded or not.
	Read []string
}

Fold is a summary a compaction pass commits onto the checkpoint it read.

type Item

type Item struct {
	RowID     string `json:"row,omitempty"`
	SummaryID string `json:"summary,omitempty"`
	// Summary is the summary's text, filled in when the checkpoint is read
	// for a request.
	Summary string `json:"-"`
}

Item is one entry of a checkpoint: a row it keeps by reference or a summary, named by its compaction log.

type Row

type Row struct {
	ID       string
	Position messagepkg.HistoryPosition
}

Row is a context row at its place in the history.

type Store

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

Store reads and writes the history checkpoints of sessions.

func NewStore

func NewStore(log *slog.Logger, queries dbstore.Queries) *Store

NewStore creates a Store.

func (*Store) Active

func (s *Store) Active(ctx context.Context, sessionID string) (Checkpoint, error)

Active is the session's active checkpoint as a request renders it, with the text of its summaries: the zero Checkpoint when the session has none.

func (*Store) Commit

func (s *Store) Commit(ctx context.Context, q dbstore.Queries, fold Fold) (Checkpoint, error)

Commit makes the checkpoint of a fold the session's active one, in the transaction q runs in, the run's fenced one. The checkpoint accounts for the history through the last row it folds, or through its parent's position when it folds none. It keeps every context row there it does not fold, the rows its parent kept included, each in history order: the ones the pass read before its summary, which absorbs its parent's, as the request that read them places the summary after them, and the ones it never read after it, since the summary was written without them. Those are logged and counted.

func (*Store) KeptBeforeTurn

func (s *Store) KeptBeforeTurn(ctx context.Context, sessionID, turnID string) (Checkpoint, error)

KeptBeforeTurn is the checkpoint the session keeps once the turn's context rows are replaced, without making it active: what an edit or retry renders before its replacement commits.

Jump to

Keyboard shortcuts

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