Skip to content

feat(git): refuse a push that does not hold origin/main #4670

Closed
1 of 1 issue completed
Closed

Description

@dan-petty

Problem or Motivation

The owner requirement of 2026-11-11 makes the push the check point. Each push to GitHub must hold the current origin/main and merge cleanly. Between pushes, an open pull request gets no catch-up update (docs/SDLC.md Phase 5).

No check enforces this today:

  • The pre-push stage of .pre-commit-config.yaml runs only lint, format and the workflow rows. No hook checks that a branch holds origin/main.
  • In the census week (2026-11-04 to 2026-11-11), 19 force pushes reached a pull request that had a conflict and started no run. 21 rebase-only pushes with no conflict started runs (about 832 runner-minutes). There were 9 local merges of main with no own change.
  • The implement Job rebases in _push (src/devops_cli/roadmap/implement/implement_run.py). Then it runs the scoped checks with up to 3 repair rounds, each command with a limit of up to 1,800 s, and then it pushes. main gets 2.5 merges an hour, so the pushed head often does not hold main. After a rebase conflict, _current_tip pushes a head that does not hold main, and a stop pushes the passed commits (push_on_conflict=True). 5 implement stops in 14 days had the class conflict.
  • The stage job rebases before its push (_commit_and_push in src/devops_cli/roadmap/stage/stage.py), but it runs git push directly. 9 git push sites in src have no shared check.

Proposed Solution & Architectural Design

One module, src/devops_cli/git/push_gate.py.

check_push(path, tip, branch, remote, default):

  1. Run git fetch <remote> <default> <branch> with a 10 s limit and one retry, because a parallel fetch in another worktree can hold the ref lock. When the remote branch is missing, the push is a first push.
  2. Refuse the push when git merge-base --is-ancestor <remote>/<default> <tip> fails. Name the conflict files from git merge-tree --write-tree --name-only --no-messages.
  3. When the remote branch exists and is not equal to the tip, refuse a catch-up-only push. A push is catch-up-only when both conditions are true: the patch-id of the own change of the tip (git diff -U0 <merge-base>..<sha> | git patch-id --stable) is equal to that of the fetched remote tip, and git merge-tree of the remote tip with <default> exits 0.

Use the fetched remote tip, not PRE_COMMIT_FROM_REF. For a new branch, or for a remote head that is not in the local objects, pre-commit sets from_ref to a parent commit (_pre_push_ns in pre-commit hook_impl.py). In a test, that let a catch-up push overwrite a merge that GitHub made.

The refusal message points to docs/SDLC.md Phase 5, and to devops pr update <n> for a failed required check whose fix is on main.

push_branch() fetches, rebases onto <remote>/<default> right before the push, runs check_push, then runs git push --force-with-lease=<branch>:<fetched tip> (with -u on a first push). A rebase conflict aborts the rebase, names the files and pushes nothing. delete_branch() pushes a delete with no check.

Two commands in the existing devops branches group.

  • check-push reads PRE_COMMIT_TO_REF, PRE_COMMIT_REMOTE_NAME and PRE_COMMIT_REMOTE_BRANCH through Typer envvar options. When PRE_COMMIT_REMOTE_BRANCH is not set, the run is not a git push, so the command passes and prints a note. Tags and other refs pass.
  • push runs push_branch for the current branch.

One hook. branch-current runs first in the pre-push stage, with language: unsupported, always_run, pass_filenames: false, require_serial and fail_fast: true (a per-hook key of pre-commit 4.6.2). A refused push then costs about 2 s, and the other rows do not run.

