Add runtime deadlines and observability #13
main fromtaren/runtime-deadlines-observability·merged by tannerlinsley What changed#
- add runtime deadlines and maximum drive durations across start, signal, approval, and sweep execution
- expose deadline helpers under
ctx.runtimeand 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
🚀 Changeset Version Preview#
2 package(s) bumped directly, 6 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/workflow-core0.0.3 → 0.0.4 Changeset @tanstack/workflow-runtime0.0.2 → 0.0.3 Changeset @tanstack/workflow-cloudflare0.0.2 → 0.0.3 Dependent @tanstack/workflow-netlify0.0.3 → 0.0.4 Dependent @tanstack/workflow-railway0.0.2 → 0.0.3 Dependent @tanstack/workflow-store-cloudflare-d10.0.3 → 0.0.4 Dependent @tanstack/workflow-store-drizzle-postgres0.0.4 → 0.0.5 Dependent @tanstack/workflow-vercel0.0.3 → 0.0.4 Dependent 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@13commit:
70ced3cReview the following changes in direct dependencies. Learn more about Socket for GitHub.
Diff Package Supply Chain
SecurityVulnerability Quality Maintenance License @opentelemetry/api@1.9.1 Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/workflow-core/package.json (1)
58-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove
@opentelemetry/apitopeerDependencies. These published libraries should not ship their own copy of the OpenTelemetry API; keep it inpeerDependencies(anddevDependenciesfor 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.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (27)
.changeset/calm-clocks-yield.md.changeset/metal-shoes-observe.mddocs/api/runtime.mddocs/concepts/primitives.mddocs/config.jsondocs/cookbook/index.mddocs/guide/index.mddocs/guide/observability.mdpackages/workflow-cloudflare/package.jsonpackages/workflow-core/package.jsonpackages/workflow-core/src/engine/run-workflow.tspackages/workflow-core/src/index.tspackages/workflow-core/src/telemetry.tspackages/workflow-core/src/types.tspackages/workflow-core/tests/telemetry.test.tspackages/workflow-netlify/package.jsonpackages/workflow-railway/package.jsonpackages/workflow-runtime/package.jsonpackages/workflow-runtime/src/index.tspackages/workflow-runtime/src/run-store-adapter.tspackages/workflow-runtime/src/runtime-driver.tspackages/workflow-runtime/src/types.tspackages/workflow-runtime/tests/runtime-driver.test.tspackages/workflow-runtime/tests/telemetry.test.tspackages/workflow-store-cloudflare-d1/package.jsonpackages/workflow-store-drizzle-postgres/package.jsonpackages/workflow-vercel/package.json
packages/workflow-core/src/telemetry.ts lines 175 to 177Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +159,21 @@159+ if (error instanceof Error) {160+ return {161+ name: error.name,162+ message: error.message,163+ }164+ }165+166+ return {167+ name: typeof error,168+ message: String(error),169+ }170+}171+172+const disabledWorkflowTelemetry: WorkflowTelemetry = {173+ enabled: false,174+ spanNamePrefix: DEFAULT_SPAN_NAME_PREFIX,175+ async startActiveSpan(_operation, _spanContext, fn) {176+ return await fn(177+ trace.getActiveSpan() ?? trace.wrapSpanContext(INVALID_SPAN_CONTEXT),178+ )179+ },🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash set -euo pipefail # Map relevant files first ast-grep outline packages/workflow-core/src/telemetry.ts --view expanded || true printf '\n---\n' fd -a 'engineStep*' packages/workflow-core/src || true printf '\n---\n' rg -n "startActiveSpan|addActiveSpanEvent|workflow\.step\.attempt|addEvent\(" packages/workflow-core/src -SRepository: TanStack/workflow
Length of output: 3105
🏁 Script executed:
#!/bin/bash set -euo pipefail printf 'telemetry.ts (around disabled implementation):\n' sed -n '1,260p' packages/workflow-core/src/telemetry.ts | cat -n | sed -n '120,220p' printf '\nengineStep references:\n' rg -n -A4 -B4 "engineStep|addEvent\(" packages/workflow-core/src -SRepository: TanStack/workflow
Length of output: 8303
Disabled telemetry still attaches step events to the ambient span
startActiveSpan()forwardstrace.getActiveSpan(), soengineStepcan still callspan.addEvent(...)on the host span when telemetry is disabled. Returntrace.wrapSpanContext(INVALID_SPAN_CONTEXT)here as well.🤖 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/src/telemetry.ts` around lines 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.✅ Addressed in commit 6d33e8e
Fixed in 6d33e8e. Disabled telemetry now always supplies a non-recording invalid-context span, with a regression test proving an ambient span is not exposed.
@tannerlinsley, thanks for fixing this and adding the regression coverage. The disabled telemetry path now preserves the intended no-op behavior without exposing the ambient span.tannerlinsley merged this87340c8
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:
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.yamlis excluded by!**/pnpm-lock.yaml📒 Files selected for processing (4)
packages/workflow-core/package.jsonpackages/workflow-core/src/telemetry.tspackages/workflow-core/tests/telemetry.test.tspackages/workflow-runtime/package.json🚧 Files skipped from review as they are similar to previous changes (1)
📝 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
packages/workflow-core/src/telemetry.ts,packages/workflow-core/src/index.ts,packages/workflow-runtime/src/index.tspackages/workflow-core/src/types.ts,packages/workflow-core/src/engine/run-workflow.tspackages/workflow-runtime/src/types.ts,packages/workflow-runtime/src/runtime-driver.ts,packages/workflow-runtime/src/run-store-adapter.tspackages/workflow-core/tests/*,packages/workflow-runtime/tests/*,docs/*,.changeset/*,packages/*/package.jsonEstimated code review effort: 5 (Critical) | ~120 minutes
Sequence Diagram(s)#
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)#
✅ Passed checks (3 passed)
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.