Skip to content

Commit 0177361

Browse files
committed
fix(review): drop lease PATCH reuse; sweep placeholders only at publish
1 parent 6fba848 commit 0177361

3 files changed

Lines changed: 20 additions & 38 deletions

File tree

‎CHANGELOG.md‎

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

111111
### Fixed
112112

113-
- Stopped stale "review started" placeholder comments from accumulating on reviewed items: retries refresh a surviving placeholder in place, and publishing the durable review comment sweeps superseded placeholders.
113+
- Stopped stale "review started" placeholder comments from accumulating on reviewed items: publishing the durable review comment now sweeps superseded placeholders.
114114
- Stopped narrow OpenClaw automerge repairs from chasing unrelated full-repository lint and typecheck failures.
115115
- Removed the synthetic Codex write preflight that could block repair before Codex saw the real task.
116116
- Kept exact-review handoff health live when the dashboard serves a stale fleet snapshot, so recovered claims no longer leave the operator rail stuck in a delayed or stalled state.

‎src/clawsweeper.ts‎

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20596,40 +20596,26 @@ function postReviewStartStatusComment(options: {
2059620596
if (initialLease) {
2059720597
return heldReviewStartStatusCommentResult(initialLease.expiresAt, false);
2059820598
}
20599-
const reapedLeaseCommentIds = reapExpiredDedicatedReviewStartLeases(
20599+
reapExpiredDedicatedReviewStartLeases(
2060020600
options.item.number,
2060120601
initialState.dedicatedLeaseComments,
2060220602
startedAtMs,
2060320603
);
2060420604
const body = renderReviewStartStatusComment(leaseOptions);
2060520605
const payload = writeCommentPayload(options.item.number, body);
20606-
// A leftover bot placeholder from a superseded attempt (typically an
20607-
// unexpired lease for an older head revision) is refreshed in place instead
20608-
// of stacking one new "review started" comment per retry. Lowest server id
20609-
// wins lease election, so reusing the oldest surviving comment also keeps
20610-
// the refreshed lease electable.
20611-
const reusableLeaseCommentId = initialState.dedicatedLeaseComments
20612-
.map((comment) => commentId(comment))
20613-
.filter((id): id is number => id !== null && !reapedLeaseCommentIds.has(id))
20614-
.sort((left, right) => left - right)[0];
20615-
const createArgs =
20616-
reusableLeaseCommentId === undefined
20617-
? [
20618-
"api",
20619-
`repos/${targetRepo()}/issues/${options.item.number}/comments`,
20620-
"--method",
20621-
"POST",
20622-
"--input",
20623-
payload,
20624-
]
20625-
: [
20626-
"api",
20627-
`repos/${targetRepo()}/issues/comments/${reusableLeaseCommentId}`,
20628-
"--method",
20629-
"PATCH",
20630-
"--input",
20631-
payload,
20632-
];
20606+
// Every acquisition POSTs a fresh comment: the lowest-server-id election
20607+
// needs distinct ids per contender, so refreshing a leftover placeholder in
20608+
// place would let two racing workers both validate ownership of the same
20609+
// comment. Superseded placeholders are swept when the durable review
20610+
// comment is published instead.
20611+
const createArgs = [
20612+
"api",
20613+
`repos/${targetRepo()}/issues/${options.item.number}/comments`,
20614+
"--method",
20615+
"POST",
20616+
"--input",
20617+
payload,
20618+
];
2063320619
const created = reviewCommentFromMutationResponse(
2063420620
ghObservedMutationCommand({
2063520621
identity: `review_lease_post:${options.item.number}:${leaseOwner}`,
@@ -20715,8 +20701,7 @@ function reapExpiredDedicatedReviewStartLeases(
2071520701
itemNumber: number,
2071620702
dedicatedLeaseComments: Record<string, unknown>[],
2071720703
nowMs: number,
20718-
): Set<number> {
20719-
const reapedCommentIds = new Set<number>();
20704+
): void {
2072020705
const expired = expiredReviewStartStatusLeases({
2072120706
comments: dedicatedLeaseComments,
2072220707
itemNumber,
@@ -20739,7 +20724,6 @@ function reapExpiredDedicatedReviewStartLeases(
2073920724
console.error(
2074020725
`[review] reaped expired review lease comment ${lease.commentId} for #${itemNumber} (lease expired ${lease.expiresAt})`,
2074120726
);
20742-
reapedCommentIds.add(lease.commentId);
2074320727
} catch (error) {
2074420728
// A failed reap must never block acquiring the new lease.
2074520729
console.error(
@@ -20749,7 +20733,6 @@ function reapExpiredDedicatedReviewStartLeases(
2074920733
);
2075020734
}
2075120735
}
20752-
return reapedCommentIds;
2075320736
}
2075420737

2075520738
const REVIEW_PLACEHOLDER_BODY_PATTERN = /^ClawSweeper status: review started\./i;

‎test/review-comment-rendering.test.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,18 +1310,17 @@ test("superseded review placeholder sweep never selects the durable review comme
13101310
);
13111311
});
13121312

1313-
test("review lease retries refresh a surviving placeholder instead of posting a new one", () => {
1313+
test("publishing the durable review comment sweeps superseded placeholders", () => {
13141314
const source = readFileSync("src/clawsweeper.ts", "utf8");
13151315
const functionStart = source.indexOf("function postReviewStartStatusComment");
13161316
const postStart = source.slice(
13171317
functionStart,
13181318
source.indexOf("function deleteOwnedDedicatedReviewStartLease", functionStart),
13191319
);
1320-
assert.match(postStart, /const reapedLeaseCommentIds = reapExpiredDedicatedReviewStartLeases\(/);
1321-
assert.match(postStart, /reusableLeaseCommentId/);
1322-
assert.match(postStart, /issues\/comments\/\$\{reusableLeaseCommentId\}/);
1323-
assert.match(postStart, /"PATCH"/);
1320+
// Lease acquisition must keep POSTing a fresh comment per contender: the
1321+
// lowest-server-id election needs distinct ids, so no in-place PATCH reuse.
13241322
assert.match(postStart, /issues\/\$\{options\.item\.number\}\/comments/);
1323+
assert.doesNotMatch(postStart, /"PATCH"/);
13251324

13261325
const applyStart = source.indexOf('syncReasons.push("updated durable Codex review comment")');
13271326
assert.ok(applyStart >= 0);

0 commit comments

Comments
 (0)