Skip to content

A pull request build compares with its base branch's approved build, never an unapproved one (sc-9247) - #178

Merged
ndbroadbent merged 2 commits into
mainfrom
app-baseline-base
Dec 4, 2026
Merged

ndbroadbent merged 2 commits into
mainfrom
app-baseline-base

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

sc-9247, from the daisyUI case study (visualci-com/daisyui builds #4 and #6).

1. A PR build compared with the default branch, not its base branch

Cause. baselines::anchor() looked for the nearest ancestor commit's build, then fell back to the default
branch's
newest approved build. Nothing recorded which branch a pull request merges into, and the CLI never sent it.
A PR into a release branch (or a stacked PR, or a fork PR into a non-default branch) with no shared build in its
history sent to VisualCI (a shallow checkout sends none) was measured against the default branch. Build #4 compared
with daisyUI 5.8.3 on the default branch instead of the PR base's approved build #3, so all 4 snapshots showed as changed.

Fix.

  • builds.base_branch (migration). The API's and MCP create_build's base_branch set it; it's ignored when it's
    the build's own branch.
  • The CLI part is a follow-up PR, opened once this server is in production. The CLI will send base_branch from
    CI: GitHub's pull_request.base.ref / GITHUB_BASE_REF, GitLab CI_MERGE_REQUEST_TARGET_BRANCH_NAME, Jenkins
    CHANGE_TARGET, Bitbucket BITBUCKET_PR_DESTINATION_BRANCH, Buildkite BUILDKITE_PULL_REQUEST_BASE_BRANCH,
    Semaphore and Travis's target branch, or VISUALCI_BASE_BRANCH, and the GitHub action's workflow_run path will
    set it too. It can't ship in this PR: CreateParams has deny_unknown_fields, and CI's visual and journeys jobs
    run the PR's CLI against production. The first run of this PR, with the CLI included, failed both jobs with
    422 unknown field base_branch.
  • Anchor order: the nearest ancestor commit's approved build (the merge-base's, when the history reaches it), then the
    base branch's newest approved build, then the default branch's.
  • For that build the base branch counts as the default branch does in four places: the anchor's walk back
    (effective), local environments' CI rows in resolve(), compare.rs's exact-match baseline queries, and
    inherited.

2. A rerun compared with the PR's own unapproved build

Cause. anchor() took the nearest ancestor commit's completed CI build whatever its review_state, and
ancestry() lists the build's own commit first. A rerun of the same commit therefore anchored on its own earlier
pending build. effective() reads a pending build's unapproved changes as "the version it was compared with", so the
rerun inherited the first run's base. In #6 that was a branch that was no longer the default (base_build 4, the
same 5.8.3 comparison), when nothing approved existed to compare with. An unapproved base can hide a PR's own changes
from review.

Fix. The anchor is only ever an approved or auto-approved build (the default branch's first build, or one with no
changes). It is never pending, rejected or failed, and never an empty build that follows another (sc-9044's
covered_by_build_id, merged in #161): a follower mirrors its build's review state, approved included, but holds no
snapshots. Nothing is lost:

  • Per-snapshot approvals of a pending build are rows in baselines and are still laid on top.
  • effective()'s walk back through the base-build chain is unchanged.
  • inherited ("N changes are already on main and unreviewed") used to rely on the anchor being main's pending build.
    It now finds the nearest base-branch build on the PR's history that is still pending and newer than the anchor
    (baselines::nearest).
  • sc-9044's follow logic mirrors the earlier build's result and review and never compares against it. A pending
    earlier build keeps its followers pending, so it hides nothing. With this change a follower can no longer be an anchor.

processing::conclude's first_on_default is unchanged: only the default branch's first CI build with no base is
auto-approved.

Review fixes (second commit)

From the independent review of 14228b4. Each behaviour fix has a test that failed before it:

  1. Partial approvals no longer lost to a later anchor. resolve() used to count approvals only when
    build_id > anchor.id. An approval now also counts when its commit is nearer than the anchor's commit in the
    build's history (the whole history when the anchor isn't on it). Case: a PR build approved in part before main
    built the PR's parent commit, so the next PR build anchored on that later main build. The rank treats such rows
    as newer. A newer main approval still beats the PR's older ones by id.
    (a_partial_approval_survives_a_later_anchor_on_an_older_commit approves a removal, which no exact match can
    rescue.)
  2. base_branch only on PR builds. It is stored as NULL, and ignored by baselines::base_branch() and compare.rs's
    SQL, when the build has no pr_number or is on the default branch. A push build naming feature-x can no longer
    pass on feature-x's unmerged approvals. (a_push_build_naming_a_base_branch_takes_nothing_from_it)
  3. When a base is named, the default branch counts only through history. trusted_branches() is the base branch,
    plus the default branch only when the anchor fell back to it. It is used in effective()'s walk and local CI rows.
    compare.rs's exact match accepts the base branch, plus the default branch only at the build's own commit or its
    parent_commits. (a_pull_request_into_a_release_branch_ignores_mains_newer_approvals)
  4. inherited looks on the base branch itself. baselines::nearest_pending_on(build, branch) finds the base
    branch's nearest pending build on the history. It must be nearer than the anchor's commit (or newer at the same
    commit). The PR's own earlier builds no longer hide it.
    (inherited_changes_are_found_from_the_pull_requests_second_build_on)
  5. A base branch with no builds falls back to the default branch for inherited, as anchor() does.
    (inherited_falls_back_to_the_default_branch_for_an_unbuilt_base)
  • Nit: the migration runs SET LOCAL lock_timeout = '5s' before its ALTER TABLE.

