Refactor audit analysis fanout to errgroup.WithContext and propagate cancellation#46973
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Refactors audit analysis fanout to use errgroup and propagate context cancellation.
Changes:
- Replaces
sync.WaitGroupwitherrgroup.WithContext. - Threads context through audit launchers and returns cancellation errors.
- Adds cancellation and soft-failure tests.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/audit.go |
Migrates concurrent audit collection to errgroup. |
pkg/cli/audit_concurrency_test.go |
Adds focused concurrency regression tests. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
pkg/cli/audit.go:740
- The context stops at this launcher:
fetchJobDetailsWithCountsinvokesworkflow.RunGHCombined, which usescontext.Background()(pkg/workflow/github_cli.go:213-225). Canceling an audit therefore cannot terminate a blockedgh apisubprocess, andg.Wait()waits for it to exit. Add a context-aware helper path usingRunGHCombinedContext, passgctx, and treat its cancellation error as hard rather than as the existing soft I/O failure.
func launchJobDetailsAnalysis(g *errgroup.Group, gctx context.Context, results *auditAnalysisResults, runID int64, verbose bool) {
g.Go(func() error {
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
| if err := g.Wait(); err != nil { | ||
| return results, err | ||
| } | ||
| launchSupplementalAuditAnalyses(&wg, &results, runOutputDir, verbose) | ||
| wg.Wait() | ||
| return results | ||
| return results, nil |
|
@copilot resolve the merge conflicts on this branch. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Resolved in |
|
Excellent work on this concurrency refactor! 🎯 The migration from What stands out:
This PR looks ready for review by the team. The refactor strengthens error handling observability without changing functional behavior for the existing audit flow.
|
|
🎉 This pull request is included in a new release. Release: |
collectAuditAnalysisResultsfanned out ~14 goroutines viasync.WaitGroup, which hid cancellation/error signaling from the caller. This change moves the fanout toerrgroup.WithContextso cancellation is observable while preserving existing soft-failure behavior for per-analysis I/O.Core concurrency migration
sync.WaitGroupwithg, gctx := errgroup.WithContext(ctx)incollectAuditAnalysisResults.(auditAnalysisResults, error)and propagated the error toAuditWorkflowRun.Context propagation across analysis launchers
gctxthrough alllaunch*helpers andrunAuditAnalysis.g.Go(func() error { ... }).Failure semantics preserved
return nil) to match prior behavior.g.Wait().Type/import cleanup
golang.org/x/sync/errgroupimport inaudit.go.syncimport fromaudit.go.Focused regression coverage
context.CanceledfromcollectAuditAnalysisResultsrunAuditAnalysisremaining non-fatal to the group