Skip to content

[Code Quality] refactor: replace ExecGH/RunGH/RunGHCombined with context-aware siblings to fix context.Background() leakage #48436

Description

@github-actions

Description

Three convenience wrappers in pkg/workflow/github_cli.go hard-code context.Background() even though all callers already hold a live signal-propagating context. This creates silent cancellation dead zones: when a user presses Ctrl+C the signal context is cancelled, but any call routed through these wrappers continues running until it times out.

Affected Functions

  • ExecGH → should call ExecGHContext(ctx, ...)
  • RunGH → should call RunGHContext(ctx, ...)
  • RunGHCombined → should call RunGHCombinedContext(ctx, ...)

Context-aware siblings (ExecGHContext, RunGHContext, RunGHCombinedContext) already exist in the same file — the fix is to thread ctx from callers instead of hard-coding context.Background().

Scope

  • 92 downstream call sites are affected
  • Entry-points already wire signal.NotifyContext correctly in cmd/gh-aw/main.go and pkg/cli/forecast.go
  • The fix propagates that cancellation signal through the entire compiler pipeline

Suggested Changes

  1. Update ExecGH, RunGH, RunGHCombined to accept ctx context.Context as first arg and delegate to the *Context siblings
  2. Update all 92 call sites to pass their local ctx
  3. Verify make test-unit passes

Files Affected

  • pkg/workflow/github_cli.go (3 functions)
  • All callers in pkg/workflow/, pkg/cli/, pkg/compiler/ (~92 sites)

Success Criteria

  • grep -r "ExecGH(\|RunGH(\|RunGHCombined(" --include=*.go pkg/ cmd/ returns 0 non-context call sites
  • All existing tests pass
  • Ctrl+C at any point cancels in-flight gh CLI subprocesses

Source

Extracted from discussion #48389 — context.Background() Call-Chain Leakage

Priority

High — affects 92 call sites, degrades signal-aware lifecycle and user-visible Ctrl+C responsiveness

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · sonnet46 · 42.7 AIC · ⌖ 5.66 AIC · ⊞ 7.2K ·

  • expires on Jul 28, 2026, 11:13 AM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions