Skip to content

Commit ebbcb2b

Browse files
committed
fix: guard exact review terminal delivery
1 parent 4944a0c commit ebbcb2b

7 files changed

Lines changed: 223 additions & 7 deletions

File tree

‎.github/workflows/exact-review-batch-publish.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ jobs:
334334
[ "$remaining_implementations" -gt 0 ] &&
335335
[ "$target_repo" = "openclaw/openclaw" ] &&
336336
[ "$(jq -r '.decision.itemKind' <<<"$item")" = "issue" ] &&
337+
{ [ "$receipt_outcome" = "accepted" ] || [ "$receipt_outcome" = "deduped" ]; } &&
337338
jq -e '.kind == "eligible"' "$outcome_path" >/dev/null; then
338339
report_path="${outcome_path%.json}.report.md"
339340
if [ -f "$report_path" ]; then

‎.github/workflows/sweep.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,19 +3216,27 @@ jobs:
32163216
TARGET_REPO: ${{ steps.finalization-context.outputs.target_repo }}
32173217
ITEM_NUMBER: ${{ steps.finalization-context.outputs.item_number }}
32183218
STATUS_MARKER: ${{ steps.finalization-context.outputs.status_marker }}
3219+
STATUS_COMMENT_ID: ${{ steps.finalization-context.outputs.status_comment_id }}
32193220
COMMAND_COMMENT_ID: ${{ steps.update-final-command-status.outputs.command_comment_id }}
32203221
COMPLETION_COMMENT_ID: ${{ steps.update-final-command-status.outputs.completion_comment_id }}
32213222
QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
32223223
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
32233224
run: |
32243225
set -euo pipefail
32253226
payload="$(node -e '
3227+
const statusMarker = process.env.STATUS_MARKER || null;
3228+
const statusCommentId = process.env.STATUS_COMMENT_ID === "" ? null : Number(process.env.STATUS_COMMENT_ID);
32263229
const commandCommentId = Number(process.env.COMMAND_COMMENT_ID);
32273230
const completionCommentId = Number(process.env.COMPLETION_COMMENT_ID);
3228-
if (!process.env.STATUS_MARKER || !Number.isInteger(commandCommentId) || commandCommentId < 1 || !Number.isInteger(completionCommentId) || completionCommentId < 1) process.exit(1);
3231+
if (
3232+
(!statusMarker && statusCommentId === null) ||
3233+
(statusCommentId !== null && (!Number.isInteger(statusCommentId) || statusCommentId < 1)) ||
3234+
!Number.isInteger(commandCommentId) || commandCommentId < 1 ||
3235+
!Number.isInteger(completionCommentId) || completionCommentId < 1
3236+
) process.exit(1);
32293237
process.stdout.write(JSON.stringify({
32303238
canonical_target_key: `${process.env.TARGET_REPO}#${process.env.ITEM_NUMBER}`,
3231-
status_marker: process.env.STATUS_MARKER,
3239+
...(statusMarker ? { status_marker: statusMarker } : {}),
32323240
command_comment_id: commandCommentId,
32333241
completion_comment_id: completionCommentId,
32343242
observed_at: Date.now(),

‎src/repair/update-command-status.ts‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,21 +426,43 @@ export function mergeCommandProgressSection(
426426

427427
export function verifiedTerminalStatusReceipt(
428428
comment: Pick<LooseRecord, "id" | "body">,
429-
options: Pick<Options, "verifyTerminalStatusReceipt" | "marker" | "state" | "detail">,
429+
options: Pick<
430+
Options,
431+
"verifyTerminalStatusReceipt" | "marker" | "statusCommentId" | "state" | "detail"
432+
>,
430433
): TerminalStatusReceipt | null {
431-
if (!options.verifyTerminalStatusReceipt || !options.marker) return null;
434+
if (!options.verifyTerminalStatusReceipt || (!options.marker && !options.statusCommentId))
435+
return null;
432436
const completionCommentId = Number(comment.id);
433437
const commandCommentIds = commandAckCommentIdsFromBody(comment.body);
434438
const statusMarkers = commandStatusMarkersFromBody(comment.body);
435439
if (
436440
!Number.isSafeInteger(completionCommentId) ||
437-
commandCommentIds.length !== 1 ||
438-
statusMarkers.length !== 1 ||
439-
statusMarkers[0] !== options.marker ||
440441
!terminalProgressMatches(comment.body, options)
441442
) {
442443
return null;
443444
}
445+
if (options.marker) {
446+
if (
447+
commandCommentIds.length !== 1 ||
448+
statusMarkers.length !== 1 ||
449+
statusMarkers[0] !== options.marker
450+
) {
451+
return null;
452+
}
453+
return { commandCommentId: commandCommentIds[0]!, completionCommentId };
454+
}
455+
const statusCommentId = options.statusCommentId;
456+
if (
457+
statusCommentId === null ||
458+
!Number.isSafeInteger(statusCommentId) ||
459+
statusCommentId < 1 ||
460+
completionCommentId !== statusCommentId ||
461+
commandCommentIds.length !== 1 ||
462+
statusMarkers.length !== 0
463+
) {
464+
return null;
465+
}
444466
return { commandCommentId: commandCommentIds[0]!, completionCommentId };
445467
}
446468

‎test/dashboard-worker.test.ts‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5202,6 +5202,98 @@ test("Worker lifecycle projection permits one command acknowledgement after dura
52025202
assert.equal(lifecycle?.acknowledgement.attempts.length, 2);
52035203
});
52045204

5205+
test("signed Worker records a status-ID-only terminal acknowledgement", async () => {
5206+
const storage = new MemoryDurableStorage();
5207+
const queue = new ExactReviewQueue({ storage }, {});
5208+
const lifecycle = new ExactReviewLifecycleProjectionStore(storage);
5209+
const identity = {
5210+
canonicalTargetKey: "openclaw/openclaw#779",
5211+
fenceKey: "openclaw/openclaw#779@exact:status-id-only",
5212+
revision: 1,
5213+
};
5214+
lifecycle.recordAdmission({
5215+
...identity,
5216+
deliveryId: "status-id-only-delivery:779",
5217+
sourceAction: "re_review",
5218+
commandOriginated: true,
5219+
statusMarker: null,
5220+
statusCommentId: 9011,
5221+
observedAt: 1_700_000_000_000,
5222+
});
5223+
lifecycle.recordCanonicalReceipt({
5224+
...identity,
5225+
outcome: "accepted",
5226+
receiptId: "status-id-only-canonical:779",
5227+
observedAt: 1_700_000_000_001,
5228+
});
5229+
lifecycle.recordRouterReceipt({
5230+
...identity,
5231+
outcome: "durable",
5232+
receiptId: "status-id-only-router:779",
5233+
observedAt: 1_700_000_000_002,
5234+
});
5235+
lifecycle.recordTerminalDisposition({
5236+
...identity,
5237+
kind: "review_completed_routed",
5238+
observedAt: 1_700_000_000_003,
5239+
});
5240+
assert.equal(
5241+
lifecycle.authorizeCommandAcknowledgement({
5242+
...identity,
5243+
statusMarker: null,
5244+
statusCommentId: 9011,
5245+
observedAt: 1_700_000_000_004,
5246+
}).allowed,
5247+
true,
5248+
);
5249+
5250+
const secret = "status-id-only-lifecycle-secret";
5251+
const payload = {
5252+
canonical_target_key: "openclaw/openclaw#779",
5253+
command_comment_id: 9010,
5254+
completion_comment_id: 9011,
5255+
observed_at: 1_700_000_000_005,
5256+
};
5257+
const body = JSON.stringify(payload);
5258+
const response = await worker.fetch(
5259+
new Request(
5260+
"https://clawsweeper.openclaw.ai/internal/exact-review/lifecycle/command-ack/observed",
5261+
{
5262+
method: "POST",
5263+
headers: {
5264+
"content-type": "application/json",
5265+
"x-clawsweeper-exact-review-signature": `sha256=${createHmac("sha256", secret)
5266+
.update(body)
5267+
.digest("hex")}`,
5268+
},
5269+
body,
5270+
},
5271+
),
5272+
{
5273+
CLAWSWEEPER_WEBHOOK_SECRET: secret,
5274+
EXACT_REVIEW_QUEUE: new MemoryDurableNamespace(queue),
5275+
},
5276+
);
5277+
5278+
assert.deepEqual(await response.json(), {
5279+
ok: true,
5280+
accepted: true,
5281+
lifecycle_state: "completed",
5282+
acknowledgement_state: "observed",
5283+
version: 1,
5284+
});
5285+
assert.deepEqual(
5286+
lifecycle.read(identity.canonicalTargetKey, identity.fenceKey, identity.revision)
5287+
?.acknowledgement.observed,
5288+
{
5289+
statusMarker: null,
5290+
commandCommentId: 9010,
5291+
completionCommentId: 9011,
5292+
observedAt: 1_700_000_000_005,
5293+
},
5294+
);
5295+
});
5296+
52055297
test("Worker lifecycle acknowledgement preserves canonical GitHub repository casing", async () => {
52065298
const storage = new MemoryDurableStorage();
52075299
const queue = new ExactReviewQueue({ storage }, {});

‎test/repair/exact-review-batch-workflow.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ test("batch workflow signs queue ownership, isolates item failures, and commits
151151
/permanent publisher result remains retryable until the durable/,
152152
);
153153
assert.match(healthyMembers.run ?? "", /\[ "\$outcome_kind" = "permanent_failure" \].*continue/s);
154+
const implementationBlock = (healthyMembers.run ?? "").slice(
155+
(healthyMembers.run ?? "").indexOf("# The optional implementation lane"),
156+
(healthyMembers.run ?? "").indexOf('report_path="${outcome_path%.json}.report.md"'),
157+
);
158+
assert.match(
159+
implementationBlock,
160+
/\{ \[ "\$receipt_outcome" = "accepted" \] \|\| \[ "\$receipt_outcome" = "deduped" \]; \} &&/,
161+
);
162+
assert.doesNotMatch(implementationBlock, /superseded|permanent/);
154163
assert.equal(
155164
workflow.jobs.publish!.steps.some(
156165
(step) => step.name === "Acknowledge terminal batch command lifecycle status",

‎test/repair/update-command-status.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,74 @@ test("terminal receipt verification accepts only the selected trusted final stat
180180
);
181181
});
182182

183+
test("terminal receipt verification accepts a status-ID-only final status", () => {
184+
const options = parseOptions([
185+
"--repo",
186+
"openclaw/openclaw",
187+
"--item-number",
188+
"81565",
189+
"--status-comment-id",
190+
"4466202001",
191+
"--state",
192+
"Complete",
193+
"--detail",
194+
"Durable review routing completed.",
195+
"--verify-terminal-status-receipt",
196+
]);
197+
const comment = {
198+
id: 4466202001,
199+
body: [
200+
"<!-- clawsweeper-command-ack:4466201488 -->",
201+
"ClawSweeper re-review requested.",
202+
"<!-- clawsweeper-command-progress:start -->",
203+
"Re-review progress:",
204+
"- State: Complete",
205+
"- Detail: Durable review routing completed.",
206+
"- Updated: 2026-08-01T00:00:00.000Z",
207+
"<!-- clawsweeper-command-progress:end -->",
208+
].join("\n"),
209+
};
210+
211+
assert.deepEqual(verifiedTerminalStatusReceipt(comment, options), {
212+
commandCommentId: 4466201488,
213+
completionCommentId: 4466202001,
214+
});
215+
assert.equal(verifiedTerminalStatusReceipt({ ...comment, id: 4466202002 }, options), null);
216+
assert.equal(
217+
verifiedTerminalStatusReceipt(
218+
{
219+
...comment,
220+
body: comment.body.replace("<!-- clawsweeper-command-ack:4466201488 -->\n", ""),
221+
},
222+
options,
223+
),
224+
null,
225+
);
226+
assert.equal(
227+
verifiedTerminalStatusReceipt(
228+
{
229+
...comment,
230+
body: comment.body.replace(
231+
"<!-- clawsweeper-command-ack:4466201488 -->",
232+
"<!-- clawsweeper-command-ack:4466201488 -->\n<!-- clawsweeper-command-ack:4466201489 -->",
233+
),
234+
},
235+
options,
236+
),
237+
null,
238+
);
239+
assert.equal(
240+
verifiedTerminalStatusReceipt(
241+
{
242+
...comment,
243+
body: `<!-- clawsweeper-command-status:81565:re_review:unexpected -->\n${comment.body}`,
244+
},
245+
options,
246+
),
247+
null,
248+
);
249+
});
250+
183251
test("parseOptions enables the terminal locked-conversation skip only when requested", () => {
184252
const options = parseOptions([
185253
"--repo",

‎test/sweep-workflow.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,23 @@ test("exact event publication derives lifecycle receipt and final command acknow
11541154
"${{ steps.finalization-context.outputs.lifecycle_revision }}",
11551155
);
11561156
assert.match(observedReceipt.if ?? "", /terminal_status_verified == 'true'/);
1157+
assert.equal(
1158+
observedReceipt.env?.STATUS_COMMENT_ID,
1159+
"${{ steps.finalization-context.outputs.status_comment_id }}",
1160+
);
11571161
assert.match(observedReceipt.run ?? "", /lifecycle\/command-ack\/observed/);
1162+
assert.match(
1163+
observedReceipt.run ?? "",
1164+
/const statusMarker = process\.env\.STATUS_MARKER \|\| null/,
1165+
);
1166+
assert.match(
1167+
observedReceipt.run ?? "",
1168+
/const statusCommentId = process\.env\.STATUS_COMMENT_ID/,
1169+
);
1170+
assert.match(
1171+
observedReceipt.run ?? "",
1172+
/\.\.\.\(statusMarker \? \{ status_marker: statusMarker \} : \{\}\)/,
1173+
);
11581174
assert.match(observedReceipt.run ?? "", /command_comment_id: commandCommentId/);
11591175
assert.match(observedReceipt.run ?? "", /completion_comment_id: completionCommentId/);
11601176
assert.match(observedReceipt.run ?? "", /acknowledgement_state == "observed"/);

0 commit comments

Comments
 (0)