Documentation
¶
Overview ¶
Package durable is the Go pluggable execution backend for Trajectory IR.
Decision (issue #16)
Coding default: LocalSQLite (and Memory for pure unit tests). Both are test fakes: a hand rolled first writer wins memoization store, not an integration with a real durable execution engine. They memoize step results by workflow id and step key so re-entry skips re-running model inference and tools, which is enough for Phase 1B Go development and the current conformance suite, but neither should be treated as a production backend. See issue #92 for the open question on wiring trajir/durable into a real DBOS or Restate client, tracked alongside #67. Production target: Temporal as the first full Go adapter (go/trajir/durable/temporal, issue #24). Restate remains a welcome second adapter later, consistent with the master README.
Rules (same as Python + DBOS)
- Model inference and tool calls must run through Step (or a backend wrapper that provides the same memoization). Never call them raw inside a workflow body if crash resume must not re-invoke them.
- Block and gate for NON_IDEMPOTENT_WRITE still uses the NodeLog (TOOL_CALL at step+seq) as source of truth, not backend internals alone.
- Do not implement custom lease, heartbeat, or retry loops outside this package and a real Temporal/Restate driver.
Index ¶
- func Infer(ctx context.Context, b Backend, workflowID, name string, ...) (any, error)
- func Step(ctx context.Context, b Backend, workflowID, stepKey string, ...) (any, error)
- func Tool(ctx context.Context, b Backend, workflowID, name string, ...) (any, error)
- type Backend
- type LocalSQLite
- type Memory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Infer ¶
func Infer(ctx context.Context, b Backend, workflowID, name string, fn func(context.Context) (any, error)) (any, error)
Infer is Step with a conventional step key prefix for model calls.
func Step ¶
func Step(ctx context.Context, b Backend, workflowID, stepKey string, fn func(context.Context) (any, error)) (any, error)
Step runs fn once per (workflowID, stepKey). On later calls it returns the memoized JSON decoded into result, without calling fn.
result must be a pointer if non-nil when loading a prior value. When fn runs, its return value is JSON marshaled. Use map[string]any or concrete structs that encode cleanly.
Types ¶
type Backend ¶
type Backend interface {
// Load returns the saved JSON for workflowID+stepKey if present.
Load(ctx context.Context, workflowID, stepKey string) (value []byte, found bool, err error)
// Save stores JSON for workflowID+stepKey. Saving twice with the same key
// should be idempotent (keep first value).
Save(ctx context.Context, workflowID, stepKey string, value []byte) error
// Close releases resources. Safe to call more than once.
Close() error
}
Backend stores memoized step outputs for a workflow id. Temporal and Restate drivers will implement this later; LocalSQLite and Memory implement it for Phase 1B coding and tests.
type LocalSQLite ¶
type LocalSQLite struct {
// contains filtered or unexported fields
}
LocalSQLite is the Phase 1B coding default Backend. It is a test fake, a hand rolled first writer wins memoization store, not an integration with a real durable execution engine; see issue #92. Step memos survive process restart when the same database path is reopened (needed for crash style tests later).
func OpenLocal ¶
func OpenLocal(path string) (*LocalSQLite, error)
OpenLocal opens or creates a SQLite memo database at path.