durableworkflow

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 0 Imported by: ? 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.

README

Durable Workflow Go SDK

Quality Gate CI

Go SDK preview. v0.1.0 is the first installable preview of the Go SDK for Durable Workflow. Use it for development and evaluation. The API may change before v1.

The module path is go.durable-workflow.com/sdk.

Source qualification covers the Native quickstart, typed Avro payloads, and live and offline replay of selected workflow histories. Cross-release replay, the full decode-recovery matrix, and the installed worker lifecycle matrix remain gates for leaving preview. Preview qualification

Run your first workflow

Use Go 1.26 or 1.27 and Durable Workflow CLI 2.15.0. On Linux x86-64, download and verify the CLI in one command.

curl -fsSLo dw https://github.com/durable-workflow/cli/releases/download/2.15.0/dw-linux-x86_64 && printf '%s  dw\n' 25429832996332d2e9cf15be084cc15156ab8afca878bbdeb33eb6197d77f221 | sha256sum -c - && chmod +x dw

In a Bash terminal, start the development server with a private token file and let it choose a free loopback port.

workdir=$(mktemp -d)
printf '%s\n' "$workdir"
(umask 077; openssl rand -hex 24 > "$workdir/token")
./dw server:start-dev --host=127.0.0.1 --port=0 --db=sqlite \
  --data-dir="$workdir/data" --token-file="$workdir/token"

From this checkout in a second terminal, run the sample. Substitute the path printed in the first terminal for /path/to/workdir. Set DW_ENDPOINT to the listening address shown by the server.

DW_ENDPOINT="http://127.0.0.1:PORT" DW_AUTH_TOKEN="$(cat /path/to/workdir/token)" go run ./examples/firstworkflow

The program registers a Go worker, starts a selected run, completes its workflow task and prints Hello, Durable Workflow!. An unavailable server returns an error that includes its address. Stop the development server with Ctrl+C when finished.

Once the preview tag is published, copy examples/firstworkflow/main.go into an empty directory to run the sample with the installed Go SDK.

go mod init hello-workflow
go get go.durable-workflow.com/sdk@v0.1.0
DW_ENDPOINT="http://127.0.0.1:PORT" DW_AUTH_TOKEN="$(cat /path/to/workdir/token)" go run .

Documentation

Update input and replay failures

If the worker cannot decode the arguments of a newly claimed update or bind them to the handler's input type, it fails the update before calling the handler. The worker reports update_argument_decode_failed with a fixed message and the run continues. The client exposes failure information through *client.UpdateFailedError, including FailureID and FailureMessage.

On Native Server 3.35.0 the caller receives a failure ID and message. The exception type appears in the unprotected UpdateCompleted history event only. With payload protection, Native records ProtectedUpdateFailed and returns “Protected update execution failed.” Server #1508 tracks preserving the fixed code for protected failures.

When replay cannot decode or bind a committed update, the worker faults the workflow task with payload_type_mismatch and the recorded history sequence. A missing handler produces update_handler_unavailable. A compatible worker can resume the same run in either case. During replay of a recorded success, a handler error or panic, a result encoding failure or a changed result produces recorded_command_detail_mismatch, which blocks replay and requires repair.

Prototype qualification on Native 3.33.2 · Shared recovery fixture

Goals

These rules guide the SDK. The qualification plan records the test evidence and the conditions for leaving preview.

Names and types are the contract.

  • Every workflow, activity, signal, query and update is bound to an explicit wire name through a typed reference, Ref[In, Out], with one input struct and one result.
  • A per-worker registry accepts closures and instantiated generic functions through named references. It requires a struct input, a non-nil handler and UTF-8 wire names and aliases of 1 to 255 bytes. It reports both registration sites for a duplicate name or alias collision before polling.
  • Names are never derived from Go function symbols, and definition identity is never a binary hash.

Determinism is the SDK's own job, and fixtures prove it.

  • Workflow tasks replay cold. The SDK owns the start and teardown of each task's goroutines, and tests run under -race with leak checks.
  • Every runtime ordering is specified and fixture-tested.
  • Runtime behaviour changes are recorded in history and gated across releases.
  • Patched and DeprecatePatch handle code changes. The live worker and the offline replayer share one matcher and one registry.
  • Payload decode failures, replay drift and workflow panics are recoverable task failures.

Go-native and light.

  • The core package imports only the Go standard library and a hand-written Avro Value codec. CI enforces this dependency budget with go list -deps.
  • A client package never imports worker code.
  • APIs use context, errors.As targets, log/slog, and Run(ctx) and Stop(ctx), which return once the worker has drained.
  • Errors cross process boundaries as data: type, message, non-retryable flag and details. Go errors retain a local cause. Non-retryable is honoured anywhere in a wrap chain.
  • Concrete client and handle types. Interfaces exist only for extension points.
  • Testing helpers, the static analyzer and OpenTelemetry live in separate modules.
  • No protobuf, gRPC or MD5.
  • Tests run on the worker's own engine and against dw server:start-dev, not on a separate simulator.

Payloads

Workflow payloads use the shared Durable Workflow Avro Value schema with single-object framing, the same wire format as the PHP, Python and Rust SDKs. The Go codec in the avro package is hand-written, matches the shared golden vectors and malformed frames byte for byte, and maps Go values to and from the eight schema branches. See the mapping design note.

Metrics

Set client.Config.Metrics or worker.RegistrationConfig.Metrics to a metrics.Recorder to receive the shared client and worker counters and seconds histograms. The recorder receives bounded route templates such as /workflows/{workflow_id}/runs/{run_id}. Use a bounded set of worker queue names to control label cardinality. Schedule-to-start samples come from the Server's negotiated ready age at workflow or activity dispatch. Configure the worker's recorder on its own registration. Omit the recorder to disable recording. An interface holding a typed nil still counts as configured. Shared metric names and labels

