Skip to content

refactor: migrate remaining RunGHWithHost call sites to RunGHContextWithHost - #49554

Merged
pelikhan merged 8 commits into
mainfrom
copilot/refactor-migrate-rungh-withhost-call-sites
Aug 1, 2026
Merged

refactor: migrate remaining RunGHWithHost call sites to RunGHContextWithHost#49554
pelikhan merged 8 commits into
mainfrom
copilot/refactor-migrate-rungh-withhost-call-sites

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

89% of cross-host gh call sites in pkg/cli were using the legacy workflow.RunGHWithHost, making GHES/data-residency operations non-cancellable and unboundable by caller timeouts.

Changes

  • pkg/workflow/github_cli.go — marks RunGHWithHost as // Deprecated: Use RunGHContextWithHost

  • pkg/cli/pr_command.go — adds ctx context.Context to createPR; both RunGHWithHost calls replaced with RunGHContextWithHost(ctx, ...)

  • pkg/cli/pr_helpers.go — adds ctx to CreatePRWithChanges, threaded through to createPR

  • pkg/cli/add_workflow_pr.go, update_command.go, upgrade_command.go, upgrade_org.go, deploy_command.go, init.go — callers of CreatePRWithChanges updated to pass cmd.Context() or existing ctx

  • pkg/cli/outcome_eval.go — 3 RunGHWithHost calls replaced with RunGHContextWithHost(context.Background(), ...); real ctx threading deferred since the eval* call chain has no ctx without a larger refactor

  • pkg/cli/add_package_manifest.go — lambda at line 990 already had ctx and now passes it through; line 938 uses context.Background() to preserve the test-mocked var signature

// Before
repoOutput, err := workflow.RunGHWithHost("Fetching repository info...", remoteHost, "repo", "view", "--json", "owner,name")

