Skip to content

fix(tooling): pre-push hook false-positives on docs/operator/ after a rebase - #300

Merged
heavygee merged 3 commits into
mainfrom
fix/pre-push-hook-rebase-false-positive
Nov 9, 2026
Merged

heavygee merged 3 commits into
mainfrom
fix/pre-push-hook-rebase-false-positive

Conversation

@heavygee

Copy link
Copy Markdown
Owner

Summary

scripts/tooling/git-hooks/pre-push diffed the raw remote_sha..local_sha range for any push to an existing ref. That's only "my branch's own changes" when remote_sha is an ancestor of local_sha (the normal incremental-push case) — after a force-push following a rebase onto an updated main, remote_sha is NOT an ancestor, and the range also includes every file any upstream-of-my-branch commit touched between the old remote tip and the new rebase base.

Hit this rebasing feat/flaky-quarantine (#275) onto main after a 5-day gap: main had picked up a routine docs/operator/AGENTS.md update in the meantime, and the push was refused for "fork canon on origin PR branch" even though that file was untouched by any of my own commits — it was already safely on origin/main, just newly an ancestor of my branch after the rebase.

Fix

Check git merge-base --is-ancestor first: if remote_sha is a true ancestor of local_sha, behavior is unchanged (exact same diff as before — zero behavior change for the common case). Otherwise, fall back to the same merge-base-against-main approach the brand-new-ref case already uses — which is also the more correct computation in general, since it matches what the eventual PR diff against main will actually show.

Verification

Reproduced in an isolated scratch repo (not just reasoned through):

  1. Confirmed the original hook genuinely reproduces the false positive — identical error text to what I hit on the real repo.
  2. Confirmed the fixed hook resolves it cleanly.
  3. Confirmed a normal incremental push still behaves identically (no regression).
  4. Confirmed a case that should still block — a new branch whose own commit genuinely adds docs/operator/ content — still correctly blocks.

Test plan

  • Scratch-repo repro: original hook fails on rebase-forward push
  • Scratch-repo repro: fixed hook succeeds on the same push
  • Scratch-repo repro: normal incremental push unaffected
  • Scratch-repo repro: genuine new operator-doc content on a feature branch still blocks

… rebase

scripts/tooling/git-hooks/pre-push diffed the raw remote_sha..local_sha
range for any push to an existing ref. That's only "my branch's own
changes" when remote_sha is an ancestor of local_sha (the normal
incremental-push case) — after a force-push following a rebase onto an
updated main, remote_sha is NOT an ancestor, and the range also includes
every file any upstream-of-my-branch commit touched between the old remote
tip and the new rebase base. Hit this rebasing feat/flaky-quarantine onto
main after a 5-day gap: main had picked up a routine docs/operator/AGENTS.md
update in the meantime, and the push was refused for "fork canon on origin
PR branch" even though that file was untouched by any of my own commits —
it was already safely on origin/main, just newly an ancestor of my branch.

Fixed by checking `git merge-base --is-ancestor` first: if remote_sha is a
true ancestor of local_sha, behavior is unchanged (exact same diff as
before). Otherwise, falls back to the same merge-base-against-main approach
the brand-new-ref case already uses — which is also the more correct
computation in general, since it matches what the eventual PR diff against
main will actually show.

Verified in an isolated scratch repo (not just read through): reproduced
the exact false positive with the original hook (identical error text to
what I hit on the real repo), confirmed the fix resolves it, confirmed a
normal incremental push still behaves identically, and confirmed a case
that SHOULD still block — a new branch whose own commit genuinely adds
docs/operator content — still correctly blocks.

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T19:07:06.161794Z b198109 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b221e15a47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/tooling/git-hooks/pre-push Resolved
Cold review on PR #300 found my own fix's fallback base-selection always
preferred origin/main regardless of which remote was actually being pushed
to. Reproduced the real failure mode in an isolated scratch repo: a branch
rebased onto fork origin/main (picking up a fork-only docs/plans/ file)
then force-pushed to upstream would compute its comparison base against
origin/main first — origin/main resolves successfully, so the || fallback
to upstream/main never triggers, and fork-only content inherited from
origin/main becomes invisible to the upstream-destination check.

Added resolve_push_base(), which prefers upstream/main when $PUSH_REMOTE is
"upstream" and origin/main otherwise (matching each destination's actual
safety boundary), falling back to the other remote only if the preferred
one can't resolve at all. Replaced both duplicated inline merge-base blocks
(the pre-existing new-ref case and my own rebase-fallback case from the
prior commit) with calls to this one shared, destination-aware helper.

Verified with four scenarios in an isolated scratch repo:
  A. Upstream push after rebasing onto fork origin/main — now BLOCKS
     (previously let fork-only content through, the exact bug this fixes).
  B. Origin push after rebasing onto origin/main — still ALLOWS (the
     original rebase false-positive this branch's prior commit fixed).
  C. Normal incremental push, unrelated to any rebase — still ALLOWS
     (confirms zero behavior change for the common case).
  D. A genuine new docs/operator/ change authored on a feature branch —
     still BLOCKS (confirms the actual protection isn't weakened).

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd66f04fb8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/tooling/git-hooks/pre-push Resolved
…ote dispatch

Second wave on PR #300: resolve_push_base's else branch only special-cased
the literal string "upstream" to prefer upstream/main, defaulting everything
else (including a remote the policy itself doesn't recognize) to origin/main
first. But fork_pre_push_path_ok's own dispatch is origin-vs-everything-else,
not origin-vs-upstream-vs-everything-else: "Unknown remotes: strict (treat
like upstream)". A push to a third remote (e.g. "mirror") after rebasing
onto fork origin/main could resolve origin/main as the base before the
strict upstream-equivalent check ever got a chance, making fork-only content
inherited from origin invisible again — same root failure mode as the first
wave, just reachable through a different remote name.

Fixed resolve_push_base to mirror the policy's actual dispatch exactly:
only "origin" prefers the fork base; everything else (upstream, or any
unrecognized remote name) prefers upstream/main first.

Verified with a 5th scenario in an isolated scratch repo — a remote named
"mirror" (with upstream ALSO configured, matching this repo's real
topology) force-pushed after rebasing onto fork origin/main now correctly
blocks on the inherited fork-only file. My first attempt at this specific
repro had an unrealistic test setup (no upstream remote configured at all,
which cannot happen in the real repo) and gave a misleading result — caught
by re-deriving the scenario with upstream properly present before trusting
the outcome either way. Re-ran all 4 scenarios from the prior two commits
(A-D) to confirm no regression.

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
@heavygee

heavygee commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: b198109fdd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@heavygee

heavygee commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Note: the green oos-linux/test status above is the estate's local CI bridge (scripts/tooling/hapi-local-ci.sh), standing in while GitHub Actions dispatch is disabled on this fork (see #301, 32+ days now). It's a real test run via the Statuses API, not a GitHub Actions run — don't mistake it for one later.

@heavygee
heavygee merged commit 89bdd3f into main Nov 9, 2026
1 check passed
@heavygee
heavygee deleted the fix/pre-push-hook-rebase-false-positive branch November 9, 2026 13:44
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