Skip to content

fix: scope branch-merge and proposed-change-review events to the default branch (closes #9761) - #10422

Merged
polmichel merged 11 commits into
developfrom
ai-bug-pipeline-9761-event-branch-scoping
Aug 27, 2026
Merged

fix: scope branch-merge and proposed-change-review events to the default branch (closes #9761)#10422
polmichel merged 11 commits into
developfrom
ai-bug-pipeline-9761-event-branch-scoping

Conversation

@polmichel

@polmichel polmichel commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Why

Webhook branch scoping matches an event against the branch carried on its metadata. Two proposed-change / branch lifecycle events carried the wrong branch there, so branch-scoped webhooks matched them inconsistently:

  • infrahub.branch.merged was emitted on the global branch, so a Default Branch scoped webhook never matched it while an Other Branches one did, exactly the inverse of infrahub.proposed_change.merged, which is already default-scoped.
  • infrahub.proposed_change.approved / rejected / approval_revoked / rejection_revoked inherited the branch of the review mutation. They reached the default branch only because the review UI happens to run in the default-branch context — a non-UI client (SDK/REST/automation) reviewing from another branch would emit them on that branch.

Goal: emit both consistently on the default branch so webhook branch scoping is deterministic and client-independent.

Non-goals: the general rule for branch-agnostic node events (#9760) and webhook form validation (#9759). branch.created / branch.deleted carry the same pattern but are intentionally left for #9760.

Future thoughts

Changes related to the global branch are matched by the "All other branches" filter and not by the "Default branch" filter. Events tied to the global branch can be misleading from a user's perspective, since this behavior relies on the fact that some objects are branch-agnostic and others are not. A dedicated "Global branch" filter could be a way to solve this.

Closes #9761

What changed

Behavioral changes:

  • infrahub.branch.merged is now scoped to the default branch.
  • The proposed-change review events (approve / reject / cancel-approve / cancel-reject) are now scoped to the default branch server-side, independent of the branch the review mutation ran on.

Implementation notes:

  • PostMergeDispatcher now stamps the merge event with self.default_branch instead of self.global_branch. The event payload (branch_name, branch_id) still identifies the branch that was merged.
  • The review mutation resolves the default branch and passes it to EventMeta.from_context(...), so only the event's scoping branch is overridden.

What stayed the same: no schema changes, no GraphQL/REST contract changes, event payloads unchanged.

How to review

  • backend/infrahub/core/merge/post_merge.py — merge event scoping (one-line change) + dropped global_branch param.
  • backend/infrahub/graphql/mutations/proposed_change.py — review event scoping override.
  • backend/infrahub/core/merge/builder.py — wiring updated for the dropped param.
  • Tests are the largest part of the diff.

How to test

uv run pytest \
  backend/tests/component/core/merge/test_post_merge.py::TestPostMergeBranchMergedEvent \
  "backend/tests/functional/proposed_change/test_review.py::TestProposedChangeReview::test_review_event_scoped_to_default_branch" \
  -v

Impact & rollout

  • Backward compatibility: infrahub.branch.merged webhook matching changes — a Default-Branch webhook starts matching it and an Other-Branches webhook stops. Documented in the changelog / release notes. Approve/reject scoping is unchanged for UI clients.

Checklist

  • Tests added/updated
  • Changelog entry added
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)
  • I have reviewed AI generated content

Review in cubic

polmichel and others added 7 commits August 26, 2026 11:13
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ranch

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the group/backend Issue related to the backend (API Server, Git Agent) label Aug 26, 2026

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes webhook event scoping: branch-merge and proposed-change review events now carry the default branch as their scoping branch, with tests pinning the behavior and a changelog entry. No contract, schema, or operational tradeoffs exposed in the diff.

Re-trigger cubic

@codspeed-hq

codspeed-hq Bot commented Aug 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 13 untouched benchmarks


Comparing ai-bug-pipeline-9761-event-branch-scoping (9bae3f7) with develop (9d38750)

Open in CodSpeed

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@polmichel polmichel left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not super confident about shipping this behavior change directly in the next minor release, since it changes the branch that some events are tied to. Maybe for this bug we should target develop branch and add a section in the 1.12 release note about this breaking change.
I'll target develop branch for now.

@polmichel
polmichel changed the base branch from stable to develop August 26, 2026 12:45
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Aug 26, 2026
@polmichel
polmichel force-pushed the ai-bug-pipeline-9761-event-branch-scoping branch from f43bffe to 9f0543a Compare August 26, 2026 13:18
polmichel and others added 2 commits August 26, 2026 16:32
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Not all branch-agnostic events are stamped to the default branch: created/deleted
stay on the global branch and rebased/migrated inherit the caller's context.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
from infrahub.database import InfrahubDatabase


def _build_dispatcher(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

extracted as this is now reused in other test classes

- Proposed change merge and review events (merged, approved, rejected, and the approval/rejection revoke variants) are stamped to the default branch, so scoping is independent of the branch the mutation ran on.
- `branch.merged` is stamped to the default branch as well, since the merge lands there. Its payload still carries the merged branch in `branch_name` / `branch_id`; only the scoping branch is the default one.
- `branch.created` and `branch.deleted` are stamped to the global branch, pending a general rule for branch-agnostic node events.
- `branch.rebased` and `branch.migrated` inherit the caller's context branch; they are not overridden.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wonder whether it would be relevant to assign the target branch for those operations

@polmichel
polmichel marked this pull request as ready for review August 27, 2026 06:41
@polmichel
polmichel requested review from a team as code owners August 27, 2026 06:41
@polmichel
polmichel requested review from pthmas and removed request for pthmas August 27, 2026 06:41
branch=source_branch,
proposed_change_id=None,
node_events=[],
context=_context(default_branch),

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.

Should this be context=_context(source_branch) to validate that the fix works properly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right, thanks @gmazoyer

Run dispatch_events with the source-branch context so the test proves the
event is deliberately scoped to the default branch, not merely inheriting it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would require human review. Webhook branch scoping change alters which branch-scoped webhooks fire for merge/review events (backward-incompatible), and the delta since the prior decline only tweaks a test, not the substantive behavior.

Re-trigger cubic

@polmichel
polmichel merged commit 580d2e0 into develop Aug 27, 2026
108 of 109 checks passed
@polmichel
polmichel deleted the ai-bug-pipeline-9761-event-branch-scoping branch August 27, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent) type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: branch merge and proposed change review events use an inconsistent branch for webhook scoping

3 participants