Skip to content

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

Merged
dan-petty merged 2 commits into
mainfrom
feat/4670-push-gate
Nov 12, 2026
Merged

dan-petty merged 2 commits into
mainfrom
feat/4670-push-gate

Conversation

@dan-petty

@dan-petty dan-petty commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Each push to GitHub must hold the latest origin/main and merge cleanly. A branch that holds origin/main always merges cleanly into main, so one git check covers the rule.

  • A new pre-push hook, branch-current, is a few lines of sh. It fetches main of origin and refuses a branch push when git merge-base --is-ancestor FETCH_HEAD <pushed commit> fails, with the fix git fetch origin && git rebase origin/main. A tag, a delete and the scoped run of the implement Job pass. check-merge-conflict stays: it finds conflict markers, 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.
  • devops ai agents names a local hook with args by its id, so it shows branch-current, not sh -c.
  • No catch-up check: refactor(pr): devops pr update acts only on a failed check #4674 deletes devops pr update, the main source of catch-up pushes.

Closes #4670

Change: openspec/changes/archive/2026-11-12-4670-push-gate/

@dan-petty dan-petty added type/feature Type feature: a new function scope/git Git commands, git configuration, and git credential handling labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Verification and measurements

Local runs on the branch (devcontainer, git 2.55.0, pre-commit 4.6.2; the host load was 25 to 77 during the whole session):

  • tests/git/test_push_gate.py, tests/commands/test_branches.py, tests/core/test_git_contract.py: pass, except the 2 review_window cases, which fail on origin/main too (filed as fix(roadmap): the review_window git transcript does not match the code #4865; intake linked it as a sub-issue of feat(git): refuse a push that does not hold origin/main #4670 because of --source, a person can unlink it).
  • tests/roadmap/implement/ push files (test_roadmap_implement_push_gate.py, _checkpoint.py, _push_current.py, _phase_marks.py), tests/roadmap/stage/test_roadmap_stage_apply.py, tests/roadmap/test_roadmap_dry_runs.py: 74 + 163 cases pass.
  • tests/invariants, tests/telemetry, tests/lang, tests/docs, tests/dry_run, tests/config: pass after the update of the two pre-push contracts in test_workflow_contracts.py.
  • uv run devops ci --check --only constructs,docs,openspec: pass. uv run ast-grep test: 21 rule tests pass.
  • The rule git-push-outside-gate over the base files finds exactly the 9 push sites (implement_run.py 1176, 1180, 1347, 1409, 1419; stage.py 2409, 2426, 2688, 2699) and none in request_plan.py; over the change it finds none.
  • A broad run of tests/roadmap tests/commands tests/core ... was stopped at 18% by the host load (2 failures seen in that part, not named); the required checks give the full result.

Dogfood: this branch was pushed with uv run devops branches push. The first try stopped on a conflict with origin/main in tests/gate/construct_gate.py, named the file and pushed nothing; after a rebase by hand, the second try rebased onto the newer main once more and pushed 881888d9.

Hook time: devops branches check-push took 24.8 s wall time at load 25 for a first push (branch not on the remote: two fetches and an ls-remote). The criterion "at most 2 s warm at a load under 5" is not verified: the load never went under 25.

Pending a person

  • Time the hook warm at a load under 5: time uv run devops branches check-push --remote-branch refs/heads/<an open branch> --to-ref HEAD.
  • One week after the merge: 0 pushed bot heads that do not hold origin/main at push time (git merge-base --is-ancestor origin/main <pushed head>), and 0 implement stops caused by a move of main with no conflict.
  • No live cluster, ConfigMap or Secret change: the jobs take the gate with the next runner image.

@dan-petty

Copy link
Copy Markdown
Owner Author

Rebuild in the small form (owner feedback of 2026-11-12)

The owner said: "pr 4879 seems like a really complicated alternative to the precommit hook check-merge-conflict". The first head (881888d9) had a module of 551 lines, two devops commands, a patch-id check, an ast-grep rule, a counter and about 1,800 lines of JSON fixtures. This head replaces it. The change outside tests, documents and the OpenSpec change is about 70 lines: .pre-commit-config.yaml +25, implement_run.py +20/-25.

A merge of main into the branch on GitHub (787f291c) was a clean merge with no change of its own (git merge-tree gave the same tree). The new head holds a newer main, so the push replaced it with a lease on that merge.

Evidence

  • Red on the base (e4fc6a9f, the new tests before the code change): 5 failed. The 3 tests of tests/git/test_branch_current_hook.py found no hook. test_a_conflict_on_the_rebase_before_the_push_pushes_nothing: origin got the second group, the docs and the archive after the conflict. test_a_conflict_at_a_wip_push_and_at_the_stop_pushes_nothing: the item branch was on origin.
  • Green on the change: the hook test and tests/roadmap/test_roadmap_runner_tools.py: 31 passed. test_roadmap_implement_job.py, test_roadmap_implement_push_current.py, test_roadmap_implement_hooks.py and the runner tools test: 149 passed. tests/core/test_roadmap_implement_checks.py: 15 passed. tests/invariants with the hook test: 776 passed. mypy on the 2 changed modules: no issues. The lint, format, docs and openspec rows pass.
  • All of tests/roadmap/implement: the run reached 70 % (1,515 passed, 304 skipped, 7 xfailed, 0 failed) before the 1,800 s limit of devops ci test, at a host load of about 50. The required checks run the rest.
  • devops ci fail-to-pass --base origin/main: the base run of the 4 changed test files ran serially and passed its 1,800 s limit at a load of about 50. The command then stopped with a raw TimeoutExpired traceback. This is a feature, and the red run above shows the same result. I filed the traceback as fix(ci): fail-to-pass prints a traceback when the base run times out #4938.
  • A real git push through the installed hook (pre-commit 4.6.2, git 2.55, a bare origin in a temporary directory): a branch one commit behind main was refused with Run: git fetch origin && git rebase origin/main, and nothing reached origin. After git rebase origin/main the push passed. A tag and a delete were pushed. A push to a second remote while origin pointed to a missing repository stopped with the fetch message.
  • The pushes of this branch ran through the new hook: branch holds origin/main ... Passed.

Steps for a person

None. After the merge, pre-commit reads the new hook from the checkout on the next push. The pre-push hook type is already installed (default_install_hook_types). The implement Job reads the configuration of main and runs the hook in its scoped checks, where it passes at its first line. No cluster, ConfigMap, Secret or image change.

The pre-push hook branch-current fetches main of origin and refuses a
push of a branch that does not hold it, with the fix
`git fetch origin && git rebase origin/main`. A branch that holds
origin/main merges cleanly, so this one check covers the push rule.

The implement Job pushes nothing after a rebase conflict: push_on_conflict
and the conflict push of _current_tip are removed.
@dan-petty

Copy link
Copy Markdown
Owner Author

Second head after the first CI run

The first run of the required checks found 4 tests that read the pre-push hooks. The head 47ab7e44 fixes them:

  • tests/invariants/test_runner_hooks.py: a local hook that does not start with uv run may start a program that the runner image holds (RUNNER_TOOLS, here sh). A uv run hook keeps the old rule.
  • tests/invariants/test_workflow_contracts.py: the pre-push hooks are branch-current, then the two devops ci hooks.
  • tests/commands/test_instruction_generator.py and src/devops_cli/ai/instruction_generator.py: devops ai agents rendered the new hook as sh -c, because it read only the entry. A local hook with args is now named by its id, as a hook of another repository is. The OpenSpec change modifies the agent-instructions requirement for this.

Local runs on this head: tests/invariants with the hook test, 776 passed. tests/commands/test_instruction_generator.py, 31 passed. The lint, format, docs and openspec rows pass.

Twice, a GitHub "Update branch" merge of main (787f291c, 230fdae8) arrived on the branch. Each was a clean merge with no change of its own: git merge-tree of its parents gave the same tree. Each new head holds a newer main, so the push replaced the merge with a lease on it. By docs/SDLC.md ("No Catch-Up Updates"), the branch needs no update to catch up with main.

@dan-petty
dan-petty merged commit f55a20b into main Nov 12, 2026
27 checks passed
@dan-petty
dan-petty deleted the feat/4670-push-gate branch November 12, 2026 06:19
dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.117.0](v0.116.2...v0.117.0)
(2026-11-12)


