Skip to content

[Docs] Cookbook update for child workflows pattern#2100

Merged
karthikscale3 merged 108 commits into
mainfrom
karthik/child-workflows-hook-completion
May 25, 2026
Merged

[Docs] Cookbook update for child workflows pattern#2100
karthikscale3 merged 108 commits into
mainfrom
karthik/child-workflows-hook-completion

Conversation

@karthikscale3
Copy link
Copy Markdown
Contributor

Summary

  • Rewrites the v4 and v5 Child Workflows cookbook to recommend hook-based completion (defineHook + withChildCompletionHook + startAndWait) instead of getRun().status polling loops
  • Updates Workflow Composition cross-links in v4/v5 to point at the hook resume pattern
  • Updates the workbench cookbook fixture to spawn a wrapped child that resumes the parent hook in finally

Why

Polling child status in a durable sleep loop works but is slower to wake, holds worker slots when combined with returnValue, and requires extra result-collection steps. The hook resume pattern lets each child signal completion directly and keeps the parent suspended with zero compute until the child finishes.

Test plan

  • pnpm --filter @workflow/docs-typecheck typecheck
  • pnpm exec vitest run test/cookbook-common.test.ts -t "child-workflows" in workbench/vitest (local plugin env issue unrelated to this diff)
  • Review updated cookbook pages at /cookbook/advanced/child-workflows for v4 and v5

Made with Cursor

Copy link
Copy Markdown
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Approve — all four asks addressed cleanly

Karthik's fix commit (1c0e18ff0 Fix child-workflows cookbook review feedback) addresses all four items from the previous review:

Ask Fix
1. Type error in resumeParentCompletion (Docs Code Samples CI) Tightened to discriminated union in both v4 and v5
2. Missing zod dep (Vitest Plugin Tests CI) Added "zod": "catalog:" to workbench/vitest/package.json + lockfile
3. Unused resumeHook import Removed
4. No changeset Added empty changeset .changeset/cookbook-child-workflows-hook-resume.md

What I verified locally

  • pnpm install --frozen-lockfile ✓ (lockfile updated cleanly)
  • pnpm turbo run build --filter '!./workbench/*'
  • pnpm --filter @workflow/docs-typecheck test:docs ✓ (911/911 tests pass — child-workflows v4 and v5 both clean)
  • cd workbench/vitest && pnpm test ✓ (34/34 tests pass, including should spawn a child workflow via start() and collect its result)

CI

  • 37 success, 0 failures, 73 in progress — both previously-failing checks now green:
    • Docs Code Samples: pass (was failing on lines 33 of both v4 and v5)
    • Vitest Plugin Tests: pass (was failing on zod resolution)

Branch hygiene

The ~10 merge commits from main are still there — they'll be squashed away on merge so it's not a blocker, but a rebase would clean up the working history.

Nice work on the pattern. The hook resume + withChildCompletionHook + startAndWait shape is clean, and the prose explanation of why hooks beat polling (zero compute, immediate wake, typed payloads, no worker-pool pressure) is well-grounded with the Eager Processing link.

Approving.

karthikscale3 and others added 2 commits May 25, 2026 10:03
Remove redundant polling comparison copy, the getRun() alternative section, and v5-only start() tips to keep the cookbook focused on the hook pattern.

Co-authored-by: Cursor <cursoragent@cursor.com>
@karthikscale3 karthikscale3 merged commit c58cae6 into main May 25, 2026
229 of 252 checks passed
@karthikscale3 karthikscale3 deleted the karthik/child-workflows-hook-completion branch May 25, 2026 23:02
@github-actions
Copy link
Copy Markdown
Contributor

No backport to stable for c58cae6 (AI decision).

All meaningful changes target docs cookbook pages (docs/content/docs/v4/cookbook/..., docs/content/docs/v5/cookbook/..., docs/lib/cookbook-tree.ts) and a workbench/vitest fixture (workbench/vitest/workflows/cookbook/child-workflows.ts) that do not exist on stable — verified via git ls-tree origin/stable. The only file present on stable is workbench/vitest/package.json, where the sole change is adding a zod dependency that solely supports the new fixture which isn't on stable, so the backport would be meaningless on its own.

To override, re-run the Backport to stable workflow manually via workflow_dispatch and paste this commit SHA into the ref input:

c58cae66122bed2c0dddfe7cf793def18c08b708

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.

2 participants