thread

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 21 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 thread folds raw history facts into conversation-owned thread items.

Index

Constants

View Source
const MaxCatchUpGap = 1024

MaxCatchUpGap is the inclusive maximum consumed history-ID distance for catch-up.

View Source
const MaxQueryItems = 256

MaxQueryItems caps ordered rows requested in a page or newest window. Active items, parent closure and ties at the lower bound are additional rows.

Variables

View Source
var (
	ErrClosed         = errors.New("thread: store is shut down")
	ErrUnloading      = errors.New("thread: conversation is unloading")
	ErrNotLoaded      = errors.New("thread: conversation is not loaded")
	ErrNotUnavailable = errors.New("thread: conversation is not unavailable")
	ErrUnavailable    = errors.New("thread: conversation view is unavailable")
)
View Source
var ErrInvalidLimit = errors.New("thread: query limit must be positive")
View Source
var ErrPersistence = errors.New("thread: cache persistence unavailable")

ErrPersistence reports a recoverable checkpoint or recovery-marker I/O failure.

Functions

This section is empty.

Types

type Change

type Change struct {
	ID, PreviousRev, Rev, Version uint64
	Addition                      *Item
	Fields                        map[string]json.RawMessage
	TextAppend                    string
}

Change applies to ID at PreviousRev, producing Rev. Fields use Item field names and replace values, including zero/null. Apply Fields, then TextAppend to Content.text, then Rev. Addition instead supplies the complete new item. Version is the consumed publication boundary, which may exceed Rev.

type Fold

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

Fold belongs to one conversation. Its owner must serialize all access. The zero value is not bound to a conversation; construct folds with New.

func New

func New(conversationID string) *Fold

New creates an independent fold for a caller-established conversation owner.

func (*Fold) Feed

func (f *Fold) Feed(entries []history.Entry) error

Feed consumes increasing IDs. Unsupported or malformed facts still advance version, but cannot affect items, attribution or joins. An invalid ID returns an error before consuming that entry; earlier entries remain consumed.

func (*Fold) FeedChanges

func (f *Fold) FeedChanges(entries []history.Entry) (Observation, error)

FeedChanges consumes entries with Feed's partial-error semantics and returns detached progress from the pre-feed baseline, after private joins resolve.

func (*Fold) Items

func (f *Fold) Items() []Item

Items returns a creation-ID-ordered snapshot that callers may mutate independently. Claimed delivery rows are represented by their permanent acceptance item.

func (*Fold) Observe

func (f *Fold) Observe() Observation

Observe returns a detached complete baseline. Fold access must be serialized.

func (*Fold) Version

func (f *Fold) Version() uint64

Version is the newest consumed valid history entry ID.

type Item

type Item struct {
	ID, Order, Rev       uint64
	EndedOrder           uint64
	Kind, Session, Agent string
	NoChild              bool
	Turn                 string
	Parent               uint64
	Status               string
	Active, Shown        bool
	Summary, Subtype     string
	Content              json.RawMessage
}

Item is a stable row. Content retains the source kind's saved JSON fields as inert data; NoChild distinguishes explicit no-child provenance from unknown.

type Observation

type Observation struct {
	Snapshot
	FromVersion      uint64
	Changes          []Change
	BaselineRequired bool
}

Observation is either a complete baseline (Items) or progress from FromVersion through Version. BaselineRequired carries no applicable changes: acquire a new baseline. Only usable observations carry epoch, versions or watermark.

type QueryResult

type QueryResult struct {
	State                                SnapshotState
	Items                                []Item
	Epoch                                string
	Version                              uint64
	LowerOrder, UpperOrder, Continuation uint64
	OlderExists                          bool
	FromVersion                          uint64 // exclusive covered bound for nonzero catch-up
	ResetRequired                        bool   // no items or covered/page bounds; acquire a newest window
	Err                                  error
}

QueryResult is detached from one publication. Only StateUsable carries items, epoch, consumed version and bounds. Continuation equals the inclusive lower order; OlderExists certifies an ordered public row strictly below it. Extras do not affect bounds, and Items has no presentation-order guarantee.

