Skip to content

Commit a55bf55

Browse files
authored
fix: guard low-signal comment sync (#484)
1 parent 3110fe8 commit a55bf55

3 files changed

Lines changed: 116 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ checkpoint, and status-only commits are intentionally omitted.
3333

3434
### Fixed
3535

36-
- Required a live `DIRTY` merge conflict and at least 30 days without contributor comments or head activity before closing low-signal pull requests, honoring longer configured stale thresholds and applying the same fail-closed policy to stale-review promotion and trusted close routing.
36+
- Required a live `DIRTY` merge conflict and at least 30 days without contributor comments or head activity before publishing or applying low-signal pull-request close verdicts, honoring longer configured stale thresholds and applying the same fail-closed policy to stale-review promotion and trusted close routing.
3737
- Retried successful GitHub CLI JSON-lines responses when their output is truncated, preventing transient list-page corruption from aborting close-apply runs.
3838
- Allowed conflict-free canonical PRs that only need a base update to back duplicate or superseded closures while retaining proof, review, check, draft, and conflict guards.
3939
- Bounded broad reconciliation with batched Git I/O and tuple checkpoints that report progress and resume safely under concurrent state writers.

‎src/clawsweeper.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21075,6 +21075,18 @@ function applyDecisionsCommandInner(args: Args, runtimeBudget: GitHubRuntimeBudg
2107521075
continue;
2107621076
}
2107721077
}
21078+
if (state === "open" && isCloseProposal && closeReason === "low_signal_unmergeable_pr") {
21079+
// Reject stale low-signal verdicts before they can become durable public comments. The
21080+
// final close gate repeats this live check to catch activity arriving after comment sync.
21081+
const lowSignalBlockReason = lowSignalUnmergeablePrApplyBlockReasonSafe(
21082+
number,
21083+
staleMinAgeDays,
21084+
);
21085+
if (lowSignalBlockReason) {
21086+
if (markApplySkipped("kept_open", lowSignalBlockReason)) break;
21087+
continue;
21088+
}
21089+
}
2107821090
existingReviewComment ??= issueReviewComment(number, [
2107921091
renderReviewCommentFromReport(markdown, closeReason ?? "none", { previousLabels }),
2108021092
reviewSectionValue(markdown, "closeComment"),
@@ -21938,6 +21950,14 @@ function applyDecisionsCommandInner(args: Args, runtimeBudget: GitHubRuntimeBudg
2193821950
if (processedCount >= processedLimit) break;
2193921951
continue;
2194021952
}
21953+
const lowSignalCommentSyncBlockReason =
21954+
closeReason === "low_signal_unmergeable_pr"
21955+
? lowSignalUnmergeablePrApplyBlockReasonSafe(number, staleMinAgeDays)
21956+
: null;
21957+
if (lowSignalCommentSyncBlockReason) {
21958+
if (markApplySkipped("kept_open", lowSignalCommentSyncBlockReason)) break;
21959+
continue;
21960+
}
2194121961
try {
2194221962
syncedComment = upsertReviewComment(number, markedReviewComment, existingReviewComment);
2194321963
const syncedCommentUpdatedAt = commentUpdatedAt(syncedComment);

‎test/apply-pr-promotion.test.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,101 @@ test("apply-decisions keeps MERGEABLE UNSTABLE low-signal proposals open", () =>
612612
);
613613
});
614614

615+
test("apply-decisions rechecks low-signal liveness before writing an unsynced close comment", () => {
616+
const root = mkdtempSync(tmpPrefix);
617+
try {
618+
const number = 371;
619+
const itemsDir = join(root, "items");
620+
const closedDir = join(root, "closed");
621+
const plansDir = join(root, "plans");
622+
const reportPath = join(root, "apply-report.json");
623+
const commentWriteLogPath = join(root, "comment-writes.log");
624+
const authorActivityAt = new Date().toISOString();
625+
mkdirSync(itemsDir, { recursive: true });
626+
mkdirSync(plansDir, { recursive: true });
627+
const sourceReport = lowSignalCloseReport({
628+
number,
629+
title: "Unsynced low-signal close guard fixture",
630+
item_created_at: "2026-02-01T00:00:00Z",
631+
item_updated_at: "2026-05-01T00:00:00Z",
632+
reviewed_at: "2026-05-01T00:00:00Z",
633+
pull_head_sha: "head-sha",
634+
});
635+
const rendered = reportWithSyncedReviewComment(
636+
sourceReport,
637+
number,
638+
"low_signal_unmergeable_pr",
639+
);
640+
writeFileSync(join(itemsDir, `${number}.md`), sourceReport, "utf8");
641+
642+
withMockGh(
643+
root,
644+
promotionGhMock({
645+
number,
646+
title: "Unsynced low-signal close guard fixture",
647+
comment: rendered.comment,
648+
commentWriteLogPath,
649+
comments: [],
650+
commentsAfterFirstRead: [
651+
{
652+
id: 9371,
653+
created_at: authorActivityAt,
654+
updated_at: authorActivityAt,
655+
user: { login: "reporter" },
656+
body: "I am still working on this PR.",
657+
},
658+
],
659+
itemCreatedAt: "2026-02-01T00:00:00Z",
660+
itemUpdatedAt: "2026-05-01T00:00:00Z",
661+
mergeable: false,
662+
mergeableState: "dirty",
663+
headActivityAt: "2026-02-01T01:00:00Z",
664+
}),
665+
() => {
666+
runApplyDecisionsForTest({
667+
targetRepo: "openclaw/openclaw",
668+
itemsDir,
669+
closedDir,
670+
plansDir,
671+
reportPath,
672+
extraArgs: [
673+
"--apply-close-reasons",
674+
"duplicate_or_superseded",
675+
"--stale-min-age-days",
676+
"30",
677+
"--processed-limit",
678+
"1",
679+
"--item-numbers",
680+
String(number),
681+
],
682+
});
683+
},
684+
);
685+
686+
const report = JSON.parse(readFileSync(reportPath, "utf8")) as Array<{
687+
number: number;
688+
action: string;
689+
reason: string;
690+
}>;
691+
assert.deepEqual(report, [
692+
{
693+
number,
694+
action: "kept_open",
695+
reason:
696+
"low_signal_unmergeable_pr requires 30 days without author comments or head activity",
697+
},
698+
]);
699+
assert.equal(existsSync(commentWriteLogPath), false);
700+
assert.equal(existsSync(join(root, `comment-state-${number}.json`)), false);
701+
assert.match(
702+
readFileSync(join(itemsDir, `${number}.md`), "utf8"),
703+
/^action_taken: kept_open$/m,
704+
);
705+
} finally {
706+
rmSync(root, { recursive: true, force: true });
707+
}
708+
});
709+
615710
test("apply-decisions keeps recently updated DIRTY low-signal proposals open", () => {
616711
const number = 342;
617712
const headSha = "3423423423423423423423423423423423423423";

0 commit comments

Comments
 (0)