Skip to content

Commit 2cc2c0d

Browse files
authored
fix: suppress semantic no-op hot review writes (#1088)
Maintainer decision: merge the reviewed implementation despite the remaining ClawSweeper real-behavior-proof gate. The exact head passed CI, CodeQL, local/remote Codex review, and ClawSweeper reported no technical or security findings. Accept the proof-risk tradeoff and monitor organic behavior for two hours after merge; rollback is a normal revert if unhealthy behavior is observed.
1 parent e699e83 commit 2cc2c0d

6 files changed

Lines changed: 499 additions & 14 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,47 @@ jobs:
810810
live_locked="$(jq -r '.locked == true' <<< "$live_item")"
811811
item_kind="$(jq -r 'if .pull_request then "pull_request" else "issue" end' <<< "$live_item")"
812812
echo "item_kind=$item_kind" >> "$GITHUB_OUTPUT"
813+
if [ "$live_state" = "open" ] && [ "$live_locked" != "true" ]; then
814+
live_head_sha=""
815+
if [ "$item_kind" = "pull_request" ]; then
816+
if ! live_head_sha="$(gh api "repos/$TARGET_REPO/pulls/$ITEM_NUMBER" --jq '.head.sha')"; then
817+
echo "::warning::Unable to read the live pull request head; preserving normal review admission."
818+
live_head_sha=""
819+
fi
820+
fi
821+
comments_error="$(mktemp)"
822+
if live_comments="$(gh api --paginate --slurp "repos/$TARGET_REPO/issues/$ITEM_NUMBER/comments?per_page=100" 2>"$comments_error" | jq 'add')"; then
823+
classification_output="$(mktemp)"
824+
if CLAIM_DECISION="$CLAIM_DECISION" LIVE_ITEM="$live_item" LIVE_COMMENTS="$live_comments" LIVE_HEAD_SHA="$live_head_sha" GITHUB_OUTPUT="$classification_output" \
825+
node scripts/classify-scheduled-review-noop.ts; then
826+
cat "$classification_output" >> "$GITHUB_OUTPUT"
827+
if grep -qx 'scheduled_noop=true' "$classification_output"; then
828+
reason="$(sed -n 's/^scheduled_noop_reason=//p' "$classification_output")"
829+
rm -f "$classification_output" "$comments_error"
830+
{
831+
echo "proceed=false"
832+
echo "terminal_noop=false"
833+
echo "scheduled_semantic_noop=true"
834+
echo "terminal_missing=false"
835+
echo "guarded_open=false"
836+
echo "guarded_open_action="
837+
} >> "$GITHUB_OUTPUT"
838+
echo "::notice::Completing $TARGET_REPO#$ITEM_NUMBER as a scheduled no-op before target checkout because $reason."
839+
exit 0
840+
fi
841+
else
842+
echo "::warning::Scheduled no-op classification failed; preserving normal review admission."
843+
fi
844+
rm -f "$classification_output"
845+
else
846+
echo "::warning::Unable to read comments for scheduled no-op classification; preserving normal review admission."
847+
cat "$comments_error" >&2
848+
fi
849+
rm -f "$comments_error"
850+
fi
813851
case "$live_state" in
814852
open)
853+
echo "scheduled_semantic_noop=false" >> "$GITHUB_OUTPUT"
815854
echo "terminal_noop=false" >> "$GITHUB_OUTPUT"
816855
echo "terminal_missing=false" >> "$GITHUB_OUTPUT"
817856
if [ "$live_locked" = "true" ]; then
@@ -826,6 +865,7 @@ jobs:
826865
fi
827866
;;
828867
closed)
868+
echo "scheduled_semantic_noop=false" >> "$GITHUB_OUTPUT"
829869
echo "proceed=false" >> "$GITHUB_OUTPUT"
830870
echo "terminal_noop=true" >> "$GITHUB_OUTPUT"
831871
echo "terminal_missing=false" >> "$GITHUB_OUTPUT"
@@ -840,7 +880,7 @@ jobs:
840880
esac
841881
842882
- name: Create target write token
843-
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.admission_retry != 'true' }}
883+
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.scheduled_semantic_noop != 'true' && steps.live-item.outputs.admission_retry != 'true' }}
844884
id: target-write-token
845885
continue-on-error: true
846886
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
@@ -886,7 +926,7 @@ jobs:
886926
887927
- uses: ./.github/actions/setup-pnpm
888928
id: setup-pnpm
889-
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.admission_retry != 'true' }}
929+
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.scheduled_semantic_noop != 'true' && steps.live-item.outputs.admission_retry != 'true' }}
890930
with:
891931
build-script: ${{ steps.live-item.outputs.proceed == 'true' && 'build:all' || 'build:repair' }}
892932

