feat: durable workflows engine runtime - #7
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The engine runtime — the layer that ties the authoring surface + execution host to a persistence store, exposing the full instance lifecycle:
durableWorkflows({ store, plugins?, alias?, sandbox?, limits?, onEvent? })→DurableWorkflowsEnginewithcreate,get,continueWorkflow,terminate,evict,restart,dispose,pendingPromises.memoryStore()— the in-memory referenceWorkflowStoreadapter (with adeployseeding helper standing in for the app's deploy layer).How it works
Every lifecycle call is one replay turn: load the instance record + boundary cache from the store → resolve the pinned definition version via the store's
getDefinition→ hydrate (cached per pinned version) a runner mounted with the plugin shims +aliasre-export modules → execute with per-run handlers → persist the grown cache + new status → return aRunOutcome.Design decisions
getDefinition(name)answers "what should a new instance get";getDefinition(name, pinnedVersion)the exact code for a replay. Writing definitions (upload/versioning/rollback) is deliberately the application's deploy layer against the same backend — contract: a handed-out(name, version)stays fetchable and byte-identical while instances pin it.durable-workflows:internaloperationshim forwards its boundary key as the leading arg (durableCall(key, name, key, ...args)); the engine strips it and hands plugin handlers the structuredDurableHandlerInput{ instanceId, workflow, run, stepId, payload }withpayload= the full forwarded argument list.evictremoves the boundary, everything after it byseq, AND its key-prefix subtree (a scope's children commit before the scope, so a seq-only prune would leave them cached).options.limits← per-definitionlimits.RunErrorlifted intoSerializedError { name, message, stack?, data?, class? };classpicked up only if a plugin attached apermanent/transientverdict.Tests
tests/engine.test.tsdrives the whole chain end-to-end (engine → shims → real kernel sandbox → handlers): create + version pinning, idempotent create, handler-input shape, suspend → continue, resume on a fresh engine against the pinned version, evict/restart, terminate, failure mapping, alias whitelabeling,onEvent+pendingPromises, definition immutability. 46 tests green across both packages; build/lint/typecheck clean.Docs
AGENTS.md(three shipped layers, architecture tree, exports) and the packageREADME.md(new "Running workflows: the engine" section) updated; changeset included (durable-workflows, minor).