Skip to content

Commit f2fc64e

Browse files
authored
fix: let maintainer automerge resume paused PRs (#385)
Summary: - The branch adds a pause-history check so newer authorized maintainer autofix/automerge comments can resume paused PRs while bot and replay paths stay blocked, with regression coverage. - Reproducibility: yes. by source inspection: current main blocks paused mode replay whenever a pause label an ... pause labels for a later maintainer command. I did not execute the router because this review is read-only. Automerge notes: - PR branch already contained follow-up commit before automerge: fix: block stale maintainer pause replays Validation: - ClawSweeper review passed for head 42999ea. - Required merge gates passed before the squash merge. Prepared head SHA: 42999ea Review: #385 (comment) Co-authored-by: masonxhuang <[email protected]> Approved-by: hxy91819
1 parent 0c85aae commit f2fc64e

3 files changed

Lines changed: 129 additions & 2 deletions

File tree

‎src/repair/comment-router-core.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,29 @@ export function existingModeStatusBlocksReplay({
773773
export function pausedModeStatusBlocksReplay({
774774
hasPauseLabels,
775775
hasExistingModeStatusResponse,
776+
allowNewMaintainerModeCommand,
776777
forceReprocess,
777778
}: LooseRecord = {}) {
778-
return Boolean(hasPauseLabels) && Boolean(hasExistingModeStatusResponse) && !forceReprocess;
779+
// A fresh maintainer mode command is the explicit resume path after `stop`;
780+
// historical/replayed mode status must stay blocked by the pause label.
781+
return (
782+
Boolean(hasPauseLabels) &&
783+
Boolean(hasExistingModeStatusResponse) &&
784+
!allowNewMaintainerModeCommand &&
785+
!forceReprocess
786+
);
787+
}
788+
789+
export function maintainerModeCommandCanResumePausedMode({
790+
command,
791+
entries = [],
792+
}: LooseRecord = {}) {
793+
if (command?.trusted_bot) return false;
794+
if (!["autofix", "automerge"].includes(String(command?.intent ?? ""))) return false;
795+
const commandAt = repairLoopControlTime(command);
796+
if (!commandAt) return false;
797+
const pauseAt = latestRepairLoopPauseTime(entries, command);
798+
return pauseAt > 0 && commandAt > pauseAt;
779799
}
780800

781801
export function isMaintainerCommandAllowed({
@@ -2385,6 +2405,28 @@ export function repairLoopStopPauseReason({ command, entries = [] }: LooseRecord
23852405
return "ClawSweeper automation was paused by a later /clawsweeper stop command";
23862406
}
23872407

2408+
function latestRepairLoopPauseTime(entries: JsonValue, command: LooseRecord) {
2409+
if (!Array.isArray(entries)) return 0;
2410+
let latest = 0;
2411+
for (const entry of entries) {
2412+
if (!entry || typeof entry !== "object") continue;
2413+
if (entry.repo !== command?.repo) continue;
2414+
if (Number(entry.issue_number) !== Number(command?.issue_number)) continue;
2415+
if (!isRepairLoopPauseEntry(entry)) continue;
2416+
latest = Math.max(latest, repairLoopControlTime(entry));
2417+
}
2418+
return latest;
2419+
}
2420+
2421+
function isRepairLoopPauseEntry(entry: LooseRecord) {
2422+
if (String(entry.intent ?? "") === "stop") return true;
2423+
if (String(entry.intent ?? "") !== "clawsweeper_needs_human") return false;
2424+
return (entry.actions ?? []).some(
2425+
(action: JsonValue) =>
2426+
action.action === "label" && String(action.label ?? "") === HUMAN_REVIEW_LABEL,
2427+
);
2428+
}
2429+
23882430
function latestRepairLoopControlTime(entries: JsonValue, command: LooseRecord, intents: string[]) {
23892431
if (!Array.isArray(entries)) return 0;
23902432
const intentSet = new Set(intents);

‎src/repair/comment-router.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
issueImplementationClusterId,
5555
issueImplementationJobPath,
5656
isReadyHumanReviewPause,
57+
maintainerModeCommandCanResumePausedMode,
5758
maintainerAutomergeOptInApprovesNeedsHuman as maintainerAutomergeOptInApprovesNeedsHumanReason,
5859
latestRepairLoopResumeTime,
5960
parseRoutedCommentCommand,
@@ -655,6 +656,10 @@ function classifyCommand(command: LooseRecord): JsonValue {
655656
command.issue_number,
656657
command.intent,
657658
),
659+
allowNewMaintainerModeCommand: maintainerModeCommandCanResumePausedMode({
660+
command: next,
661+
entries: repairLoopControlEntries(),
662+
}),
658663
forceReprocess,
659664
})
660665
) {
@@ -1406,7 +1411,9 @@ function repairLoopControlEntries() {
14061411
}
14071412

14081413
function isRepairLoopControlIntent(command: LooseRecord) {
1409-
return ["stop", "autofix", "automerge"].includes(String(command?.intent ?? ""));
1414+
return ["stop", "autofix", "automerge", "clawsweeper_needs_human"].includes(
1415+
String(command?.intent ?? ""),
1416+
);
14101417
}
14111418

14121419
function executeCommand(command: LooseRecord) {

‎test/repair/comment-router-core.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
isMaintainerCommandAllowed,
4646
isIssueImplementationCommandAllowed,
4747
maintainerAutomergeOptInApprovesNeedsHuman,
48+
maintainerModeCommandCanResumePausedMode,
4849
parseCommand,
4950
parseRoutedCommentCommand,
5051
planCommandAckConvergence,
@@ -531,6 +532,26 @@ test("force reprocess bypasses existing command status guards", () => {
531532
}),
532533
true,
533534
);
535+
assert.equal(
536+
pausedModeStatusBlocksReplay({
537+
hasPauseLabels: true,
538+
hasExistingModeStatusResponse: true,
539+
allowNewMaintainerModeCommand: true,
540+
forceReprocess: false,
541+
}),
542+
false,
543+
"old shared automerge status plus human-review must not block a fresh maintainer automerge command",
544+
);
545+
assert.equal(
546+
pausedModeStatusBlocksReplay({
547+
hasPauseLabels: true,
548+
hasExistingModeStatusResponse: true,
549+
allowNewMaintainerModeCommand: false,
550+
forceReprocess: false,
551+
}),
552+
true,
553+
"bot replay and label-sweep mode status should stay paused until a maintainer asks again",
554+
);
534555
assert.equal(
535556
pausedModeStatusBlocksReplay({
536557
hasPauseLabels: true,
@@ -695,6 +716,63 @@ test("later stop command pauses older automerge automation", () => {
695716
);
696717
});
697718

719+
test("paused mode resume requires a maintainer command after the pause", () => {
720+
const entries = [
721+
{
722+
repo: "openclaw/openclaw",
723+
issue_number: 93209,
724+
intent: "automerge",
725+
status: "executed",
726+
comment_updated_at: "2026-06-15T09:45:21Z",
727+
},
728+
{
729+
repo: "openclaw/openclaw",
730+
issue_number: 93209,
731+
intent: "stop",
732+
status: "executed",
733+
comment_updated_at: "2026-06-15T09:45:57Z",
734+
},
735+
];
736+
737+
assert.equal(
738+
maintainerModeCommandCanResumePausedMode({
739+
command: {
740+
repo: "openclaw/openclaw",
741+
issue_number: 93209,
742+
intent: "automerge",
743+
comment_updated_at: "2026-06-15T09:45:21Z",
744+
},
745+
entries,
746+
}),
747+
false,
748+
);
749+
assert.equal(
750+
maintainerModeCommandCanResumePausedMode({
751+
command: {
752+
repo: "openclaw/openclaw",
753+
issue_number: 93209,
754+
intent: "automerge",
755+
comment_updated_at: "2026-07-02T02:31:23Z",
756+
},
757+
entries,
758+
}),
759+
true,
760+
);
761+
assert.equal(
762+
maintainerModeCommandCanResumePausedMode({
763+
command: {
764+
repo: "openclaw/openclaw",
765+
issue_number: 93209,
766+
intent: "automerge",
767+
trusted_bot: true,
768+
comment_updated_at: "2026-07-02T02:31:23Z",
769+
},
770+
entries,
771+
}),
772+
false,
773+
);
774+
});
775+
698776
test("automerge job helpers create stable adopted PR job identity", () => {
699777
assert.equal(automergeClusterId("openclaw/openclaw", 74112), "automerge-openclaw-openclaw-74112");
700778
assert.equal(

0 commit comments

Comments
 (0)