Harden runtime lease recovery and event publishing #15
main fromtaren/runtime-lease-recovery·merged by tannerlinsley What changed#
- heartbeat active run leases while the runtime is driving workflow code
- recover expired running executions during
sweep()by replaying durable checkpoints - add best-effort live event publishing at runtime and per-call scope
- expose recovered sweep results and limits
- cover initialized and pre-initialization crash recovery across runtime and store contracts
Why#
The execution-store contract already supported lease heartbeats and stale-run claims, but the runtime driver did not use them. A worker crash could therefore leave a run stuck as running, while long steps could outlive their lease. The runtime also collected core events to completion without exposing core's live publisher hook.
This makes leases operational, gives sweeps a complete crash-recovery path, and provides the live event seam needed by streaming integrations without changing durable event semantics.
Impact#
Existing workflows continue to run unchanged. sweep() now returns a recovered collection and accepts maxRecoveredRuns. Valid lease durations behave as before; invalid non-positive or non-finite durations now fail before mutating the store.
Validation#
pnpm test:pr- core and runtime durability tests
- shared store contract against in-memory, Cloudflare D1, and Drizzle Postgres
- package type checks, lint, docs checks, and builds
Summary by CodeRabbit#
New Features
- Added recovery for interrupted workflow runs during runtime sweeps.
- Added automatic lease heartbeats for long-running executions.
- Added best-effort live event publishing at runtime and per-operation levels.
- Added recovery limits and recovered-run details to sweep results.
- Exported the event publisher type for integration use.
Documentation
- Updated runtime documentation with lease, recovery, sweep, and live event behavior.
Tests
- Added coverage for execution recovery, lease renewal, event publishing, and stale-run handling.
- 1
🚀 Changeset Version Preview#
2 package(s) bumped directly, 6 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/workflow-core0.0.4 → 0.0.5 Changeset @tanstack/workflow-runtime0.0.3 → 0.0.4 Changeset @tanstack/workflow-cloudflare0.0.3 → 0.0.4 Dependent @tanstack/workflow-netlify0.0.4 → 0.0.5 Dependent @tanstack/workflow-railway0.0.3 → 0.0.4 Dependent @tanstack/workflow-store-cloudflare-d10.0.4 → 0.0.5 Dependent @tanstack/workflow-store-drizzle-postgres0.0.5 → 0.0.6 Dependent @tanstack/workflow-vercel0.0.4 → 0.0.5 Dependent More templates
@tanstack/react-template
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/react-template@15@tanstack/react-template-devtools
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/react-template-devtools@15@tanstack/solid-template
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/solid-template@15@tanstack/solid-template-devtools
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/solid-template-devtools@15@tanstack/template
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/template@15@tanstack/template-devtools
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/template-devtools@15@tanstack/workflow-cloudflare
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-cloudflare@15@tanstack/workflow-core
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-core@15@tanstack/workflow-netlify
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-netlify@15@tanstack/workflow-railway
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-railway@15@tanstack/workflow-runtime
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-runtime@15@tanstack/workflow-store-cloudflare-d1
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-store-cloudflare-d1@15@tanstack/workflow-store-drizzle-postgres
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-store-drizzle-postgres@15@tanstack/workflow-vercel
npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-vercel@15commit:
0bc426btannerlinsley merged thisb928717
tannerlinsley closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
70089aff-1a1f-448b-be04-48b2cf945e7a📥 Commits
Reviewing files that changed from the base of the PR and between fa3290351713c95db92657fbe1bbf04387282adc and 0bc426bdf0be6415d1d4727f835419e3155a95a5.
📒 Files selected for processing (10)
.changeset/bright-runs-recover.mddocs/api/runtime.mddocs/guide/runtime-model.mdpackages/workflow-core/src/engine/run-workflow.tspackages/workflow-core/tests/engine.durability.test.tspackages/workflow-runtime/src/index.tspackages/workflow-runtime/src/runtime-driver.tspackages/workflow-runtime/src/types.tspackages/workflow-runtime/tests/contracts/workflow-execution-store.contract.tspackages/workflow-runtime/tests/runtime-driver.test.ts📝 Walkthrough
Walkthrough#
The workflow core now supports checkpoint recovery for reclaimed runs. The runtime renews active leases, recovers stale executions during sweeps, exposes recovery limits and results, and supports best-effort live event publishing through configured or per-call publishers.
Changes#
Workflow runtime reliability
packages/workflow-core/src/engine/run-workflow.ts,packages/workflow-core/tests/engine.durability.test.ts,docs/guide/runtime-model.mdpackages/workflow-runtime/src/runtime-driver.ts,packages/workflow-runtime/tests/contracts/*,packages/workflow-runtime/tests/runtime-driver.test.tspackages/workflow-runtime/src/types.ts,packages/workflow-runtime/src/index.ts,packages/workflow-runtime/src/runtime-driver.ts,packages/workflow-runtime/tests/runtime-driver.test.ts,docs/api/runtime.md,docs/guide/runtime-model.mdpackages/workflow-runtime/src/runtime-driver.ts,packages/workflow-runtime/tests/runtime-driver.test.ts,docs/api/runtime.md,docs/guide/runtime-model.md,.changeset/bright-runs-recover.mdmaxRecoveredRuns, replay them with recovery enabled, and include recovered runs in summaries and documentation.Estimated code review effort: 4 (Complex) | ~60 minutes
Sequence Diagram(s)#
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.