Tests (app/tests/baselines.rs)

Each failed on main before the fix:

  • a_pull_request_into_a_release_branch_compares_with_the_release_branchs_approved_build: base was main's build;
    now release-1's, and only the PR's own change shows.
  • a_rerun_never_compares_with_its_own_unapproved_build: the daisyUI case. The rerun's base was its own pending build;
    now there's no base and both snapshots are added, still waiting for review.
  • a_pending_build_on_the_branch_is_never_the_base: base was the branch's pending build; now main's approved build.
    It also checks that a partial approval still counts.
  • a_build_that_follows_another_is_never_the_base: base was the empty follower; now the build it follows.
  • a_pull_request_on_an_unreviewed_main_build_marks_the_inherited_changes guards the inherited rework.

The full cargo test -p visualci-app suite, fmt --check, and clippy -D warnings pass. docs/design.md is updated,
and api.md documents base_branch.

@visualci-com

visualci-com Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #564 · 414 unchanged · no changes

This PR vs base: 24 changed, 22 added since #432, across 4 builds

docspring/visualci · journeys · build #559 · 42 unchanged · no changes

This PR vs base: 6 changed, 12 added since #430, across 4 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

@ndbroadbent
ndbroadbent force-pushed the app-baseline-base branch 2 times, most recently from 29b7978 to 9064e2c Compare December 4, 2026 07:35
…uild, and a base is only ever an approved build (sc-9247)

Two baseline bugs from the daisyUI case study:

1. A PR build compared with the default branch, never the PR's base branch. Builds now record `base_branch` (the API's
   and MCP create_build's `base_branch`; the CLI sends it in a follow-up, once this server is live). The anchor falls
   back to the base branch's newest approved build before the default branch's, and the base branch counts like the
   default branch in the anchor walk, local environments' rows, the exact-match passes and the inherited-changes note.

2. The anchor took the nearest ancestor commit's completed build whatever its review, so a rerun of a PR's commit
   anchored on its own pending build and compared with whatever that build had been compared with. The anchor is now
   only ever an approved (or auto-approved) build, never a pending, rejected or failed one, and never an empty build
   that follows another (sc-9044's reruns). Per-snapshot approvals of pending builds still count through the baselines
   table; `inherited` finds the unreviewed base-branch build on the PR's history itself.
…mmit count, base_branch only on PR builds, the default branch only through history when a base is named, inherited looks on the base branch itself
@ndbroadbent
ndbroadbent merged commit 5add582 into main Dec 4, 2026
16 checks passed
@ndbroadbent
ndbroadbent deleted the app-baseline-base branch December 4, 2026 08:53
ndbroadbent added a commit that referenced this pull request Dec 4, 2026
…ts, so a migration that adds a column never fails the previous release's SELECT * (cached plan must not change result type: #178's rollout 500)
ndbroadbent added a commit that referenced this pull request Dec 4, 2026
…ts, so a migration that adds a column never fails the previous release's SELECT * (cached plan must not change result type: #178's rollout 500)
ndbroadbent added a commit that referenced this pull request Dec 4, 2026
…ts, so a migration that adds a column never fails the previous release's SELECT * (cached plan must not change result type: #178's rollout 500) (#201)
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