Skip to content

Fix red main, and stop the post-checkout install from deadlocking a rebase - #2442

Merged
malibio merged 3 commits into
mainfrom
fix-post-checkout-rebase-guard
Sep 8, 2026
Merged

malibio merged 3 commits into
mainfrom
fix-post-checkout-rebase-guard

Conversation

@malibio

@malibio malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Two small, independent commits. main is currently red — the first commit fixes that and is the one to prioritise.

1. main is red: a fixture missing its required reverse fields

object_property_round_trips_through_relationship_get declares held_at → venue with no reverseName/reverseCardinality, which the validation added in #2437 rejects. The test fails at schema creation, before reaching what it exists to verify.

Neither PR's gate could have caught it: #2436 added the fixture, #2437 added the rule, and each was validated against a base predating the other. The squash merges landed 33 minutes apart.

This is the third instance of the same failure mode in this sequence — #2437's review caught the identical collision between #2435 and #2437 before merge. The pattern is worth naming: a green pre-push gate proves the branch passes on its base, and says nothing about the merge result. With several PRs in flight touching the same validation surface, that gap is not hypothetical.

A concert is held at one venue and a venue hosts many concerts, so the inverse is concerts/many.

2. post-checkout deadlocks any rebase

Git checks out the base commit to begin a rebase, firing post-checkout. The bun install that followed rewrote bun.lock, leaving the tree dirty before the first commit was replayed:

error: cannot rebase: You have unstaged changes.

Retrying re-ran the hook and re-dirtied the tree, so the rebase could not progress without disabling hooks wholesale (git -c core.hooksPath=/dev/null rebase). This cost three failed attempts during #2437.

The guard skips the install while a rebase, merge, or cherry-pick is replaying. Nothing is lost: a sequencing operation ends on a real checkout of the final branch, which fires the hook again — resolving dependencies once against the finished tree rather than once per replayed commit. Ordinary checkouts are unaffected.

git rev-parse --git-path rather than a literal .git/ path, so it also works inside a worktree, where the state files live under .git/worktrees/<name>/.

Verified against the original failure

Reproduced the deadlock on a throwaway branch, then confirmed the fix: a rebase that previously failed three times in a row completes with hooks fully enabled and leaves bun.lock clean.

One property worth knowing: the guard cannot protect the rebase that introduces it — the base checkout installs the older hook first — so it takes effect once merged.

Root cause is upstream of this fix

The churn exists because the repo's Bun version is unpinned: packageManager: "[email protected]" and engines.bun: ">=1.0.0" are floors, not pins. The committed lockfile carries a configVersion key that Bun 1.2.16 strips on write, so a lockfile written by a newer Bun is silently reverted by an older one. configVersion has been in the lockfile since June 2026, so the committed format is the intended one and the older Bun is the outlier.

This PR addresses the mechanism, not the cause. Pinning is deliberately left out: it requires choosing the canonical version for the team, and doing it from a machine running the outlier would risk stripping configVersion repo-wide.

Verification

  • cargo test --workspace — 2926 passed, exit 0
  • Pre-push gate (test:all + cargo build --bin nodespaced + full e2e) — passed in full
  • bun run skill:check — in sync

One flake seen and confirmed unrelated: checked_in_skill_md_is_up_to_date failed once under parallel load, then passed in isolation (11/11) and on a clean full run. It shells out to regenerate skill content while other tests touch the same paths.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX

@malibio

malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type

Initial Review — no prior reviews or comments on this PR.

Requirements Check

No linked GitHub issue. The branch is fix-post-checkout-rebase-guard, not issue-<N>-*, and this was maintenance work requested directly in-session rather than tracked work. There are no acceptance criteria to check off, so this section is informational rather than a pass/fail gate.

On the process deviation: CLAUDE.md's startup sequence (worktree, baseline comment, gh:assign, gh:status) presupposes an issue and a feature-sized change. For a two-line hook fix plus a three-line test fixture correction — one of which unblocks a red main — the ceremony would cost more than it returns, and skipping it did not degrade this change. The deviation is fine here. Worth noting only that commit 1 is an urgent red-main fix and, had it been filed as an issue, would have been the kind of thing worth a fast-track label.

Code Review Findings

🔴 The hook's central safety claim is false — a completed rebase does not re-fire post-checkout

📁 .husky/post-checkout:11-13

# Nothing is lost by skipping: a sequencing operation ends on a real checkout
# of the final branch, which fires this hook again with dependencies resolved
# once, against the finished tree, instead of once per replayed commit.