type Snapshot

type Snapshot struct {
	Active           bool // includes private unresolved work omitted from Items
	State            SnapshotState
	Items            []Item
	Version          uint64
	LastShownVersion uint64 // latest first shown publication or nonempty shown text append
	Epoch            string
	Err              error
}

Snapshot is a detached view. Only StateUsable carries items, versions and epoch; ErrUnavailable describes recoverable failure without exposing source errors.

type SnapshotState

type SnapshotState uint8

SnapshotState describes whether a conversation has a complete consumed view.

const (
	StateNotLoaded SnapshotState = iota
	StateRebuilding
	StateUsable
	StateUnavailable
)

type Store

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

Store follows raw history for caller-authorized conversations. Construct it with NewStore; all public methods are safe for concurrent use.

func NewStore

func NewStore(h *history.Store, beforeFold ...func(context.Context, conversations.ConversationID) error) *Store

NewStore creates a background cache owner; history is the durable source. Tail notifications cover commits through the supplied history Store only. An optional fold barrier runs before each replay/tail chunk. It must return promptly or honor cancellation; failure withdraws the conversation view.

func (*Store) CatchUp

func (s *Store) CatchUp(ctx context.Context, id conversations.ConversationID, epoch string, afterVersion uint64, limit int) (QueryResult, error)

CatchUp returns current full states touched in (afterVersion, Version], every active public item and complete public parents. The caller must be authorized for id. It neither loads nor waits for recovery nor reads history. Nonzero queries ignore limit; zero selects NewestWindow with its validation and clamp. ResetRequired carries the current epoch/version but no items or covered bounds. Cancellation discards partial results and leaves the worker running.

func (*Store) Changes

func (s *Store) Changes(ctx context.Context, id conversations.ConversationID, epoch string, after uint64) (Observation, error)

Changes waits for progress beyond after in epoch. Only retained publication boundaries establish continuity. Missing ranges, epoch mismatches and suppressed rows require a fresh Observe baseline. Cancellation returns the context error; retirement/failure returns a nonusable observation. No waiter owns a worker.

func (*Store) HistoryPage

func (s *Store) HistoryPage(ctx context.Context, id conversations.ConversationID, upperOrder uint64, limit int) (QueryResult, error)

HistoryPage selects the newest ordered public range below upperOrder, plus complete public parent closure. The caller must already be authorized for id. It does not load, wait for recovery or read history.

func (*Store) Load

Load starts background replay without waiting for history I/O. Repeated loads keep the existing worker, including an unavailable view requiring Retry. ctx governs the loaded worker's lifetime, rather than just the Load call. The caller must already be authorized for id.

func (*Store) NewestWindow

func (s *Store) NewestWindow(ctx context.Context, id conversations.ConversationID, limit int) (QueryResult, error)

NewestWindow selects the newest ordered range below consumed Version+1, plus every active public item and complete public parents of all returned rows. The caller must already be authorized for id.

func (*Store) Observe

Observe acquires a consistent detached baseline without history I/O.

func (*Store) Retry

Retry replaces an unavailable view with fresh replay, discarding all private reader/fold progress. It never replaces a rebuilding or usable worker.

func (*Store) Shutdown

func (s *Store) Shutdown() error

Shutdown closes admission, joins workers and checkpoints every conversation opened in this lifetime, including unloaded ones. Only successful completion certifies epoch reuse on reopen. Concurrent callers share the same result.

func (*Store) Snapshot

func (s *Store) Snapshot(id conversations.ConversationID) Snapshot

Snapshot does no history I/O. Items/content are copied from an immutable publication, keeping their revisions and consumed Version consistent.

func (*Store) Unload

func (s *Store) Unload(id conversations.ConversationID) error

Unload checkpoints complete progress, cancels and joins one worker, and releases all items/private fold state. It does not certify a clean lifetime. Persistence or incomplete recovery failures are returned without source data.

Jump to

Keyboard shortcuts

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