Skip to content

implement err group as an alternative to a wait group so errors from activities can be propagated upwards nicely#462

Open
DerkSchooltink wants to merge 3 commits intocschleiden:mainfrom
DerkSchooltink:feature/implement-err-group
Open

implement err group as an alternative to a wait group so errors from activities can be propagated upwards nicely#462
DerkSchooltink wants to merge 3 commits intocschleiden:mainfrom
DerkSchooltink:feature/implement-err-group

Conversation

@DerkSchooltink
Copy link
Copy Markdown

implement #461

…activities can be propagated upwards nicely
@DerkSchooltink DerkSchooltink marked this pull request as ready for review December 1, 2025 10:36
@cschleiden cschleiden requested a review from Copilot February 28, 2026 15:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a workflow-native ErrGroup (errgroup-style) abstraction so concurrent workflow coroutines can return errors that are aggregated and propagated via Wait, and includes a sample demonstrating the new API.

Changes:

  • Expose workflow.ErrGroup and workflow.WithErrGroup as public workflow APIs.
  • Implement internal/sync.ErrGroup with tests for success and “first error wins”.
  • Add a new sample (samples/concurrent-errgroup) demonstrating concurrent activity execution with error propagation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
workflow/sync.go Exposes the new ErrGroup type alias and WithErrGroup helper at the workflow API layer.
internal/sync/errgroup.go Implements the scheduler-compatible errgroup abstraction.
internal/sync/errgroup_test.go Adds unit tests validating basic ErrGroup behavior.
samples/concurrent-errgroup/concurrent_errgroup.go Demonstrates usage of workflow.WithErrGroup in a runnable sample.
Comments suppressed due to low confidence (2)

internal/sync/errgroup.go:40

  • errGroup has a waiting flag intended for misuse detection, but it’s currently unused beyond being set in Wait. Either remove it to avoid dead state, or use it to enforce a clear contract (e.g., disallow calling Go after Wait starts, similar to WaitGroup).

This issue also appears on line 58 of the same file.

	// track if Wait was called to detect certain misuses (optional)
	waiting bool

internal/sync/errgroup.go:60

  • Wait sets waiting=true, but Go does not check it. This allows Go to be called after Wait has started/returned, which can make Wait return without waiting for the newly launched coroutine (i.e., silent misuse). Consider adding a panic/guard in Go when waiting is already true (mirroring WaitGroup’s misuse detection) so incorrect usage fails fast.
func (g *errGroup) Go(f func(Context) error) {
	g.n += 1


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/sync/errgroup.go Outdated
Comment on lines +3 to +9
// ErrGroup provides a way to run functions concurrently and collect the first error.
//
// It is conceptually similar to golang.org/x/sync/errgroup.Group but adapted to the
// workflow scheduler and Context. It cancels the derived Context when the first function
// returns a non-nil error. Wait waits for all functions to finish and returns the first
// error that was observed. If the Context passed to Wait is canceled before completion,
// Wait returns that context error instead.
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The doc comment states that if the Context passed to Wait is canceled before completion, Wait returns that context error. But Wait blocks on g.done.Get(ctx) and Future.Get doesn’t observe ctx.Done()/ctx.Err(), so cancellation won’t unblock Wait. Please update the comment to match behavior, or make the wait cancellation-aware.

Copilot uses AI. Check for mistakes.
Comment thread internal/sync/errgroup.go
ctx Context

// track if Wait was called to detect certain misuses (optional)
waiting bool
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

the copilot code review comment about this seems accurate, do we need to check that?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yeah good point, modified the doc string to match actual behavior.

also wired up the waiting flag to panic on calling Go after Wait, which is consistent with WaitGroup#Add.

Future.Get does not observe ctx.Done, so the doc comment promising
cancellation-aware Wait was incorrect. Aligns with WaitGroup behavior.
Also wires up the waiting flag to panic on Go called after Wait, matching
the WaitGroup.Add misuse detection pattern.
@DerkSchooltink DerkSchooltink force-pushed the feature/implement-err-group branch from b0a3bae to 8968430 Compare April 29, 2026 20:24
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.

3 participants