I tested this empirically in a throwaway repo (git 2.39.5, matching this machine), logging every post-checkout invocation with its $1/$2/$3 and the rebase-state files. Across three scenarios:

Scenario Hooks fired
Plain git rebase main (2 commits) 1 — at the start, flag=1, rebase-merge=YES
Rebase where package.json changed 1 — same, at the start only
Conflicted rebase + git rebase --continue 1 — at the start only

In every case the only invocation is the initial base checkout — precisely the one this guard now skips — and nothing fires at completion. git rebase finishes by moving the branch ref and resetting the index/worktree in place; it does not perform a checkout that triggers the hook.

The consequence is a real behavioral regression, not a theoretical one: after this change, a rebase that pulls in package.json/bun.lock changes leaves node_modules stale with no install at all. Previously the install ran (many times, badly, and it deadlocked — but it ran). Now it runs zero times. The developer is left with dependencies silently out of sync until they happen to switch branches again.

The same holds for the other three guarded states, which I also tested — and here the finding is different in kind: git merge, git cherry-pick, and git revert never fire post-checkout at all, conflicted or clean, with MERGE_HEAD/CHERRY_PICK_HEAD present. So those three entries in the loop are dead code. They cost nothing, but they also protect nothing, and their presence in the list makes the guard look broader and better-tested than it is.

Principle — correctness claims must be verified, not reasoned: the comment block is doing the work of a test here. It states a mechanism ("fires this hook again") that reads plausibly and is wrong, and because it is committed as an explanatory comment it will be trusted by the next reader rather than re-derived. This is the risk of encoding an unverified causal claim as documentation.

To be fair about severity: the change is still arguably a net improvement over the status quo, because the previous behavior was an unrecoverable deadlock — strictly worse than stale node_modules. I am flagging this 🔴 not because the guard should be reverted, but because the stated rationale is wrong and must not ship as-is, and because the resulting gap deserves an explicit, honest treatment rather than a reassurance that it doesn't exist.

Suggested fix — make the skip deferred rather than silent. Keep the guard, drop the false claim, and tell the developer what to do:

for state in rebase-merge rebase-apply MERGE_HEAD CHERRY_PICK_HEAD REVERT_HEAD sequencer; do
  if [ -e "$(git rev-parse --git-path "$state")" ]; then
    echo "husky: skipping 'bun install' during a git sequencing operation."
    echo "       Run 'bun install' yourself once it finishes if deps changed."
    exit 0
  fi
done

A one-line notice converts a silent correctness gap into a visible, actionable one, which is the difference between a trade-off and a bug. If you want to close the gap properly rather than paper over it, the durable place is a post-rewrite hook (which does fire after git rebase completes) — but that is a follow-up, and the notice is enough for this PR.

🟡 Guard set is incomplete — REVERT_HEAD and sequencer/ are missing

📁 .husky/post-checkout:17

for state in rebase-merge rebase-apply MERGE_HEAD CHERRY_PICK_HEAD; do

Two states are absent. REVERT_HEAD exists during a conflicted git revert, and sequencer/ exists during a multi-commit git cherry-pick A..B or git revert A..B — the multi-commit sequencer is the case most likely to replay many commits and thus most analogous to the rebase failure this PR fixes.

My testing showed none of these currently fire post-checkout on git 2.39.5, so this is not an active bug. But the loop is cheap and the cost of an omission is another silent deadlock on some future git version or workflow. Since three of the four existing entries are already defensive-only, the set may as well be complete.

Principle — defense in depth should be uniform: a guard list that covers some of a category invites the reader to assume the category is covered. Either enumerate it fully or narrow it to the one state that demonstrably matters (rebase-merge).

🟡 Test fixture: verified correct, and the inverse is semantically right

📁 packages/core/tests/object_valued_property_roundtrip_test.rs:170-172

I verified the red-main claim independently. On origin/main:

running 9 tests
test object_property_round_trips_through_relationship_get ... FAILED
Error: concert schema: invalid params: Relationship 'held_at' (entry 0) is missing
  "reverseName" and "reverseCardinality".
test result: FAILED. 8 passed; 1 failed

On this branch: test result: ok. 9 passed; 0 failed. The claim is accurate and the fix resolves it. As described, the test fails at schema creation — before reaching the object-valued-property round-trip it exists to verify — so main was not merely red but had lost the coverage entirely.

