Skip to content
Source
Sign inSign up
TanStack/workflow

Add runtime deadlines and observability #13

Mergedtannerlinsleymerged 5 commits intomain fromtaren/runtime-deadlines-observabilitymerged by tannerlinsley

tannerlinsleycommented

What changed

  • add runtime deadlines and maximum drive durations across start, signal, approval, and sweep execution
  • expose deadline helpers under ctx.runtime and automatically yield before fresh durable work when the remaining budget is low
  • persist cooperative yields as timer waits, release run leases, and resume them on a later sweep
  • make timer delivery identities include the durable operation ID
  • add OpenTelemetry spans for runtime operations, durable store calls, and fresh step execution
  • document runtime budgets and observability

Why

Applications currently have to hand-roll wall-clock checks and arbitrary queue batch sizes to avoid host execution limits. The runtime should own that policy and checkpoint cleanly without treating a yield as an error.

The timer identity change prevents sequential waits at the same timestamp from reusing an already-consumed signal delivery ID.

Impact

Existing workflows remain unbounded unless a runtime deadline or maximum duration is supplied. Step timeouts remain independent. Official context fields are grouped under the reserved runtime namespace.

Verification

  • pnpm test:ci
  • 116 workflow-core tests
  • 41 workflow-runtime tests
  • Postgres and Cloudflare D1 store suites
  • host adapter type checks and builds
  • docs link verification

