Skip to content

Commit ecc87d3

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(fork-sync): carry a retired delete/modify through sync/resolution (#1856)
## Problem The second live `fork-sync` job ([run_defab30d](https://agent.rsi.nz/runs/run_defab30d63c4ff22d0a58102733a70b6)) decided every seam, then blocked on a driver gap. It retired `shikiReviewHighlighter.ts`: upstream deleted it, and the fork edit is not net-zero. - **Rerere:** records no delete/modify stop - **Export:** so the retirement never carried - **Tip fixups:** apply after the rebase; too late - **Result:** the next run stops at the same seam ## Change - **Detect:** fork-modified path the stop dropped - **Export:** a `retired` list on `sync/resolution` - **Import:** reads it as data, beside rerere - **Replay:** `git rm` a listed upstream delete - **Row:** `via: retired`, with its reason - **Docs and skill:** `git rm` retires; the new file The list only accepts deletions upstream already made, so it cannot add content. ## Scope and approval Part of #1841: one blocked sync lands with no human session. ## Verification - [x] **Extended test:** `git rm`, export, replay - [x] **Without the fix:** it fails - [x] `vp test run scripts/fork-sync.test.ts` → 79 ok - [x] `vp run fork:ci` → exit 0 Not yet proven: a live job carrying a retirement. Claude Opus 5.5 in Claude Code. ## Fork trailers Fork-Domain: fork-meta Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 4c97819 commit ecc87d3

5 files changed

Lines changed: 110 additions & 24 deletions

File tree

‎.agents/skills/fork-sync/SKILL.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ No human reviews it: candidate CI gates the landing.
154154
3. Run `vp run fork:sync <tag> --dry-run`
155155
4. Resolve `manual` paths per [Conflict](#conflict)
156156
5. `git add` them in the kept worktree; rerun
157+
- **Retire:** `git rm` the path instead
157158
6. Repeat until the rebase finishes
158159
7. Commit tip adaptation there; rerun once
159160
8. `git update-ref --no-deref HEAD refs/fork-sync/resolution`
@@ -189,6 +190,7 @@ It is one parentless commit:
189190
rr-cache/<id>/preimage one per resolved stop
190191
rr-cache/<id>/postimage
191192
fixups.mbox tip commits above the rebase
193+
retired paths kept deleted at a delete/modify stop
192194
```
193195

194196
The next run imports it before it rebases: rerere replays each stop, and the fixups apply when its `Fork-Sync-Tag` matches.

‎docs/fork/operations/fork-sync.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Conflict resolution is machine-owned, in this order.
9393
| 1 | Rerere replays resolutions from the run's rebase and [`sync/resolution`](#resolution-data), and stages them |
9494
| 2 | Hook re-apply re-inserts the marked fork hooks a conflicted file declares, from the fork side onto the upstream text |
9595
| 3 | An upstream delete of a path whose fork trunk blob still equals the base blob (a net-zero fork edit) is accepted with `git rm` |
96+
| 3a | So is an upstream delete of a path [`sync/resolution`](#resolution-data) lists as retired |
9697
| 4 | A [regenerable file](#regenerable-files) regenerates once every other path in the stop resolves |
9798
| 5 | Anything left is a `manual` row and stops the run |
9899

@@ -107,7 +108,8 @@ The driver keeps them as git data instead.
107108

108109
- **Export:** `refs/fork-sync/resolution`, per rebase
109110
- **Shape:** one parentless commit, no workflows
110-
- **Contents:** resolved rerere, `fixups.mbox`
111+
- **Contents:** resolved rerere, `fixups.mbox`, `retired`
112+
- **Retired:** paths a resolver `git rm`'d at a delete/modify stop
111113
- **Scope:** this sync's stops and every import
112114
- **Push:** rsi-pr-agent or a hand resolver
113115
- **Import:** each run, before the rebase

‎scripts/fork-sync.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ it("accepts an upstream delete whose fork edit is net-zero and continues the reb
11031103
);
11041104
});
11051105

1106-
it("still blocks a delete/modify whose fork edit is not net-zero", () => {
1106+
it("blocks a delete/modify whose fork edit is not net-zero, then carries its retirement", () => {
11071107
withFixture(
11081108
{
11091109
forkContent: "line1\nline2 fork\nline3\n",
@@ -1129,6 +1129,29 @@ it("still blocks a delete/modify whose fork edit is not net-zero", () => {
11291129
assert.deepStrictEqual(report.decision.paths, ["shared.txt"]);
11301130
// The modified text still stands in the worktree, awaiting a manual resolution.
11311131
assert.strictEqual(NodeFS.existsSync(NodePath.join(f.worktree, "shared.txt")), true);
1132+
1133+
// A resolver retires it; rerere records nothing, yet the export carries it.
1134+
const resolve = (): number =>
1135+
capture(() => run(["v2.0.0", "--dry-run"], { runner: exec().runner, root: f.root })).value;
1136+
f.git(["rm", "--quiet", "shared.txt"], f.worktree);
1137+
assert.strictEqual(resolve(), 0);
1138+
const exported = "refs/fork-sync/resolution";
1139+
assert.strictEqual(f.git(["show", `${exported}:retired`], f.root), "shared.txt");
1140+
f.git(["push", "--quiet", "origin", `${exported}:refs/heads/sync/resolution`], f.root);
1141+
1142+
// a fresh runner replays the retirement and never stops
1143+
f.git(["worktree", "remove", "--force", f.worktree], f.root);
1144+
NodeFS.rmSync(NodePath.join(f.root, ".t3", "fork-sync", "worktree.json"));
1145+
assert.strictEqual(resolve(), 0);
1146+
const replayed = readReport(f.root, "v2.0.0");
1147+
assert.deepStrictEqual(
1148+
replayed.conflicts.map((conflict) => [conflict.via, conflict.reason]),
1149+
[["retired", "upstream deleted; retired by sync/resolution"]],
1150+
);
1151+
assert.strictEqual(
1152+
f.git(["ls-tree", "--name-only", replayed.trunk.after!, "--", "shared.txt"], f.root),
1153+
"",
1154+
);
11321155
},
11331156
);
11341157
});

‎scripts/fork-sync.ts‎

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,19 @@ const trunkSha = (runner: CommandRunner, root: string): string => {
126126
: "unknown";
127127
};
128128

129-
/** How a conflict row resolved: hook re-apply, an accepted net-zero delete, regeneration, or a manual resolution. */
130-
export const ConflictVia = Schema.Literals(["hook", "manual", "net-zero-delete", "regenerate"]);
129+
/** How a conflict row resolved: hook re-apply, an accepted net-zero delete, a carried retirement, regeneration, or a manual resolution. */
130+
export const ConflictVia = Schema.Literals([
131+
"hook",
132+
"manual",
133+
"net-zero-delete",
134+
"retired",
135+
"regenerate",
136+
]);
131137

132138
/** The recorded reason when an upstream deletion meets a net-zero fork edit. */
133139
export const NET_ZERO_REASON = "upstream deleted; fork edit is net-zero";
140+
/** The recorded reason when an upstream deletion meets a path a resolver retired. */
141+
export const RETIRED_REASON = "upstream deleted; retired by sync/resolution";
134142

135143
export const ConflictRow = Schema.Struct({
136144
/** Repo-relative path of the conflicted file. */
@@ -147,7 +155,7 @@ export const ConflictRow = Schema.Struct({
147155
hooksReapplied: Schema.Array(Schema.String),
148156
/** Why hook re-apply refused the path; set on `manual` rows that carried hooks. */
149157
refuseReason: Schema.optionalKey(Schema.String),
150-
/** Why an automatic rule resolved the path; set on `net-zero-delete` and `regenerate` rows. */
158+
/** Why an automatic rule resolved the path; set on `net-zero-delete`, `retired`, and `regenerate` rows. */
151159
reason: Schema.optionalKey(Schema.String),
152160
});
153161
export interface ConflictRow extends Schema.Schema.Type<typeof ConflictRow> {}
@@ -358,6 +366,8 @@ const WorktreeState = Schema.Struct({
358366
rebased: Schema.optionalKey(Schema.String),
359367
/** The rerere ids to export: every stop's, plus every imported one, since a replay records none. */
360368
rerere: Schema.optionalKey(Schema.Array(Schema.String)),
369+
/** The paths a resolver retired, plus every imported one: rerere records no delete/modify stop. */
370+
retired: Schema.optionalKey(Schema.Array(Schema.String)),
361371
/** The `sync/resolution` commit this worktree imported; a moved branch refuses adoption. */
362372
resolution: Schema.optionalKey(Schema.String),
363373
});
@@ -929,8 +939,12 @@ export const refuseDroppedLinks = (
929939
* block again and resolved ones continue; a finished HEAD is taken as the
930940
* rebased tip as long as it contains the target.
931941
*
932-
* `conflicts` collects this run's rows and `rerere` each stop's rerere ids as
933-
* they happen; `rebaseOnto` owns both.
942+
* A delete/modify a resolver settled by keeping upstream's deletion leaves
943+
* the path out of the index, where rerere never looks: each stop records such
944+
* paths in `retired`, and a later replay accepts the same deletion again.
945+
*
946+
* `conflicts` collects this run's rows, `rerere` each stop's rerere ids, and
947+
* `retired` each stop's retired paths as they happen; `rebaseOnto` owns all three.
934948
*/
935949
const replayOnto = (
936950
runner: CommandRunner,
@@ -940,6 +954,7 @@ const replayOnto = (
940954
adopted: boolean,
941955
conflicts: ConflictRow[],
942956
rerere: string[],
957+
retired: string[],
943958
): RebaseOutcome => {
944959
const worktree = worktreePath(root);
945960
// The fork stack above `target` sits on this upstream commit — for a normal
@@ -1003,6 +1018,26 @@ const replayOnto = (
10031018
`git rebase failed without a stop: ${status.stderr.trim() || status.stdout.trim() || "no output"}`,
10041019
);
10051020
rerere.push(...stopRerereIds(runner, worktree));
1021+
const modified = lines(
1022+
git(runner, worktree, [
1023+
"diff-tree",
1024+
"--no-commit-id",
1025+
"--name-only",
1026+
"-r",
1027+
"--diff-filter=MT",
1028+
"REBASE_HEAD",
1029+
]),
1030+
);
1031+
if (modified.length > 0) {
1032+
const tracked = new Set(lines(git(runner, worktree, ["ls-files", "--", ...modified])));
1033+
retired.push(
1034+
...modified.filter(
1035+
(path) =>
1036+
!tracked.has(path) &&
1037+
gitResult(runner, root, ["cat-file", "-e", `${target.sha}:${path}`]).status !== 0,
1038+
),
1039+
);
1040+
}
10061041
const forkCommit = git(runner, worktree, ["rev-parse", "REBASE_HEAD"]);
10071042
const forkSubject = git(runner, worktree, ["log", "-1", "--format=%s", "REBASE_HEAD"]);
10081043
const unmerged = lines(git(runner, worktree, ["diff", "--name-only", "--diff-filter=U"]));
@@ -1018,24 +1053,27 @@ const replayOnto = (
10181053
}
10191054
// Delete/modify with the deletion on the upstream (rebase base) side:
10201055
// when the fork trunk's final blob for the path equals the base blob,
1021-
// the fork edit is net-zero and the deletion is accepted outright. Any
1022-
// other delete/modify shape falls through to hook re-apply, which
1023-
// refuses it, and then to a manual row.
1024-
if (
1056+
// the fork edit is net-zero and the deletion is accepted outright, as
1057+
// it is for a path a resolver already retired. Any other delete/modify
1058+
// shape falls through to hook re-apply, which refuses it, and then to
1059+
// a manual row.
1060+
const upstreamDeleted =
10251061
stageContent(runner, worktree, 2, path) === null &&
1026-
stageContent(runner, worktree, 3, path) !== null &&
1027-
gitResult(runner, root, ["diff", "--quiet", baseSha, oldSha, "--", path]).status === 0
1028-
) {
1062+
stageContent(runner, worktree, 3, path) !== null;
1063+
const netZero =
1064+
upstreamDeleted &&
1065+
gitResult(runner, root, ["diff", "--quiet", baseSha, oldSha, "--", path]).status === 0;
1066+
if (netZero || (upstreamDeleted && retired.includes(path))) {
10291067
git(runner, worktree, ["rm", "--quiet", "--", path]);
10301068
conflicts.push({
10311069
path,
10321070
forkCommit,
10331071
forkSubject,
10341072
upstreamCommit: touch.sha,
10351073
upstreamSubject: touch.subject,
1036-
via: "net-zero-delete",
1074+
via: netZero ? "net-zero-delete" : "retired",
10371075
hooksReapplied: [],
1038-
reason: NET_ZERO_REASON,
1076+
reason: netZero ? NET_ZERO_REASON : RETIRED_REASON,
10391077
});
10401078
continue;
10411079
}
@@ -1119,7 +1157,8 @@ export type SyncRebase = RebaseOutcome & {
11191157
* A new worktree runs the repo's setup step before the rebase starts, so a
11201158
* stop has dependencies. Each stop's rows persist beside the worktree as they
11211159
* are recorded, so the run that finishes the rebase still reports them.
1122-
* `imported` (from `sync/resolution`) joins the exported rerere ids, and its
1160+
* `imported` (from `sync/resolution`) joins the exported rerere ids and
1161+
* retired paths, and its
11231162
* fixups apply above a rebase this run finishes; every outcome exports the
11241163
* resolution data for the next run.
11251164
*/
@@ -1159,14 +1198,16 @@ export const rebaseOnto = (
11591198
const carried = state.conflicts ?? [];
11601199
const conflicts: ConflictRow[] = [];
11611200
const rerere: string[] = [...(imported?.rerere ?? [])];
1201+
const retired: string[] = [...(state.retired ?? []), ...(imported?.retired ?? [])];
11621202
let outcome: RebaseOutcome;
11631203
try {
1164-
outcome = replayOnto(runner, root, target, oldSha, adopted, conflicts, rerere);
1204+
outcome = replayOnto(runner, root, target, oldSha, adopted, conflicts, rerere, retired);
11651205
} finally {
11661206
state = {
11671207
...state,
11681208
conflicts: mergeStops(carried, conflicts),
11691209
rerere: [...new Set([...(state.rerere ?? []), ...rerere])],
1210+
retired: [...new Set(retired)],
11701211
};
11711212
writeWorktreeState(root, state);
11721213
}

‎scripts/lib/fork-sync-resolution.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ import {
2020
* them to one parentless commit at `RESOLUTION_REF`; whoever resolved a stop
2121
* pushes that commit to `sync/resolution`, and the next run imports it before
2222
* it rebases. The import treats the branch purely as data: it accepts only
23-
* rerere entries and one mbox, and nothing in it ever executes.
23+
* rerere entries, one mbox, and one list of retired paths, and nothing in it
24+
* ever executes. Rerere never records a delete/modify stop, so the paths a
25+
* resolver retired (kept upstream's deletion) travel as that list.
2426
*/
2527
export const RESOLUTION_REF = "refs/fork-sync/resolution";
2628
const RESOLUTION_REMOTE_REF = `refs/remotes/origin/${SYNC_RESOLUTION_BRANCH}`;
2729
const RESOLUTION_TAG_TRAILER = "Fork-Sync-Tag";
2830
const FIXUPS_FILE = "fixups.mbox";
31+
const RETIRED_FILE = "retired";
2932
const RERERE_PATH = /^rr-cache\/[0-9a-f]{40,64}\/(?:pre|post)image(?:\.\d+)?$/;
3033

3134
/** The rerere ids the current stop recorded (`MERGE_RR` holds `<id>[.<n>]\t<path>\0`). */
@@ -62,9 +65,9 @@ const withScratchIndex = <T>(
6265
};
6366

6467
/**
65-
* Write `RESOLUTION_REF`: the resolved rerere entries `state` names, plus the
66-
* tip commits above the finished rebase as `fixups.mbox`. Nothing to carry
67-
* deletes it.
68+
* Write `RESOLUTION_REF`: the resolved rerere entries `state` names, the
69+
* retired paths, plus the tip commits above the finished rebase as
70+
* `fixups.mbox`. Nothing to carry deletes it.
6871
*/
6972
export const exportResolution = (
7073
runner: CommandRunner,
@@ -74,6 +77,7 @@ export const exportResolution = (
7477
readonly tag: string;
7578
readonly rebased?: string;
7679
readonly rerere?: ReadonlyArray<string>;
80+
readonly retired?: ReadonlyArray<string>;
7781
},
7882
): void => {
7983
const commonDir = git(runner, root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
@@ -100,6 +104,11 @@ export const exportResolution = (
100104
]),
101105
);
102106
const entries = files.map((path, index) => `100644 ${shas[index]}\t${path}`);
107+
const retired = [...new Set(state.retired ?? [])].toSorted();
108+
if (retired.length > 0)
109+
entries.push(
110+
`100644 ${runRequire(runner, "git", ["hash-object", "-w", "--stdin"], { cwd: root, input: `${retired.join("\n")}\n` }).trim()}\t${RETIRED_FILE}`,
111+
);
103112
if (
104113
state.rebased !== undefined &&
105114
gitResult(runner, worktree, ["merge-base", "--is-ancestor", state.rebased, "HEAD"]).status === 0
@@ -141,12 +150,15 @@ export interface ImportedResolution {
141150
readonly rerere: ReadonlyArray<string>;
142151
/** The fixups mbox, only when made for this sync's tag. */
143152
readonly fixups: string | null;
153+
/** Paths whose upstream deletion a resolver kept; a delete/modify stop on one accepts it. */
154+
readonly retired: ReadonlyArray<string>;
144155
}
145156

146157
/**
147158
* Import `origin/sync/resolution` before the rebase: its rerere entries join
148159
* the local rr-cache without replacing one, and its fixups return only when
149-
* they were made for `tag`. Anything but rerere entries and the mbox refuses
160+
* they were made for `tag`. Anything but rerere entries, the mbox, and the
161+
* retired list refuses
150162
* the run: the branch is data an agent writes, never code the driver trusts.
151163
*/
152164
export const importResolution = (
@@ -165,14 +177,16 @@ export const importResolution = (
165177
const entries = lines(git(runner, root, ["ls-tree", "-r", "--full-tree", RESOLUTION_REMOTE_REF]));
166178
const rerere: string[] = [];
167179
let fixups: string | null = null;
180+
let retired: string | null = null;
168181
for (const entry of entries) {
169182
const match = /^100644 blob ([0-9a-f]+)\t(.+)$/.exec(entry);
170183
const path = match?.[2] ?? entry;
171184
if (match !== null && RERERE_PATH.test(path)) rerere.push(path);
172185
else if (match !== null && path === FIXUPS_FILE) fixups = match[1] ?? null;
186+
else if (match !== null && path === RETIRED_FILE) retired = match[1] ?? null;
173187
else
174188
throw new Error(
175-
`origin/${SYNC_RESOLUTION_BRANCH} holds ${path}, which is not resolution data; only rr-cache entries and ${FIXUPS_FILE} import`,
189+
`origin/${SYNC_RESOLUTION_BRANCH} holds ${path}, which is not resolution data; only rr-cache entries, ${FIXUPS_FILE}, and ${RETIRED_FILE} import`,
176190
);
177191
}
178192
const commonDir = git(runner, root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
@@ -198,5 +212,9 @@ export const importResolution = (
198212
fixups !== null && madeFor === tag
199213
? runRequire(runner, "git", ["cat-file", "blob", fixups], { cwd: root })
200214
: null,
215+
retired:
216+
retired === null
217+
? []
218+
: lines(runRequire(runner, "git", ["cat-file", "blob", retired], { cwd: root })),
201219
};
202220
};

0 commit comments

Comments
 (0)