Documentation
¶
Overview ¶
Package thread folds raw history facts into conversation-owned thread items.
Index ¶
- Constants
- Variables
- type Change
- type Fold
- type Item
- type Observation
- type QueryResult
- type Snapshot
- type SnapshotState
- type Store
- func (s *Store) CatchUp(ctx context.Context, id conversations.ConversationID, epoch string, ...) (QueryResult, error)
- func (s *Store) Changes(ctx context.Context, id conversations.ConversationID, epoch string, ...) (Observation, error)
- func (s *Store) HistoryPage(ctx context.Context, id conversations.ConversationID, upperOrder uint64, ...) (QueryResult, error)
- func (s *Store) Load(ctx context.Context, id conversations.ConversationID) error
- func (s *Store) NewestWindow(ctx context.Context, id conversations.ConversationID, limit int) (QueryResult, error)
- func (s *Store) Observe(id conversations.ConversationID) Observation
- func (s *Store) Retry(ctx context.Context, id conversations.ConversationID) error
- func (s *Store) Shutdown() error
- func (s *Store) Snapshot(id conversations.ConversationID) Snapshot
- func (s *Store) Unload(id conversations.ConversationID) error
Constants ¶
const MaxCatchUpGap = 1024
MaxCatchUpGap is the inclusive maximum consumed history-ID distance for catch-up.
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 ¶
var ( ErrClosed = errors.New("thread: store is shut down") ErrUnloading = errors.New("thread: conversation is unloading") ErrNotLoaded = errors.New("thread: conversation is not loaded") )
var ErrInvalidLimit = errors.New("thread: query limit must be positive")
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 (*Fold) Feed ¶
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 ¶
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.
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 ¶
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 )
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 ¶
func (s *Store) Load(ctx context.Context, id conversations.ConversationID) error
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 ¶
func (s *Store) Observe(id conversations.ConversationID) Observation
Observe acquires a consistent detached baseline without history I/O.
func (*Store) Retry ¶
func (s *Store) Retry(ctx context.Context, id conversations.ConversationID) error
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 ¶
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.