@@ -1303,7 +1343,7 @@ jobs:
13031343
13041344
- name: Create exact review artifact bundle
13051345
id: create-exact-review-bundle
1306-
if: ${{ always() && steps.claim-exact-review-queue.outputs.claimed == 'true' && !cancelled() && steps.target.outputs.target_enabled == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.admission_retry != 'true' && steps.setup-pnpm.outcome == 'success' && steps.review-exact-event-item.outputs.superseded != 'true' && (steps.live-item.outputs.proceed != 'true' || (steps.review-exact-event-item.outcome == 'success' && steps.review-exact-event-item.outputs.retry_at == '')) }}
1346+
if: ${{ always() && steps.claim-exact-review-queue.outputs.claimed == 'true' && !cancelled() && steps.target.outputs.target_enabled == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.scheduled_semantic_noop != 'true' && steps.live-item.outputs.admission_retry != 'true' && steps.setup-pnpm.outcome == 'success' && steps.review-exact-event-item.outputs.superseded != 'true' && (steps.live-item.outputs.proceed != 'true' || (steps.review-exact-event-item.outcome == 'success' && steps.review-exact-event-item.outputs.retry_at == '')) }}
13071347
env:
13081348
EXACT_REVIEW_ACTION_LEDGER_ROOT: ${{ env.CLAWSWEEPER_ACTION_LEDGER_OUTPUT_ROOT }}
13091349
EXACT_REVIEW_BUNDLE_DIR: .artifacts/exact-review-bundle
@@ -1679,6 +1719,7 @@ jobs:
16791719
DIRECT_PUBLICATION_RETRY_AT: ${{ steps.prepare-direct-exact-review-publication.outputs.retry_at }}
16801720
TARGET_ENABLED: ${{ steps.target.outputs.target_enabled }}
16811721
LIVE_OUTCOME: ${{ steps.live-item.outcome }}
1722+
SCHEDULED_SEMANTIC_NOOP: ${{ steps.live-item.outputs.scheduled_semantic_noop || 'false' }}
16821723
REVIEW_OUTCOME: ${{ steps.review-exact-event-item.outcome }}
16831724
REVIEW_SUPERSEDED: ${{ steps.review-exact-event-item.outputs.superseded || 'false' }}
16841725
RESERVATION_STATUS: ${{ steps.reserve-exact-review-lease.outputs.status }}
@@ -1702,6 +1743,8 @@ jobs:
17021743
requeue_latest=true
17031744
elif [ "$TARGET_ENABLED" = "false" ]; then
17041745
outcome=success
1746+
elif [ "$SCHEDULED_SEMANTIC_NOOP" = "true" ] && [ "$LIVE_OUTCOME" = "success" ]; then
1747+
outcome=success
17051748
elif [ "$RESERVATION_STATUS" = "superseded" ] || [ "$REVIEW_SUPERSEDED" = "true" ]; then
17061749
outcome=success
17071750
elif [ "$REVIEW_OUTCOME" = "cancelled" ]; then
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import { createHash } from "node:crypto";
2+
import { appendFileSync } from "node:fs";
3+
import { pathToFileURL } from "node:url";
4+
5+
const TRUSTED_AUTHORS = new Set(
6+
[
7+
"clawsweeper",
8+
"clawsweeper[bot]",
9+
"openclaw-clawsweeper[bot]",
10+
process.env.CLAWSWEEPER_COMMENT_AUTHOR_LOGIN?.toLowerCase(),
11+
].filter((value): value is string => Boolean(value)),
12+
);
13+
const SOURCE_REVISION_PATTERN =
14+
/<!--\s+clawsweeper-review-version\b[^>]*\bsource_revision=([0-9a-f]{64})\b[^>]*-->/g;
15+
const REVIEWED_SHA_PATTERN = /<!--\s+clawsweeper-review-version\b[^>]*\bsha=([^\s>]+)\b[^>]*-->/g;
16+
const SETTLING_WINDOW_MS = 30_000;
17+
type JsonObject = Record<string, unknown>;
18+
19+
function object(value: unknown): JsonObject {
20+
return value && typeof value === "object" && !Array.isArray(value) ? (value as JsonObject) : {};
21+
}
22+
23+
function scalar(value: unknown): string {
24+
if (value === null || value === undefined) return "";
25+
if (typeof value === "string") return value;
26+
if (typeof value === "number" || typeof value === "boolean") return String(value);
27+
return JSON.stringify(value);
28+
}
29+
30+
function login(value: unknown): string {
31+
return scalar(object(value).login).trim().toLowerCase();
32+
}
33+
34+
function labelName(value: unknown): string {
35+
return scalar(object(value).name || value)
36+
.trim()
37+
.toLowerCase();
38+
}
39+
40+
function ignorableOwnedLabel(label: string): boolean {
41+
if (label === "proof: override") return false;
42+
return (
43+
/^(?:status|rating|proof|merge-risk|impact|issue-rating):/.test(label) ||
44+
/^p[0-3]$/.test(label) ||
45+
label === "maturity:stable" ||
46+
(label.startsWith("clawsweeper:") &&
47+
!["clawsweeper:human-review", "clawsweeper:manual-only", "clawsweeper:bulk-filed"].includes(
48+
label,
49+
)) ||
50+
[
51+
"clawsweeper-recovery-stuck",
52+
"no-stale",
53+
"stale",
54+
"feature: ✨ showcase",
55+
"good first issue",
56+
"mantis: telegram-visible-proof",
57+
"triage: needs-real-behavior-proof",
58+
].includes(label)
59+
);
60+
}
61+
62+
function trustedClawSweeperComment(comment: JsonObject): boolean {
63+
return TRUSTED_AUTHORS.has(login(comment.user) || scalar(comment.author).trim().toLowerCase());
64+
}
65+
66+
export function scheduledReviewSemanticSourceRevision(
67+
issue: unknown,
68+
comments: readonly unknown[],
69+
): string {
70+
const source = object(issue);
71+
const snapshot = {
72+
title: scalar(source.title),
73+
body: scalar(source.body),
74+
labels: (Array.isArray(source.labels) ? source.labels : [])
75+
.map(labelName)
76+
.filter(Boolean)
77+
.filter((label) => !ignorableOwnedLabel(label))
78+
.sort(),
79+
comments: comments
80+
.map(object)
81+
.filter((comment) => !trustedClawSweeperComment(comment))
82+
.map((comment) => ({
83+
id: scalar(comment.id),
84+
author: scalar(login(comment.user) || comment.author),
85+
body: scalar(comment.body),
86+
updated_at: scalar(comment.updated_at ?? comment.updatedAt ?? comment.created_at),
87+
}))
88+
.sort((left, right) =>
89+
`${left.id}:${left.updated_at}`.localeCompare(`${right.id}:${right.updated_at}`),
90+
),
91+
};
92+
return createHash("sha256").update(JSON.stringify(snapshot)).digest("hex");
93+
}
94+
95+
function durableSourceRevision(body: string): string | null {
96+
let revision: string | null = null;
97+
for (const match of body.matchAll(SOURCE_REVISION_PATTERN)) revision = match[1] ?? null;
98+
return revision;
99+
}
100+
101+
function durableReviewedSha(body: string): string | null {
102+
let sha: string | null = null;
103+
for (const match of body.matchAll(REVIEWED_SHA_PATTERN)) sha = match[1] ?? null;
104+
return sha;
105+
}
106+
107+
export function classifyScheduledReviewNoop(options: {
108+
decision: unknown;
109+
issue: unknown;
110+
comments: readonly unknown[];
111+
liveHeadSha?: string;
112+
}): { noop: boolean; reason: string } {
113+
const decision = object(options.decision);
114+
const issue = object(options.issue);
115+
if (decision.sourceAction !== "scheduled_hot_intake") {
116+
return { noop: false, reason: "not_scheduled_hot" };
117+
}
118+
if (issue.state !== "open" || issue.locked === true) {
119+
return { noop: false, reason: "live_state_requires_guard" };
120+
}
121+
const queuedUpdatedAt = Date.parse(scalar(decision.sourceUpdatedAt));
122+
const liveUpdatedAt = Date.parse(scalar(issue.updated_at));
123+
if (!Number.isFinite(queuedUpdatedAt) || queuedUpdatedAt !== liveUpdatedAt) {
124+
return { noop: false, reason: "queued_source_drift" };
125+
}
126+
const liveRevision = scheduledReviewSemanticSourceRevision(issue, options.comments);
127+
for (const comment of [...options.comments].map(object).reverse()) {
128+
if (!trustedClawSweeperComment(comment)) continue;
129+
const recordedRevision = durableSourceRevision(scalar(comment.body));
130+
const recordedSha = durableReviewedSha(scalar(comment.body));
131+
const commentUpdatedAt = Date.parse(scalar(comment.updated_at ?? comment.created_at));
132+
if (
133+
recordedRevision === liveRevision &&
134+
(!issue.pull_request ||
135+
(Boolean(options.liveHeadSha) && recordedSha === options.liveHeadSha)) &&
136+
Number.isFinite(commentUpdatedAt) &&
137+
liveUpdatedAt >= commentUpdatedAt &&
138+
liveUpdatedAt - commentUpdatedAt <= SETTLING_WINDOW_MS
139+
) {
140+
return { noop: true, reason: "trusted_owned_activity_only" };
141+
}
142+
}
143+
return { noop: false, reason: "missing_or_changed_durable_source" };
144+
}
145+
146+
function run(): void {
147+
const result = classifyScheduledReviewNoop({
148+
decision: JSON.parse(process.env.CLAIM_DECISION || "{}"),
149+
issue: JSON.parse(process.env.LIVE_ITEM || "{}"),
150+
comments: JSON.parse(process.env.LIVE_COMMENTS || "[]"),
151+
liveHeadSha: process.env.LIVE_HEAD_SHA,
152+
});
153+
const output = `scheduled_noop=${result.noop}\nscheduled_noop_reason=${result.reason}\n`;
154+
if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, output);
155+
else process.stdout.write(output);
156+
}
157+
158+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) run();