Summary by CodeRabbit

  • New Features
    • Added OpenTelemetry tracing across workflow runtime operations, durable store calls, and step execution, with configurable tracing options and privacy-safe span data.
    • Introduced runtime deadline/budget controls and cooperative yielding via ctx.runtime (including helpers to check remaining time and pause/resume execution).
  • Documentation
    • Expanded observability and runtime docs, including tracing configuration and deadline/yield semantics.
  • Tests
    • Added coverage for tracing behavior/privacy and deadline/yield pause/resume behavior.
  • Releases
    • Patch version updates across workflow core, runtime, and supported adapters.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Review Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 1f8c23bf-97f4-4a6f-a9ff-741817f55a85

      📥 Commits

      Reviewing files that changed from the base of the PR and between e6ad72a9e89e8939b45f962001f10a92f4250870 and 70ced3ccc78c1899a9f2ddfb6e9a2a6243ae973d.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (4)
      • packages/workflow-core/package.json
      • packages/workflow-core/src/telemetry.ts
      • packages/workflow-core/tests/telemetry.test.ts
      • packages/workflow-runtime/package.json
      🚧 Files skipped from review as they are similar to previous changes (1)
      • packages/workflow-core/src/telemetry.ts

      📝 Walkthrough

      Walkthrough

      Adds OpenTelemetry tracing and deadline-aware cooperative yielding to workflow core and runtime execution. New runtime context helpers, durable yield timers, telemetry exports, store spans, sweep budgeting, tests, documentation, and package release metadata are included.

      Changes

      Runtime observability and cooperative execution

      Layer / File(s)Summary
      Telemetry contracts and implementation
      packages/workflow-core/src/telemetry.ts, packages/workflow-core/src/index.ts, packages/workflow-runtime/src/index.ts
      Adds configurable OpenTelemetry spans, safe attributes, exception handling, disabled tracing, metadata mapping, and public telemetry exports.
      Engine runtime budgeting and yielding
      packages/workflow-core/src/types.ts, packages/workflow-core/src/engine/run-workflow.ts
      Adds runtime deadline helpers, explicit and automatic durable yielding, yield timing controls, and step attempt tracing.
      Runtime driver integration
      packages/workflow-runtime/src/types.ts, packages/workflow-runtime/src/runtime-driver.ts, packages/workflow-runtime/src/run-store-adapter.ts
      Threads telemetry and deadline controls through run, signal, approval, timer, and sweep paths while tracing store operations and synchronizing yielded runs.
      Validation, documentation, and release metadata
      packages/workflow-core/tests/*, packages/workflow-runtime/tests/*, docs/*, .changeset/*, packages/*/package.json
      Adds telemetry and deadline/yield coverage, documents configuration and runtime behavior, updates observability navigation, and records package version changes.

      Estimated code review effort: 5 (Critical) | ~120 minutes

      Sequence Diagram(s)

      sequenceDiagram
        participant RuntimeDriver
        participant RunStore
        participant WorkflowEngine
        participant WorkflowTelemetry
        participant TimerStore
        RuntimeDriver->>WorkflowTelemetry: start runtime or sweep span
        RuntimeDriver->>RunStore: claim and load workflow state
        RuntimeDriver->>WorkflowEngine: drive workflow with deadline
        WorkflowEngine->>WorkflowTelemetry: record step spans and attempt events
        WorkflowEngine->>TimerStore: schedule durable yield continuation
        RuntimeDriver->>RunStore: synchronize timers and release lease

      Possibly related PRs

      • TanStack/workflow#9: Both changes modify workflow engine runtime context and reserved-field handling.
      🚥 Pre-merge checks | ✅ 3 | ❌ 2

      ❌ Failed checks (2 warnings)

      Check nameStatusExplanationResolution
      Description check⚠️ WarningThe description covers the change well, but it omits the required checklist and release impact template sections.Rename the first section to Changes and add the required Checklist and Release Impact sections with the requested checkboxes.
      Docstring Coverage⚠️ WarningDocstring coverage is 2.38% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (3 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly summarizes the main addition of runtime deadlines and observability.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      ✨ Finishing Touches
      📝 Generate docstrings
      • Create stacked PR
      • Commit on current branch
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `taren/runtime-deadlines-observability`

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Changeset Version Preview

      2 package(s) bumped directly, 6 bumped as dependents.

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/workflow-core0.0.3 → 0.0.4Changeset
      @tanstack/workflow-runtime0.0.2 → 0.0.3Changeset
      @tanstack/workflow-cloudflare0.0.2 → 0.0.3Dependent
      @tanstack/workflow-netlify0.0.3 → 0.0.4Dependent
      @tanstack/workflow-railway0.0.2 → 0.0.3Dependent
      @tanstack/workflow-store-cloudflare-d10.0.3 → 0.0.4Dependent
      @tanstack/workflow-store-drizzle-postgres0.0.4 → 0.0.5Dependent
      @tanstack/workflow-vercel0.0.3 → 0.0.4Dependent
    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@13

      @tanstack/react-template-devtools

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

      @tanstack/solid-template

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

      @tanstack/solid-template-devtools

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

      @tanstack/template

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

      @tanstack/template-devtools

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

      @tanstack/workflow-cloudflare

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-cloudflare@13

      @tanstack/workflow-core

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

      @tanstack/workflow-netlify

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-netlify@13

      @tanstack/workflow-railway

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-railway@13

      @tanstack/workflow-runtime

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-runtime@13

      @tanstack/workflow-store-cloudflare-d1

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-store-cloudflare-d1@13

      @tanstack/workflow-store-drizzle-postgres

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-store-drizzle-postgres@13

      @tanstack/workflow-vercel

      npm i https://pkg.pr.new/TanStack/workflow/@tanstack/workflow-vercel@13

      commit: 70ced3c

    4. socket-security[bot](GitHub profile, opens in a new tab)commented

      Review the following changes in direct dependencies. Learn more about Socket for GitHub.

      Diff Package Supply Chain
      Security
      Vulnerability Quality Maintenance License
      Added@​opentelemetry/​api@​1.9.110010010086100

      View full report

    5. Actionable comments posted: 1

      🧹 Nitpick comments (1)
      packages/workflow-core/package.json (1)

      58-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

      Move @opentelemetry/api to peerDependencies. These published libraries should not ship their own copy of the OpenTelemetry API; keep it in peerDependencies (and devDependencies for local builds/tests) in both package manifests so the host app’s tracer provider stays visible.

      🤖 Prompt for AI Agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      In `@packages/workflow-core/package.json` at line 58, Move `@opentelemetry/api` from
      dependencies to both peerDependencies and devDependencies in
      packages/workflow-core/package.json and packages/workflow-runtime/package.json,
      preserving the existing version range so local builds/tests can resolve it while
      published packages reuse the host application’s API instance.
      🤖 Prompt for all review comments with AI agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      Inline comments:
      In `@packages/workflow-core/src/telemetry.ts`:
      - Around line 175-179: Update startActiveSpan to always pass
      trace.wrapSpanContext(INVALID_SPAN_CONTEXT) to the callback when telemetry is
      disabled, instead of falling back to trace.getActiveSpan(). Preserve the
      existing async callback execution and return behavior.
      
      ---
      
      Nitpick comments:
      In `@packages/workflow-core/package.json`:
      - Line 58: Move `@opentelemetry/api` from dependencies to both peerDependencies
      and devDependencies in packages/workflow-core/package.json and
      packages/workflow-runtime/package.json, preserving the existing version range so
      local builds/tests can resolve it while published packages reuse the host
      application’s API instance.
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 84578070-b222-4200-aa41-89968015bfa9

      📥 Commits

      Reviewing files that changed from the base of the PR and between 602cdec439876335168d96f5443c0dc59e4cc436 and bdd7f683c89ff33e6deb4e2e683c53c49ca35d46.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (27)
      • .changeset/calm-clocks-yield.md
      • .changeset/metal-shoes-observe.md
      • docs/api/runtime.md
      • docs/concepts/primitives.md
      • docs/config.json
      • docs/cookbook/index.md
      • docs/guide/index.md
      • docs/guide/observability.md
      • packages/workflow-cloudflare/package.json
      • packages/workflow-core/package.json
      • packages/workflow-core/src/engine/run-workflow.ts
      • packages/workflow-core/src/index.ts
      • packages/workflow-core/src/telemetry.ts
      • packages/workflow-core/src/types.ts
      • packages/workflow-core/tests/telemetry.test.ts
      • packages/workflow-netlify/package.json
      • packages/workflow-railway/package.json
      • packages/workflow-runtime/package.json
      • packages/workflow-runtime/src/index.ts
      • packages/workflow-runtime/src/run-store-adapter.ts
      • packages/workflow-runtime/src/runtime-driver.ts
      • packages/workflow-runtime/src/types.ts
      • packages/workflow-runtime/tests/runtime-driver.test.ts
      • packages/workflow-runtime/tests/telemetry.test.ts
      • packages/workflow-store-cloudflare-d1/package.json
      • packages/workflow-store-drizzle-postgres/package.json
      • packages/workflow-vercel/package.json
    6. tannerlinsley merged this87340c8

    7. tannerlinsley closed this

Sign in to join this conversation.