On the semantics: concerts/many is correct. A concert is held at exactly one venue (cardinality: "one" on the forward edge), and a venue hosts many concerts, so the reverse is many. It is plural, which matches the validator's own guidance ("plural where that end may hold many"), and reads naturally as a traversal from the venue end. It also avoids shadowing any core property. No objection.

Principle — a test's failure mode should be its subject: worth noting that this bug class is invisible precisely because the test still "ran." A fixture that fails during setup reports as a test failure indistinguishable from a real regression, which is why this took a human to diagnose rather than being obvious from CI output.

🟡 Two unrelated commits in one PR — acceptable here, but the red-main fix should land independently

The two commits share no code, no cause, and no reviewer context: one is a test-fixture correction, the other a git-hook change. Under normal circumstances this is a clean split into two PRs (atomicity — a PR should have one reason to be reverted).

Here I would not block on it, but for a specific reason that cuts the other way: main is currently red, and commit e0a4970b fixes it. Bundling an urgent unblock behind a hook change that has an open correctness question (see 🔴) means the red-main fix cannot merge until the hook discussion resolves. That is the actual cost of the bundling, and it argues for splitting now rather than as a matter of principle.

Recommendation: cherry-pick e0a4970b onto its own PR and merge it immediately to green main; keep this PR for the hook, where the rationale needs revision.

🟡 Deferring the Bun pin is the right call, and the reasoning holds up

📁 package.json:107,112

I verified the premises. engines.bun: ">=1.0.0" and packageManager: "[email protected]" are both floors, not pins. bun.lock carries "configVersion": 1 at line 3, and local Bun is 1.2.16 — which strips that key on write, making this machine the outlier relative to the committed format.

The author's reasoning for not pinning here — that choosing the canonical version is a team decision, and pinning from the outlier machine risks stripping configVersion repo-wide — is sound and correctly scoped. Pinning to 1.2.16 from this machine would encode the outlier as canonical and churn the lockfile for everyone else; that is a worse outcome than the current churn.

Principle — separate the mechanism from the policy: fixing the deadlock (mechanism) is a local, reversible engineering decision. Choosing the team's Bun version (policy) has blast radius beyond the author. Splitting them is correct, and the PR body documents the deferral clearly enough that it won't be lost. No change requested — this is the right judgment, recorded well. Worth filing as a follow-up issue so the deferral has a home.

🟢 Hook is POSIX-safe, correctly quoted, and worktree-correct

📁 .husky/post-checkout:17-21

Verified each mechanism:

  • POSIX compliance: sh -n and dash -n both parse it clean. Husky's runner (.husky/_/h) invokes hooks via sh -e "$s" "$@", so dash compatibility is the relevant bar and it passes. No bashisms ([[, arrays, local).
  • Quoting: "$(git rev-parse --git-path "$state")" is correctly quoted at both levels. Nested double quotes inside $(...) are valid POSIX and parse as intended. No word-splitting risk — and none of the state names contain spaces regardless.
  • --git-path in a worktree: confirmed directly. From a linked worktree it returned /Users/.../.git/worktrees/mainwt/rebase-merge, not the main .git/. This is exactly right and a literal .git/rebase-merge would have been wrong. Given CLAUDE.md's worktree-per-issue workflow, this detail matters more than usual — good catch by the author.
  • sh -e interaction: the guard exits 0 cleanly; the for/if construct doesn't trip -e, and a failing git rev-parse inside a command substitution in an if condition doesn't either.

🟢 Ordinary checkouts still install

📁 .husky/post-checkout:23-25

The $3 = 1 branch-checkout check is untouched and still gated behind the guard only when sequencing state exists. I confirmed a normal invocation with flag=0 exits 0 without installing, and the flag=1 path is unchanged. No regression for the common case.

🟢 CLAUDE.md compliance

  • No lint suppression, no any, no #[allow(dead_code)] — n/a to both files.
  • No new .md files in this repo. Correct.
  • scripts/ should be TypeScript, but .husky/ hooks are genuinely shell — this is the right read. CLAUDE.md's rule targets scripts/ tooling and explicitly allows shell "where shell is genuinely required." A git hook invoked by git via sh before bun install has necessarily run is exactly that case; it cannot be TypeScript. Note the sibling pre-push hook is a one-line shell shim delegating to scripts/test-gate.ts — the established pattern is thin shell, logic in TS. This hook's logic is small enough that inlining it is proportionate.
  • Issue numbers in code comments: the hook's comment block references no issue or PR numbers — the author correctly stripped them when moving the rationale from the commit message into the file. The commit messages do reference #2436/#2437, which is explicitly permitted (process mechanics in commit/PR text). Compliant on both counts — this is a distinction that's easy to get wrong and was gotten right.
  • No backward-compat/migration code. Correct.

