Skip to content

fix(workflow): forward parent pointer when spawning a child with discard:true#6241

Merged
tim-smart merged 2 commits into
Effect-TS:mainfrom
jcalem-rogo:fix/workflow-discard-parent-pointer
May 19, 2026
Merged

fix(workflow): forward parent pointer when spawning a child with discard:true#6241
tim-smart merged 2 commits into
Effect-TS:mainfrom
jcalem-rogo:fix/workflow-discard-parent-pointer

Conversation

@jcalem-rogo
Copy link
Copy Markdown
Contributor

Summary

Workflow.execute(payload, { discard: true }) takes a fast path inside WorkflowEngine.execute that omits the parent option when delegating to the underlying engine. As a result, ClusterWorkflowEngine never writes "~@effect/workflow/parent" into the child's persisted cluster_messages.payload row.

The non-discard branch a few lines below DOES forward parent, so the discard path looks like an oversight — parent carries two concerns and only one of them (interrupt linkage) is moot for discarded children. The other (the persisted causality breadcrumb) is still load-bearing for any observability surface that wants to reconstruct a parent/child workflow tree from message storage.

Before this fix:

if (opts.discard) {
  yield* options.execute(self, {
    executionId,
    payload: payload as object,
    discard: true
    //                ↑ no `parent` — child's payload is missing the parent pointer
  })
  return executionId
}

After:

if (opts.discard) {
  yield* options.execute(self, {
    executionId,
    payload: payload as object,
    discard: true,
    parent: Option.getOrUndefined(parentInstance)
  })
  return executionId
}

The fix is one line. The parent option is already typed as optional on the engine's execute signature, so no other surfaces change.

Why this matters

The dominant fan-out shape in @effect/cluster workflows — Effect.forEach(items, (item) => ChildWorkflow.execute(item, { discard: true })) — was leaving every child's payload without a parent pointer. Tools that read cluster_messages to reconstruct a Temporal-like workflow tree end up with orphaned children and no way to link them back to their parent, except by falling back to OTel trace_id grouping (which is lossy and ambiguous for nested fan-outs).

Test

Added a regression test in packages/cluster/test/ClusterWorkflowEngine.test.ts that spawns a child with discard: true and asserts the persisted child run-envelope carries "~@effect/workflow/parent" pointing back at the parent's actual executionId.

Changeset

@effect/workflow: patch.

Test plan

  • pnpm vitest run in packages/cluster — all 9 tests pass, including the new one.
  • pnpm vitest run in packages/workflow — all 6 tests pass.
  • tsc -b clean across both packages.
  • eslint clean on the touched files.

🤖 Generated with Claude Code

…ard:true

The discard fast-path in WorkflowEngine.execute omitted the `parent` option
when delegating to the engine, so ClusterWorkflowEngine never wrote
`"~@effect/workflow/parent"` into the child's persisted payload. This broke
causality tracking for fire-and-forget fan-outs — a common pattern when one
workflow spawns many children and doesn't need to await them. Discarded
children now carry the same parent pointer non-discarded children already
did, restoring observability without changing fire-and-forget semantics.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jcalem-rogo jcalem-rogo requested a review from tim-smart as a code owner May 19, 2026 20:34
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog May 19, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: fdd957b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@effect/workflow Patch
@effect/cluster Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/cluster/test/ClusterWorkflowEngine.test.ts Outdated
Comment thread .changeset/forward-parent-pointer-discard.md Outdated
Co-authored-by: Tim <hello@timsmart.co>
@tim-smart tim-smart enabled auto-merge (squash) May 19, 2026 21:52
@tim-smart tim-smart merged commit e5998a4 into Effect-TS:main May 19, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog May 19, 2026
@github-actions github-actions Bot mentioned this pull request May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants