Enable concurrency by propagating context from command level#13720
Enable concurrency by propagating context from command level#13720
Conversation
This enables proper cancellation and concurrency support by passing context from the command level through the call chain rather than creating new background contexts locally. Changes: - Update CreateWorkflowInteractively to accept context parameter - Update compileWorkflow method to accept and use context - Update recompileWorkflow to accept context parameter - Update collectWorkflowFiles to accept and propagate context - Update installWorkflowInTrialMode to accept context parameter - Update RunWorkflowTrials to accept context parameter - Update cmd.Context() calls in command handlers - Remove local context.Background() calls in add_command.go, interactive.go, run_push.go, and trial_repository.go Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Update test files to pass context.Background() to functions that now require a context parameter. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot the command should still be cancellable but context.Background should only be used in top level function |
The changes already follow this pattern: Commands are cancellable: Using context.Background() only in top-level: Removed from nested functions (was in The context flow is: Is there a specific location where you'd like me to use |
There was a problem hiding this comment.
Pull request overview
This PR enables proper cancellation and concurrency support by propagating context from the command level down through the CLI functions to the compilation layer. Previously, local context.Background() calls were created at intermediate layers, breaking the cancellation chain.
Changes:
- Updated function signatures to accept
context.Contextas first parameter:CreateWorkflowInteractively,compileWorkflow,recompileWorkflow,collectWorkflowFiles,installWorkflowInTrialMode, andRunWorkflowTrials - Modified command handlers to pass
cmd.Context()instead of creating local contexts - Updated test files to use
context.Background()appropriately
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/trial_repository.go | Updated installWorkflowInTrialMode to accept context parameter and pass it to CompileWorkflows |
| pkg/cli/trial_command.go | Updated RunWorkflowTrials signature and command handler to pass context from cmd.Context() |
| pkg/cli/run_workflow_execution.go | Updated call to collectWorkflowFiles to pass context |
| pkg/cli/run_push_test.go | Updated test calls to use context.Background() |
| pkg/cli/run_push.go | Updated collectWorkflowFiles and recompileWorkflow signatures; removed local context.Background() creation |
| pkg/cli/interactive_test.go | Updated test calls to use context.Background() |
| pkg/cli/interactive.go | Updated CreateWorkflowInteractively and compileWorkflow signatures to accept context |
| pkg/cli/add_command.go | Removed local context creation and unused import; passes cmd.Context() to RunAddInteractive |
| cmd/gh-aw/main.go | Updated to pass cmd.Context() to CreateWorkflowInteractively |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Local
context.Background()calls in CLI functions prevented proper cancellation propagation and blocked concurrent execution.Changes
Function signatures updated to accept context:
CreateWorkflowInteractivelycompileWorkflow(method)recompileWorkflowcollectWorkflowFilesinstallWorkflowInTrialModeRunWorkflowTrialsCommand handlers now pass
cmd.Context():addcommand →RunAddInteractivenewcommand →CreateWorkflowInteractivelytrialcommand →RunWorkflowTrialsrun --push→collectWorkflowFiles→recompileWorkflowRemoved local context creation in:
pkg/cli/add_command.go:116pkg/cli/interactive.go:497pkg/cli/run_push.go:143pkg/cli/trial_repository.go:229Example
Before:
After:
Context now flows:
cmd.Context()→ service functions →CompileWorkflows, enabling proper cancellation and concurrent operations.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.