workflow 0.0.1-preview.1
Incremental workflow engine: steps, dependencies, fingerprints, caching, and services
workflow#
An incremental workflow execution engine for Zena: dependency graphs, content fingerprints, cache keys with early cutoff, fine-grained per-output invalidation, and on-demand service lifecycles.
workflow performs no I/O of its own. Hosts supply leaf fingerprints, a digest function, a step cache, and step callbacks; the engine schedules work in dependency order with bounded parallelism and returns the updated state.
Installation#
zena pkg add zena-lang:workflow
Example#
import { NullCache } from 'zena-lang:workflow/cache';
import { Engine, StepSource, Succeeded } from 'zena-lang:workflow/engine';
import { Fingerprint } from 'zena-lang:workflow/fingerprint';
import { Graph } from 'zena-lang:workflow/graph';
import { OutputEntry, OutputManifest } from 'zena-lang:workflow/manifest';
import { EngineState } from 'zena-lang:workflow/state';
import { LeafInput, StepKey, StepOutputs, TaskStep } from 'zena-lang:workflow/step';
let compile = new TaskStep(
new StepKey('compile'),
new Fingerprint('cmd:compile-v1'),
[new LeafInput('src/main.zena')],
async (ctx) => {
return new OutputManifest([
new OutputEntry('out/main.wasm', new Fingerprint('wasm-hash-1')),
]);
},
);
let bundle = new TaskStep(
new StepKey('bundle'),
new Fingerprint('cmd:bundle-v1'),
[new StepOutputs(new StepKey('compile'))],
async (ctx) => {
return new OutputManifest([
new OutputEntry('dist/app.wasm', new Fingerprint('bundle-hash-1')),
]);
},
);
let graph = new Graph([compile, bundle]);
let leaves = {'src/main.zena' => new Fingerprint('src-hash-1')};
let engine = new Engine((data) => new Fingerprint( sha256(data) ), new NullCache());
// First run executes both steps in topological order.
let first = await engine.run(graph, leaves, EngineState.empty());
// Second run with identical inputs and prior state is a no-op (StepSource.Fresh).
let second = await engine.run(graph, leaves, first.state);
Core Concepts#
- Steps and inputs (
workflow/step):TaskStep: runs to completion and returns anOutputManifest.ServiceStep: starts on demand only when a dependent step actually executes, and stops when its last dependent settles (or stays pinned across watch runs in aServicePool).LeafInput(name): a named external input resolved from theleavesmap passed toEngine.run.LeafSet(name, resolve): a lazy input set resolved after upstream dependencies finish (for example, expanding globs over generated files).StepOutputs(step): a dependency on another step whose output manifest (or service identity) enters this step's cache key. Because dependents key on upstream output fingerprints rather than upstream input fingerprints, an upstream step that reruns and produces identical outputs leaves downstream dependents fresh (early cutoff).StepOrder(step): an ordering-only dependency (like Wireit's"cascade": false) that waits for the upstream step without folding its outputs into the dependent's cache key.
- Validated graph (
workflow/graph):Graphchecks that step keys are unique, all referenced steps exist, no step lists duplicate inputs, and the dependency graph is acyclic (reporting the cycle path inWorkflowError), producing a deterministic topological order. - Caching and freshness (
workflow/engine,workflow/cache,workflow/state):- If a step's
CacheKeymatches theStepRecordin the previousEngineState(and optionalRunOptions.verifyOutputssucceeds), the step isStepSource.Freshwithout consulting the cache or starting services. - Otherwise
StepCache.getis checked (StepSource.Cache), falling back to executing the step callback (StepSource.Ran) under the run's parallelism limit.
- If a step's
- Incremental per-output deltas (
workflow/delta,workflow/manifest):- Each
OutputEntryin anOutputManifestcan recorddependsOn(the namespaced inputsleaf:...,step:...it was derived from). - When a step reruns with the same
configfingerprint,RunContextprovidesdelta(changed,added,removed),previous(OutputManifest), andstaleOutputs. The engine verifies before caching that any output carried over as non-stale kept its previous fingerprint.
- Each
Libraries#
workflow/engine—Engine,RunOptions,RunResult,StepOutcome(Succeeded,Failed,Skipped),StepSource,ServicePool, andPinnedService.workflow/step—Step,TaskStep,ServiceStep,StepKey,InputRef(LeafInput,LeafSet,StepOutputs,StepOrder),RunContext,ServiceContext, andServiceHandle.workflow/graph—Graphvalidation and deterministic topological sorting.workflow/manifest—OutputManifestandOutputEntry.workflow/state—EngineStateandStepRecordfor persisting prior-run state across runs.workflow/cache—StepCacheinterface andNullCache.workflow/fingerprint—Fingerprint,CacheKey, andDigest.workflow/canonical— Canonical length-prefixed encodings (cacheKeyFor,manifestFingerprint,ResolvedInput,compareStrings,sortBy).workflow/delta—InputDelta,computeDelta, andstaleOutputNames.workflow/errors—WorkflowError.
License#
MIT
656 bytes
Raw
/**
* A digest of some content, produced by the host — typically a content
* hash of a file, or a digest of configuration. The library compares
* fingerprints and combines them into cache keys; it never computes one
* from raw bytes.
*/
export class Fingerprint(value: String)
/**
* Identifies a cached step result: a digest of the step's config
* fingerprint and its resolved input fingerprints. Derived in
* `canonical.zena`.
*/
export class CacheKey(value: String)
/**
* A host-supplied digest function over canonical encodings. Hosts that
* share a cache must use the same digest.
*/
export type Digest = (data: String) => Fingerprint;
| Version | Published | Dependencies | Approved by |
|---|---|---|---|
| 0.0.1-preview.1 | 2026-11-19 | none |
|