The implement and stage jobs push through the gate. The Job runs pre-commit with --from-ref/--to-ref, which sets no PRE_COMMIT_REMOTE_*, so a hook alone does not cover the Job.

  • push_branch replaces the pushes in _publish, _push_with_lease and _withdraw of the implement Job, and in _commit_and_push of the stage job. delete_branch replaces the branch deletes in implement_run.py and stage.py.
  • Final push: push_branch rebases right before the push. When the -U0 patch-id of the own change is different after that rebase, the Job runs the scoped checks once more, at most once for each push, and does not loop on checked_sha. Then it pushes the rebased head.
  • A rebase conflict at any push, a checkpoint too, stops the item at once. The stop names the conflict files and pushes nothing, so at most one task group stays only in the Pod.
  • A catch-up-only result pushes nothing and sets published_sha and the watched sha to the remote tip, so _watch reads a sha that GitHub has.
  • _withdraw rebases the restored base first. A conflict there makes the item Blocked with the files. This is a new path, and the docs state it.
  • request_plan.py lists the fetch of the gate in the dry-run plan.
  • An ast-grep rule refuses a git push in src outside push_gate.py. Its patterns are self._git("push", ...), _git($P, "push", ...), git($P, "push", ...) and git_result($P, "push", ...). Today it finds exactly the 9 sites and not request_plan.py.

Telemetry. A counter devops_cli_git_push_gate_total, with result = passed, behind, conflict, catch_up or fetch_failed, goes through the existing telemetry.

In the same pull request:

  • docs/SDLC.md Phase 5 says "before each push" in place of "before the first push".
  • CONTRIBUTING.md lists the hook and says "push one branch at a time", because pre-commit checks only the first ref of a push.
  • Update the local-runs line of ADR 0014.
  • Update docs/ROADMAP_WORKFLOW.md (Checkpoints, Before the push).
  • The devops-pr-ci skill (source and copies) says to push with devops branches push.

This issue is the one push gate of the iteration lane and of the hooks review of 2026-11-11 (owner decision of 2026-11-11). The module and the hook can merge in a first task group, and the job push sites in a second.

Target Subsystem

SDLC, Git & PR Governance (src/devops_cli/git/, the devops branches group, the pre-push hook, the push sites of the implement and stage jobs).

Existing Tool Considered

git covers each check: merge-base --is-ancestor, merge-tree --write-tree and patch-id. The pre-commit pre-push stage and its documented PRE_COMMIT_* variables run the hook. ast-grep holds the push-site rule. No open hook checks "holds origin/main" or "catch-up only", so one thin module joins the git checks. The ruleset setting "require branches to be up to date" acts only at the merge, and the owner keeps it off. Cost (estimate): about 800,000 tokens and 2 days to build (the module and the hook, then the job push sites), near 0 to keep, about 30,000 tokens to fix.

Acceptance Criteria

Tests on a temporary bare origin:

  • A new branch behind main is refused, with no conflict and with a conflict. The conflict case names the file.
  • A rebased branch passes.
  • A rebase-only push of an existing pull request with no conflict is refused.
  • A rebase plus an own change passes.
  • A push that resolves a conflict passes.
  • A catch-up-only --force push over a GitHub merge that is not fetched locally is refused.
  • A delete and a tag pass.
  • check-push passes when PRE_COMMIT_REMOTE_BRANCH is not set.

Tests with doubles at the git edge of the jobs:

  • main moves with no conflict during the scoped checks. The Job pushes a head that holds the new main and does not stop.
  • The move changes the context of the own change. The scoped checks run once more, then the Job pushes.
  • A conflict at a checkpoint stops the item at once, names the files and pushes nothing.
  • A catch-up-only push sets published_sha to the remote tip, and _watch reads that sha.
  • A conflict in the _withdraw rebase ends Blocked with the files.
  • The stage job pushes through push_branch.
  • The rule test fails on a new git push outside push_gate.py.

Other criteria:

  • devops branches push on a branch 5 commits behind main rebases and pushes. On a conflict it pushes nothing and names the files.
  • The hook takes at most 2 s warm at a load under 5 (1.6 s measured).
  • The counter has only the 5 result values.
  • docs/SDLC.md Phase 5 says "before each push".
  • One week after the merge: 0 pushed bot heads that do not hold origin/main at push time (check with git merge-base --is-ancestor on the pushed heads), and 0 implement stops caused by a move of main with no conflict.

Dependencies

None.

