Skip to content

Enable concurrency by propagating context from command level#13720

Merged
pelikhan merged 5 commits intomainfrom
copilot/remove-global-context-object
Feb 4, 2026
Merged

Enable concurrency by propagating context from command level#13720
pelikhan merged 5 commits intomainfrom
copilot/remove-global-context-object

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

Local context.Background() calls in CLI functions prevented proper cancellation propagation and blocked concurrent execution.

Changes

Function signatures updated to accept context:

  • CreateWorkflowInteractively
  • compileWorkflow (method)
  • recompileWorkflow
  • collectWorkflowFiles
  • installWorkflowInTrialMode
  • RunWorkflowTrials

Command handlers now pass cmd.Context():

  • add command → RunAddInteractive
  • new command → CreateWorkflowInteractively
  • trial command → RunWorkflowTrials
  • run --pushcollectWorkflowFilesrecompileWorkflow

Removed local context creation in:

  • pkg/cli/add_command.go:116
  • pkg/cli/interactive.go:497
  • pkg/cli/run_push.go:143
  • pkg/cli/trial_repository.go:229

Example

Before:

func collectWorkflowFiles(workflowPath string, verbose bool) ([]string, error) {
    ctx := context.Background()  // Local context breaks cancellation chain
    if err := recompileWorkflow(ctx, workflowPath, verbose); err != nil {
        return nil, err
    }
    // ...
}

After:

func collectWorkflowFiles(ctx context.Context, workflowPath string, verbose bool) ([]string, error) {
    if err := recompileWorkflow(ctx, workflowPath, verbose); err != nil {
        return nil, err
    }
    // ...
}

Context now flows: cmd.Context() → service functions → CompileWorkflows, enabling proper cancellation and concurrent operations.

Original prompt

Remove the global context object created in the cli in favor of a local variable context that gets passed around. This will allow concurrency.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 4, 2026 13:18
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 AI changed the title [WIP] Remove global context object in CLI for concurrency Enable concurrency by propagating context from command level Feb 4, 2026
Copilot AI requested a review from pelikhan February 4, 2026 13:28
@pelikhan
Copy link
Contributor

pelikhan commented Feb 4, 2026

@copilot the command should still be cancellable but context.Background should only be used in top level function

Copy link
Contributor Author

Copilot AI commented Feb 4, 2026

@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 cmd.Context() in command handlers (e.g., add_command.go:115, main.go:100, trial_command.go:159) which properly handles SIGINT and cancellation signals from Cobra.

context.Background() only in top-level: Removed from nested functions (was in add_command.go:116, interactive.go:497, run_push.go:143, trial_repository.go:229). Now only used in test files where it's appropriate.

The context flow is: cmd.Context()RunAddInteractive/CreateWorkflowInteractively/etcCompileWorkflows, enabling proper cancellation propagation throughout the call chain.

Is there a specific location where you'd like me to use context.Background() instead of cmd.Context()?

@pelikhan pelikhan marked this pull request as ready for review February 4, 2026 15:25
Copilot AI review requested due to automatic review settings February 4, 2026 15:25
Copy link
Contributor

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 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.Context as first parameter: CreateWorkflowInteractively, compileWorkflow, recompileWorkflow, collectWorkflowFiles, installWorkflowInTrialMode, and RunWorkflowTrials
  • 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.

@pelikhan pelikhan merged commit 725337e into main Feb 4, 2026
@pelikhan pelikhan deleted the copilot/remove-global-context-object branch February 4, 2026 16:15
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

Comments