‎src/clawsweeper-review-comment-state.ts‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ import { normalizeRepo } from "./repository-profiles.js";
1717
import { trailingHtmlComments } from "./review-comment-markers.js";
1818
import { neutralizeReviewControlMarkers } from "./review-history.js";
1919
import type { ReviewCommentWorkflowDependencies } from "./clawsweeper-review-comment-dependencies.js";
20+
21+
export function normalizeNoopReviewMarkerMetadata(body: string): string {
22+
return body.replace(
23+
/<!--\s+clawsweeper-(?:review-version|verdict:[^\s>]+|action:[^\s>]+|security:[^\s>]+)\b[^>]*-->/g,
24+
(marker) =>
25+
marker.replace(/\s(?:reviewed_at|updated_at|lease_owner|lease_comment_id)=[^\s>]+/g, ""),
26+
);
27+
}
2028
import type { createReviewCommentIdentity } from "./clawsweeper-review-comment-identity.js";
2129

2230
export function createReviewCommentState(
@@ -548,9 +556,14 @@ export function createReviewCommentState(
548556
const actual = commentBody(comment)?.trim();
549557
const expected = body.trim();
550558
if (actual === expected) return true;
551-
if (!actual || !options.allowApplyCloseActionUpgrade) return false;
559+
if (!actual) return false;
560+
const normalizedActual = normalizeNoopReviewMarkerMetadata(actual);
561+
const normalizedExpected = normalizeNoopReviewMarkerMetadata(expected);
562+
if (normalizedActual === normalizedExpected) return true;
563+
if (!options.allowApplyCloseActionUpgrade) return false;
552564
return (
553-
normalizeApplySyncCloseMarkerAction(actual) === normalizeApplySyncCloseMarkerAction(expected)
565+
normalizeApplySyncCloseMarkerAction(normalizedActual) ===
566+
normalizeApplySyncCloseMarkerAction(normalizedExpected)
554567
);
555568
}
556569

@@ -562,15 +575,16 @@ export function createReviewCommentState(
562575
options: { allowApplyCloseActionUpgrade?: boolean } = {},
563576
): boolean {
564577
if (storedHash === expectedHash) return true;
565-
if (!storedHash || !options.allowApplyCloseActionUpgrade) return false;
578+
if (!storedHash) return false;
566579
const actual = commentBody(comment)?.trim();
567580
if (!actual) return false;
568-
if (
569-
normalizeApplySyncCloseMarkerAction(actual) !==
570-
normalizeApplySyncCloseMarkerAction(body.trim())
571-
) {
572-
return false;
573-
}
581+
const normalizedActual = normalizeNoopReviewMarkerMetadata(actual);
582+
const normalizedExpected = normalizeNoopReviewMarkerMetadata(body.trim());
583+
const equivalent = options.allowApplyCloseActionUpgrade
584+
? normalizeApplySyncCloseMarkerAction(normalizedActual) ===
585+
normalizeApplySyncCloseMarkerAction(normalizedExpected)
586+
: normalizedActual === normalizedExpected;
587+
if (!equivalent) return false;
574588
return storedHash === reviewCommentBodyDigest(actual);
575589
}
576590

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
import { normalizeNoopReviewMarkerMetadata } from "../dist/clawsweeper-review-comment-state.js";
4+
5+
const marker = () =>
6+
`<!-- clawsweeper-review-version item=41 reviewed_at=2026-08-09T21:12:00Z sha=na source_revision=${"a".repeat(64)} lease_owner=run-1 lease_comment_id=101 v=1 -->`;
7+
8+
test("no-op public identity ignores only review clock and lease metadata", () => {
9+
const prior = marker();
10+
const refreshed = prior
11+
.replace("21:12:00", "21:32:00")
12+
.replace("run-1", "run-2")
13+
.replace("101", "102");
14+
assert.equal(
15+
normalizeNoopReviewMarkerMetadata(prior),
16+
normalizeNoopReviewMarkerMetadata(refreshed),
17+
);
18+
});
19+
20+
test("no-op public identity preserves semantic source and verdict markers", () => {
21+
const prior = marker();
22+
assert.notEqual(
23+
normalizeNoopReviewMarkerMetadata(prior),
24+
normalizeNoopReviewMarkerMetadata(prior.replace("a".repeat(64), "b".repeat(64))),
25+
);
26+
const keepOpen = `<!-- clawsweeper-verdict:keep-open item=41 reviewed_at=2026-08-09T21:12:00Z confidence=high -->`;
27+
assert.notEqual(
28+
normalizeNoopReviewMarkerMetadata(keepOpen),
29+
normalizeNoopReviewMarkerMetadata(keepOpen.replace("keep-open", "needs-human")),
30+
);
31+
});

0 commit comments

Comments
 (0)