chore: Check closed issues again up to 3 times

This commit is contained in:
LisoUseInAIKyrios committed 2026-11-26 15:19:04 +00:00
1 parent 662f8fdc8f
commit 118e04c2fd
3 files changed
+35 -31

No files matched your search

+30 -27
View File
@@ -2,7 +2,8 @@
// //
// - New issues get a title that matches the body. // - New issues get a title that matches the body.
// - Issues without enough information to act on are closed, with a comment that asks for the details. // - Issues without enough information to act on are closed, with a comment that asks for the details.
// - The first edit or comment of the author after that gets one more check, which can reopen the issue. // - An edit or comment of the author after that gets the issue checked again, which can reopen it.
// This happens at most MAX_RECHECKS times.
// //
// The issue text is written by anyone, so the AI reply is treated as untrusted. // The issue text is written by anyone, so the AI reply is treated as untrusted.
// Every field is validated, and comments are built only from the fixed text in this file. // Every field is validated, and comments are built only from the fixed text in this file.
@@ -29,10 +30,13 @@ const MAX_COMMENTS = 5;
const BOT_LOGIN = 'github-actions[bot]'; const BOT_LOGIN = 'github-actions[bot]';
const MAINTAINER_ASSOCIATIONS = ['OWNER', 'MEMBER', 'COLLABORATOR']; const MAINTAINER_ASSOCIATIONS = ['OWNER', 'MEMBER', 'COLLABORATOR'];
// Hidden markers that start the comment posted when an issue is closed. They hold the whole state: // How often a closed issue is checked again after changes of its author. Each check is an AI request.
// CLOSED_MARKER means the one re-check is still available, RECHECKED_MARKER means it was used. const MAX_RECHECKS = 3;
const CLOSED_MARKER = '<!-- issue-triage:closed -->';
const RECHECKED_MARKER = '<!-- issue-triage:rechecked -->'; // A hidden marker starts the comment posted when an issue is closed. It holds the whole state,
// which is the number of re-checks used so far.
const closedMarker = (rechecks) => `<!-- issue-triage:closed rechecks=${rechecks} -->`;
const CLOSED_MARKER_PATTERN = /^<!-- issue-triage:closed rechecks=(\d+) -->/;
const TITLE_PREFIXES = { bug: 'bug', feature: 'feat', question: 'question' }; const TITLE_PREFIXES = { bug: 'bug', feature: 'feat', question: 'question' };
@@ -251,19 +255,18 @@ function parseModels(value) {
function closeComment(missing) { function closeComment(missing) {
const keys = missing.length > 0 ? missing : DEFAULT_MISSING_INFO; const keys = missing.length > 0 ? missing : DEFAULT_MISSING_INFO;
return [ return [
CLOSED_MARKER, closedMarker(0),
'This issue was closed automatically because it does not have enough information to act on. Please add:', 'This issue was closed automatically because it does not have enough information to act on. Please add:',
'', '',
...keys.map((key) => `- ${MISSING_INFO_TEXT[key]}`), ...keys.map((key) => `- ${MISSING_INFO_TEXT[key]}`),
'', '',
'Edit the issue or reply here, and it will be checked again and reopened if there is enough information.', 'Edit the issue or reply here, and it will be checked again and reopened if there is enough information.',
'**It is only checked again once**, so please add everything in a single edit or reply.',
].join('\n'); ].join('\n');
} }
const STILL_CLOSED_COMMENT = const LAST_RECHECK_COMMENT =
'This issue was checked again and still does not have enough information, so it stays closed. ' + 'This issue still does not appear to have enough information. ' +
'It will not be checked again automatically. A maintainer can reopen it after more details are added.'; 'A maintainer can reopen this when the needed information is provided.';
function escapeHtml(text) { function escapeHtml(text) {
return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
@@ -340,17 +343,16 @@ async function findTask({ github, context, core, owner, repo, issue, includeMain
per_page: 100, per_page: 100,
}); });
const botComments = comments.filter((comment) => comment.user?.login === BOT_LOGIN); const botComments = comments.filter((comment) => comment.user?.login === BOT_LOGIN);
const closedComment = botComments.find((comment) => comment.body.startsWith(CLOSED_MARKER)); const closedComment = botComments.find((comment) => CLOSED_MARKER_PATTERN.test(comment.body));
if (issue.state === 'open') { if (issue.state === 'open') {
if (!manual && !isNewIssue) return skip('is open'); if (!manual && !isNewIssue) return skip('is open');
// An issue is only closed once. A maintainer may have reopened it. // An issue is only closed once. A maintainer may have reopened it.
const closedBefore = return { task: 'triage', closedBefore: Boolean(closedComment), comments };
Boolean(closedComment) || botComments.some((comment) => comment.body.startsWith(RECHECKED_MARKER));
return { task: 'triage', closedBefore, comments };
} }
if (!closedComment) return skip('is closed and has no re-check available'); const rechecks = Number(CLOSED_MARKER_PATTERN.exec(closedComment?.body || '')?.[1] ?? MAX_RECHECKS);
if (rechecks >= MAX_RECHECKS) return skip('is closed and has no re-check available');
if (issue.state_reason !== 'not_planned') return skip('is not closed as not planned'); if (issue.state_reason !== 'not_planned') return skip('is not closed as not planned');
// An issue that a person closed again stays closed. // An issue that a person closed again stays closed.
@@ -363,7 +365,7 @@ async function findTask({ github, context, core, owner, repo, issue, includeMain
const lastClose = events.filter((event) => event.event === 'closed').pop(); const lastClose = events.filter((event) => event.event === 'closed').pop();
if (lastClose?.actor?.login !== BOT_LOGIN) return skip('was not last closed by the triage'); if (lastClose?.actor?.login !== BOT_LOGIN) return skip('was not last closed by the triage');
return { task: 'recheck', closedComment, comments }; return { task: 'recheck', closedComment, rechecks, comments };
} }
async function run({ github, context, core, fetchImpl, retryDelayMs }) { async function run({ github, context, core, fetchImpl, retryDelayMs }) {
@@ -375,7 +377,7 @@ async function run({ github, context, core, fetchImpl, retryDelayMs }) {
const includeMaintainers = process.env.INCLUDE_MAINTAINERS === 'true'; const includeMaintainers = process.env.INCLUDE_MAINTAINERS === 'true';
const { data: issue } = await github.rest.issues.get({ owner, repo, issue_number: issueNumber }); const { data: issue } = await github.rest.issues.get({ owner, repo, issue_number: issueNumber });
const { task, closedBefore, closedComment, comments } = await findTask({ const { task, closedBefore, closedComment, rechecks, comments } = await findTask({
github, github,
context, context,
core, core,
@@ -424,22 +426,23 @@ async function run({ github, context, core, fetchImpl, retryDelayMs }) {
} }
if (task === 'recheck') { if (task === 'recheck') {
// Use up the re-check first, so a failure of a later step cannot cause a second one. const used = rechecks + 1;
// Count the re-check first, so a failure of a later step cannot give an extra one.
actions.unshift({ actions.unshift({
description: 'Use up the one re-check', description: `Use re-check ${used} of ${MAX_RECHECKS}`,
run: () => run: () =>
github.rest.issues.updateComment({ github.rest.issues.updateComment({
owner, owner,
repo, repo,
comment_id: closedComment.id, comment_id: closedComment.id,
body: closedComment.body.replace(CLOSED_MARKER, RECHECKED_MARKER), body: closedComment.body.replace(CLOSED_MARKER_PATTERN, closedMarker(used)),
}), }),
}); });
actions.push( if (!close) {
close actions.push({ description: 'Reopen', run: () => update({ state: 'open' }) });
? { description: 'Keep closed and comment', run: () => comment(STILL_CLOSED_COMMENT) } } else if (used >= MAX_RECHECKS) {
: { description: 'Reopen', run: () => update({ state: 'open' }) } actions.push({ description: 'Keep closed and comment', run: () => comment(LAST_RECHECK_COMMENT) });
); }
} else if (close && issue.state === 'open' && !closedBefore) { } else if (close && issue.state === 'open' && !closedBefore) {
// Comment first, so the issue is never closed without an explanation. // Comment first, so the issue is never closed without an explanation.
actions.push({ actions.push({
@@ -469,8 +472,8 @@ async function run({ github, context, core, fetchImpl, retryDelayMs }) {
module.exports = run; module.exports = run;
Object.assign(module.exports, { Object.assign(module.exports, {
DEFAULT_MODELS, DEFAULT_MODELS,
CLOSED_MARKER, MAX_RECHECKS,
RECHECKED_MARKER, closedMarker,
askModels, askModels,
buildMessages, buildMessages,
hasEvidence, hasEvidence,
+1 -1
View File
@@ -28,7 +28,7 @@ jobs:
github.event.issue.state == 'closed' && github.event.issue.state == 'closed' &&
github.event.issue.state_reason == 'not_planned' && github.event.issue.state_reason == 'not_planned' &&
github.event.sender.login == github.event.issue.user.login) github.event.sender.login == github.event.issue.user.login)
# One run at a time for each issue, so an issue cannot be re-checked twice. # One run at a time for each issue, so the number of re-checks is counted correctly.
concurrency: concurrency:
group: issue-triage-${{ github.event.issue.number || inputs.issue_number }} group: issue-triage-${{ github.event.issue.number || inputs.issue_number }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
+4 -3
View File
@@ -68,8 +68,9 @@ AI model to help with new issues:
- It rewrites titles that do not match the issue text, as `bug:`, `feat:` or `question:`. - It rewrites titles that do not match the issue text, as `bug:`, `feat:` or `question:`.
- It closes issues without enough information to act on, and asks the author for the missing details. - It closes issues without enough information to act on, and asks the author for the missing details.
When the author then edits the issue or replies, it is checked **only once** more, and reopened if there is When the author then edits the issue or replies, it is checked again, and reopened if there is enough
enough information. Issues with logs, screenshots or other attachments are never closed. information. This happens at most 3 times (`MAX_RECHECKS` in [triage.js](.github/scripts/issue-triage/triage.js)).
Issues with logs, screenshots or other attachments are never closed.
### Setup ### Setup
@@ -96,7 +97,7 @@ To triage an issue again, such as after a failed run, use Actions > Issue triage
- OpenRouter [limits free models](https://openrouter.ai/docs/api/reference/limits) to 20 requests per minute and - OpenRouter [limits free models](https://openrouter.ai/docs/api/reference/limits) to 20 requests per minute and
50 per day, or 1000 per day after buying at least $10 of credits. An issue normally uses one request, 50 per day, or 1000 per day after buying at least $10 of credits. An issue normally uses one request,
or two if it is checked again. plus one for each time it is checked again. Failed requests are retried with the fallback models.
- Free models come and go. If runs start to fail, set `OPENROUTER_MODEL` to another model. - Free models come and go. If runs start to fail, set `OPENROUTER_MODEL` to another model.
- The text of issues is sent to OpenRouter and to the provider of the model, which may log it or use it - The text of issues is sent to OpenRouter and to the provider of the model, which may log it or use it
for training. Your OpenRouter [privacy settings](https://openrouter.ai/settings/privacy) must allow the for training. Your OpenRouter [privacy settings](https://openrouter.ai/settings/privacy) must allow the