Skip to content

Commit 054495d

Browse files
authored
fix(ci): verify stale bugs before closure (#114365)
1 parent fee6db7 commit 054495d

6 files changed

Lines changed: 371 additions & 5 deletions

File tree

‎.github/workflows/clawsweeper-dispatch.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ jobs:
3030
(github.actor != 'clawsweeper[bot]' && github.actor != 'openclaw-clawsweeper[bot]')) &&
3131
!(
3232
endsWith(github.actor, '[bot]') &&
33-
(github.event.action == 'labeled' || github.event.action == 'unlabeled')
33+
(github.event.action == 'labeled' || github.event.action == 'unlabeled') &&
34+
!(
35+
github.event_name == 'issues' &&
36+
github.event.action == 'labeled' &&
37+
github.event.label.name == 'stale' &&
38+
contains(github.event.issue.labels.*.name, 'bug') &&
39+
(github.actor_id == '257215752' || github.actor_id == '264559031')
40+
)
3441
)
3542
}}
3643
env:

‎.github/workflows/stale.yml‎

Lines changed: 289 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
days-before-pr-close: 7
7575
stale-issue-label: stale
7676
stale-pr-label: stale
77-
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
77+
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,bug,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
7878
exempt-pr-labels: maintainer,no-stale,bad-barnacle
7979
operations-per-run: 2000
8080
ascending: true
@@ -106,7 +106,7 @@ jobs:
106106
days-before-pr-stale: -1
107107
days-before-pr-close: -1
108108
stale-issue-label: stale
109-
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
109+
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,bug,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
110110
operations-per-run: 2000
111111
ascending: true
112112
include-only-assigned: true
@@ -178,7 +178,7 @@ jobs:
178178
days-before-pr-close: 7
179179
stale-issue-label: stale
180180
stale-pr-label: stale
181-
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
181+
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,bug,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
182182
exempt-pr-labels: maintainer,no-stale,bad-barnacle
183183
operations-per-run: 2000
184184
ascending: true
@@ -209,7 +209,7 @@ jobs:
209209
days-before-pr-stale: -1
210210
days-before-pr-close: -1
211211
stale-issue-label: stale
212-
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
212+
exempt-issue-labels: enhancement,maintainer,pinned,security,no-stale,bad-barnacle,bug,clawsweeper:queueable-fix,clawsweeper:source-repro,clawsweeper:fix-shape-clear
213213
operations-per-run: 2000
214214
ascending: true
215215
include-only-assigned: true
@@ -246,6 +246,190 @@ jobs:
246246
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
247247
That channel is the escape hatch for high-quality PRs that get auto-closed.
248248
249+
stale-bug-verification:
250+
if: ${{ github.event_name != 'workflow_dispatch' || inputs.backfill_stale_closures != true }}
251+
permissions:
252+
issues: write
253+
runs-on: ubuntu-24.04
254+
steps:
255+
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
256+
id: app-token
257+
continue-on-error: true
258+
with:
259+
app-id: "2729701"
260+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
261+
permission-issues: write
262+
permission-metadata: read
263+
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
264+
id: app-token-fallback
265+
continue-on-error: true
266+
with:
267+
app-id: "2971289"
268+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
269+
permission-issues: write
270+
permission-metadata: read
271+
- name: Mark inactive bugs for ClawSweeper verification
272+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
273+
with:
274+
github-token: ${{ steps.app-token.outputs.token || steps.app-token-fallback.outputs.token }}
275+
retries: 3
276+
script: |
277+
const dayMs = 24 * 60 * 60 * 1000;
278+
const nowMs = Date.now();
279+
const maxMarks = 25;
280+
const barnacleActorIds = new Set([257215752, 264559031]);
281+
const exemptLabels = new Set([
282+
"enhancement",
283+
"maintainer",
284+
"pinned",
285+
"security",
286+
"no-stale",
287+
"bad-barnacle",
288+
"clawsweeper:queueable-fix",
289+
"clawsweeper:source-repro",
290+
"clawsweeper:fix-shape-clear",
291+
]);
292+
const { owner, repo } = context.repo;
293+
const marked = [];
294+
const unmarked = [];
295+
296+
const labelNames = item =>
297+
new Set(
298+
(item.labels || []).map(label =>
299+
(typeof label === "string" ? label : label.name).toLowerCase(),
300+
),
301+
);
302+
const eventTimestamp = event =>
303+
Date.parse(event.created_at || event.submitted_at || "");
304+
const isBarnacleStaleComment = event =>
305+
event.event === "commented" &&
306+
barnacleActorIds.has(event.actor?.id || event.user?.id || 0) &&
307+
String(event.body || "").includes("marked as stale");
308+
const hasSubstantiveUpdateSinceStale = (item, timeline) => {
309+
const orderedTimeline = timeline
310+
.map((event, index) => ({ event, index, timestamp: eventTimestamp(event) }))
311+
.filter(entry => Number.isFinite(entry.timestamp))
312+
.toSorted(
313+
(left, right) => left.timestamp - right.timestamp || left.index - right.index,
314+
);
315+
const staleEventIndex = orderedTimeline.findLastIndex(
316+
entry =>
317+
entry.event.event === "labeled" &&
318+
String(entry.event.label?.name || "").toLowerCase() === "stale",
319+
);
320+
if (staleEventIndex < 0) return false;
321+
const staleAtMs = orderedTimeline[staleEventIndex].timestamp;
322+
const updatedAtMs = Date.parse(item.updated_at);
323+
if (!Number.isFinite(updatedAtMs)) return false;
324+
const laterEvents = orderedTimeline
325+
.slice(staleEventIndex + 1)
326+
.map(entry => entry.event);
327+
if (laterEvents.some(event => !isBarnacleStaleComment(event))) return true;
328+
const lastAutomationAtMs = Math.max(staleAtMs, ...laterEvents.map(eventTimestamp));
329+
return updatedAtMs > lastAutomationAtMs;
330+
};
331+
const removeStale = async item => {
332+
try {
333+
await github.rest.issues.removeLabel({
334+
owner,
335+
repo,
336+
issue_number: item.number,
337+
name: "stale",
338+
});
339+
unmarked.push(item);
340+
} catch (error) {
341+
if (error.status !== 404) throw error;
342+
}
343+
};
344+
345+
for await (const response of github.paginate.iterator(github.rest.issues.listForRepo, {
346+
owner,
347+
repo,
348+
state: "open",
349+
labels: "bug",
350+
sort: "updated",
351+
direction: "asc",
352+
per_page: 100,
353+
})) {
354+
for (const listedItem of response.data) {
355+
if (listedItem.pull_request) continue;
356+
const listedLabels = labelNames(listedItem);
357+
const isExempt = [...listedLabels].some(label => exemptLabels.has(label));
358+
359+
if (listedLabels.has("stale")) {
360+
if (isExempt) {
361+
await removeStale(listedItem);
362+
continue;
363+
}
364+
const timeline = await github.paginate(
365+
github.rest.issues.listEventsForTimeline,
366+
{ owner, repo, issue_number: listedItem.number, per_page: 100 },
367+
);
368+
if (hasSubstantiveUpdateSinceStale(listedItem, timeline)) {
369+
await removeStale(listedItem);
370+
}
371+
// Existing stale bugs are intentionally not re-labeled or
372+
// dispatched; #114238 requires separate backfill approval.
373+
continue;
374+
}
375+
376+
if (isExempt || marked.length >= maxMarks) continue;
377+
const assigned = (listedItem.assignees || []).length > 0;
378+
const staleAfterDays = assigned ? 30 : 14;
379+
if (Date.parse(listedItem.updated_at) >= nowMs - staleAfterDays * dayMs) continue;
380+
381+
// Re-read immediately before mutation so a recent comment,
382+
// assignment, or exemption cannot be raced by the scan.
383+
const { data: item } = await github.rest.issues.get({
384+
owner,
385+
repo,
386+
issue_number: listedItem.number,
387+
});
388+
const currentLabels = labelNames(item);
389+
const currentlyExempt = [...currentLabels].some(label => exemptLabels.has(label));
390+
const currentlyAssigned = (item.assignees || []).length > 0;
391+
const currentStaleAfterDays = currentlyAssigned ? 30 : 14;
392+
if (
393+
item.state !== "open" ||
394+
currentLabels.has("stale") ||
395+
!currentLabels.has("bug") ||
396+
currentlyExempt ||
397+
Date.parse(item.updated_at) >= nowMs - currentStaleAfterDays * dayMs
398+
) {
399+
continue;
400+
}
401+
402+
await github.rest.issues.addLabels({
403+
owner,
404+
repo,
405+
issue_number: item.number,
406+
labels: ["stale"],
407+
});
408+
const body = [
409+
currentlyAssigned
410+
? "This assigned bug report has been automatically marked as stale after 30 days of inactivity."
411+
: "This bug report has been automatically marked as stale due to inactivity.",
412+
"ClawSweeper is checking whether current `main` already fixes the reported behavior.",
413+
"Inactivity alone will not close a bug report.",
414+
].join("\n");
415+
await github.rest.issues.createComment({
416+
owner,
417+
repo,
418+
issue_number: item.number,
419+
body,
420+
});
421+
marked.push(item);
422+
}
423+
}
424+
425+
core.info(`Marked ${marked.length} bug issue(s) for ClawSweeper verification.`);
426+
core.info(`Removed stale from ${unmarked.length} updated or exempt bug issue(s).`);
427+
await core.summary
428+
.addHeading("Bug stale verification")
429+
.addRaw(`Marked for ClawSweeper review: ${marked.length}\n\n`)
430+
.addRaw(`Returned to active/exempt state: ${unmarked.length}\n\n`)
431+
.write();
432+
249433
backfill-stale-closures:
250434
if: ${{ github.event_name == 'workflow_dispatch' && inputs.backfill_stale_closures == true }}
251435
permissions:
@@ -286,6 +470,7 @@ jobs:
286470
"security",
287471
"no-stale",
288472
"bad-barnacle",
473+
"bug",
289474
"clawsweeper:queueable-fix",
290475
"clawsweeper:source-repro",
291476
"clawsweeper:fix-shape-clear",
@@ -497,6 +682,106 @@ jobs:
497682
}
498683
}
499684
685+
audit-bug-closure-reasons:
686+
needs: stale
687+
if: ${{ github.event_name != 'workflow_dispatch' || inputs.backfill_stale_closures != true }}
688+
permissions:
689+
issues: read
690+
runs-on: ubuntu-24.04
691+
steps:
692+
- name: Reject Barnacle NOT_PLANNED bug closures
693+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
694+
with:
695+
github-token: ${{ github.token }}
696+
script: |
697+
const auditWindowMs = 48 * 60 * 60 * 1000;
698+
const cutoffMs = Date.now() - auditWindowMs;
699+
// Immutable GitHub bot account ids for openclaw-barnacle[bot] and
700+
// barnacle-openclaw[bot]. Logins are display-only and spoofable.
701+
const barnacleActorIds = new Set([257215752, 264559031]);
702+
const { owner, repo } = context.repo;
703+
const violations = [];
704+
const escapeSummaryCell = value =>
705+
String(value)
706+
.replaceAll("&", "&amp;")
707+
.replaceAll("<", "&lt;")
708+
.replaceAll(">", "&gt;")
709+
.replaceAll('"', "&quot;")
710+
.replaceAll("'", "&#39;");
711+
712+
pages: for await (const response of github.paginate.iterator(
713+
github.rest.issues.listForRepo,
714+
{
715+
owner,
716+
repo,
717+
state: "closed",
718+
sort: "updated",
719+
direction: "desc",
720+
per_page: 100,
721+
},
722+
)) {
723+
const items = response.data;
724+
725+
for (const item of items) {
726+
const updatedAtMs = Date.parse(item.updated_at);
727+
if (Number.isFinite(updatedAtMs) && updatedAtMs < cutoffMs) break pages;
728+
if (item.pull_request || item.state_reason !== "not_planned") continue;
729+
const closedAtMs = Date.parse(item.closed_at || "");
730+
if (!Number.isFinite(closedAtMs) || closedAtMs < cutoffMs) continue;
731+
const labels = (item.labels || []).map(label =>
732+
typeof label === "string" ? label : label.name,
733+
);
734+
if (!labels.includes("bug")) continue;
735+
736+
const timeline = await github.paginate(github.rest.issues.listEventsForTimeline, {
737+
owner,
738+
repo,
739+
issue_number: item.number,
740+
per_page: 100,
741+
});
742+
const closeEvent = timeline
743+
.filter(event => event.event === "closed")
744+
.toSorted((left, right) =>
745+
Date.parse(left.created_at || "") - Date.parse(right.created_at || ""),
746+
)
747+
.at(-1);
748+
if (!closeEvent || !barnacleActorIds.has(closeEvent.actor?.id || 0)) continue;
749+
violations.push({
750+
number: item.number,
751+
title: item.title,
752+
actor: closeEvent.actor.login,
753+
url: item.html_url,
754+
});
755+
}
756+
}
757+
758+
if (violations.length === 0) {
759+
core.info("No Barnacle NOT_PLANNED bug closures found in the last 48 hours.");
760+
return;
761+
}
762+
763+
await core.summary
764+
.addHeading("Barnacle bug closure invariant failed")
765+
.addRaw(
766+
"Bug-labeled issues must be verified by ClawSweeper instead of closed by Barnacle as not planned.\n\n",
767+
)
768+
.addTable([
769+
[
770+
{ data: "Issue", header: true },
771+
{ data: "Title", header: true },
772+
{ data: "Actor", header: true },
773+
],
774+
...violations.map(violation => [
775+
`[#${violation.number}](${violation.url})`,
776+
escapeSummaryCell(violation.title),
777+
violation.actor,
778+
]),
779+
])
780+
.write();
781+
core.setFailed(
782+
`Found ${violations.length} Barnacle NOT_PLANNED bug closure(s) in the last 48 hours.`,
783+
);
784+
500785
lock-closed-issues:
501786
needs: stale
502787
if: ${{ github.event_name != 'workflow_dispatch' || inputs.backfill_stale_closures != true }}

