[repository-quality] Repository Quality Improvement Report - Context Propagation & Process Cancellability #36655
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-06-04T14:26:25.924Z.
|
Beta Was this translation helpful? Give feedback.
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 Propagation & Process Cancellability
Analysis Date: 2026-06-03
Focus Area: Context Propagation & Process Cancellability
Strategy Type: Custom
Executive Summary
A scan of all subprocess invocations reveals 109 bare
exec.Commandcalls vs only 24exec.CommandContextcalls — meaning 82% of subprocesses cannot be cancelled, timed out, or interrupted by a caller-provided context. This directly undermines the CLI'ssignal.NotifyContextinterrupt handling: when a user presses Ctrl+C, in-flight git operations are orphaned.The problem is most severe in
pkg/cli/run_push.go, where functions receivectx context.Contextfor compilation but ignore it for 4 git subprocess calls (commit, push, add, diff). Similarly,pkg/cli/git.go(18 bare calls) andpkg/cli/pr_command.go(20 bare calls) contain foundational helpers with no context parameters. The repository already has actxbackgroundlinter — extending it to coverexec.Commandwould prevent future regressions automatically.Full Analysis Report
Current State Assessment
exec.Commandbare callsexec.CommandContextcallsctxbackgroundpresentTop offenders:
pkg/cli/pr_command.gopkg/cli/git.gopkg/parser/remote_fetch.gopkg/cli/trial_repository.gopkg/cli/run_push.goFindings
Strengths
exec.CommandContextused correctly inpkg/workflow/docker_validation.goand theRunGHContextfamilysignal.NotifyContextused inforecast.gofor interrupt propagationctxbackgroundlinter already exists inpkg/linters/Areas for Improvement
run_push.goreceivesctxfor compilation but drops it before git subprocess calls on lines ~426, 439, 582, 596git.gocore helpers (getCurrentBranch,commitChanges,pushBranch) lack ctx parameter, blocking propagationpr_command.go20-call helper chain (applyPatchToRepo,createTransferPR) has no ctxremote_fetch.gogit clone/ls-remote calls (13 occurrences) can run for minutes with no timeoutctxbackgroundonly flagscontext.Background(), not bareexec.Command🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Fix
run_push.go— Pass ctx to Git SubprocessesPriority: High
Estimated Effort: Small
Description:
pushWorkflowFilesand helpers receive noctxeven though callers do. Addctx context.ContexttopushWorkflowFilesand replace 4 bareexec.Commandcalls (lines ~426, 439, 582, 596) withexec.CommandContext(ctx, ...).Acceptance Criteria:
pushWorkflowFilesacceptsctx context.Contextas first parameterexec.Command("git", ...)calls replaced withexec.CommandContext(ctx, "git", ...)make fmtand tests passCode Region:
pkg/cli/run_push.goTask 2: Add Context to
pkg/cli/git.goCore HelpersPriority: High
Estimated Effort: Medium
Description: Add
ctx context.ContexttogetCurrentBranch,createAndSwitchBranch,switchBranch,commitChanges,pushBranch,checkCleanWorkingDirectory, andcheckWorkflowFileStatus. Replace all 18 bareexec.Commandcalls withexec.CommandContext(ctx, ...). Update callers to passcmd.Context()from cobra handlers.Acceptance Criteria:
ctx context.Contextas first parametercontext.Background()escapes introducedmake fmtand tests passCode Region:
pkg/cli/git.goTask 3: Thread Context Through
pr_command.goHelper ChainPriority: Medium
Estimated Effort: Medium
Description:
applyPatchToRepo(line 261),createTransferPR(line 411), andtransferPR(line 540) account for 20 bare calls in a long-running git operation sequence. Add ctx and useexec.CommandContext. For cleanup/abort operations, usecontext.WithTimeout(context.Background(), 10*time.Second)so cleanup still runs after cancellation.Acceptance Criteria:
transferPR,applyPatchToRepo,createTransferPRacceptctx context.Contextmake fmtand tests passCode Region:
pkg/cli/pr_command.goTask 4: Extend
ctxbackgroundLinter to Flagexec.Commandin Context-Aware FunctionsPriority: High
Estimated Effort: Small
Description: Extend (or add companion
execnocontextlinter) to flagexec.Command(...)calls inside functions that have acontext.Contextparameter in scope, suggestingexec.CommandContext(ctx, ...). Register and add test data.Acceptance Criteria:
exec.Commandwhen ctx param is in scope with message suggestingexec.CommandContextmake lintpassesCode Region:
pkg/linters/ctxbackground/ctxbackground.goTask 5: Thread Context Into
remote_fetch.goGit OperationsPriority: Medium
Estimated Effort: Medium
Description:
remote_fetch.gohas 13 bare exec.Command calls for network-touching git operations (clone, ls-remote, archive). Addctx context.ContexttoresolveRefToSHAViaGit,downloadFileViaGit,downloadFileViaGitClone, andgetOrCreateListRepoClone. Update public API (DownloadFileFromGitHubForHost,ResolveRefToSHAForHost) to accept ctx.Acceptance Criteria:
make fmtand tests passCode Region:
pkg/parser/remote_fetch.go📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions
run_push.go— git ops during cancel corrupt state — Priority: Highctxbackgroundlinter forexec.Command— self-enforcing — Priority: HighShort-term
git.gohelpers — enables full CLI cancellation — Priority: Highpr_command.go— Priority: MediumLong-term
remote_fetch.gopublic API — enables network op timeouts — Priority: Medium📈 Success Metrics
References: §26890744714
Beta Was this translation helpful? Give feedback.
All reactions