From da7f138a87bcbafbd0107dd8abd2e0bd6e11d19f Mon Sep 17 00:00:00 2001 From: Garrett Tolbert Date: Thu, 23 Oct 2025 17:10:30 -0500 Subject: [PATCH 1/4] add step reusability docs --- .../docs/foundations/workflows-and-steps.mdx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/content/docs/foundations/workflows-and-steps.mdx b/docs/content/docs/foundations/workflows-and-steps.mdx index 00c8c305a..38c8785f5 100644 --- a/docs/content/docs/foundations/workflows-and-steps.mdx +++ b/docs/content/docs/foundations/workflows-and-steps.mdx @@ -83,7 +83,25 @@ By default, steps have a maximum of 3 retry attempts before they fail and propag Step functions are primarily meant to be used inside a workflow. -Calling a step from outside a workflow, or from another step will essentially run the step in the same process like a normal function (in other words, the `use step` directive is a no-op). +Calling a step from outside a workflow, or from another step will essentially run the step in the same process like a normal function (in other words, the `use step` directive is a no-op). This means you can reuse step functions in other parts of your codebase without needing to duplicate business logic. + + +```typescript lineNumbers +async function updateUser(userId: string) { + "use step"; + await db.insert(...); +} + +// 🚫 No need to duplicate business logic here +export async function POST() { + await db.insert(...); +} + +// ✅ Reuse the step function instead +export async function POST() { + await updateUser("123"); +} +``` --- From 782dd62863b7af0b3cb2515c1145b79802dce2ea Mon Sep 17 00:00:00 2001 From: Garrett Tolbert Date: Thu, 23 Oct 2025 22:13:27 -0500 Subject: [PATCH 2/4] update snippet --- docs/content/docs/foundations/workflows-and-steps.mdx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/content/docs/foundations/workflows-and-steps.mdx b/docs/content/docs/foundations/workflows-and-steps.mdx index 38c8785f5..8ebe42ff7 100644 --- a/docs/content/docs/foundations/workflows-and-steps.mdx +++ b/docs/content/docs/foundations/workflows-and-steps.mdx @@ -92,14 +92,17 @@ async function updateUser(userId: string) { await db.insert(...); } -// 🚫 No need to duplicate business logic here -export async function POST() { - await db.insert(...); +// Used inside a workflow +export async function userOnboardingWorkflow(userId: string) { + "use workflow"; + await updateUser(userId); + // ... more steps } -// ✅ Reuse the step function instead +// Used directly outside a workflow export async function POST() { await updateUser("123"); + // ... more logic } ``` From ba87cf468609a841502801f30e5251fceeea1094 Mon Sep 17 00:00:00 2001 From: Garrett Tolbert Date: Fri, 24 Oct 2025 14:55:34 -0500 Subject: [PATCH 3/4] add callout --- docs/content/docs/foundations/workflows-and-steps.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/content/docs/foundations/workflows-and-steps.mdx b/docs/content/docs/foundations/workflows-and-steps.mdx index 8ebe42ff7..27369deaa 100644 --- a/docs/content/docs/foundations/workflows-and-steps.mdx +++ b/docs/content/docs/foundations/workflows-and-steps.mdx @@ -106,6 +106,10 @@ export async function POST() { } ``` + +Keep in mind that calling a step function outside of a workflow function will not have retry semantics nor will it be observable. + + --- ### Suspension and Resumption From 3869a34e831b58dec783955a57ec30f195a6da28 Mon Sep 17 00:00:00 2001 From: Garrett Tolbert Date: Fri, 24 Oct 2025 18:55:08 -0500 Subject: [PATCH 4/4] add getStepMetada to callout --- docs/content/docs/foundations/workflows-and-steps.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/docs/foundations/workflows-and-steps.mdx b/docs/content/docs/foundations/workflows-and-steps.mdx index 27369deaa..f1d1fd278 100644 --- a/docs/content/docs/foundations/workflows-and-steps.mdx +++ b/docs/content/docs/foundations/workflows-and-steps.mdx @@ -107,7 +107,7 @@ export async function POST() { ``` -Keep in mind that calling a step function outside of a workflow function will not have retry semantics nor will it be observable. +Keep in mind that calling a step function outside of a workflow function will not have retry semantics nor will it be observable. Additionally, certain workflow-specific functions like [`getStepMetadata()`](/docs/api-reference/workflow/get-step-metadata) will throw an error when used inside a step that's called outside a workflow. ---