Skip to content

Add sleep workflow node backed by durable step.sleep - #1

Open
goroggabriel wants to merge 1 commit into
Consensys:masterfrom
goroggabriel:feat/workflow-sleep-node
Open

Add sleep workflow node backed by durable step.sleep#1
goroggabriel wants to merge 1 commit into
Consensys:masterfrom
goroggabriel:feat/workflow-sleep-node

Conversation

@goroggabriel

Copy link
Copy Markdown

Summary

  • Adds a Sleep node (logic category) so a workflow can pause for a fixed duration and then continue, e.g. the L0 alert triage flow that acks an Opsgenie alert, waits 5 minutes, and re-checks it. This removes the need for the KV-blob + cron workaround discussed with @gabriel.gorog.
  • The compiled workflow calls Cloudflare Workflows step.sleep(nodeId + ":sleep", duration) directly, mirroring how user-approval calls step.waitForEvent. The workflow consumes no compute while sleeping.
  • No runtime ABI change: the sleep behavior lives entirely in the compiled per-workflow artifact; the versioned runtime kernel modules are untouched, so CURRENT_WORKFLOW_RUNTIME_ABI_VERSION stays at 2 and the kernel source fingerprint is unchanged. No manifest migration is needed either (new node type only, no shape change to existing manifests).

Changes

  • packages/shared/src/workflow-nodes/definitions.ts: sleep node type, inline executor, catalog entry (value in → value out pass-through, default duration 5 minutes), timer icon, sleep-duration option validation rule.
  • packages/shared/src/workflow-nodes.ts: duration validation accepting positive integer milliseconds or Cloudflare duration labels (30 seconds, 5 minutes, 1 day, ...).
  • packages/api/src/server/background/workflows/compiler.ts: runSleepNode in the generated runtime + run-loop branch; invalid durations fall back to the default instead of failing mid-run.
  • apps/web: inspector Duration field and Timer icon for the builder.
  • Tests: catalog/defaults/validation in tests/workflows/nodes.test.ts, durable sleep + pass-through + fallback in tests/workflows/compiler.test.ts.

Test plan

  • vitest run tests/workflows — 17 files, 147 tests passing
  • nub run typecheck — clean
  • nub run lint — no errors
  • nub run format — clean

Made with Cursor

Adds a logic-category sleep node so workflows can pause for a fixed
duration (e.g. the L0 alert triage 5 minute wait) without cron/KV
workarounds. The compiled workflow calls Cloudflare Workflows
step.sleep directly, mirroring how user-approval uses
step.waitForEvent, so no runtime kernel ABI change or manifest
migration is needed. Includes shared duration validation, builder
inspector config, and nodes/compiler tests.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 0417b92. Configure here.

return Number.isInteger(value) && value > 0
}
return typeof value === "string" && WORKFLOW_SLEEP_DURATION_PATTERN.test(value)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sleep duration exceeds platform limit

Medium Severity

isValidWorkflowSleepDuration accepts any positive integer milliseconds or unit label, including values above Cloudflare Workflows' step.sleep maximum of 365 days (for example 2 years, 53 weeks, or very large millisecond counts). Those options pass draft validation and compile, then fail when the durable sleep runs.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0417b92. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant