Skip to content

Update tracked branch heads from full scans - #479

Open
David Larsen (dc-larsen) wants to merge 1 commit into
dl/default-branch-explicit-argsfrom
dl/tracked-branch-pending-head
Open

David Larsen (dc-larsen) wants to merge 1 commit into
dl/default-branch-explicit-argsfrom
dl/tracked-branch-pending-head

Conversation

@dc-larsen

@dc-larsen David Larsen (dc-larsen) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #478. Review only the top commit. When #478 merges, GitHub retargets this PR to main.

Python CLI scans of a branch that matches the org's tracked branch patterns (Settings > Alerts > Scans) never become that branch's head scan, so their findings never reach the organization Alerts page. Only default-branch scans do.

Behavior change

  • socketcli.py sent set_as_pending_head=is_default_branch. The API makes a scan a branch's head only when the request sets set_as_pending_head and the branch is the default branch or matches a tracked pattern; it ignores the flag elsewhere.
  • Branch runs now send set_as_pending_head=true and the API decides. make_default_branch is unchanged.
  • A run counts as a pull or merge request when it has a PR number, when the SCM adapter selected the comparison flow, or when the CI environment describes a PR or MR event (is_pull_request_environment). Those runs don't request promotion for a non-default branch, including a GitHub PR event with --pr-number 0.
  • A scan marked as the default branch still requests promotion on any run, as before. That includes an explicit --default-branch on a PR run, which keeps its existing behavior.
  • --no-default-branch (from Check --branch and --commit-sha before marking scan as default branch #478) never requests promotion.
  • --pending-head stays a deprecated no-op. Its warning, the CLI reference ("Branch heads", linked to Settings > Alerts > Scans) and a README pointer describe the behavior. Shares the 2.16.0 version set in Check --branch and --commit-sha before marking scan as default branch #478.

Upgrade effect: an org that already has tracked patterns will see those branches' findings on the Alerts page once their full scans run on 2.16.0. Untracked branches are unaffected.

Testing

  • Full suite with the API key unset: 1,211 passed, also with GITHUB_ACTOR set, and with GITHUB_EVENT_NAME=pull_request / GITHUB_REF=refs/pull/1/merge set to match CI. ruff check clean.
  • CLI-path tests in tests/core/test_pending_head_params.py: a tracked-branch run requests the head without becoming the default branch; a default-branch run does both; a PR scan of a non-default branch does neither; a GitHub PR event with --pr-number 0 doesn't request it, through API mode and through the --scm github comparison flow (both fail on the previous head); explicit --default-branch on a PR still requests it; --no-default-branch requests neither on a default or tracked branch. is_pull_request_environment has unit tests per CI provider.

Validation

Run against production with this branch's build (b398abc; the later #478 fix only changes --commit-sha handling, which these cases don't use), in an internal test org, on a new repository with main as the default branch. A release/* org pattern was added for the test and removed afterwards.

Case Flags sent Result
main (default branch) default=true, head=true main head set (tracked_reason=default); repository default branch main
release/1.0 (tracked) default=false, head=true release/1.0 head set (tracked_reason=pattern); default branch still main
feature/x (untracked) default=false, head=true no head for feature/x; default branch still main
release/1.0 --no-default-branch default=false, head=false release/1.0 head unchanged (still the earlier scan); default branch still main

Heads were read from org_repo_branch_head_sbom_tag and the default branch from the repositories API.

Public Changelog

Full scans of branches that match an organization's tracked branch patterns can update those branch heads, so findings from those branches can appear on the organization Alerts page after upgrade. Untracked branches are not eligible, pull request and merge request scans of a non-default branch don't request it, and --no-default-branch opts a scan out.


Refs: CE-529

@dc-larsen
David Larsen (dc-larsen) requested a review from a team as a code owner December 1, 2026 19:36
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes when scans update branch heads on the Alerts page; PR/MR detection affects set_as_pending_head, so misclassified CI env could differ from prior behavior on branch pushes.

Overview
Full scans on non-default branches can now ask the API to promote them as that branch's head scan, not only when the run is marked as the default branch. The API still decides promotion (default branch or org tracked branch patterns); untracked branches are unchanged.

request_branch_head() drives set_as_pending_head: --no-default-branch never requests it; default-branch scans still request on any run (including PRs with --default-branch); PR/MR runs on non-default branches do not, including when CI looks like a pull request but --pr-number 0, via new is_pull_request_environment() and existing diff/comment SCM paths.

Docs and --pending-head deprecation text describe Branch heads behavior; tests cover the matrix in test_pending_head_params.py.

Reviewed by Cursor Bugbot for commit 29b1612. Configure here.

@lelia

lelia commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@lelia lelia self-assigned this Dec 2, 2026

@lelia lelia 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.

David Larsen (@dc-larsen), please tighten the promotion gate and verify the server behavior before including this in 2.16.0.

Use scan context to decide head eligibility

  • The promotion check treats a missing PR number as a branch run. I reproduced a GitHub PR event with --pr-number 0 requesting head promotion, including when the SCM adapter selected the comparison flow. Use resolved scan context to keep PR/MR runs out of the new promotion path even when a PR number is unavailable. Add a regression test through the CLI path.
  • An explicit --default-branch on a PR still requests head promotion today. Please test this case and align the code, docs, and PR body with the intended compatibility behavior. If the existing explicit behavior stays, say so and avoid the blanket promise that PR scans never request promotion. Test --no-default-branch on a tracked-branch run too.
  • Validate the revised build in staging for a default branch, a tracked non-default branch, an untracked branch, and the explicit opt-out. Confirm which scans update the branch head and that the tracked scan leaves the repository’s default branch intact. The current live check predates the opt-out gate.

Docs, changelog, and stack

  • Suggested title: Update tracked branch heads from full scans. Keep the body focused on the behavior change, the dependency on #478, and the final validation. In code, keep one comment describing server-side eligibility. Remove the historical wording from the test comment and name the PR test for the case it covers.
  • Under Changed in the shared 2.16.0 changelog and in the Public Changelog block, explain the upgrade effect: “Full scans of branches that match an organization’s tracked branch patterns can update those branch heads, so findings from those branches can appear on the organization Alerts page after upgrade.” Note the --no-default-branch opt-out and explain that untracked branches are ineligible. The CLI reference should link the behavior to Settings > Alerts > Scans and clarify that --pending-head remains deprecated and has no effect. A pointer from the existing README CI guidance is enough.
  • Rebase and retarget this PR to main after #478 lands. Keep #478’s 2.16.0 version and drop the independent 2.15.9 bump. #478’s new public flag drives the minor bump. This PR’s upgrade impact belongs in the same release notes. Rerun CI and Bugbot on the final stack.

@dc-larsen
David Larsen (dc-larsen) force-pushed the dl/default-branch-explicit-args branch from 81105de to 8cae773 Compare December 2, 2026 15:40
@dc-larsen
David Larsen (dc-larsen) force-pushed the dl/tracked-branch-pending-head branch from 6a297e9 to b398abc Compare December 2, 2026 15:50
@dc-larsen David Larsen (dc-larsen) changed the title Ask for the branch head on every non-PR full scan Update tracked branch heads from full scans Dec 2, 2026
@dc-larsen

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Full scans sent set_as_pending_head=is_default_branch, so only a
default-branch scan could become a head. The API also makes a scan the
head of a branch that matches the organization's tracked branch patterns
(Settings > Alerts > Scans), but only when the request sets
set_as_pending_head, and it ignores the flag on branches it doesn't track.
Python CLI scans of a tracked branch were never that branch's head, so
their findings never reached the organization Alerts page.

Branch runs now send set_as_pending_head=true and let the API decide.
make_default_branch is unchanged. A run counts as a pull or merge request
when it has a PR number, when the SCM adapter selected the comparison
flow, or when the CI environment describes a PR or MR event, so a PR run
with --pr-number 0 stays out of the new path. A scan marked as the default
branch, including one with an explicit --default-branch on a PR, still
requests it as before, and --no-default-branch keeps it off.

--pending-head stays a deprecated no-op. Its warning, the CLI reference,
the README and the CHANGELOG describe the new behavior. Shares the 2.16.0
version set in #478.
@dc-larsen
David Larsen (dc-larsen) force-pushed the dl/tracked-branch-pending-head branch from b398abc to 29b1612 Compare December 2, 2026 16:03
@dc-larsen

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 29b1612. Configure here.

This branch was previously deployed

1 inactive (outdated) deployment
socket-firewall — 6a297e94 Deployed Dec 1, 2026 by dc-larsen via python-sfw-smoke-enterprise #720
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.

2 participants