‎docs/ci.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ General activity is observation, not delivery-by-default. The ClawSweeper agent
152152

153153
Treat GitHub titles, comments, bodies, review text, branch names, and commit messages as untrusted data throughout this path. They are input for summarization and triage, not instructions for the workflow or agent runtime.
154154

155+
Barnacle treats bug-labeled issues as verification candidates rather than inactivity-close candidates. It may add the `stale` label, which dispatches one exact ClawSweeper review, but it cannot close that issue. ClawSweeper may then apply an evidence-backed resolution; a proven fix on current `main` closes as completed, while current or inconclusive bugs stay open. The stale workflow also audits recent close events and fails when a Barnacle identity closes a bug as `not_planned`.
156+
155157
## Manual dispatches
156158

157159
Manual CI dispatches run the same job graph as normal CI but force every non-Android scoped lane on: Linux Node shards, bundled-plugin shards, plugin and channel contract shards, Node 22 compatibility, `check-*`, `check-additional-*`, built-artifact smoke checks, docs checks, Python skills, Windows, macOS, iOS build, and Control UI/native app i18n. Automatic source PRs verify native extraction inventory and Android/Apple localization safety without requiring translated or platform-generated output in the same PR. The serialized Native App Locale Refresh workflow rebuilds those artifacts in one isolated PR and enables exact-head auto-merge after required checks pass. Full native parity remains blocking for generated-artifact PRs, manual CI, Full Release Validation, and release prep. Control UI locale parity remains advisory on automatic PR and `main` runs and blocking on manual/release CI. Standalone manual CI dispatches run Android only with `include_android=true` (the `release_gate` input also forces Android); the full release umbrella enables Android by passing `include_android=true`. Plugin prerelease static checks, the release-only `agentic-plugins` shard, the full extension batch sweep, and plugin prerelease Docker lanes are excluded from CI. The Docker prerelease suite runs only when `Full Release Validation` dispatches the separate `Plugin Prerelease` workflow with the release-validation gate enabled.

‎scripts/test-projects.test-support.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([
749749
[".github/workflows/clawsweeper-dispatch.yml", ["test/scripts/ci-workflow-guards.test.ts"]],
750750
[".github/workflows/labeler.yml", ["test/scripts/ci-workflow-guards.test.ts"]],
751751
[".github/workflows/real-behavior-proof.yml", ["test/scripts/ci-workflow-guards.test.ts"]],
752+
[".github/workflows/stale.yml", ["test/scripts/ci-workflow-guards.test.ts"]],
752753
[
753754
".github/workflows/security-sensitive-guard.yml",
754755
["test/scripts/security-sensitive-guard-workflow.test.ts"],

0 commit comments

Comments
 (0)