durable

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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)

  1. 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.
  2. Block and gate for NON_IDEMPOTENT_WRITE still uses the NodeLog (TOOL_CALL at step+seq) as source of truth, not backend internals alone.
  3. Do not implement custom lease, heartbeat, or retry loops outside this package and a real Temporal/Restate driver.

Index

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.

func Tool

func Tool(ctx context.Context, b Backend, workflowID, name string, fn func(context.Context) (any, error)) (any, error)

Tool is Step with a conventional step key prefix for tool calls.

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.

func (*LocalSQLite) Close

func (s *LocalSQLite) Close() error

Close implements Backend.

func (*LocalSQLite) Load

func (s *LocalSQLite) Load(ctx context.Context, workflowID, stepKey string) ([]byte, bool, error)

Load implements Backend.

func (*LocalSQLite) Save

func (s *LocalSQLite) Save(ctx context.Context, workflowID, stepKey string, value []byte) error

Save implements Backend. First writer wins (INSERT OR IGNORE).

type Memory

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

Memory is a test fake Backend, not a durable execution engine integration. Fine for unit tests. Does not survive process exit. See issue #92.

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty Memory backend.

func (*Memory) Close

func (m *Memory) Close() error

Close implements Backend.

func (*Memory) Load

func (m *Memory) Load(_ context.Context, workflowID, stepKey string) ([]byte, bool, error)

Load implements Backend.

func (*Memory) Save

func (m *Memory) Save(_ context.Context, workflowID, stepKey string, value []byte) error

Save implements Backend. First writer wins.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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