Repository navigation
fix(tooling): pre-push hook false-positives on docs/operator/ after a rebase - #300
Conversation
… 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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
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]>
There was a problem hiding this comment.
💡 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".
…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]>
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Note: the green |
Summary
scripts/tooling/git-hooks/pre-pushdiffed the rawremote_sha..local_sharange for any push to an existing ref. That's only "my branch's own changes" whenremote_shais an ancestor oflocal_sha(the normal incremental-push case) — after a force-push following a rebase onto an updatedmain,remote_shais 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) ontomainafter a 5-day gap:mainhad picked up a routinedocs/operator/AGENTS.mdupdate 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 onorigin/main, just newly an ancestor of my branch after the rebase.Fix
Check
git merge-base --is-ancestorfirst: ifremote_shais a true ancestor oflocal_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 againstmainwill actually show.Verification
Reproduced in an isolated scratch repo (not just reasoned through):
docs/operator/content — still correctly blocks.Test plan