[repository-quality] Repository Quality Improvement Report — context.Background() Call-Chain Leakage #48389
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-07-28T13:54:45.558Z.
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🎯 Repository Quality Improvement Report — context.Background() Call-Chain Leakage
Analysis Date: 2026-07-27
Focus Area: context.Background() Call-Chain Leakage — Uncancellable Sub-calls Despite Cobra Signal Context at Entry Points
Strategy Type: Custom
Custom Area: Yes — distinct from prior context-propagation runs (2026-06-03/09/22) which targeted
exec.Command; this run targets wrappers and helper functions that hard-codecontext.Background()even when caller context existsExecutive Summary
The repository's entry-point commands consistently capture a cancellable context via
signal.NotifyContext(context.Background(), ...)and thread it through cobraRunEhandlers. However, 40context.Background()calls exist in non-test production code below the entry points, many inside functions that are already called with a live context — or whose callers hold one. This creates silent cancellation dead zones: when a user presses Ctrl+C, the signal context is cancelled and most work stops cleanly, but calls routed through the affected helpers continue running until they time out or finish naturally.The most impactful cluster is in
pkg/workflow/github_cli.go: three convenience wrappers (ExecGH,RunGH,RunGHCombined) discard their callers' contexts and hard-codecontext.Background(), affecting 92 downstream call sites. Context-aware siblings (ExecGHContext,RunGHContext,RunGHCombinedContext) already exist and are the correct fix path. A secondary cluster inpkg/parser/remote_workflow_spec.gohas threecontext.Background()network calls with an existing TODO comment acknowledging the gap.Five high-value fixes would eliminate the largest leakage surface, propagate cancellation signals through compiler pipelines, validation helpers, and log-download flows, and bring the codebase closer to fully honouring its own signal-aware lifecycle contract.
Full Analysis Report
Focus Area: context.Background() Call-Chain Leakage
Current State Assessment
Entry points (
cmd/gh-aw/main.go,pkg/cli/forecast.go) correctly anchor a signal-aware context:This context flows through cobra's
cmd.Context()intoRunEhandlers and option structs. However, deeper helpers bypass it.Metrics Collected:
context.Background()calls in non-test production codecontext.Contextparam (ctxbackground violations)ghwrappers (ExecGH,RunGH,RunGHCombined)context.TODO()calls in production codeFindings
Strengths
ghwrappersctxbackgroundlinter exists and catches in-function violations — but doesn't catch wrapper functions that create the context before delegatingAreas for Improvement
pkg/workflow/github_cli.go:106,191,213—ExecGH,RunGH,RunGHCombinedeach call their*Contextsiblings with a hard-codedcontext.Background(). Any caller that has a valid context and uses the non-context variant loses cancellation for all gh CLI network I/Opkg/parser/remote_workflow_spec.go:91,93,156— ThreedownloadFileFromGitHub/resolveRefToSHAcalls hard-codecontext.Background(). The enclosing functions are called during compilation; an in-progress compile cannot be cancelled at this step. A TODO comment at line 71 already acknowledges thispkg/cli/logs_orchestrator_filters.go:167—fetchJobStatusesForProcessedRun(context.Background(), ...)insidebuildRunsModel; the enclosing flow is called from log-download commands that carry a live contextpkg/cli/update_extension_check.go:49—upgradeExtensionIfOutdatedcreates no context parameter; its only caller (runUpgradeCommandat line 245) holdsopts.ctxfrom cobra. GitHub API call for the latest release is fully uncancellablepkg/cli/syft.go:67—RunSyftOnLockFilesis called fromcompilePipelinewhich checksctx.Err()right before the call, butrunSyftScanscreates a freshcontext.Background()internally and never propagates cancellation into the image-scan loopDetailed Analysis
pkg/workflow/github_cli.go— Non-context gh wrappers (92 downstream callers)The three context-less wrappers exist for convenience but create a systemic leakage:
All 92 call sites of these functions could inherit caller context if the functions were removed and callers migrated to the
*Contextvariants.pkg/parser/remote_workflow_spec.go— Acknowledged TODOThe calling functions accept no
ctxparameter, so fixing requires a signature change to propagate the compiler's context.pkg/cli/logs_orchestrator_filters.go:167The
fetchJobStatusesForProcessedRunfunction accepts acontext.Context; only the call site supplies the wrong one.pkg/cli/update_extension_check.go:49+pkg/cli/upgrade_command.go:245The fix requires adding
ctx context.ContexttoupgradeExtensionIfOutdatedand threading it fromopts.ctxinrunUpgradeCommand.🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Deprecate Non-Context gh Wrappers and Migrate Top Call Sites
Priority: High
Estimated Effort: Medium
Focus Area: context.Background() Call-Chain Leakage
Description: The three context-less wrapper functions
ExecGH,RunGH, andRunGHCombinedinpkg/workflow/github_cli.go(lines 106, 191, 213) hard-codecontext.Background()while calling their context-aware siblings. Identify all call sites usinggrep -rn 'ExecGH\|RunGH\|RunGHCombined' pkg/ cmd/(excluding the*Contextvariants), add a// Deprecated:doc comment to each wrapper, and migrate call sites insidepkg/cli/that already have actxvariable in scope to the corresponding*Contextvariant.Acceptance Criteria:
ExecGH,RunGH,RunGHCombinedeach have a// Deprecated: use the *Context variantdoc commentpkg/cli/that have a localctx context.Contextin scope are migrated to pass that contextmake fmtpassesmake test-unitpassesCode Region:
pkg/workflow/github_cli.go,pkg/cli/Task 2: Propagate Caller Context Through Remote Workflow Spec Fetchers
Priority: High
Estimated Effort: Medium
Focus Area: context.Background() Call-Chain Leakage
Description:
pkg/parser/remote_workflow_spec.gocontains threecontext.Background()network calls on lines 91, 93, and 156 with a TODO comment at line 71 acknowledging the gap. The enclosing functions (downloadRemoteFileForImport,resolveRemoteRef) lackctxparameters. Addctx context.Contextparameters to these functions and propagate the compiler's context from callers inpkg/parser/andpkg/cli/.Acceptance Criteria:
downloadRemoteFileForImportandresolveRemoteRef(or equivalent enclosing functions) acceptctx context.Contextcontext.Background()calls on lines 91/93/156 are replaced with the propagated ctxpkg/parser/andpkg/cli/are updated to pass contextmake test-unitpassesCode Region:
pkg/parser/remote_workflow_spec.goTask 3: Thread Context Through upgradeExtensionIfOutdated
Priority: Medium
Estimated Effort: Small
Focus Area: context.Background() Call-Chain Leakage
Description:
upgradeExtensionIfOutdatedinpkg/cli/update_extension_check.go(line 49) has noctx context.Contextparameter, so its internal call togetLatestRelease(context.Background(), ...)(line 63) cannot be cancelled. Its only production callerrunUpgradeCommandinpkg/cli/upgrade_command.go(line 245) holdsopts.ctx. Add actxparameter and thread it.Acceptance Criteria:
upgradeExtensionIfOutdatedsignature becomesfunc upgradeExtensionIfOutdated(ctx context.Context, verbose bool, includePrereleases bool) (bool, string, error)getLatestReleasecall at line 63 uses the passed-in ctxrunUpgradeCommandat line 245 passesopts.ctx_test.gofiles are updatedmake test-unitpassesCode Region:
pkg/cli/update_extension_check.go,pkg/cli/upgrade_command.goTask 4: Fix context.Background() in logs_orchestrator_filters and syft scan loop
Priority: Medium
Estimated Effort: Small
Focus Area: context.Background() Call-Chain Leakage
Description: Two related context-leakage points in the log/scan pipeline: (a)
pkg/cli/logs_orchestrator_filters.go:167callsfetchJobStatusesForProcessedRun(context.Background(), ...)insidebuildRunsModel— the outer pipeline carries a live context that should flow here; (b)pkg/cli/syft.go:67creates a standalonecontext.Background()forrunSyftOnImagecalls inside an image-scan loop, whilecompile_pipeline.gochecksctx.Err()right before callingRunSyftOnLockFilesbut the ctx never reaches the loop.Acceptance Criteria:
buildRunsModel(or its enclosing function) inpkg/cli/logs_orchestrator_filters.goreceives actxparameter and passes it tofetchJobStatusesForProcessedRunRunSyftOnLockFiles/runSyftScansinpkg/cli/syft.goandpkg/cli/compile_external_tools.goacceptctx context.Contextand the scan loop uses itcompile_pipeline.gocall sites pass their localctxto the syft functionmake test-unitpassesCode Region:
pkg/cli/logs_orchestrator_filters.go,pkg/cli/syft.go,pkg/cli/compile_external_tools.go,pkg/cli/compile_pipeline.goTask 5: Add ctxbackground Linter Coverage for Wrapper Functions That Synthesise Background Context
Priority: Low
Estimated Effort: Small
Focus Area: context.Background() Call-Chain Leakage
Description: The existing
ctxbackgroundlinter inpkg/linters/ctxbackground/flagscontext.Background()inside functions that already receive a context parameter — but it does not flag wrapper functions whose only purpose is to call a*Contextsibling withcontext.Background()(e.g.ExecGH,RunGH,RunGHCombined). Extend the linter or add a new lint rule to detect this pattern: a function with nocontext.Contextparameter that calls an identically-named*Contextsibling with a hardcodedcontext.Background()as first argument.Acceptance Criteria:
ctxbackgroundflags the pattern:func Foo(args) { return FooContext(context.Background(), args) }github_cli.go(once deprecated) trigger the new rule or are excluded vianolintwith rationalepkg/linters/all.go(if a new analyzer)make test-unitpasses includingpkg/linters/...testsCode Region:
pkg/linters/ctxbackground/,pkg/linters/all.go📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
Short-term Actions (This Month)
Long-term Actions (This Quarter)
📈 Success Metrics
*Contextvariants)Next Steps
References:
[§30271523540]— workflow run that generated this reportGenerated by Repository Quality Improvement Agent
All reactions