Source: #4667

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/git
    status/new
    value/medium
    effort/high
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/git. The (git) scope of the title gives the scope.
    • Priority: P2-Medium. It prevents broken pushes and wasted runner time but the system functions without it.
    • Value: Medium. It stops 19 force pushes per week from reaching PRs with conflicts and saves about 832 runner-minutes.
    • Effort: High. It adds a new module, two CLI commands, a pre-push hook, and rewires two jobs to use the gate.
    • Related: fix(roadmap): rebase the branch before its first push #4380, which asks for a different change. Both ensure a branch holds main before push, but 4380 fixes the rebase timing in the implement job while the candidate adds a refusal gate that blocks any push not holding origin/main.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the CI audit (2026-11-11)

    Another workflow builds this item now. This comment only adds the measured cost of pure rebases and an acceptance criterion.

    • On 2026-11-11, 13 topic-PR runs came from a pure rebase: the base moved, and the zero-context patch-id stayed the same (measured). The 7 of them that changed job files used 571 runner-min. The strict policy is off, and ADR 0014 asks for a rebase only on a conflict. Thus these runs do no work that the merge needs.
    • The source is not confirmed. Leads that are not verified: src/devops_cli/roadmap/implement/implement_run.py:790-793 fetches and rebases onto the default branch at the start of each run, and src/devops_cli/roadmap/stage/stage.py:2358-2379 rebases a staged branch.
    • AGENTS.md rule 2 first: find the source from the push actors and the Service logs of these runs.
    • Owner rule of 2026-11-11: each push carries a branch that contains the current origin/main and merges cleanly, and an open PR gets no catch-up rebase when nothing else changes. So a path pushes only when the patch changes or the branch has a conflict with origin/main. git merge-tree --write-tree reports a conflict with no checkout.
    • Added acceptance (for refactor(pr): devops pr update acts only on a failed check #4674 and feat(git): refuse a push that does not hold origin/main #4670 together): the item names the source with evidence. Over one day, 0 topic-PR runs come from a push with a moved base and the same patch-id, except after a conflict (from 13).
    • Saving: 1,000-1,100 runner-min per day at the rate of 2026-11-11 (estimated).
  6. added
    owner/agent
    on Nov 11, 2026
  7. added
    status/in-progress
    and removed
    status/new
    on Nov 12, 2026
  8. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Smaller scope after the owner feedback of 2026-11-12

    The owner said of the first build of #4879: "pr 4879 seems like a really complicated alternative to the precommit hook check-merge-conflict". That build had a module of 551 lines, two devops commands, a patch-id check of catch-up pushes, an ast-grep rule, a counter and about 1,800 lines of JSON fixtures.

    #4879 now holds the smallest form that meets the rule "each push holds the latest origin/main and merges cleanly". A branch that holds origin/main always merges cleanly into main, so no merge-tree and no patch-id check is necessary.

    In scope:

    • One pre-push hook branch-current in .pre-commit-config.yaml: a few lines of sh that fetch main of origin and refuse the push when git merge-base --is-ancestor FETCH_HEAD <pushed commit> fails. The message names git fetch origin && git rebase origin/main. A fetch failure has its own message. A tag, a delete and a run of the stage that is no git push pass. check-merge-conflict stays: it finds conflict markers in files, not a branch behind main.
    • The implement Job pushes nothing after a rebase conflict (push_on_conflict and the conflict push of _current_tip are removed). The rebases before each push stay.
    • Documents: docs/SDLC.md, CONTRIBUTING.md, ADR 0014, docs/ROADMAP_WORKFLOW.md, the skill devops-pr-ci.

    Out of scope (dropped from the body above):

    • The module push_gate.py, the commands devops branches check-push and devops branches push, the catch-up-only refusal, the ast-grep rule over the push sites, the counter devops_cli_git_push_gate_total, the changes to _publish, _withdraw and the stage job, and the second run of the scoped checks after a late rebase.
    • Catch-up pushes: refactor(pr): devops pr update acts only on a failed check #4674 deletes devops pr update, their main source.

    The acceptance criteria in the body that name the dropped parts no longer apply. The criteria that stay: a branch behind main is refused, a rebased branch passes, a tag and a delete pass, a conflict in the implement Job pushes nothing, and docs/SDLC.md Phase 5 says "before each push".

  9. removed
    status/in-progress
    owner/agent
    on Nov 12, 2026
  10. added a commit that references this issue on Nov 12, 2026
  11. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 07:00 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/gitsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions