Skip to content
Source
Sign inSign up
TanStack/workflow

feat(workflow-core)!: closure engine + middleware + docs + supply-chain audit #2

Mergedtannerlinsleymerged 10 commits intomain fromrefs/pull/2/headmerged by tannerlinsley

tannerlinsleycommented

Summary

Consolidates seven commits that establish @tanstack/workflow-core as a closure-based durable execution engine, with end-to-end inference, ported examples from Alem's PR #542 and Kyle Mathews's RFC + gist, recipe-style docs, and a supply-chain hardening pass against TanStack/query's current baseline.

What's in the PR

CommitWhat
feat(run-core)Initial engine extraction from @tanstack/ai-orchestration (TanStack/ai#542). AI-specific surface (agents, orchestrators) left in ai-orchestration; pure workflow primitives lifted to @tanstack/run-core.
chore(workflow-core)Rename @tanstack/run-core → @tanstack/workflow-core.
feat(workflow-core)!BREAKING: rewrite engine around closure handler + ctx-as-arg + typed middleware. Drop generator API + source-text fingerprinting + patched. Unified WorkflowEvent log. Webhook entry point alongside runWorkflow.
feat(workflow-core)Lock the inference contract: handler return narrows WorkflowOutput<typeof wf>; add WorkflowInput / WorkflowOutput / WorkflowState helper types; 14 expectTypeOf assertions.
test(workflow-core)Port Alem's article + orchestrator demos and Kyle's expense + AI-agent + durable-agent examples as live tests; pick up Alem's deferred engine.attach + engine.publisher tests.
docs(workflow-core)Recipe-style docs (overview, quick-start, primitives, middleware, replay-and-resume); README rewrite; WorkflowCtx helper alias.
choreSupply-chain hardening: zizmor + CODEOWNERS + SHA-pinned actions + workflow-level permissions: {} + persist-credentials: false; fix root package.json template refs; drop TEMPLATE_GUIDE.md.

Test plan

  • pnpm install — lockfile clean
  • pnpm exec tsc --noEmit from packages/workflow-core — clean
  • pnpm test:eslint from packages/workflow-core — clean
  • pnpm build (tsdown + publint --strict) from packages/workflow-core — clean
  • pnpm test:lib from packages/workflow-core — 102 / 102 across 21 files
  • zizmor .github/workflows/ — no findings at default severity
  • CI green (verified by reviewer)

Breaking changes

This is the first published version, so no upgrade-from-prior-version path is needed. For developers tracking the prototype on the feat/durable-workflows branch of TanStack/ai, the shape changes are documented in docs/concepts/ and migration is a clean rewrite — generator workflows don't auto-translate.

Summary by CodeRabbit

  • New Features

    • Launched durable workflow execution engine with automatic replay and pause-resume capabilities
    • Added workflow definition builders, middleware system for typed context extensions, and event-sourced state reconstruction
    • Introduced approval-based pausing and signal-based resuming for external control flow
  • Documentation

    • Added comprehensive guides covering workflow primitives, middleware composition, and replay/resume semantics
    • Provided quick-start recipes and installation instructions for the new workflow core
  • Chores

    • Enhanced GitHub Actions security with stricter permissions and pinned action versions
    • Added automated security analysis workflow

Review Change Stack

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Caution

      Review failed

      The pull request is closed.

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: b01a89a6-0345-4706-bbe9-77d04314340b

      📥 Commits

      Reviewing files that changed from the base of the PR and between 0d398f936b61cb73a80dc08d81edbee7ffefe605 and 334cf5f3da2e80dce4211def585b9a287e2f93e5.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (66)
      • .gitattributes
      • .github/CODEOWNERS
      • .github/workflows/autofix.yml
      • .github/workflows/pr.yml
      • .github/workflows/release.yml
      • .github/workflows/zizmor.yml
      • TEMPLATE_GUIDE.md
      • docs/concepts/middleware.md
      • docs/concepts/primitives.md
      • docs/concepts/replay-and-resume.md
      • docs/config.json
      • docs/framework/react/adapter.md
      • docs/framework/react/reference/functions/useTemplate.md
      • docs/framework/react/reference/index.md
      • docs/framework/solid/adapter.md
      • docs/framework/solid/reference/functions/createTemplateSignal.md
      • docs/framework/solid/reference/index.md
      • docs/installation.md
      • docs/overview.md
      • docs/quick-start.md
      • docs/reference/classes/Template.md
      • docs/reference/functions/createTemplate.md
      • docs/reference/index.md
      • docs/reference/interfaces/TemplateOptions.md
      • package.json
      • packages/workflow-core/README.md
      • packages/workflow-core/eslint.config.js
      • packages/workflow-core/package.json
      • packages/workflow-core/src/define/define-workflow.ts
      • packages/workflow-core/src/engine/handle-webhook.ts
      • packages/workflow-core/src/engine/run-workflow.ts
      • packages/workflow-core/src/engine/state-diff.ts
      • packages/workflow-core/src/index.ts
      • packages/workflow-core/src/middleware/create-middleware.ts
      • packages/workflow-core/src/registry/select-version.ts
      • packages/workflow-core/src/result.ts
      • packages/workflow-core/src/run-store/in-memory.ts
      • packages/workflow-core/src/server/index.ts
      • packages/workflow-core/src/server/parse-request.ts
      • packages/workflow-core/src/types.ts
      • packages/workflow-core/tests/engine.attach.test.ts
      • packages/workflow-core/tests/engine.cas.test.ts
      • packages/workflow-core/tests/engine.durability.test.ts
      • packages/workflow-core/tests/engine.idempotency.test.ts
      • packages/workflow-core/tests/engine.primitives.test.ts
      • packages/workflow-core/tests/engine.publisher.test.ts
      • packages/workflow-core/tests/engine.retry.test.ts
      • packages/workflow-core/tests/engine.signals.test.ts
      • packages/workflow-core/tests/engine.smoke.test.ts
      • packages/workflow-core/tests/engine.timeout.test.ts
      • packages/workflow-core/tests/examples.alem-article.test.ts
      • packages/workflow-core/tests/examples.alem-orchestrator.test.ts
      • packages/workflow-core/tests/examples.kyle-ai-agent.test.ts
      • packages/workflow-core/tests/examples.kyle-durable-agent.test.ts
      • packages/workflow-core/tests/examples.kyle-expense.test.ts
      • packages/workflow-core/tests/in-memory-store.test.ts
      • packages/workflow-core/tests/inference.test.ts
      • packages/workflow-core/tests/middleware.test.ts
      • packages/workflow-core/tests/parse-request.test.ts
      • packages/workflow-core/tests/registry.test.ts
      • packages/workflow-core/tests/state-diff.test.ts
      • packages/workflow-core/tests/test-utils.ts
      • packages/workflow-core/tsconfig.docs.json
      • packages/workflow-core/tsconfig.json
      • packages/workflow-core/tsdown.config.ts
      • packages/workflow-core/vitest.config.ts

      📝 Walkthrough

      Walkthrough

      Adds a new @tanstack/workflow-core package (types, builder, engine, run-store, registry, server helpers), extensive docs and examples, CI hardening and packaging, and comprehensive tests exercising durable replay/pause/resume primitives.

      Changes

      Repository & CI Hardening

      Layer / File(s)Summary
      Repository and CI configuration updates
      .gitattributes, .github/CODEOWNERS, .github/workflows/autofix.yml, .github/workflows/pr.yml, .github/workflows/release.yml, .github/workflows/zizmor.yml
      Normalize LF endings, add CODEOWNERS, pin actions to SHAs, tighten workflow token permissions, remove doc regen step, and add Zizmor security workflow.

      Documentation

      Layer / File(s)Summary
      Workflow concepts & guides
      docs/concepts/primitives.md, docs/concepts/middleware.md, docs/concepts/replay-and-resume.md, docs/overview.md, docs/quick-start.md, docs/installation.md, docs/config.json
      Add primitives, middleware, replay/resume concepts, overview, quick-start recipes, installation notes, and update docs config for workflow site.

      Core Package Implementation

      Layer / File(s)Summary
      Type system
      packages/workflow-core/src/types.ts
      New central type definitions: schema helpers, WorkflowEvent union, checkpoint events, Step/Wait/Approve contracts, Ctx/WorkflowCtx, RunStore and RunState, SignalDelivery, public errors.
      Workflow builder & middleware
      packages/workflow-core/src/define/define-workflow.ts, packages/workflow-core/src/middleware/create-middleware.ts
      createWorkflow fluent builder with middleware accumulation and reserved-field checks; createMiddleware() server builder for typed ctx extensions.
      Persistence & registry
      packages/workflow-core/src/run-store/in-memory.ts, packages/workflow-core/src/registry/select-version.ts
      inMemoryRunStore with TTL and CAS appendEvent, event retrieval and subscribe; selectWorkflowVersion and createWorkflowRegistry for version routing.
      Execution engine
      packages/workflow-core/src/engine/run-workflow.ts
      runWorkflow async-generator implementing start/resume/attach, driveHandler replay loop, durable primitives (step, waitForEvent, approve, now, uuid), state diffs, middleware composition, abort handling, and seed append for resume idempotency/loss.
      Supporting helpers
      packages/workflow-core/src/engine/handle-webhook.ts, packages/workflow-core/src/engine/state-diff.ts, packages/workflow-core/src/result.ts, packages/workflow-core/src/server/parse-request.ts
      Webhook handler collecting events, state diff (RFC6902-style with undefined→null), succeed/fail result helpers, and request parsing with signal/approval normalization and parse errors.
      Public API & package
      packages/workflow-core/src/index.ts, packages/workflow-core/package.json, packages/workflow-core/tsdown.config.ts, packages/workflow-core/tsconfig.json, packages/workflow-core/vitest.config.ts, packages/workflow-core/eslint.config.js, packages/workflow-core/README.md
      Barrel exports, package metadata, build config, test and lint configs, and README with examples.

      Testing

      Layer / File(s)Summary
      Test utilities
      packages/workflow-core/tests/test-utils.ts
      collect(), findRunId(), simulateRestart() helpers.
      Engine & integration tests
      packages/workflow-core/tests/*.test.ts
      Extensive Vitest suites covering smoke, primitives (step/now/uuid), retry/timeout, signals/sleep, approval pause/resume, idempotency/CAS, durability/replay, attach mode, publisher forwarding, in-memory store, registry selection, parse request errors, state-diff normalization, middleware composition, and compile-time type inference.
      Example workflows
      packages/workflow-core/tests/examples.*.test.ts
      Real-world example tests: article review, feature orchestrator, AI agent, durable agent, expense approval, illustrating engine features and patterns.

      🎯 4 (Complex) | ⏱️ ~60 minutes

      🐰 A durable engine blooms, events flow like streams, Pause and resume bring resilient dreams, Type-safe workflows dance through middleware's grace, TanStack Workflow claims its rightful place! ✨🌿

      ✨ Finishing Touches
      📝 Generate docstrings
      • Create stacked PR
      • Commit on current branch
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Changeset Version Preview

      No changeset entries found. Merging this PR will not cause a version bump for any packages.

    3. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @tanstack/react-template

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/react-template@2

      @tanstack/react-template-devtools

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/react-template-devtools@2

      @tanstack/solid-template

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/solid-template@2

      @tanstack/solid-template-devtools

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/solid-template-devtools@2

      @tanstack/template

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/template@2

      @tanstack/template-devtools

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/template-devtools@2

      @tanstack/workflow-core

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-core@2

      commit: 334cf5f

    4. tannerlinsley merged thisa443f75

    5. tannerlinsley closed this

Sign in to join this conversation.