Skip to content

Commit 4bcb299

Browse files
donjor-agent[bot]donjor
authored andcommitted
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

File tree

‎scripts/fork-fold.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,11 @@ const splitRepair = (root: string, repair: string, repairLine: string) => {
674674
return { alphaFixup, betaFixup, residue: git(root, ["rev-parse", "HEAD"]) };
675675
};
676676

677-
const cli = (root: string, args: ReadonlyArray<string>) => {
677+
const cli = (root: string, args: ReadonlyArray<string>, env?: NodeJS.ProcessEnv) => {
678678
const result = NodeChildProcess.spawnSync(process.execPath, [forkFoldScript, ...args], {
679679
cwd: root,
680680
encoding: "utf8",
681+
...(env === undefined ? {} : { env: { ...process.env, ...env } }),
681682
});
682683
return { status: result.status ?? -1, stdout: result.stdout, stderr: result.stderr };
683684
};
@@ -802,7 +803,11 @@ it("falls back to a worktree rebase at the first refused block and resumes acros
802803
`${alphaFeature}\t${alphaDependent}\n${betaCleanup}\t${betaEdit}\n`,
803804
);
804805
const worktree = worktreeDir(root);
805-
const apply = () => cli(root, ["apply", "plan.tsv", "--base", base]);
806+
const apply = (env?: NodeJS.ProcessEnv) =>
807+
cli(root, ["apply", "plan.tsv", "--base", base], env);
808+
// Repo scope outranks a developer's global opt-out, so the commit each
809+
// resume runs would detach auto maintenance here exactly as it does on CI.
810+
git(root, ["config", "maintenance.auto", "true"]);
806811

807812
// The alpha fold carries the fast path; the beta pair refuses there — it
808813
// cannot replay before its dependent — and moves to the worktree rebase.
@@ -815,10 +820,14 @@ it("falls back to a worktree rebase at the first refused block and resumes acros
815820
assert.strictEqual(NodeFS.existsSync(worktree), true);
816821

817822
resolveStop(root, worktree, "A1!\nl2\nl3\nl4\nl5\n");
818-
const second = apply();
823+
const trace = NodePath.join(root, "trace2.json");
824+
const second = apply({ GIT_TRACE2_EVENT: trace });
819825
assert.strictEqual(second.status, 1, second.stderr);
820826
assert.include(second.stderr, "stopped: ");
821827
assert.include(second.stderr, "fix: beta edit");
828+
// A detached maintenance run's `rerere gc` would race the next pick for
829+
// MERGE_RR.lock and kill the rebase mid-stop (RSI-Software/t3code-hyprws#1459).
830+
assert.notInclude(NodeFS.readFileSync(trace, "utf8"), '"maintenance","run"');
822831

823832
resolveStop(root, worktree, "A1!\nB2\nl3\nl4\nl5\n");
824833
const third = apply();

‎scripts/fork-sync.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,20 @@ it("accepts an upstream delete whose fork edit is net-zero and continues the reb
641641
f.git(["push", "--quiet", "upstream", "main", "v2.0.0"], f.root);
642642
f.git(["checkout", "--quiet", "hyprws"], f.root);
643643

644-
const { runner } = exec();
644+
const { runner, calls } = exec();
645645
const applied = capture(() => run(["v2.0.0", "--dry-run"], { runner, root: f.root }));
646646
assert.strictEqual(applied.value, 0);
647647
const report = readReport(f.root, "v2.0.0");
648648
assert.strictEqual(report.outcome, "applied");
649649
assert.notStrictEqual(report.trunk.after, null);
650650
assert.strictEqual(report.conflicts.length, 2);
651+
// Auto maintenance detached by a sequencer commit would race the next
652+
// pick for MERGE_RR.lock (RSI-Software/t3code-hyprws#1459).
653+
const rebases = calls.filter(
654+
({ command, args }) => command === "git" && args.includes("rebase"),
655+
);
656+
assert.isTrue(rebases.some(({ args }) => args.includes("--continue")));
657+
for (const { args } of rebases) assert.include(args, "maintenance.auto=false");
651658
for (const row of report.conflicts) {
652659
assert.strictEqual(row.path, "shared.txt");
653660
assert.strictEqual(row.via, "net-zero-delete");

‎scripts/fork-sync.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,21 @@ export const resolveTarget = (
340340
// Rebase
341341
// ---------------------------------------------------------------------------
342342

343+
/**
344+
* `maintenance.auto=false`: every `git commit` the sequencer runs would
345+
* otherwise detach a `git maintenance run --auto` whose `rerere gc` holds
346+
* MERGE_RR.lock while the next pick conflicts, and the rebase dies on that lock
347+
* after clearing REBASE_HEAD but before recording the stop.
348+
*/
343349
const REBASE_CONFIG = [
344350
"-c",
345351
"core.commentChar=auto",
346352
"-c",
347353
"diff.algorithm=histogram",
348354
"-c",
349355
"rerere.enabled=true",
356+
"-c",
357+
"maintenance.auto=false",
350358
];
351359

352360
export const worktreePath = (root: string): string => NodePath.join(root, SYNC_DIR, WORKTREE_DIR);

‎scripts/lib/fork-fold-rebase.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ export const resolveForkOwnedTree = (
102102
}
103103
};
104104

105-
/** Flags mirror the sync rebase's configuration (scripts/fork-sync.ts REBASE_CONFIG). */
105+
/** Flags mirror the sync rebase's configuration (scripts/fork-sync.ts REBASE_CONFIG), which explains each. */
106106
const REBASE_FLAGS = [
107107
"-c",
108108
"core.commentChar=auto",
109109
"-c",
110110
"diff.algorithm=histogram",
111111
"-c",
112112
"rerere.enabled=true",
113+
"-c",
114+
"maintenance.auto=false",
113115
];
114116

115117
export interface FoldRebaseRequest {

0 commit comments

Comments
 (0)