### Features

* **git:** refuse a push that does not hold origin/main
([#4879](#4879))
([f55a20b](f55a20b)),
closes [#4670](#4670)


### Bug Fixes

* **k8s:** replace the SearXNG worker before its memory limit
([#4951](#4951))
([95abe10](95abe10))
* **mcp:** mark the tools that write local state not read-only
([#4942](#4942))
([6d93d77](6d93d77))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
@dan-petty

Copy link
Copy Markdown
Owner Author

Review findings after the merge:

  1. Major, confirmed: the final push of the implement Job does not fetch and rebase right before the push. In _push (src/devops_cli/roadmap/implement/implement_run.py at f55a20b9), _sync() runs before the scoped checks and the fix steps, and _publish() or _push_with_lease() then pushes _head() with no new fetch or rebase. The Job runs pre-commit install-hooks only, so the hook branch-current does not catch this push. The acceptance criteria of feat(git): refuse a push that does not hold origin/main #4670 asked for a head that holds a main that moved during the scoped checks. No open issue covered it (feat(roadmap): the implement Job opens its PR at the end #4713 covers the wip: and checkpoint pushes only). What I did: this pull request is merged, so I filed fix(roadmap): the final push of the implement Job can miss the latest main #4957 with the evidence, a small fix (_current_tip(in_step=False) after the scoped checks) and a test-first plan. No code change here.

About the question "is this a complicated alternative to check-merge-conflict": the merged form already replaced the first build (551 lines, two commands) with one sh hook of about 10 lines. check-merge-conflict does not do the same work. It finds conflict markers in the files of a commit and does not read origin, so it passes a branch that is behind main. Both hooks stay.

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

Labels

scope/git Git commands, git configuration, and git credential handling type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant