postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres is kōjō's production store: one Postgres database holds the queue (FOR UPDATE SKIP LOCKED), sessions and checkpoints (JSONB), team memory (pgvector, with a full-text fallback), the append-only audit log, config revisions (hot reload through LISTEN/NOTIFY) and everything else.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// URL is a Postgres connection string.
	URL      string
	MaxConns int
	Logger   *slog.Logger
}

Options configure Open.

type Store

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

Store is a store.Store on Postgres.

func Open

func Open(ctx context.Context, o Options) (*Store, error)

Open connects to Postgres. It does not migrate: call Migrate.

func (*Store) ActivateRevision

func (s *Store) ActivateRevision(ctx context.Context, id string) (*store.Revision, error)

ActivateRevision implements store.Store.

func (*Store) ActiveRevision

func (s *Store) ActiveRevision(ctx context.Context, scope, object string) (*store.Revision, error)

ActiveRevision implements store.Store.

func (*Store) ActiveRevisions

func (s *Store) ActiveRevisions(ctx context.Context, scope string) ([]store.Revision, error)

ActiveRevisions implements store.Store.

func (*Store) AddMemory

func (s *Store) AddMemory(ctx context.Context, m *store.Memory) error

AddMemory implements store.Store.

func (*Store) AddSessionMessage

func (s *Store) AddSessionMessage(ctx context.Context, m *store.SessionMessage, max int) error

AddSessionMessage implements store.Store. The session's row is locked while its state is checked and the message written, so the message cannot land after the worker wrote the session's last status, and two messages cannot take the same Seq.

func (*Store) AppendAudit

func (s *Store) AppendAudit(ctx context.Context, e store.AuditEntry) error

AppendAudit implements store.Store.

func (*Store) AppendStep

func (s *Store) AppendStep(ctx context.Context, st *store.Step) error

AppendStep implements store.Store.

func (*Store) Claim

func (s *Store) Claim(ctx context.Context, worker string, lease time.Duration) (*store.Session, error)

Claim implements store.Store.

func (*Store) ClaimWithin added in v0.3.0

func (s *Store) ClaimWithin(ctx context.Context, worker string, lease time.Duration, caps store.Caps) (*store.Session, error)

ClaimWithin implements store.Store.

Without caps it is Claim. With caps, claims take turns: each one holds a transaction-scoped advisory lock while it counts the running sessions and marks the one it picks running, and commits before the next one counts. Under READ COMMITTED two claims that did not take turns would each count without seeing the other's uncommitted session, and both start one for a repository with one slot left. The lock is per schema, so it covers every worker of every replica of one install. A claim holds it for one count and one update; FOR UPDATE SKIP LOCKED still keeps a claim from waiting on a session another statement holds.

func (*Store) Close

func (s *Store) Close()

Close implements store.Store.

func (*Store) DecideApproval

func (s *Store) DecideApproval(ctx context.Context, id, status, by string) (*store.Approval, error)

DecideApproval implements store.Store.

func (*Store) DeleteDraft

func (s *Store) DeleteDraft(ctx context.Context, id string) error

DeleteDraft implements store.Store.

func (*Store) DeleteMemory

func (s *Store) DeleteMemory(ctx context.Context, id string) error

DeleteMemory implements store.Store.

func (*Store) Enqueue

func (s *Store) Enqueue(ctx context.Context, req store.Request) (*store.Session, error)

Enqueue implements store.Store.

func (*Store) GetApproval

func (s *Store) GetApproval(ctx context.Context, id string) (*store.Approval, error)

GetApproval implements store.Store.

func (*Store) GetDraft

func (s *Store) GetDraft(ctx context.Context, id string) (*store.SkillDraft, error)

GetDraft implements store.Store.

func (*Store) GetEvalRun

func (s *Store) GetEvalRun(ctx context.Context, id string) (*store.EvalRun, error)

GetEvalRun implements store.Store.

func (*Store) GetMemory

func (s *Store) GetMemory(ctx context.Context, id string) (*store.Memory, error)

GetMemory implements store.Store.

func (*Store) GetProposal

func (s *Store) GetProposal(ctx context.Context, id string) (*store.Proposal, error)

GetProposal implements store.Store.

func (*Store) GetPullRequest

func (s *Store) GetPullRequest(ctx context.Context, repo string, number int) (*store.PullRequest, error)

GetPullRequest implements store.Store.

func (*Store) GetRevision

func (s *Store) GetRevision(ctx context.Context, id string) (*store.Revision, error)

GetRevision implements store.Store.

func (*Store) GetScheduleState

func (s *Store) GetScheduleState(ctx context.Context, key string) (*store.ScheduleState, error)

GetScheduleState implements store.Store.

func (*Store) GetSession

func (s *Store) GetSession(ctx context.Context, id string) (*store.Session, error)

GetSession implements store.Store.

func (*Store) HasVector

func (s *Store) HasVector() bool

HasVector reports whether team memory can store embeddings (pgvector).

func (*Store) Heartbeat

func (s *Store) Heartbeat(ctx context.Context, sessionID, worker string, lease time.Duration) error

Heartbeat implements store.Store.

func (*Store) ListAudit

func (s *Store) ListAudit(ctx context.Context, f store.AuditFilter) ([]store.AuditEntry, error)

ListAudit implements store.Store.

func (*Store) ListDrafts

func (s *Store) ListDrafts(ctx context.Context, scope string) ([]store.SkillDraft, error)

ListDrafts implements store.Store.

func (*Store) ListEvalRuns

func (s *Store) ListEvalRuns(ctx context.Context, skill string, limit int) ([]store.EvalRun, error)

ListEvalRuns implements store.Store.

func (*Store) ListMemory

