history

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package history is the append-only audit log for agentmutex: every lease state change (acquired, renewed, released, force-released, expired, reclaimed) is recorded in a SQLite database at <root>/history.db.

Recording is strictly BEST-EFFORT: the lock protocol's correctness never depends on the history database. Callers treat any error here as a warning at most — a full disk or a corrupt history.db must never block a deploy from acquiring or releasing its lease.

Concurrency: many CLI processes append concurrently. WAL mode plus a busy timeout makes multi-process appends safe; writes happen outside the per-key flock guard so they never extend a lock critical section.

Index

Constants

View Source
const (
	EventAcquired      = "acquired"
	EventRenewed       = "renewed"
	EventReleased      = "released"
	EventForceReleased = "force-released"
	EventExpired       = "expired" // lease ended by TTL (displaced or pruned)
	EventReclaimed     = "reclaimed"
)

Event types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID          int64     `json:"id"`
	TS          time.Time `json:"ts"`
	Key         string    `json:"key"`
	Event       string    `json:"event"`
	LeaseID     string    `json:"lease_id,omitempty"`
	Agent       string    `json:"agent,omitempty"`
	PID         int       `json:"pid,omitempty"`
	Host        string    `json:"host,omitempty"`
	Reason      string    `json:"reason,omitempty"`
	TTLSeconds  float64   `json:"ttl_seconds,omitempty"`
	HeldSeconds float64   `json:"held_seconds,omitempty"`
	Detail      string    `json:"detail,omitempty"`
}

Event is one row of the lock changelog. LeaseID correlates all events of a single lease (it is public — never the lease token).

type Log

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

Log is a handle on the history database.

func Open

func Open(root string) (*Log, error)

Open opens (creating if needed) the history database under root. The file is created 0600-equivalent via SQLite defaults inside the 0700 state root.

func (*Log) Close

func (l *Log) Close() error

func (*Log) Query

func (l *Log) Query(o QueryOpts) ([]Event, error)

Query returns matching events, newest first.

func (*Log) Record

func (l *Log) Record(e Event) error

Record appends one event. TS defaults to now.

type QueryOpts

type QueryOpts struct {
	Key           string    // "" = all keys
	Since         time.Time // zero = no lower bound
	IncludeRenews bool
	Limit         int // <= 0 means a sane default
}

QueryOpts filters Query.

Jump to

Keyboard shortcuts

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