Fix context propagation in execute operations#437
Open
timothyF95 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI and internal clients to propagate context.Context through “execute” paths (deploy/simulate/hash/build + registry/storage interactions), enabling cancellation/timeouts to flow through HTTP, GraphQL, contract calls, retries, and workflow compilation. This aligns with DEVSVCS-4957.
Changes:
- Thread
context.Contextthrough workflow commands/handlers and registry/storage client methods (GraphQL + EVM contract calls). - Make HTTP fetches and workflow compilation context-aware (
http.NewRequestWithContext,exec.CommandContext). - Add context support to retries (
retry.Context(ctx)) and replace blocking sleeps with a context-cancelable sleep helper.
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/testutil/workflow/test_workflow.go | Updates workflow registry upsert helper to pass a context. |
| internal/client/storageclient/storageclient.go | Adds parent-context-based timeouts and propagates ctx through GraphQL/HTTP + retries. |
| internal/client/privateregistryclient/privateregistryclient.go | Adds ctx-aware service timeout creation and ctx parameters for key GraphQL operations. |
| internal/client/privateregistryclient/privateregistryclient_test.go | Updates tests for new ctx-aware private registry client APIs. |
| cmd/workflow/simulate/simulate.go | Passes cobra command context into simulation execution, fetch, and compile steps. |
| cmd/workflow/simulate/simulate_test.go | Updates simulate tests to pass context. |
| cmd/workflow/pause/registry_pause_strategy_private.go | Updates private registry pause flow to use new ctx-aware API (currently via Background). |
| cmd/workflow/pause/registry_pause_strategy_onchain.go | Updates on-chain pause workflow listing calls for ctx-aware signature (currently via Background). |
| cmd/workflow/hash/hash.go | Passes cobra command context through hash execution, fetch, compile, and config load. |
| cmd/workflow/hash/hash_test.go | Updates hash tests to pass context. |
| cmd/workflow/deploy/registry_deploy_strategy.go | Extends deploy strategy interface to accept ctx for prechecks/existence checks/upsert. |
| cmd/workflow/deploy/registry_deploy_strategy_private.go | Threads ctx through private registry deploy existence check and upsert. |
| cmd/workflow/deploy/registry_deploy_strategy_onchain.go | Threads ctx through init-wait, prechecks, existence checks, DON limit checks, and upsert. |
| cmd/workflow/deploy/register.go | Threads ctx to workflow registry upsert call. |
| cmd/workflow/deploy/register_test.go | Updates register tests to pass context. |
| cmd/workflow/deploy/private_registry_test.go | Updates private registry deploy tests to pass context. |
| cmd/workflow/deploy/limits.go | Adds ctx to workflow-list pagination used for DON limit checks. |
| cmd/workflow/deploy/deploy.go | Threads ctx through artifact preparation and upload, plus deploy strategy operations. |
| cmd/workflow/deploy/deploy_test.go | Updates DON limit test fakes/calls for ctx-aware listing method. |
| cmd/workflow/deploy/compile.go | Threads ctx into workflow compilation. |
| cmd/workflow/deploy/compile_test.go | Updates compile tests to pass context to compile helpers. |
| cmd/workflow/deploy/auto_link.go | Threads ctx through owner-link checks and adds context-cancelable sleep and retry context. |
| cmd/workflow/deploy/auto_link_test.go | Updates auto-link tests for ctx-aware APIs. |
| cmd/workflow/deploy/artifacts.go | Threads ctx into storage artifact upload operations. |
| cmd/workflow/deploy/artifacts_test.go | Updates artifact upload tests to pass context. |
| cmd/workflow/delete/registry_delete_strategy_private.go | Updates private registry delete flow to use new ctx-aware API (currently via Background). |
| cmd/workflow/delete/registry_delete_strategy_onchain.go | Updates on-chain delete workflow listing call for ctx-aware signature (currently via Background). |
| cmd/workflow/build/build.go | Passes cobra command context into compilation. |
| cmd/workflow/activate/registry_activate_strategy_private.go | Updates private registry activate flow to use new ctx-aware API (currently via Background). |
| cmd/workflow/activate/registry_activate_strategy_onchain.go | Updates on-chain activate workflow listing call for ctx-aware signature (currently via Background). |
| cmd/secrets/common/handler.go | Updates owner-link check to use ctx-aware registry client API (currently via Background). |
| cmd/common/fetch.go | Makes URL fetching context-aware. |
| cmd/common/fetch_test.go | Updates fetch tests to pass context. |
| cmd/common/compile.go | Makes compilation context-aware via exec.CommandContext and plumbs ctx through build steps. |
| cmd/common/compile_test.go | Updates compile tests to pass context. |
| cmd/client/workflow_registry_v2_client.go | Adds ctx-aware call opts for contract reads and threads ctx into workflow upsert + some read methods. |
| cmd/client/tx.go | Adds ctx parameter to transaction execution to allow cancellation/timeouts during gas estimation/price suggestion. |
| cmd/account/unlink_key/unlink_key.go | Updates owner-link check to use ctx-aware registry client API (currently via Background). |
| cmd/account/link_key/link_key.go | Updates owner-link check to use ctx-aware registry client API (currently via Background). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
31
to
+37
| // FetchURL performs an HTTP GET and returns the response body bytes. | ||
| func FetchURL(url string) ([]byte, error) { | ||
| resp, err := http.Get(url) //nolint:gosec,noctx | ||
| func FetchURL(ctx context.Context, url string) ([]byte, error) { | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("HTTP GET %s: %w", url, err) | ||
| } | ||
| defer resp.Body.Close() | ||
| resp, err := http.DefaultClient.Do(req) //nolint:gosec // URL validated by caller |
Comment on lines
139
to
172
| @@ -167,7 +168,7 @@ func CompileWorkflowToWasm(workflowPath string, opts WorkflowCompileOptions) ([] | |||
| return nil, fmt.Errorf("unsupported workflow language for file %s", workflowMainFile) | |||
| } | |||
|
|
|||
| buildStep, err := getBuildCmd(workflowRootFolder, workflowMainFile, language, opts) | |||
| buildStep, err := getBuildCmd(ctx, workflowRootFolder, workflowMainFile, language, opts) | |||
| if err != nil { | |||
Comment on lines
123
to
164
| @@ -138,7 +139,7 @@ func (c *TxClient) executeTransactionByTxType(txFn func(opts *bind.TransactOpts) | |||
| Value: simulateTx.Value(), | |||
| Data: simulateTx.Data(), | |||
| } | |||
| estimatedGas, gasErr := c.EthClient.Client.EstimateGas(c.EthClient.Context, msg) | |||
| estimatedGas, gasErr := c.EthClient.Client.EstimateGas(ctx, msg) | |||
| if gasErr != nil { | |||
| c.Logger.Warn().Err(gasErr).Msg("Failed to estimate gas usage") | |||
| } | |||
| @@ -159,7 +160,7 @@ func (c *TxClient) executeTransactionByTxType(txFn func(opts *bind.TransactOpts) | |||
|
|
|||
| // Calculate and print total cost for sending the transaction on-chain | |||
| if gasErr == nil { | |||
| gasPriceWei, gasPriceErr := c.EthClient.Client.SuggestGasPrice(c.EthClient.Context) | |||
| gasPriceWei, gasPriceErr := c.EthClient.Client.SuggestGasPrice(ctx) | |||
| if gasPriceErr != nil { | |||
Comment on lines
239
to
275
| @@ -251,7 +258,7 @@ func (c *Client) UploadArtifactWithRetriesAndGetURL( | |||
| err := retry.Do( | |||
| func() error { | |||
| var err error | |||
| g, err = c.GeneratePostUrlForArtifact(workflowID, artifactType, content) | |||
| g, err = c.GeneratePostUrlForArtifact(ctx, workflowID, artifactType, content) | |||
| if err != nil { | |||
| if strings.Contains(err.Error(), "already exists") { | |||
| shouldUpload = false | |||
| @@ -264,6 +271,7 @@ func (c *Client) UploadArtifactWithRetriesAndGetURL( | |||
| }, | |||
| retry.Attempts(3), | |||
| retry.LastErrorOnly(true), | |||
| retry.Context(ctx), | |||
| ) | |||
Comment on lines
166
to
182
| @@ -177,7 +178,7 @@ func fetchAllWorkflows( | |||
| ) | |||
|
|
|||
| for { | |||
| list, err := wrc.GetWorkflowListByOwnerAndName(owner, name, start, limit) | |||
| list, err := wrc.GetWorkflowListByOwnerAndName(context.Background(), owner, name, start, limit) | |||
| if err != nil { | |||
Comment on lines
60
to
64
| ownerAddr := common.HexToAddress(workflowOwner) | ||
|
|
||
| const pageLimit = 200 | ||
| workflows, err := a.wrc.GetWorkflowListByOwnerAndName(ownerAddr, workflowName, big.NewInt(0), big.NewInt(pageLimit)) | ||
| workflows, err := a.wrc.GetWorkflowListByOwnerAndName(context.Background(), ownerAddr, workflowName, big.NewInt(0), big.NewInt(pageLimit)) | ||
| if err != nil { |
Comment on lines
57
to
61
| workflowName := h.inputs.WorkflowName | ||
| workflowOwner := common.HexToAddress(h.inputs.WorkflowOwner) | ||
|
|
||
| allWorkflows, err := a.wrc.GetWorkflowListByOwnerAndName(workflowOwner, workflowName, big.NewInt(0), big.NewInt(100)) | ||
| allWorkflows, err := a.wrc.GetWorkflowListByOwnerAndName(context.Background(), workflowOwner, workflowName, big.NewInt(0), big.NewInt(100)) | ||
| if err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JIRA
https://smartcontract-it.atlassian.net/browse/DEVSVCS-4957