Skip to content

fix: adopt --remote fails when branches aren't ordered parent-first#679

Open
simsinght wants to merge 1 commit intomasterfrom
fix/adopt-remote-batch-ordering
Open

fix: adopt --remote fails when branches aren't ordered parent-first#679
simsinght wants to merge 1 commit intomasterfrom
fix/adopt-remote-batch-ordering

Conversation

@simsinght
Copy link
Copy Markdown
Contributor

@simsinght simsinght commented Mar 20, 2026

Summary

  • av adopt --remote fails with "ancestor branch is missing from av metadata" when adopting stacks
  • Root cause: initAdoption built the branches slice by iterating chosenTargets from the tree selector, which has no guaranteed order. The remote PR walker returns PRs leaf-first, but chosenTargets doesn't preserve that order. When a child branch was adopted before its parent, ValidateNoCycle failed because the parent wasn't in metadata yet.
  • Fix: iterate prs in reverse (parent-first) filtered to chosen targets, instead of iterating chosenTargets directly. Only the --remote codepath is affected; local adopt is unchanged.

Test plan

  • Existing TestAdopt e2e tests pass
  • pre-commit run --all-files passes
  • Manually verified with a 7-branch stack (av adopt --remote inbox/suspense) that previously failed

@simsinght simsinght requested a review from a team as a code owner March 20, 2026 00:38
@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Mar 20, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Mar 20, 2026

🔃 FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • 🔒 aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • 🔒 cmd/av/adopt.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.

@aviator-app aviator-app bot requested a review from davi-maciel March 20, 2026 00:38
@gemini-code-assist

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@davi-maciel davi-maciel requested review from tulioz and removed request for davi-maciel March 20, 2026 17:55
@simsinght simsinght force-pushed the fix/adopt-remote-batch-ordering branch from d9fadd6 to 675168c Compare March 20, 2026 20:19
The remote PR walker builds the branch list leaf-first (starting from
the given branch and walking up to trunk). initAdoption iterated
chosenTargets from the tree selector, which has no guaranteed order,
and adopted each branch sequentially. When a child was processed
before its parent, ValidateNoCycle failed with "ancestor branch is
missing from av metadata".

Fix by iterating prs in reverse (parent-first) filtered to chosen
targets, so parents are always adopted before their children.
@simsinght simsinght force-pushed the fix/adopt-remote-batch-ordering branch from 675168c to 2caa729 Compare March 20, 2026 20:20
@simsinght
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a bug in av adopt --remote that caused adoption to fail when branches were not processed in parent-first order. The fix correctly iterates through pull requests in reverse to establish the right adoption sequence and also improves performance by using a map for lookups. While reviewing, I identified a separate potential bug concerning parent branch resolution when a parent PR is closed, which I've detailed in a specific comment.

Comment on lines 389 to 393
ab := actions.AdoptingBranch{
Name: target.Short(),
Name: pr.Name,
Parent: pr.Parent,
PullRequest: &pr.PullRequest,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

There appears to be a bug in how the parent branch is determined. The ab variable is initialized with pr.Parent on line 391. However, the subsequent loop (lines 395-401) modifies pr.Parent to find the correct ancestor if the direct parent's PR is merged or closed. The ab variable that is appended to the branches slice on line 402 does not reflect this change, as it was created before its parent was updated in the loop. This could lead to incorrect parent metadata for the adopted branches.

To resolve this, the initialization of ab should be moved to after the loop that finalizes the parent branch (i.e., after line 401).

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.

1 participant