Skip to content

Preserve the active branch when delegating to the cloud agent#4841

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-cloud-agent-branch-issue
Draft

Preserve the active branch when delegating to the cloud agent#4841
Copilot wants to merge 3 commits intomainfrom
copilot/fix-cloud-agent-branch-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Delegation to the cloud agent could silently switch the PR base from the user's current branch back to the repository default branch. This broke continuation from branch-specific work unless the branch had already been explicitly reselected through repository resolution.

  • Branch selection

    • Preserve an existing base_ref when delegating within the current repository.
    • Re-resolve the base branch only when:
      • no base_ref is available, or
      • the user selected a different repository for delegation.
  • Resolution guardrails

    • Extract the base-branch decision into a small helper to make the behavior explicit.
    • Ignore malformed selected-repository values instead of treating them as a repository switch.
    • Handle cases where current repository metadata is unavailable by falling back to branch resolution.
  • Focused coverage

    • Add unit coverage for:
      • current repo + existing branch
      • default repository selection
      • missing base_ref
      • alternate selected repository
      • malformed repository identifiers
      • missing current repository metadata
if (!baseRefToUse || shouldResolveDelegationBaseRef(baseRefToUse, { owner: repoOwner, name: repoName }, selectedRepository)) {
	const { default_branch } = await this._githubRepositoryService.getRepositoryInfo(repoOwner, repoName);
	baseRefToUse = default_branch;
}

This keeps cloud delegation aligned with the branch the user is actually working on, while preserving the previous fallback behavior for cross-repo delegation and missing branch state.

Copilot AI and others added 2 commits March 30, 2026 21:40
Copilot AI changed the title [WIP] Fix cloud agent to honor current branch during remote jobs Preserve the active branch when delegating to the cloud agent Mar 30, 2026
Copilot AI requested a review from joshspicer March 30, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Delegate to cloud agent" uses wrong branch

2 participants