Skip to content

Commit 42999ea

Browse files
committed
fix: block stale maintainer pause replays
1 parent 7b0766b commit 42999ea

3 files changed

Lines changed: 100 additions & 2 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,18 @@ export function pausedModeStatusBlocksReplay({
786786
);
787787
}
788788

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;
799+
}
800+
789801
export function isMaintainerCommandAllowed({
790802
authorAssociation,
791803
repositoryPermission = null,
@@ -2393,6 +2405,28 @@ export function repairLoopStopPauseReason({ command, entries = [] }: LooseRecord
23932405
return "ClawSweeper automation was paused by a later /clawsweeper stop command";
23942406
}
23952407

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+
23962430
function latestRepairLoopControlTime(entries: JsonValue, command: LooseRecord, intents: string[]) {
23972431
if (!Array.isArray(entries)) return 0;
23982432
const intentSet = new Set(intents);

‎src/repair/comment-router.ts‎

Lines changed: 8 additions & 2 deletions
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,7 +656,10 @@ function classifyCommand(command: LooseRecord): JsonValue {
655656
command.issue_number,
656657
command.intent,
657658
),
658-
allowNewMaintainerModeCommand: !command.trusted_bot,
659+
allowNewMaintainerModeCommand: maintainerModeCommandCanResumePausedMode({
660+
command: next,
661+
entries: repairLoopControlEntries(),
662+
}),
659663
forceReprocess,
660664
})
661665
) {
@@ -1407,7 +1411,9 @@ function repairLoopControlEntries() {
14071411
}
14081412

14091413
function isRepairLoopControlIntent(command: LooseRecord) {
1410-
return ["stop", "autofix", "automerge"].includes(String(command?.intent ?? ""));
1414+
return ["stop", "autofix", "automerge", "clawsweeper_needs_human"].includes(
1415+
String(command?.intent ?? ""),
1416+
);
14111417
}
14121418

14131419
function executeCommand(command: LooseRecord) {

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

Lines changed: 58 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,
@@ -715,6 +716,63 @@ test("later stop command pauses older automerge automation", () => {
715716
);
716717
});
717718

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+
718776
test("automerge job helpers create stable adopted PR job identity", () => {
719777
assert.equal(automergeClusterId("openclaw/openclaw", 74112), "automerge-openclaw-openclaw-74112");
720778
assert.equal(

0 commit comments

Comments
 (0)