Repository navigation
Commit 4bcb299
fix(fork): fold and sync rebases run without auto maintenance racing their stops (#1502)
## Problem
The fork-fold worktree fallback fails intermittently on CI when a resumed rebase stops again:
```text
AssertionError: expected 'failed: git rev-parse REBASE_HEAD fai…' to include 'stopped: '
```
It reproduces locally at 17 of 64 runs once the global git config matches the CI runner.
The sync rebase in `scripts/fork-sync.ts` resumes stops the same way and shares the cause.
## Change
Both fork rebases now run with `-c maintenance.auto=false`.
The sync rebase's `REBASE_CONFIG` carries the flag and its explanation, and the fold rebase's flags mirror it beside the existing `rerere.enabled=true`.
**Cause:** `rebase --continue` commits the resolved stop with a child `git commit`, which runs `git maintenance run --auto --detach`.
In git 2.55 the default auto maintenance includes `rerere-gc`, which runs whenever `rr-cache` has an entry, and both rebases enable rerere.
The detached `git rerere gc` holds `MERGE_RR.lock` while the sequencer picks the next commit:
1. `pick_commits` deletes `REBASE_HEAD` for the new item.
2. The pick conflicts, then `repo_rerere` calls `setup_rerere` with `LOCK_DIE_ON_ERROR` and the rebase dies (exit 128).
3. `make_patch` never runs, so `REBASE_HEAD` and `stopped-sha` are never written; `rebase-merge/` stays, so the fold reads a stop that has no `REBASE_HEAD`.
The race also hits real folds and syncs, where `rr-cache` is rarely empty after the first stop.
The CI runner has git 2.55 and no global config, so auto maintenance runs there.
Local runs passed because the developer config sets `maintenance.auto=false`, and git 2.43 has no `rerere-gc` task.
Two guards cover it:
- The fold fallback test sets `maintenance.auto=true` in the fixture repo, which outranks a global opt-out, and asserts that the resumed apply starts no `maintenance run`.
- The sync net-zero-delete test, which continues its rebase, asserts that every recorded `git rebase` argv, `--continue` included, carries `maintenance.auto=false`.
## Scope and approval
Closes #1459, an Urgent fork tooling bug that turned trunk CI red.
The change touches only `scripts/fork-sync.ts`, `scripts/lib/fork-fold-rebase.ts`, and their tests.
## Close conditions
- [x] **Stable:** passes on repeated CI runs: green on `4fe7c95`, `ca1db16`, and `3d01b2d`
- [x] **Cause:** missing `REBASE_HEAD` explained
## Verification
| Run | Result |
| --- | --- |
| Unfixed, two fallback tests x64, git 2.55, empty global config, 8 parallel | 17 failed with the CI error |
| Fixed, same two tests x100, same conditions | 100 passed |
| Fixed, whole `fork-fold.test.ts` x16, same conditions | 16 passed |
| Fixed, `fork-fold.test.ts` and `fork-sync.test.ts` x8, same conditions | 8 passed |
| New fold assertion without the fix, git 2.43 and 2.55 | fails on both |
| New sync assertion with the flag flipped to `true` | fails |
| `vp test run fork-fold.test.ts fork-sync.test.ts` (scripts, default env) | 89 passed |
<details>
<summary>Evidence: trace and deterministic reproduction</summary>
A trace2 log of the second apply on the unfixed tree under git 2.55 shows the detached `rerere gc` starting while the rebase reads its index for the next pick:
```text
04:51:41.675152 git commit -n --no-gpg-sign -F .../rebase-merge/message -e --allow-empty
04:51:41.677242 git maintenance run --auto --no-quiet --detach
04:51:41.677733 region maintenance/rerere-gc
04:51:41.678408 git rerere gc
04:51:41.678408 (rebase) do_read_index
```
A `post-commit` hook that creates `MERGE_RR.lock` at the point the detached `rerere gc` takes it reproduces the CI state every time:
```text
STATUS 128
Rebasing (2/3)error: could not apply 33e7ef5... fix: beta edit
fatal: Unable to create '.../.git/worktrees/worktree/MERGE_RR.lock': File exists.
rebase-merge: done ends at "fixup 33e7ef5", no stopped-sha, no patch
shared.txt: both modified
```
With the fix, the same trace shows one `git commit` and zero `maintenance run` starts.
</details>
| Command | Exit |
| --- | --- |
| `vp run fork:ci` | 0 |
| `vp run typecheck` (scripts) | 0 |
| `vp test run fork-fold.test.ts fork-sync.test.ts` (scripts) | 0 |
Done by claude-opus-5-5 in Claude Code.
## Fork trailers
Fork-Domain: fork-meta
Fork-Tier: core
Co-authored-by: donjor <[email protected]>1 parent 985a836 commit 4bcb299
4 files changed
Lines changed: 31 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
677 | | - | |
| 677 | + | |
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
| 681 | + | |
681 | 682 | | |
682 | 683 | | |
683 | 684 | | |
| |||
802 | 803 | | |
803 | 804 | | |
804 | 805 | | |
805 | | - | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
806 | 811 | | |
807 | 812 | | |
808 | 813 | | |
| |||
815 | 820 | | |
816 | 821 | | |
817 | 822 | | |
818 | | - | |
| 823 | + | |
| 824 | + | |
819 | 825 | | |
820 | 826 | | |
821 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
822 | 831 | | |
823 | 832 | | |
824 | 833 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
644 | | - | |
| 644 | + | |
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
651 | 658 | | |
652 | 659 | | |
653 | 660 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
343 | 349 | | |
344 | 350 | | |
345 | 351 | | |
346 | 352 | | |
347 | 353 | | |
348 | 354 | | |
349 | 355 | | |
| 356 | + | |
| 357 | + | |
350 | 358 | | |
351 | 359 | | |
352 | 360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| |||
0 commit comments