// After — ctx from cmd.Context() propagated through createPR
func createPR(ctx context.Context, branchName, title, body string, verbose bool) (int, string, error) {
    ...
    repoOutput, err := workflow.RunGHContextWithHost(ctx, "Fetching repository info...", remoteHost, "repo", "view", "--json", "owner,name")

After this change grep -rn "workflow\.RunGHWithHost(" pkg/cli --include='*.go' | grep -v _test.go returns zero results.


run: https://github.com/github/gh-aw/actions/runs/30716547955

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13.2 AIC · ⌖ 5.91 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Run URL: https://github.com/github/gh-aw/actions/runs/30719603092

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.21 AIC · ⌖ 6.88 AIC · ⊞ 8.1K ·
Comment /souschef to run again

…ithHost

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor: Migrate remaining RunGHWithHost call sites to RunGHContextWithHost refactor: migrate remaining RunGHWithHost call sites to RunGHContextWithHost Aug 1, 2026
Copilot AI requested a review from pelikhan August 1, 2026 08:27
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Triage

Category: refactor · Risk: medium · Priority: medium · Score: 42/100 (impact 20, urgency 10, quality 12)

Recommended action: defer

Mechanical migration of RunGHWithHostRunGHContextWithHost across 12 files. Draft with no CI yet; medium risk due to breadth of touched call sites — defer until CI is green and draft is marked ready.

Generated by 🔧 PR Triage Agent · auto · 49.2 AIC · ⌖ 8.64 AIC · ⊞ 8K ·

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: refactor
  • Risk: medium
  • Priority: low
  • Score: 34/100 (Impact20/Urgency8/Quality6)
  • Recommended action: defer

Draft; large call-site migration (RunGHWithHost -> RunGHContextWithHost), moderate blast radius, still draft.

Generated by 🔧 PR Triage Agent · auto · 73.4 AIC · ⌖ 10.1 AIC · ⊞ 8K ·

@pelikhan
pelikhan marked this pull request as ready for review August 1, 2026 19:33
Copilot AI review requested due to automatic review settings August 1, 2026 19:33
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #49554 does not have the implementation label and has only 25 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates cross-host gh operations toward context-aware execution, though several calls still use non-cancellable background contexts.

Changes:

  • Deprecates RunGHWithHost.
  • Threads caller contexts through PR creation paths.
  • Replaces remaining legacy calls in package and outcome evaluation paths.
Show a summary per file
File Description
pkg/workflow/github_cli.go Deprecates the legacy host wrapper.
pkg/cli/pr_command.go Adds context-aware PR operations.
pkg/cli/pr_helpers.go Propagates context into PR creation.
pkg/cli/add_workflow_pr.go Passes the existing workflow context.
pkg/cli/add_package_manifest.go Migrates package lookup calls.
pkg/cli/outcome_eval.go Migrates outcome API calls.
pkg/cli/update_command.go Passes contexts when creating update PRs.
pkg/cli/upgrade_command.go Passes the command context.
pkg/cli/upgrade_org.go Passes the target-repository context.
pkg/cli/deploy_command.go Threads context through deploy PR creation.
pkg/cli/init.go Passes initialization context.
pkg/cli/README.md Documents the updated helper signature.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Suppressed comments (3)

pkg/cli/outcome_eval.go:308

  • The GraphQL request is still unboundable because context.Background() never observes caller cancellation or deadlines. Propagate the command/audit context to this helper rather than replacing the legacy wrapper with a background context.
		output, err = workflow.RunGHContextWithHost(context.Background(), "Checking outcome...", host, args...)

pkg/cli/add_package_manifest.go:990

  • Although this lambda accepts a context, resolveRepositoryPackageLatestRelease invokes it only via resolveLatestReleaseWithDeps(context.Background(), ...) below, while resolveRepositoryPackage already has a real caller context. The release lookup consequently remains uncancellable; thread that existing context through the helper and function variable.
				return workflow.RunGHContextWithHost(ctx, "Fetching releases...", host, args...)

pkg/cli/outcome_eval.go:287

  • This background context preserves the legacy call's non-cancellable behavior for array API requests, contrary to the migration's purpose. Pass the originating command/audit context through the outcome evaluator chain instead.
		output, err = workflow.RunGHContextWithHost(context.Background(), "Checking outcome...", host, args...)
  • Files reviewed: 12/12 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread pkg/cli/outcome_eval.go Outdated
var err error
if host != "" {
output, err = workflow.RunGHWithHost("Checking outcome...", host, args...)
output, err = workflow.RunGHContextWithHost(context.Background(), "Checking outcome...", host, args...)
Comment thread pkg/cli/add_package_manifest.go Outdated
var err error
if host != "" {
output, err = workflow.RunGHWithHost("Fetching repo info...", host, args...)
output, err = workflow.RunGHContextWithHost(context.Background(), "Fetching repo info...", host, args...)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, consistent context-propagation refactor. All call sites that already had a context thread it through correctly; the three context.Background() uses in outcome_eval.go are an acceptable placeholder given those functions do not yet accept a context parameter (pre-existing design).

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 11.8 AIC · ⌖ 13.7 AIC · ⊞ 5.4K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design — no blocking issues, two minor TODO comment suggestions.

📋 Summary

Positive highlights

  • ✅ Clean mechanical refactor — every RunGHWithHost call in pkg/cli now uses the context-aware variant
  • Deprecated: godoc annotation on RunGHWithHost correctly guides future callers
  • ✅ Context is properly threaded from cmd.Context() all the way down through CreatePRWithChangescreatePR
  • ✅ README kept in sync with the updated CreatePRWithChanges signature

Suggestions (non-blocking)

  1. pkg/cli/outcome_eval.go lines 262, 287, 308 — three context.Background() calls are acknowledged deferrals, but lack a TODO comment. Without one, future readers cannot distinguish intentional deferral from an oversight.

  2. pkg/cli/add_package_manifest.go line 938context.Background() is constrained by the test-mock var signature (getRepositoryPackageDefaultBranch has no ctx). A brief comment explaining this constraint would help the next refactor.

Neither issue affects correctness; both affect long-term maintainability.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 26.3 AIC · ⌖ 7.92 AIC · ⊞ 7.1K
Comment /matt to run again

Comment thread pkg/cli/add_package_manifest.go Outdated
var err error
if host != "" {
output, err = workflow.RunGHWithHost("Fetching repo info...", host, args...)
output, err = workflow.RunGHContextWithHost(context.Background(), "Fetching repo info...", host, args...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] context.Background() here is forced by the test-mock var (getRepositoryPackageDefaultBranch) whose signature has no ctx. The constraint is real but silent — a // TODO: add ctx to getRepositoryPackageDefaultBranch once the mock var signature supports it comment would surface this for the next refactor pass rather than leaving an unexplained context.Background().

@copilot please address this.

Comment thread pkg/cli/outcome_eval.go Outdated
var err error
if host != "" {
output, err = workflow.RunGHWithHost("Checking outcome...", host, args...)
output, err = workflow.RunGHContextWithHost(context.Background(), "Checking outcome...", host, args...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] context.Background() here silently discards any cancellation or deadline from the caller. The PR body notes this is deferred — a // TODO: thread real ctx once the eval* call chain is refactored comment on lines 262, 287, and 308 would make the intent visible and prevent the pattern from being copied as a template.

@copilot please address this.

@pelikhan

pelikhan commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

…lity

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot make wasm golden more resilient

Fix https://github.com/github/gh-aw/actions/runs/30715022301/job/91409111260

Fixed in commit fix: add copilot version normalization to wasm golden tests for stability.

Added testDefaultCopilotInfoVersionRE and testDefaultCopilotAgentInfoVersionRE normalization regexes to wasm_golden_test.go, mirroring the pattern used for codex and pi. Updated all affected golden files to use the stable COPILOT_VERSION placeholder instead of a hardcoded version number. TestWasmGolden_AllEngines/copilot now passes regardless of DefaultCopilotVersion bumps.

@pelikhan

pelikhan commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts on this branch.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage for this PR:

  • Merge conflicts are blocking merge. Please run make merge-main, resolve the conflicts cleanly, rerun any impacted validation, and summarize the conflict resolution in your reply.
  • Review follow-up still worth closing out after the branch is green:
    1. copilot-pull-request-reviewer — thread the caller context through the remaining context.Background() outcome-eval/release-lookup paths rather than leaving them uncancellable. refactor: migrate remaining RunGHWithHost call sites to RunGHContextWithHost #49554
    2. Matt Pocock Skills Reviewer — if the context.Background() deferrals stay, add explicit TODO/comments so the limitation is intentional and discoverable. https://github.com/github/gh-aw/actions/runs/30715022335
  • There is also a recent maintainer request to make the wasm golden more resilient; verify that fix still holds after resolving conflicts.
  • Please run the pr-finisher skill before handoff.

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13.2 AIC · ⌖ 5.91 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 1, 2026 20:26
…ION normalization

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts on this branch.

Resolved. Merged origin/main into the branch. The only conflicts were in the copilot golden files — main had bumped them to the hardcoded 1.0.77 while our branch used the stable COPILOT_VERSION placeholder. Resolved by keeping the placeholder (consistent with the normalization regexes in wasm_golden_test.go), then recompiled workflows to bring lock files in sync.

…paths

- outcomeEvaluator type now includes ctx context.Context as first param
- All eval* functions (evalCreatePullRequest, evalCreateIssue, evalAddComment,
  evalReplaceLabel, evalAddLabels, evalAssignToAgent, evalAddReviewer,
  evalSubmitPullRequestReview, evalCloseSticky, evalGenericSticky,
  evalDispatchWorkflow, evalUpdateDiscussion, evalUpdateIssue,
  evalUpdatePullRequest, evalRetainedUpdate) now take ctx
- ghAPIGet/ghAPIGetArray/ghAPIGraphQL now take ctx; context.Background() removed
- mutableStateLoader type includes ctx; extractCurrentIssueUpdateState and
  extractCurrentPullRequestUpdateState take ctx
- EvaluateOutcomes and RunOutcomes take ctx; cobra passes cmd.Context()
- buildAuditData/addAuditOutcomeSummary take ctx; audit.go passes real ctx
- resolveRepositoryPackageDefaultBranch/LatestRelease take ctx; callers pass ctx
- All test files updated to match new signatures

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage for this PR:

  • Merge conflicts are blocking merge. Please run make merge-main, resolve the conflicts cleanly, rerun any impacted validation, and summarize the conflict resoluti...

Done. Context threading is now complete:

Outcome eval subsystemoutcomeEvaluator type, all 15 eval* functions, ghAPIGet/Array/GraphQL, and mutableStateLoader now carry ctx. EvaluateOutcomes and RunOutcomes accept ctx; cobra passes cmd.Context(). buildAuditData/addAuditOutcomeSummary in audit_report.go also propagate the real ctx.

Package manifestresolveRepositoryPackageDefaultBranch and resolveRepositoryPackageLatestRelease now accept and use the caller's ctx (already available in resolveRepositoryPackage). No context.Background() remains in either path.

grep -rn "context\.Background()" pkg/cli/outcome_eval*.go pkg/cli/add_package_manifest.go returns zero results in production code.

All test files updated to match new signatures, make fmt run, unit tests pass. Commit: fix: thread caller context through outcome eval and package manifest paths.

Copilot AI requested a review from gh-aw-bot August 1, 2026 21:00
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot
Please investigate this PR and move it toward merge readiness.
Failed checks:

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.21 AIC · ⌖ 6.88 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Please investigate this PR and move it toward merge readiness.
Failed checks:...

Fixed in commit fix: add Copilot version normalization to wasm golden JS test script.

Root cause: scripts/test-wasm-golden.mjs was missing Copilot version normalization, so the wasm output GH_AW_INFO_VERSION: "1.0.77" didn't match the golden files' COPILOT_VERSION placeholder. Two bugs fixed:

  1. Added copilotVersion: getVersion("DefaultCopilotVersion") to loadDefaultRuntimeVersions and the corresponding .replace() calls for GH_AW_INFO_VERSION/GH_AW_INFO_AGENT_VERSION in normalizeDefaultRuntimeVersions — mirroring testDefaultCopilotInfoVersionRE in the Go test.
  2. Fixed getVersion regex to use ^ anchor with multiline flag ("m") to prevent matching commented-out constant definitions (the file has //\tconst DefaultCopilotVersion Version = "0.0.369" on line 10 which was being matched instead of the live "1.0.77" declaration).

@pelikhan
pelikhan merged commit 7fd2403 into main Aug 1, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/refactor-migrate-rungh-withhost-call-sites branch August 1, 2026 22:33
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Quality] refactor: migrate remaining RunGHWithHost call sites to RunGHContextWithHost (89% still legacy)

4 participants