postgres

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package postgres

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open added in v0.5.0

func Open(ctx context.Context, dsn string) (*pgxpool.Pool, error)

Types

type Driver

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

func NewDriver

func NewDriver(ctx context.Context, connStr string) (*Driver, error)

func (*Driver) Ancestry added in v0.5.0

func (d *Driver) Ancestry(ctx context.Context, hash string) ([]*merkle.Node, error)

func (*Driver) AncestryChain added in v0.5.0

func (d *Driver) AncestryChain(ctx context.Context, hash string) (*storage.Chain, error)

func (*Driver) AncestryChains added in v0.5.0

func (d *Driver) AncestryChains(ctx context.Context, hashes []string) (map[string]*storage.Chain, error)

func (*Driver) BackfillSession added in v0.10.0

BackfillSession links existing legacy nodes to a session table row. It is used by transcript backfills where the node DAG already exists but the original ingest path predated session envelopes.

func (*Driver) BackfillSessionStatus added in v0.13.0

func (d *Driver) BackfillSessionStatus(ctx context.Context) (storage.BackfillSessionStatusResult, error)

BackfillSessionStatus recomputes derived_status (plus the sticky has_git_activity flag and tool_result_count / tool_error_count) for sessions still at the default 'unknown' status — the rows that predate the ingest-time computation. It walks each session's nodes with the same signal helpers ingest uses (sessions.CountToolResults / CountToolResultErrors / BlocksHaveGitActivity over every node, sessions.DetermineStatus over the chronologically-last node as the leaf). Live ingest keeps status current on its own.

Scoping to 'unknown' keeps re-runs cheap and idempotent — already-classified rows are skipped. Re-classifying already-decided rows after a classifier change is intentionally out of scope for this endpoint.

Safe to run online: a concurrent live turn re-runs the same UpdateSessionStatus path, so the worst case is a redundant equal write. Each session's recompute is its own statement; there is no global lock.

func (*Driver) Close added in v0.5.0

func (d *Driver) Close() error

func (*Driver) CountSessions added in v0.5.0

func (d *Driver) CountSessions(ctx context.Context, opts storage.ListOpts) (storage.SessionStats, error)

func (*Driver) DB added in v0.5.0

func (d *Driver) DB() *pgxpool.Pool

func (*Driver) Depth added in v0.5.0

func (d *Driver) Depth(ctx context.Context, hash string) (int, error)

func (*Driver) Get added in v0.5.0

func (d *Driver) Get(ctx context.Context, hash string) (*merkle.Node, error)

func (*Driver) GetByParent added in v0.5.0

func (d *Driver) GetByParent(ctx context.Context, parentHash *string) ([]*merkle.Node, error)

func (*Driver) GetSessionRecord added in v0.12.0

func (d *Driver) GetSessionRecord(ctx context.Context, orgID, id string) (*storage.SessionRecord, error)

GetSessionRecord returns a single session by its UUID, or nil if not found.

func (*Driver) GetSessionRecordByHarness added in v0.15.0

func (d *Driver) GetSessionRecordByHarness(
	ctx context.Context,
	orgID string,
	harnessID string,
	harnessSessionID string,
) (*storage.SessionRecord, error)

GetSessionRecordByHarness returns the single session matching the org-scoped natural key (org_id, harness_id, harness_session_id), or nil if no row matches. The lookup is an exact-match point read on the sessions_harness_uq unique index, mirroring the GetSessionRecord nil-on-no-rows contract.

func (*Driver) Has added in v0.5.0

func (d *Driver) Has(ctx context.Context, hash string) (bool, error)

func (*Driver) IngestTurn added in v0.10.0

IngestTurn implements storage.SessionIngester for the Postgres driver. The session-tracking flow runs in a single transaction: resolve / UPSERT a sessions row, resolve the optional fork-parent FK (placeholder-inserting the parent when its own first turn hasn't landed yet), insert every node in the supplied chain, stamp session_id onto each newly-inserted node, and roll up the per-turn counters.

func (*Driver) Leaves added in v0.5.0

func (d *Driver) Leaves(ctx context.Context) ([]*merkle.Node, error)

func (*Driver) List added in v0.5.0

func (d *Driver) List(ctx context.Context) ([]*merkle.Node, error)

func (*Driver) ListNodesBySession added in v0.12.0

func (d *Driver) ListNodesBySession(ctx context.Context, sessionID string) ([]*merkle.Node, error)

ListNodesBySession returns all nodes attributed to a session ordered by created_at ASC (chronological order).

func (*Driver) ListParentRefs added in v0.5.0

func (d *Driver) ListParentRefs(ctx context.Context) ([]storage.ParentRef, error)

func (*Driver) ListSessionRecords added in v0.12.0

func (d *Driver) ListSessionRecords(
	ctx context.Context,
	orgID string,
	authSubject string,
	limit int,
	cursorTs *time.Time,
	cursorID *string,
) ([]storage.SessionRecord, error)

ListSessionRecords returns a page of sessions for an org ordered by last_seen_at DESC. Pass nil cursorTs/cursorID to start from the beginning. A non-empty authSubject narrows the page to sessions captured for that gateway-stamped JWT subject (exact match on the indexed column); empty lists every user's sessions.

func (*Driver) ListSessions added in v0.5.0

func (d *Driver) ListSessions(ctx context.Context, opts storage.ListOpts) (*storage.Page[*merkle.Node], error)

func (*Driver) LoadDag added in v0.5.0

func (d *Driver) LoadDag(ctx context.Context, hash string) (*merkle.Dag, error)

func (*Driver) Open added in v0.5.0

func (d *Driver) Open(ctx context.Context) error

func (*Driver) Put added in v0.5.0

func (d *Driver) Put(ctx context.Context, n *merkle.Node) (bool, error)

func (*Driver) Roots added in v0.5.0

func (d *Driver) Roots(ctx context.Context) ([]*merkle.Node, error)

func (*Driver) SessionIdentityByHash added in v0.10.0

func (d *Driver) SessionIdentityByHash(ctx context.Context, orgID, hash string) (*storage.SessionIdentity, error)

SessionIdentityByHash returns the harness identity for the sessions row attached to a node hash, scoped to orgID. Older rows, legacy Put writes, and non-Postgres stores may not have session tracking metadata; those return nil without error so read APIs can expose the field opportunistically.

The org_id predicate is load-bearing, not cosmetic: nodes is keyed by the composite (org_id, hash), so identical content yields one row per org. A lookup on hash alone would return an arbitrary org's row for shared content, leaking another tenant's harness_session_id. An empty orgID maps to the nil-UUID sentinel bucket (legacy / non-session writes).

func (*Driver) UpdateUsage added in v0.5.0

func (d *Driver) UpdateUsage(ctx context.Context, hash string, usage *llm.Usage) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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