func (s *Store) ListMemory(ctx context.Context, f store.MemoryFilter) ([]store.Memory, error)

ListMemory implements store.Store.

func (*Store) ListProposals

func (s *Store) ListProposals(ctx context.Context, f store.ProposalFilter) ([]store.Proposal, error)

ListProposals implements store.Store.

func (*Store) ListPullRequests

func (s *Store) ListPullRequests(ctx context.Context, f store.PullRequestFilter) ([]store.PullRequest, error)

ListPullRequests implements store.Store.

func (*Store) ListRevisions

func (s *Store) ListRevisions(ctx context.Context, scope, object string, limit int) ([]store.Revision, error)

ListRevisions implements store.Store.

func (*Store) ListSessionMessages

func (s *Store) ListSessionMessages(ctx context.Context, sessionID string) ([]store.SessionMessage, error)

ListSessionMessages implements store.Store.

func (*Store) ListSessions

func (s *Store) ListSessions(ctx context.Context, f store.SessionFilter) ([]store.Session, error)

ListSessions implements store.Store.

func (*Store) ListSkillIndex

func (s *Store) ListSkillIndex(ctx context.Context, repo string) ([]store.SkillIndexEntry, error)

ListSkillIndex implements store.Store.

func (*Store) ListSteps

func (s *Store) ListSteps(ctx context.Context, sessionID string) ([]store.Step, error)

ListSteps implements store.Store.

func (*Store) ListUsers

func (s *Store) ListUsers(ctx context.Context) ([]store.User, error)

ListUsers implements store.Store.

func (*Store) MarkSessionMessages

func (s *Store) MarkSessionMessages(ctx context.Context, sessionID string, ids []string, status, to string) ([]store.SessionMessage, error)

MarkSessionMessages implements store.Store. The update only matches pending rows, so of two concurrent calls each message goes to one.

func (*Store) Migrate

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

Migrate applies every migration that has not run yet and returns how many it applied. Replicas starting together serialize on an advisory lock.

func (*Store) PendingMigrations

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

PendingMigrations returns how many migrations have not been applied.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping implements store.Store.

func (*Store) PutApproval

func (s *Store) PutApproval(ctx context.Context, a *store.Approval) error

PutApproval implements store.Store.

func (*Store) PutDraft

func (s *Store) PutDraft(ctx context.Context, d *store.SkillDraft) error

PutDraft implements store.Store.

func (*Store) PutEvalRun

func (s *Store) PutEvalRun(ctx context.Context, r *store.EvalRun) error

PutEvalRun implements store.Store.

func (*Store) PutProposal

func (s *Store) PutProposal(ctx context.Context, p *store.Proposal) error

PutProposal implements store.Store. The partial unique index skill_proposals_open is what keeps one open proposal per skill and scope.

func (*Store) PutRevision

func (s *Store) PutRevision(ctx context.Context, r store.Revision, activate bool) (*store.Revision, error)

PutRevision implements store.Store.

func (*Store) PutScheduleState

func (s *Store) PutScheduleState(ctx context.Context, st store.ScheduleState) error

PutScheduleState implements store.Store.

func (*Store) RecordPullRequest

func (s *Store) RecordPullRequest(ctx context.Context, pr store.PullRequest) error

RecordPullRequest implements store.Store.

func (*Store) Release

func (s *Store) Release(ctx context.Context, sessionID, worker string, status store.SessionStatus, runAfter time.Time) error

Release implements store.Store.

func (*Store) ReplaceSkillIndex

func (s *Store) ReplaceSkillIndex(ctx context.Context, repo string, entries []store.SkillIndexEntry) error

ReplaceSkillIndex implements store.Store.

func (*Store) RequestCancel

func (s *Store) RequestCancel(ctx context.Context, id string) error

RequestCancel implements store.Store.

func (*Store) SearchMemory

func (s *Store) SearchMemory(ctx context.Context, q store.MemoryQuery) ([]store.Memory, error)

SearchMemory implements store.Store.

func (*Store) SpendByRepo added in v0.3.0

func (s *Store) SpendByRepo(ctx context.Context, from, to time.Time) (map[string]float64, error)

SpendByRepo implements store.Store.

func (*Store) SpendSince

func (s *Store) SpendSince(ctx context.Context, t time.Time) (float64, error)

SpendSince implements store.Store.

func (*Store) TryLead

func (s *Store) TryLead(ctx context.Context, name string) (func(), bool, error)

TryLead implements store.Store with a session-level advisory lock held on a dedicated connection. If that connection dies Postgres frees the lock, so two replicas never lead at once for longer than a failed tick.

func (*Store) UndeliveredMessages

func (s *Store) UndeliveredMessages(ctx context.Context, sessionID string) ([]store.SessionMessage, error)

UndeliveredMessages implements store.Store.

func (*Store) UpdatePullRequest

func (s *Store) UpdatePullRequest(ctx context.Context, pr *store.PullRequest) error

UpdatePullRequest implements store.Store.

func (*Store) UpdateSession

func (s *Store) UpdateSession(ctx context.Context, ses *store.Session) error

UpdateSession implements store.Store.

func (*Store) UpdateStep

func (s *Store) UpdateStep(ctx context.Context, st *store.Step) error

UpdateStep implements store.Store.

func (*Store) UpsertUser

func (s *Store) UpsertUser(ctx context.Context, u store.User) error

UpsertUser implements store.Store.

func (*Store) WatchConfig

func (s *Store) WatchConfig(ctx context.Context) (<-chan store.ConfigChange, error)

WatchConfig implements store.Store. It holds one connection on LISTEN. When that connection drops it reconnects and sends a change with Scope "*", which tells the receiver to reload everything it may have missed.

Jump to

Keyboard shortcuts

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