Verdict

COMMENT — one blocking correction to the rationale, plus a recommended split

The engineering here is careful: the --git-path choice is right and non-obvious, the quoting and POSIX compliance are clean, the empirical validation of the original deadlock was real, and the Bun-pin deferral is well-reasoned and honestly documented. The test fix is verified correct and unblocks a genuinely red main.

But the hook ships with a factually incorrect justification — a completed rebase does not re-fire post-checkout, which I confirmed across three scenarios — and that error is load-bearing, because it converts "installs run redundantly" into "installs don't run at all" after a dependency-changing rebase. The change is still net-positive against a deadlock, so this is not a revert; it is a fix the comment and surface the gap request.

Before merge:

  1. 🔴 Correct the comment at .husky/post-checkout:11-13 — remove the "fires this hook again" claim and state the real trade-off. Add the one-line echo so the skip is visible rather than silent.
  2. 🟡 Split e0a4970b into its own PR and merge it now — main is red and shouldn't wait on the hook discussion.

Optional: add REVERT_HEAD and sequencer to the loop; file a follow-up issue for the Bun pin so the deferral is tracked.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: COMMENT (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Address Review — all findings addressed

🔴 The false safety claim — verified, then closed rather than documented

I reproduced the reviewer's finding independently before changing anything, in a throwaway repo with an instrumented hook logging $1/$2/$3 plus rebase state:

FIRED prev=63e6900 new=f95662b flag=1 rebase=YES

Exactly one firing, at the start, with rebase=YES — precisely the invocation the guard skips. Nothing on completion. The review is correct and my original rationale was wrong: the guard alone turned "the install runs redundantly" into "the install never runs."

The suggested fix was an echo telling the developer to run bun install, with post-rewrite as a follow-up. I went to the follow-up directly, because I could confirm it works:

POST_REWRITE fired arg=rebase

So .husky/post-rewrite now runs the install after a replay — once, against the finished tree, which is also cheaper than the per-commit behavior it replaced. A visible gap is better than a silent one, but no gap is better than either, and the durable fix was one verified hook away.

End-to-end proof with instrumented copies of both hooks, rebasing across a package.json change:

Scenario Result
Rebase over a package.json change ✅ completes, installs exactly once from post-rewrite
Two ordinary branch checkouts ✅ installs both times from post-checkout
Pre-fix behavior ❌ unrecoverable deadlock
Guard-only (as first pushed) ❌ zero installs

The post-checkout comment now states the measured behavior — that a rebase fires it once and nothing on completion — and names post-rewrite as what closes the window, so the next reader inherits the measurement rather than my assumption.

🟡 Guard set — narrowed, not widened

The review suggested adding REVERT_HEAD and sequencer/. I went the other way and removed MERGE_HEAD/CHERRY_PICK_HEAD, because the review's own stronger finding was that those operations never fire post-checkout at all. Adding two more dead states would compound the problem it identified — a list implying coverage the hook does not have. Only rebase-merge/rebase-apply remain, with a comment saying why the others are absent.

🟡 Split — done, and it revealed a dependency

The red-main fix is now #2443, standalone and mergeable, so it need not wait on this PR.

Worth flagging: with the fixture commit removed, this branch's own gate now fails on that same red-main test. That is correct behavior, not a regression — it is main's breakage blocking a branch that no longer carries the fix. So the merge order is forced:

  1. Merge Fix red main: give the concert->venue fixture its required reverse fields #2443 first (unblocks main)
  2. Rebase this branch onto green main, then merge

The remote for this PR still shows the pre-split commits, since the force-push was correctly blocked by the gate. I will push the split version once #2443 lands.

🟡 Bun pin deferral — confirmed, no change

🟢 POSIX/quoting/worktree/CLAUDE.md — confirmed, no change

sh -n and dash -n clean on both hooks; post-rewrite has its executable bit set (husky requires it).

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: The 🔴 finding was addressed by adding a new hook rather than editing a comment — new executable behavior on every developer's machine, which is more than the review asked for and deserves a second look. The guard was also narrowed in the opposite direction from the literal suggestion. My verification is empirical rather than self-assessed, but a second pass should confirm post-rewrite is the right mechanism, that $1 = "rebase" is the correct condition (an amend rewrite is deliberately excluded), and that no path now double-installs.

Re-review is best run after #2443 merges and this branch is rebased, so it reviews the final shape against a green base — the same stale-base problem that caused the red main in the first place.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX

@malibio

malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type

Re-Review — prior review 5579838942, author response 5580223754.

⚠️ Reviewed the local commits, not the GitHub diff. A force-push carrying the split was blocked by the pre-push gate, so the remote head is e0a4970b (still bundling the fixture commit) while the local branch is 4781eaf5. git diff origin/main...origin/fix-post-checkout-rebase-guard does not show the reviewed state. Scope reviewed: acebb173..4781eaf5, and the full branch origin/main...4781eaf5 = .husky/post-checkout (+28) and .husky/post-rewrite (+16, new). Nothing else.

Previous Review Summary

  • Previous recommendations: 5 (1 🔴, 4 🟡/🟢-informational)
  • Addressed: 4 — 🔴 false rationale, 🟡 guard set, 🟡 PR split, 🟡 Bun-pin deferral
  • Deliberately diverged (justified): 1 — guard set narrowed rather than widened
  • New issues found: 2 (1 🟡, 1 🟢)
Prior finding Status
🔴 "a completed rebase re-fires post-checkout" is false ✅ Fixed properly — comment corrected and the gap closed via post-rewrite, not just documented
🟡 Add REVERT_HEAD/sequencer ✅ Inverted, correctly — MERGE_HEAD/CHERRY_PICK_HEAD removed instead
🟡 Split the red-main fix ✅ Done — now #2443, standalone and MERGEABLE
🟡 Bun-pin deferral sound ✅ Unchanged, still correct
🟢 POSIX/quoting/worktree/CLAUDE.md ✅ Re-verified below

Requirements Check

No linked GitHub issue and no acceptance criteria. This is in-session maintenance work; the branch is fix-post-checkout-rebase-guard, not issue-<N>-*. There are no criteria to check off, and I am not inventing any. Skipping the issue-based startup sequence remains proportionate for a two-file hook change.

Verification Method

I re-derived every load-bearing claim independently in throwaway repos on git 2.39.5 (Apple Git-154) — the same version the comments cite — rather than accepting the code comments or the author's summary. I ran the actual PR hooks with bun install replaced by an instrumented marker, so the results below describe this code, not a paraphrase of it.

Confirmed: the central mechanism works

Scenario post-checkout post-rewrite Installs
Rebase (merge backend) across a package.json change skipped (guard hit, rebase-merge=Y) arg=rebase exactly 1 ✅
Conflicted rebase + --continue skipped arg=rebase (after continue) exactly 1 ✅
git pull --rebase skipped arg=rebase exactly 1 ✅
Interactive rebase w/ squash and reword skipped arg=rebase once exactly 1 ✅
Ordinary branch checkout ×2 fires, $3=1 — 2 ✅
File checkout ($3=0) fires, no-op — 0 ✅
git merge / git cherry-pick never fires — 0

Three specific things I set out to falsify and could not:

  1. post-rewrite is the right mechanism. It fires exactly once after the replay, with the finished tree checked out. The prior review's suggestion was an echo notice plus a follow-up; going straight to the hook is the stronger fix and it demonstrably works.
  2. $1 = "rebase" is the correct condition. A reword inside an interactive rebase — the obvious double-install trap, since it runs commit --amend mid-replay — fires post-rewrite once with arg=rebase, not twice. A standalone git commit --amend fires arg=amend and is correctly excluded. No path double-installs on the default backend.
  3. The original deadlock is real and is fixed. Reproducing the old hook (origin/main's bare 3-line install) faithfully: FIRE flag=1 at the base checkout → install dirties the lockfile → Could not apply …, tree left M lock.txt. With the new hooks under identical conditions the rebase completes and the tree is clean.

Also re-verified: sh -n and dash -n clean on both files; both are mode 100755; husky's runner (.husky/_/h) dispatches via sh -e "$s" "$@", so post-rewrite genuinely receives $1, and .husky/_/post-rewrite exists so the hook is actually wired up. --git-path checked from a real linked worktree in this repo resolves to /…/.git/worktrees/issue-2432-focus-or-open-node/rebase-merge — correct, and load-bearing given the worktree-per-issue workflow (two live worktrees right now).

Code Review Findings

🟡 New: git rebase --apply is unguarded — the deadlock survives there, and it double-installs

📁 .husky/post-checkout:22-25

The guard tests only for the existence of rebase-merge/rebase-apply. On the --apply backend git tears its state directory down before firing post-checkout, so no state file exists at hook time:

POST_CHECKOUT flag=1 gitdir-entries=[COMMIT_EDITMSG config description HEAD hooks index info logs objects ORIG_HEAD refs ]

No rebase-apply, no rebase-merge — the guard cannot see it by any state-file check. The hook fires at the start, detached at the base commit, exactly as the merge backend does. Running the real PR hooks over a package.json change on that backend:

=== APPLY backend (unguarded) — tree clean before ===
M	lock.txt
Falling back to patching base and 3-way merge...
installs: [INSTALL post-checkout INSTALL post-rewrite ]

Two consequences, both observed: the tree is dirtied mid-rebase (the very failure this PR exists to prevent, forcing a 3-way-merge fallback), and dependencies resolve twice.

Severity is 🟡, not 🔴, and deliberately so. --apply is not the default — git has defaulted to the merge backend since 2.26; rebase.backend is unset in both local and global config, there is no committed git config that could set it (.gitattributes is the only tracked config-adjacent file), and git grep "git rebase" over all tracked files returns zero invocations, so no script or doc passes --apply/-C/--whitespace. Reaching this requires a developer typing it by hand. Narrow and opt-in, and the PR remains a large net improvement on every path anyone here actually takes.

I am flagging it because the hook's comment states "Only rebase is checked" — which reads as all rebases, and one backend is silently exempt. Given the prior review turned on precisely this failure mode (a plausible-sounding comment that measurement contradicts), the same standard should apply to the new text.

Suggested fix — cheap and backend-independent. Rather than enumerating state files, detect the detached-HEAD base checkout that both backends share, or simply scope the claim honestly:

# Only the merge backend (git's default since 2.26) is guarded. `git rebase
# --apply` tears down its state directory before firing this hook, so no
# state file check can catch it.

Engineering principle — a comment's scope should match its guard's scope. One-line wording change is sufficient; widening the guard is optional.

🟢 New: rebase --abort resolves dependencies zero times

📁 .husky/post-checkout:22-25 + .husky/post-rewrite:14

=== E1: rebase --abort (real hooks) ===
installs: []

post-checkout fires at the base checkout and is skipped; --abort rewrites nothing, so post-rewrite never fires. If the base checkout pulled in dependency changes before the abort, node_modules is left unresolved.

In practice an abort restores the original HEAD, so the tree returns to a state the developer's node_modules most likely already matched — this is close to harmless and I would not hold the PR for it. Worth a sentence in the post-rewrite comment so the next reader isn't surprised, since the file currently implies rebase coverage is total.

🟢 Removing MERGE_HEAD/CHERRY_PICK_HEAD was the right call

📁 .husky/post-checkout:22-25

The prior review suggested adding REVERT_HEAD and sequencer; the author removed two entries instead. I verified the reasoning: git merge fires post-merge, not post-checkout; git cherry-pick fires neither. Those entries protected nothing while implying breadth the hook lacks — the same defect the review named. Diverging from the literal suggestion in favor of its underlying principle is correct, and the comment now says why the others are absent.

🟢 Comments now carry the measurement, not an assumption

📁 .husky/post-checkout:11-16, .husky/post-rewrite:3-13

The replacement text states the measured behavior ("Measured on git 2.39.5: a rebase fires post-checkout exactly once … and fires nothing on completion") and names post-rewrite as the counterpart. Both claims reproduce exactly. The post-rewrite comment's justification for excluding amend is also correct as written. This is the right correction to the 🔴: the next reader inherits a verified fact with its git version attached.

Principle — documentation asserting a causal mechanism is load-bearing and should be verified like code. Pinning the git version in the comment is a genuinely good habit; it makes the claim falsifiable later.

🟢 PR is now atomic; merge order is real and correctly identified

The branch touches only the two hook files (git diff --stat origin/main...HEAD confirms), and the fixture fix is now #2443 (MERGEABLE). The author's stated ordering — merge #2443 first, then rebase this branch — is correct and not merely procedural: I confirmed object_property_round_trips_through_relationship_get fails on this branch, and that this PR is not the cause. The fixture here is byte-identical to origin/main (empty diff under packages/core/tests/), so the failure is inherited from main and #2443 carries the fix.

🟢 Testing, dependencies, security, CLAUDE.md

  • Tests: none, and none warranted. Git hook behavior is testable only by driving real git operations; the repo has no hook test coverage at all (git grep -i husky over tests returns zero hits, and scripts/test-gate.ts never invokes these hooks — it is invoked by pre-push), so this PR is not regressing a standard, and building a harness for 44 lines fails the YAGNI bar. The empirical verification in the commit messages is the proportionate substitute — and unusually, it is reproducible from the description, which is what makes it acceptable.
  • No caller depends on the hook. Every bun install reference in the repo is an explicit manual step (CLAUDE.md:43,61,253, README.md:60, CI's --frozen-lockfile); nothing assumes the hook installs for it. So changing when the install fires cannot break a documented workflow — which is what makes the remaining gaps tolerable rather than load-bearing.
  • Dependencies: no new ones. Uses husky already at ^9.1.7.
  • Security: no input handling, no secrets, no network. post-rewrite inherits git's rewrite list on stdin (2 lines, verified) which bun install does not read — benign.
  • CLAUDE.md: shell is legitimate here (a git hook runs before bun install has necessarily run); no new .md files; no issue numbers in code comments (correctly kept to commit messages); no lint suppression; no backward-compat or migration code.

Verdict

APPROVE

The 🔴 from the prior round is genuinely closed rather than papered over. The author was told the rationale was false and could have satisfied the review with a comment edit plus an echo; instead the underlying gap was closed with a mechanism I independently confirmed fires exactly once, on every rebase path a developer here will actually use — including the reword case that would have been the natural double-install bug. The guard was also narrowed rather than widened, against the literal suggestion but in line with its reasoning, which is the better read. Comments now carry measurements with a git version attached.

The two new findings are both narrow and neither blocks: --apply is an opt-in backend nobody here invokes, and --abort restores the tree it started from. Against the baseline — an unrecoverable deadlock that cost three failed attempts on a real rebase — this is a clear net improvement, which is the bar.

Optional before merge (neither is a gate):

  • 🟡 Scope the "Only rebase is checked" comment to the merge backend, so it doesn't repeat the over-broad-claim pattern the last review caught.
  • 🟢 Note the --abort case in post-rewrite's comment.

Merge order stands as the author described: #2443 first to green main, then rebase this branch. Not merging — that call is yours.

Still-open follow-up, unchanged from the last round and correctly out of scope here: the Bun version remains unpinned (packageManager: "[email protected]", engines.bun: ">=1.0.0" — floors, against a local Bun of 1.2.16 and a bun.lock carrying configVersion: 1). That is the root cause this PR deliberately treats only the mechanism of. Worth an issue so the deferral has a home.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Address Review — both suggestions taken

Verdict was APPROVE with two optional, non-gating suggestions. I took both, because the 🟡 one is the same class of defect the first review of this file caught.

🟡 --apply backend — reproduced, then scoped honestly

I reproduced this before writing anything, running the real PR hooks over a package.json change:

=== rebase --apply ===
M	lock.txt
Falling back to patching base and 3-way merge...
=== installs ===
INSTALL(.git/hooks/post-checkout)
INSTALL(.git/hooks/post-rewrite)
=== tree dirty? ===
 M lock.txt

Exactly as reported: the guard misses, the tree is dirtied mid-replay, and dependencies resolve twice. A genuine hole in my own testing — I validated only the default backend and generalised from it.

The guard is left as-is, because there is nothing to extend. Git tears the rebase state directory down before firing post-checkout on that backend, so no state-file check can see it. Extending the loop would add a check that cannot fire — the same dead-code defect that got MERGE_HEAD/CHERRY_PICK_HEAD removed last round.

What I fixed is the claim. Only rebase is checked read as all rebases, and the review is right that a plausible-sounding comment contradicted by measurement is precisely what the first review of this file turned on. The comment now names the merge backend, states why --apply cannot be covered by this mechanism, and notes it is opt-in (rebase.backend unset; no tracked file invokes it).

🟢 rebase --abort — noted in the comment

Skipped on the way in, and post-rewrite never fires because nothing was rewritten, so no install runs. Harmless in practice — an abort restores the original HEAD, the tree node_modules already matched — but better stated than rediscovered.

Verification

Comments only; git diff confirms no non-comment line changed. Re-verified after the edit rather than assuming:

Check Result
Rebase over a package.json change installs exactly 1 ✅
Two ordinary branch checkouts installs 2 ✅
sh -n / dash -n clean ✅
Executable bit preserved ✅

Push is still blocked, and correctly so

The gate fails on object_property_round_trips_through_relationship_get — main's inherited breakage, fixed in #2443, not by anything here. Confirmed it is the only failure. So the remote head remains stale until #2443 lands; the local branch is at 0bef27c7.

Merge order stands: #2443 first to green main, then rebase this branch and push.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: This round changed comments only — git diff shows no non-comment line touched, and the three behaviours were re-verified unchanged after the edit. The reviewer explicitly marked both suggestions as non-gating on an APPROVE verdict, and neither was addressed by altering logic. There is no new functionality, no refactor, and nothing interconnected for a further pass to catch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX

malibio and others added 3 commits September 8, 2026 08:44
Git checks out the base commit to begin a rebase, which fires post-checkout.
The `bun install` that followed rewrote bun.lock — the committed lockfile
carries a `configVersion` key that older Bun releases strip on write — leaving
the tree dirty before the first commit was replayed. The rebase then stopped
with "cannot rebase: You have unstaged changes", and retrying re-ran the hook
and re-dirtied the tree, so it could not make progress without disabling hooks
wholesale (`git -c core.hooksPath=/dev/null rebase`).

Skip the install while a rebase, merge, or cherry-pick is replaying. Nothing is
lost: a sequencing operation ends on a real checkout of the final branch, which
fires this hook again — resolving dependencies once against the finished tree
rather than once per replayed commit.

Uses `git rev-parse --git-path` rather than a literal `.git/` path so it also
works inside a worktree, where the state files live under
`.git/worktrees/<name>/`.

Verified against the original failure: a rebase that previously failed three
times in a row now completes with hooks fully enabled and leaves bun.lock
clean. Note the guard cannot protect the rebase that introduces it — the base
checkout installs the older hook first — so it takes effect once on main.

This addresses the mechanism only. The underlying cause is that the repo's Bun
version is unpinned (`packageManager: "[email protected]"` and `engines.bun: ">=1.0.0"`
are floors, not pins), so a lockfile written by a newer Bun is rewritten by an
older one. Pinning is left as a separate decision, since it requires choosing
the canonical version for the team.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX
…ires post-checkout

Review disproved the rationale the rebase guard shipped with. The comment
claimed "a sequencing operation ends on a real checkout of the final branch,
which fires this hook again". Measured on git 2.39.5, it does not: a rebase
fires post-checkout exactly once — the base checkout the guard skips — and
fires nothing on completion. Reproduced independently before changing anything.

So the guard alone turned "the install runs redundantly" into "the install
never runs": a rebase pulling in package.json or bun.lock changes would resolve
dependencies zero times. Still better than the unrecoverable deadlock it
replaced, but a silent correctness gap.

Close it rather than document it. post-rewrite does fire after a replay (verified:
`arg=rebase`), so the install moves there — once, against the finished tree,
which is also cheaper than the per-commit behavior it replaces.

Also drop MERGE_HEAD and CHERRY_PICK_HEAD from the guard. Those operations
never fire post-checkout at all, so the states were dead code implying a
breadth of coverage this hook does not have. Only rebase is checked now, and
the comment says why.

Verified end to end with instrumented copies of both hooks: a rebase across a
package.json change completes and installs exactly once from post-rewrite;
ordinary branch checkouts still install from post-checkout.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX
Review found a backend my testing missed, and I reproduced it before writing
this: on `git rebase --apply`, git tears the rebase state directory down BEFORE
firing post-checkout, so no state-file check can see it. Running the real hooks
over a package.json change on that backend dirties the tree mid-replay
("Falling back to patching base and 3-way merge...") and installs twice — the
exact failure this guard exists to prevent.

The guard is left as-is rather than extended, because there is nothing to
extend: the state files are already gone by the time the hook runs. `--apply`
is opt-in (rebase.backend unset here, no tracked file invokes it), so the
narrow uncovered path is acceptable — but the comment claiming "Only rebase is
checked" read as ALL rebases, and a plausible-sounding comment that measurement
contradicts is precisely what the first review of this file caught. Scope the
claim to the merge backend and name the exemption.

Also note the `rebase --abort` gap: skipped on the way in, and post-rewrite
never fires because nothing was rewritten, so no install runs. Harmless — an
abort restores the original HEAD, the tree node_modules already matched — but
better stated than rediscovered.

Comments only; no behavior change. Re-verified after the edit: rebase installs
exactly once, ordinary checkouts install both times, `sh -n`/`dash -n` clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KHdtH4eZHiU7RzhCuHArQX
@malibio
malibio force-pushed the fix-post-checkout-rebase-guard branch from e0a4970 to f375689 Compare September 8, 2026 06:48
@malibio
malibio merged commit 7e6541c into main Sep 8, 2026
@malibio
malibio deleted the fix-post-checkout-rebase-guard branch September 8, 2026 06:56
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