Supported Go versions

The SDK supports the two most recent major Go releases, matching the Go project's own release policy. Today that is Go 1.26 and Go 1.27.

  • go.mod declares the older supported release (go 1.26). The SDK does not use language features or standard-library APIs newer than that release.
  • CI runs vet, the race-enabled tests and the golden vectors on both supported releases.
  • When a new major Go release ships, CI adds it, and a later SDK release raises the go directive to drop the release that left Go's support window. That change is recorded in the changelog.
  • The Go version floor follows this policy, never a dependency: the core module has no third-party dependencies.

Development

gofmt -l .
go vet ./...
go test -race ./...
scripts/ci/check-dependency-budget.sh

See CONTRIBUTING.md for the review and fixture rules.

Security

See SECURITY.md.

License

MIT

Documentation

Overview

Package durableworkflow is the Go SDK for Durable Workflow.

This module is a pre-release design prototype written against the published Durable Workflow protocol. Its API is not stable, it has no release, and it must not be used in production.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityError added in v0.2.0

type ActivityError struct {
	ActivityType        string
	ActivityExecutionID string
	AttemptID           string
	FailureID           string
	// TimeoutKind is the recorded deadline kind for a terminal timeout.
	TimeoutKind string
	Cause       *ApplicationError
}

ActivityError is a terminal failure returned by a recorded workflow activity. Cause carries the application failure from Server history. A terminal timeout sets TimeoutKind and leaves Cause nil.

func (*ActivityError) Error added in v0.2.0

func (*ActivityError) Error() string

func (*ActivityError) Unwrap added in v0.2.0

func (err *ActivityError) Unwrap() error

Unwrap exposes the recorded application failure to errors.As.

type ActivityRef

type ActivityRef[In, Out any] struct{ Ref[In, Out] }

ActivityRef is a typed reference to an activity.

func Activity

func Activity[In, Out any](name string) ActivityRef[In, Out]

Activity names an activity with one input struct and one result.

type ApplicationError

type ApplicationError struct {
	Type         string
	Message      string
	NonRetryable bool
	Details      any
	Cause        error
}

ApplicationError is a failure with a portable type and retry decision. Details use the SDK payload mapping. Cause is available through Go's errors.Is and errors.As within the process.

func (*ApplicationError) Error

func (err *ApplicationError) Error() string

func (*ApplicationError) Unwrap

func (err *ApplicationError) Unwrap() error

Unwrap returns the local cause of the application error.

type QueryRef

type QueryRef[In, Out any] struct{ Ref[In, Out] }

QueryRef is a typed reference to a read-only workflow query.

func Query

func Query[In, Out any](name string) QueryRef[In, Out]

Query names a query with one input struct and one result.

type Ref

type Ref[In, Out any] struct {
	// contains filtered or unexported fields
}

Ref identifies an operation with input type In and result type Out. The wire name is part of the durable contract and must remain stable when a Go function moves or is renamed.

func (Ref[In, Out]) Name

func (r Ref[In, Out]) Name() string

Name returns the explicit wire name of the operation.

type SignalRef

type SignalRef[In any] struct{ Ref[In, Unit] }

SignalRef is a typed reference to a workflow signal.

func Signal

func Signal[In any](name string) SignalRef[In]

Signal names a signal with one input struct and no result.

type Unit

type Unit struct{}

Unit is the result type for operations that return no value.

type UpdateRef

type UpdateRef[In, Out any] struct{ Ref[In, Out] }

UpdateRef is a typed reference to a workflow update.

func Update

func Update[In, Out any](name string) UpdateRef[In, Out]

Update names an update with one input struct and one result.

type WorkflowRef

type WorkflowRef[In, Out any] struct{ Ref[In, Out] }

WorkflowRef is a typed reference to a workflow.

func Workflow

func Workflow[In, Out any](name string) WorkflowRef[In, Out]

Workflow names a workflow with one input struct and one result.

Example
issueInvoice := durableworkflow.Workflow[invoiceInput, invoiceResult]("billing.issue-invoice")
fmt.Println(issueInvoice.Name())
Output:
billing.issue-invoice

Directories

Path Synopsis
Package avro implements the Durable Workflow Avro Value codec.
Package avro implements the Durable Workflow Avro Value codec.
Package client provides the control-plane client for Durable Workflow.
Package client provides the control-plane client for Durable Workflow.
examples
firstworkflow command
integrations
laravel module
internal
names
Package names validates names shared by the control plane and worker.
Package names validates names shared by the control plane and worker.
transport
Package transport sends versioned Durable Workflow HTTP requests.
Package transport sends versioned Durable Workflow HTTP requests.
workflowcontext
Package workflowcontext holds the context state supplied by the workflow engine.
Package workflowcontext holds the context state supplied by the workflow engine.
Package metrics defines the shared Durable Workflow SDK instruments.
Package metrics defines the shared Durable Workflow SDK instruments.
otel module
scripts
conformance/worker_lifecycle/sigterm command
Command sigterm exercises an activity worker draining on SIGTERM against a disposable Native server.
Command sigterm exercises an activity worker draining on SIGTERM against a disposable Native server.
Package worker registers handlers for Durable Workflow tasks.
Package worker registers handlers for Durable Workflow tasks.
internal/failure
Package failure prepares worker failure reports.
Package failure prepares worker failure reports.
Package workflow provides replay-safe types for workflow and handler code.
Package workflow provides replay-safe types for workflow and handler code.
workflowtest module

Jump to

Keyboard shortcuts

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