You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🎯 Repository Quality Improvement Report — Remote Fetch API Context Gap
Analysis Date: 2026-07-02 Focus Area: Remote Fetch API Context Gap — Public parser functions strip caller context Strategy Type: Custom Custom Area: Yes — caller context is silently discarded by 8 public wrappers in pkg/parser/remote_fetch.go
Executive Summary
pkg/parser/remote_fetch.go exposes 8 public functions with no context.Context parameter. All 8 delegate to private implementations that do accept context, but 7 auth-fallback sites hard-code context.Background() instead of threading the caller's context.
Nine callers in pkg/cli/ already hold a cobra cmd.Context() but cannot pass it — so Ctrl-C does not cancel in-flight HTTP requests. The fix is to add ctx context.Context to the 8 public APIs, propagate through the private chain, replace the 7 context.Background() fallback sites, update CLI callers, and add a linter to prevent regression.
Full Analysis
Public APIs with no context (pkg/parser/remote_fetch.go)
DownloadFileFromGitHub line 876
DownloadFileFromGitHubForHost line 885
ResolveRefToSHAForHost line 893
ListWorkflowFiles line 1030
ListWorkflowFilesForHost line 1036
ListDirAllFilesForHost line 1095
ListDirAllFilesRecursivelyForHost line 1208
ListDirSubdirsForHost line 1354
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Task 1: Add context.Context to 8 public parser APIs
Priority: High | Effort: Medium Code Region: pkg/parser/remote_fetch.go
Add ctx context.Context as the first parameter to DownloadFileFromGitHub, DownloadFileFromGitHubForHost, ResolveRefToSHAForHost, ListWorkflowFiles, ListWorkflowFilesForHost, ListDirAllFilesForHost, ListDirAllFilesRecursivelyForHost, ListDirSubdirsForHost. Thread ctx into private implementations (downloadFileFromGitHubWithDepth, listWorkflowFilesForHost, etc.) and replace the 7 context.Background() fallback sites with the incoming ctx.
Acceptance Criteria:
All 8 public functions accept ctx context.Context as first param
7 context.Background() fallback sites replaced with caller ctx
go build ./... and go test ./pkg/parser/... pass
Task 2: Update CLI callers to pass cmd.Context()
Priority: High | Effort: Medium Code Region: pkg/cli/dispatch.go, pkg/cli/includes.go, pkg/cli/resources.go, pkg/cli/list_workflows_command.go, pkg/cli/add_package_manifest.go
After Task 1, update all 9 call sites in pkg/cli/ to pass the cobra command context. Update fileDownloadFn type in dispatch.go to include ctx context.Context as first param. Thread ctx from cobra RunE handlers into helper functions.
Acceptance Criteria:
All 9 CLI call sites pass a real context (not context.Background())
fileDownloadFn type updated in dispatch.go
go build ./... and go test ./pkg/cli/... pass
Task 3: Fix remaining context.Background() in CLI helpers
Priority: Medium | Effort: Small Code Region: pkg/cli/copilot_agents.go, pkg/cli/resources.go, pkg/cli/includes.go
buildAgenticWorkflowsSkillContent() (copilot_agents.go:222) calls listAgenticWorkflowsMarkdownFiles(context.Background()). resources.go:82 and includes.go:140 call getRepoDefaultBranch(context.Background(), ...). Thread the cobra context from the upstream RunE callers into these helpers.
Acceptance Criteria:
buildAgenticWorkflowsSkillContent accepts and uses ctx
resources.go:82 and includes.go:140 use caller ctx for getRepoDefaultBranch
go build ./... and go test ./pkg/cli/... pass
Task 4: Add httpbgctx linter to flag http.NewRequestWithContext(context.Background(), ...)
Priority: Medium | Effort: Small Code Region: pkg/linters/
Create pkg/linters/httpbgctx/ analyzer that flags http.NewRequestWithContext(context.Background(), ...) in non-test production code. Register in pkg/linters/linters.go and spec_test.go. Add testdata golden file.
Acceptance Criteria:
Analyzer reports the 7 pre-fix sites in remote_fetch.go
After Tasks 1-3 apply, zero findings
testdata golden-file test passes
Registered in linters.go and spec_test.go
📈 Success Metrics
context.Background() in auth-fallback paths: 7 → 0
Public parser APIs accepting context: 0/8 → 8/8
CLI callers passing real context: 0/9 → 9/9
Linter coverage for http.NewRequestWithContext(context.Background()): 0 → 1
Next Steps
Task 1 → Task 2 (sequential; Task 2 depends on Task 1 API change)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
🎯 Repository Quality Improvement Report — Remote Fetch API Context Gap
Analysis Date: 2026-07-02
Focus Area: Remote Fetch API Context Gap — Public
parserfunctions strip caller contextStrategy Type: Custom
Custom Area: Yes — caller context is silently discarded by 8 public wrappers in
pkg/parser/remote_fetch.goExecutive Summary
pkg/parser/remote_fetch.goexposes 8 public functions with nocontext.Contextparameter. All 8 delegate to private implementations that do accept context, but 7 auth-fallback sites hard-codecontext.Background()instead of threading the caller's context.Nine callers in
pkg/cli/already hold a cobracmd.Context()but cannot pass it — so Ctrl-C does not cancel in-flight HTTP requests. The fix is to addctx context.Contextto the 8 public APIs, propagate through the private chain, replace the 7context.Background()fallback sites, update CLI callers, and add a linter to prevent regression.Full Analysis
Public APIs with no context (pkg/parser/remote_fetch.go)
context.Background() hard-coded in fallback paths
CLI callers that cannot propagate context
Metrics:
🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Task 1: Add
context.Contextto 8 public parser APIsPriority: High | Effort: Medium
Code Region:
pkg/parser/remote_fetch.goAdd
ctx context.Contextas the first parameter toDownloadFileFromGitHub,DownloadFileFromGitHubForHost,ResolveRefToSHAForHost,ListWorkflowFiles,ListWorkflowFilesForHost,ListDirAllFilesForHost,ListDirAllFilesRecursivelyForHost,ListDirSubdirsForHost. Thread ctx into private implementations (downloadFileFromGitHubWithDepth,listWorkflowFilesForHost, etc.) and replace the 7context.Background()fallback sites with the incoming ctx.Acceptance Criteria:
ctx context.Contextas first paramcontext.Background()fallback sites replaced with caller ctxgo build ./...andgo test ./pkg/parser/...passTask 2: Update CLI callers to pass
cmd.Context()Priority: High | Effort: Medium
Code Region:
pkg/cli/dispatch.go,pkg/cli/includes.go,pkg/cli/resources.go,pkg/cli/list_workflows_command.go,pkg/cli/add_package_manifest.goAfter Task 1, update all 9 call sites in pkg/cli/ to pass the cobra command context. Update
fileDownloadFntype indispatch.goto includectx context.Contextas first param. Thread ctx from cobra RunE handlers into helper functions.Acceptance Criteria:
fileDownloadFntype updated in dispatch.gogo build ./...andgo test ./pkg/cli/...passTask 3: Fix remaining context.Background() in CLI helpers
Priority: Medium | Effort: Small
Code Region:
pkg/cli/copilot_agents.go,pkg/cli/resources.go,pkg/cli/includes.gobuildAgenticWorkflowsSkillContent()(copilot_agents.go:222) callslistAgenticWorkflowsMarkdownFiles(context.Background()).resources.go:82andincludes.go:140callgetRepoDefaultBranch(context.Background(), ...). Thread the cobra context from the upstream RunE callers into these helpers.Acceptance Criteria:
buildAgenticWorkflowsSkillContentaccepts and uses ctxresources.go:82andincludes.go:140use caller ctx forgetRepoDefaultBranchgo build ./...andgo test ./pkg/cli/...passTask 4: Add
httpbgctxlinter to flaghttp.NewRequestWithContext(context.Background(), ...)Priority: Medium | Effort: Small
Code Region:
pkg/linters/Create
pkg/linters/httpbgctx/analyzer that flagshttp.NewRequestWithContext(context.Background(), ...)in non-test production code. Register inpkg/linters/linters.goandspec_test.go. Add testdata golden file.Acceptance Criteria:
📈 Success Metrics
Next Steps
References: §28593277510
Beta Was this translation helpful? Give feedback.
All reactions