Skip to content

Expose workflow.Cause to retrieve cancellation cause - #483

Merged
cschleiden merged 3 commits into
mainfrom
copilot/expose-workflow-cause
Jun 5, 2026
Merged

Expose workflow.Cause to retrieve cancellation cause#483
cschleiden merged 3 commits into
mainfrom
copilot/expose-workflow-cause

Conversation

Copilot AI commented May 30, 2026

Copy link
Copy Markdown
Contributor

Cause(ctx) only lived in the internal sync package, so workflows had no way to retrieve the error passed to WithCancelCause. ctx.Err() only yields the generic context canceled, losing the underlying cause.

Changes

  • workflow/context.go: Add exported Cause(c Context) error wrapping sync.Cause, following the existing WithCancel/WithCancelCause delegation pattern.
  • workflow/context_test.go: Add TestCause covering the pre-cancellation (nil) and post-cancellation cases.

Usage

func Workflow(ctx workflow.Context, input string) (string, error) {
    ctx, cancel := workflow.WithCancelCause(ctx)
    cancel(errors.New("This workflow is canceled"))
    return "", workflow.Cause(ctx) // returns the original error instead of "context canceled"
}

Copilot AI changed the title [WIP] Expose workflow.Cause function in internal package Expose workflow.Cause to retrieve cancellation cause May 30, 2026
Copilot AI requested a review from cschleiden May 30, 2026 05:19
@cschleiden
cschleiden marked this pull request as ready for review June 1, 2026 03:16
@cschleiden
cschleiden enabled auto-merge (rebase) June 1, 2026 03:16
auto-merge was automatically disabled June 1, 2026 16:50

Head branch was pushed to by a user without write access

@cschleiden
cschleiden enabled auto-merge (rebase) June 4, 2026 04:22
@cschleiden
cschleiden disabled auto-merge June 5, 2026 16:46
@cschleiden
cschleiden merged commit 8ef4f86 into main Jun 5, 2026
5 checks passed
@cschleiden
cschleiden deleted the copilot/expose-workflow-cause branch June 5, 2026 16:47
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