Skip to content

Commit f2a4cbb

Browse files
committed
fix router approval durability
1 parent ee5a861 commit f2a4cbb

2 files changed

Lines changed: 42 additions & 31 deletions

File tree

‎src/repair/comment-router.ts‎

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,38 +2232,17 @@ function executeCommand(command: LooseRecord) {
22322232
.filter((action: JsonValue) => action.action === "remove_label")
22332233
.map((action: JsonValue) => String(action.label ?? ""))
22342234
.filter(Boolean);
2235-
if (pauseLabels.length > 0) {
2236-
for (const pausedLabel of pauseLabels) {
2237-
runGitHubBestEffortMutation(
2238-
command,
2239-
"label_remove",
2240-
{ repository: command.repo, number: command.issue_number, label: pausedLabel },
2241-
[
2242-
"issue",
2243-
"edit",
2244-
String(command.issue_number),
2245-
"--repo",
2246-
command.repo,
2247-
"--remove-label",
2248-
pausedLabel,
2249-
],
2250-
githubNotFoundNoMutation,
2251-
);
2252-
}
2253-
command.target = {
2254-
...command.target,
2255-
labels: (command.target?.labels ?? []).filter(
2256-
(label: JsonValue) => !pauseLabels.includes(String(label)),
2257-
),
2258-
};
2259-
}
2235+
const deferPauseLabelRemoval = command.intent === "maintainer_approve_automerge";
2236+
if (pauseLabels.length > 0 && !deferPauseLabelRemoval) applyRemoveLabelActions(command);
22602237
const merge = executeAutomerge(command);
22612238
dispatched = { ...dispatched, merge };
22622239
command.actions = command.actions.map((action: JsonValue) =>
22632240
action.action === "label"
22642241
? { ...action, status: "executed", label: action.label }
22652242
: action.action === "remove_label"
2266-
? { ...action, status: "executed", label: action.label }
2243+
? deferPauseLabelRemoval
2244+
? action
2245+
: { ...action, status: "executed", label: action.label }
22672246
: action.action === "update_description_note"
22682247
? { ...action, status: "executed" }
22692248
: action.action === "merge"
@@ -2306,12 +2285,16 @@ function executeCommand(command: LooseRecord) {
23062285
mode: command.target.mode,
23072286
...dispatchRepairActionStatus(repair),
23082287
});
2288+
if (deferPauseLabelRemoval) applyRemoveLabelActions(command);
23092289
if (repair.status === "claimed") {
23102290
keepCommandClaimed(command);
23112291
return;
23122292
}
23132293
}
23142294
}
2295+
if (deferPauseLabelRemoval && merge.status === "executed") {
2296+
applyRemoveLabelActions(command);
2297+
}
23152298
}
23162299
if (
23172300
command.intent === "clawsweeper_needs_human" &&
@@ -4160,7 +4143,9 @@ function validateAutomergeReadiness({ command, view, target }: LooseRecord) {
41604143
if (!hasLabel(target, AUTOMERGE_LABEL)) {
41614144
return "PR is not opted into ClawSweeper automerge";
41624145
}
4163-
if (hasLabel(target, HUMAN_REVIEW_LABEL)) return "PR is paused for human review";
4146+
if (hasLabel(target, HUMAN_REVIEW_LABEL) && command.intent !== "maintainer_approve_automerge") {
4147+
return "PR is paused for human review";
4148+
}
41644149
if (view.state && view.state !== "OPEN")
41654150
return `pull request is ${String(view.state).toLowerCase()}`;
41664151
if (view.isDraft) return "pull request is draft";

‎test/e2e/automerge/run.mjs‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ export function runAutomergeE2E({
257257
const repairedHead = currentRef(targetFixture.remote, targetFixture.headRef);
258258
assertFixturePostRepair(targetFixture, repairedHead);
259259
if (
260-
scenario === "approve-intent-persistence" ||
261260
scenario === "completed-verdict-resume" ||
262261
scenario === "completed-verdict-source-drift" ||
263262
scenario === "resume-intent-persistence"
@@ -288,9 +287,36 @@ export function runAutomergeE2E({
288287
assert.match(String(behindMerge?.repair_reason ?? ""), /cloud rebase repair/);
289288
assert.equal(
290289
behindCommand?.actions.find((action) => action.action === "dispatch_repair")?.status,
290+
"waiting",
291+
);
292+
let behindState = JSON.parse(fs.readFileSync(statePath, "utf8"));
293+
assert.equal(
294+
behindState.pr.labels.includes("clawsweeper:human-review"),
295+
true,
296+
"approval must preserve the pause label until the newly written repair job is durable",
297+
);
298+
assert.equal(
299+
behindState.workflowDispatches.length,
300+
0,
301+
"a newly written repair job must not dispatch before its durable publication",
302+
);
303+
runCommentRouterExact(runtimeRoot, baseEnv, artifacts, "09-comment-router-approve-durable", {
304+
commentId: approvalId,
305+
});
306+
const durableReport = readRouterReport(runtimeRoot);
307+
const durableCommand = durableReport.commands.find(
308+
(command) => command.intent === "maintainer_approve_automerge",
309+
);
310+
assert.equal(
311+
durableCommand?.actions.find((action) => action.action === "dispatch_repair")?.status,
291312
"executed",
292313
);
293-
const behindState = JSON.parse(fs.readFileSync(statePath, "utf8"));
314+
behindState = JSON.parse(fs.readFileSync(statePath, "utf8"));
315+
assert.equal(
316+
behindState.pr.labels.includes("clawsweeper:human-review"),
317+
false,
318+
"the pause label may clear after the durable repair job dispatches",
319+
);
294320
const repairDispatch = behindState.workflowDispatches.at(-1);
295321
assert.equal(
296322
repairDispatch?.inputs.job,
@@ -492,8 +518,8 @@ export function runAutomergeE2E({
492518
assert.equal(idempotentRouterReport.actionable, 0);
493519
assert.equal(
494520
state.calls.filter((call) => call.args[0] === "pr" && call.args[1] === "merge").length,
495-
scenario === "approve-intent-persistence" ? 2 : 1,
496-
"an idempotent router replay must not attempt a second merge",
521+
scenario === "approve-intent-persistence" ? 3 : 1,
522+
"only the durable approval replay and final exact-head verdict may retry merge",
497523
);
498524
assert.ok(state.calls.some((call) => call.token === "read"));
499525
assert.ok(state.calls.some((call) => call.token === "write"));

0 commit comments

Comments
 (0)