Documentation
¶
Overview ¶
Package resume holds the persistence contract and default implementation for resumable step transcripts. The zenflow root package re-exports these names via type aliases for backward compatibility.
Index ¶
- Constants
- Variables
- type InMemoryTranscriptStore
- func (s *InMemoryTranscriptStore) Append(runID, stepID string, msgs []provider.Message) error
- func (s *InMemoryTranscriptStore) Delete(runID, stepID string) error
- func (s *InMemoryTranscriptStore) Load(runID, stepID string) (*StepTranscript, error)
- func (s *InMemoryTranscriptStore) LoadTruncated(runID, stepID string, maxMessages int) (*StepTranscript, error)
- func (s *InMemoryTranscriptStore) SetMetadata(runID, stepID, systemPrompt, model string)
- type InMemoryTranscriptStoreOption
- type MetadataSetter
- type StepTranscript
- type TranscriptStore
- type TranscriptTruncatedLoader
Constants ¶
const DefaultMaxTranscriptBytes = 50 * 1024 * 1024 // 50 MiB
DefaultMaxTranscriptBytes is the default per-step byte cap applied to InMemoryTranscriptStore when the caller does not override it via WithTranscriptCaps or Orchestrator.WithMaxTranscriptBytes. 50 MiB. Exported so external consumers and the WithMaxTranscriptBytes docstring stay in sync if the value changes. Stable.
const DefaultMaxTranscriptMessages = 10000
DefaultMaxTranscriptMessages is the default per-step message-count cap applied to InMemoryTranscriptStore when the caller does not override it via WithTranscriptCaps or Orchestrator.WithMaxTranscriptMessages. Exported so external consumers and the WithMaxTranscriptMessages docstring stay in sync if the value changes. Stable.
const DefaultTruncatedResumeMessages = 1000
DefaultTruncatedResumeMessages bounds LoadTruncated when the caller doesn't supply an explicit cap.
Variables ¶
var ( // ErrNoTranscript indicates Load found no matching transcript. // Routed to DropReasonNoTranscript by Router.Send when a resume // attempt on a sealed step has no history to restore. ErrNoTranscript = errors.New("zenflow: transcript not found") // ErrTranscriptTooLarge indicates an Append would exceed the // configured cap (WithMaxTranscriptMessages / // WithMaxTranscriptBytes). Routed to DropReasonTranscriptTooLarge. ErrTranscriptTooLarge = errors.New("zenflow: transcript exceeds size cap") )
Sentinel errors returned by TranscriptStore implementations.
Functions ¶
This section is empty.
Types ¶
type InMemoryTranscriptStore ¶
type InMemoryTranscriptStore struct {
// contains filtered or unexported fields
}
InMemoryTranscriptStore is the Day-1 default TranscriptStore. It provides intra-run resume only - transcripts live in memory and disappear when the Executor.Run exits. Cross-run / cross-process resume requires a persistent backend (file or SQLite) wired via WithTranscriptStore. Thread-safety: a single sync.Mutex guards the map and size counters. Append/Load/Delete all take the full lock; this is adequate for the intra-run workload where contention is bounded by the number of concurrent steps.
func NewInMemoryTranscriptStore ¶
func NewInMemoryTranscriptStore() *InMemoryTranscriptStore
NewInMemoryTranscriptStore constructs an empty store using the default caps. Use WithMaxTranscriptMessages / WithMaxTranscriptBytes on the Orchestrator to override.
func NewInMemoryTranscriptStoreWithCaps ¶
func NewInMemoryTranscriptStoreWithCaps(maxMessages int, maxBytes int64) *InMemoryTranscriptStore
NewInMemoryTranscriptStoreWithCaps constructs a store with explicit caps. Zero or negative values fall back to the defaults. Primarily used internally by the Orchestrator factory path; external callers typically use NewInMemoryTranscriptStoreWithOptions + WithTranscriptCaps.
func NewInMemoryTranscriptStoreWithOptions ¶
func NewInMemoryTranscriptStoreWithOptions(opts ...InMemoryTranscriptStoreOption) *InMemoryTranscriptStore
NewInMemoryTranscriptStoreWithOptions constructs a store with the default caps and then applies each option in order. Use WithTranscriptCaps to override caps. Stable.
func (*InMemoryTranscriptStore) Append ¶
func (s *InMemoryTranscriptStore) Append(runID, stepID string, msgs []provider.Message) error
Append implements TranscriptStore. Cap enforcement is atomic: the new byte/message totals are computed up front, and if they would exceed the cap the append is rejected with ErrTranscriptTooLarge - no partial mutation.
func (*InMemoryTranscriptStore) Delete ¶
func (s *InMemoryTranscriptStore) Delete(runID, stepID string) error
Delete implements TranscriptStore. Idempotent.
func (*InMemoryTranscriptStore) Load ¶
func (s *InMemoryTranscriptStore) Load(runID, stepID string) (*StepTranscript, error)
Load implements TranscriptStore. The returned transcript is a defensive copy (the Messages slice is duplicated) so the caller can mutate it freely.
func (*InMemoryTranscriptStore) LoadTruncated ¶
func (s *InMemoryTranscriptStore) LoadTruncated(runID, stepID string, maxMessages int) (*StepTranscript, error)
LoadTruncated implements TranscriptTruncatedLoader. Returns up to maxMessages tail messages regardless of whether the slot was sealed. Used by ResumeStep when WithTruncationOnCapReached is enabled so a sealed transcript can still be resumed from a truncated prefix. VA-3b.
func (*InMemoryTranscriptStore) SetMetadata ¶
func (s *InMemoryTranscriptStore) SetMetadata(runID, stepID, systemPrompt, model string)
SetMetadata records the system prompt + model identifier for a transcript. Called by AgentRunner on the first Append so a later Resume can reconstruct the invocation. Idempotent: the values are overwritten each call (the last Run wins), which matches the expectation that a single AgentRunner instance serves a single step per Run.
type InMemoryTranscriptStoreOption ¶
type InMemoryTranscriptStoreOption func(*InMemoryTranscriptStore)
InMemoryTranscriptStoreOption is a functional option for NewInMemoryTranscriptStoreWithOptions. Stable.
func WithTranscriptCaps ¶
func WithTranscriptCaps(maxMessages int, maxBytes int64) InMemoryTranscriptStoreOption
WithTranscriptCaps sets the per-store message-count and byte caps. Zero or negative values are ignored (defaults apply). Use as an argument to NewInMemoryTranscriptStoreWithOptions. Stable.
type MetadataSetter ¶
type MetadataSetter interface {
SetMetadata(runID, stepID, systemPrompt, model string)
}
MetadataSetter is an optional extension implemented by transcript stores that persist the system prompt + model identifier. AgentRunner calls SetMetadata on first Append when the store implements this interface. Implementations that don't need metadata persistence (e.g., transient test stubs) can omit it. Stable.
type StepTranscript ¶
type StepTranscript struct {
StepID string
RunID string
Messages []provider.Message
SystemPrompt string
Model string // "provider:model-id" - consumer reconstructs
SavedAt time.Time
}
StepTranscript is the persisted conversation state for a single step. SystemPrompt + Model are captured at Run start so a resume can reconstruct the exact invocation.
type TranscriptStore ¶
type TranscriptStore interface {
// Append adds messages to stepID's transcript under runID. Returns
// ErrTranscriptTooLarge when the transcript would exceed the
// configured size cap. On cap-exceeded the returned
// error wraps ErrTranscriptTooLarge and the messages ARE NOT
// appended - the caller should surface the cap to the router so it
// can emit DropReasonTranscriptTooLarge.
Append(runID, stepID string, msgs []provider.Message) error
// Load returns the full transcript for (runID, stepID). Returns
// ErrNoTranscript when no transcript exists. Returns
// ErrTranscriptTooLarge when a prior Append hit the cap and sealed
// the slot - callers (Router via Executor.ResumeStep) MUST surface
// DropReasonTranscriptTooLarge rather than resuming from a
// truncated history. The returned *StepTranscript is a defensive
// copy - callers may mutate the Messages slice without affecting
// the store.
Load(runID, stepID string) (*StepTranscript, error)
// Delete removes a transcript. Idempotent: returns nil if no
// transcript exists.
Delete(runID, stepID string) error
}
TranscriptStore is the persistence contract for resumable step transcripts. Implementations MUST be safe for concurrent Append from a single AgentRunner; Load/Delete are called from the executor's Resume path and may race with Appends on a LIVE step (see serial queue - resumes of a step that is still running are not permitted; the step must have reached terminal state before Router.Send triggers resume).
type TranscriptTruncatedLoader ¶
type TranscriptTruncatedLoader interface {
// LoadTruncated returns up to maxMessages tail messages from the
// sealed transcript. Returns ErrNoTranscript when no transcript
// exists. Never returns ErrTranscriptTooLarge - the whole point
// is to bypass the seal.
LoadTruncated(runID, stepID string, maxMessages int) (*StepTranscript, error)
}
TranscriptTruncatedLoader is an optional extension implemented by transcript stores that can surface a truncated view of a sealed transcript. When a store implements this interface AND the Executor's TruncateOnCapReached option is enabled, ResumeStep falls back to LoadTruncated after a sealed-slot Load returns ErrTranscriptTooLarge - preserving operability at the cost of potentially-incomplete history. VA-3b.