Skip to content

Commit 6002e09

Browse files
committed
fix(actions): harden issue-triage duplicate detection
Keep reason non-empty, distinguish clear duplicates from near-related candidates, and wire detect-language outputs to the parse step.
1 parent 770c17d commit 6002e09

1 file changed

Lines changed: 52 additions & 17 deletions

File tree

‎.github/workflows/issue-triage.yml‎

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
permissions:
1616
models: read
1717
outputs:
18-
requires_translation: ${{ steps.ai.outputs.requires_translation }}
19-
translated_title: ${{ steps.ai.outputs.translated_title }}
20-
translated_body: ${{ steps.ai.outputs.translated_body }}
21-
detected_language: ${{ steps.ai.outputs.detected_language }}
18+
requires_translation: ${{ steps.parse.outputs.requires_translation }}
19+
translated_title: ${{ steps.parse.outputs.translated_title }}
20+
translated_body: ${{ steps.parse.outputs.translated_body }}
21+
detected_language: ${{ steps.parse.outputs.detected_language }}
2222
steps:
2323
- name: Detect and translate
2424
id: ai
@@ -137,18 +137,32 @@ jobs:
137137
cat existing.json >> prompt.txt
138138
cat >> prompt.txt << 'PROMPT'
139139
140-
Return JSON: {"issues":["<number>",...], "reason":"<one sentence>"}
141-
List only clear duplicates (max 5). Empty array if none.
140+
Compare the new issue against the existing open issues.
141+
142+
Return JSON only:
143+
{
144+
"duplicates": ["<number>", ...],
145+
"related": ["<number>", ...],
146+
"reason": "<one sentence>"
147+
}
148+
149+
Rules:
150+
- duplicates: clear same-bug / same-request matches only (max 5)
151+
- related: near matches such as timeout vs slow response, same area/symptom with different root cause (max 5)
152+
- never leave reason empty
153+
- if both lists are empty, reason must still explain why (for example "No clear duplicates or related issues found.")
154+
- do not invent issue numbers
142155
PROMPT
143156
- name: Run inference
144157
id: infer
145158
uses: actions/ai-inference@b81b2afb8390ee6839b494a404766bef6493c7d9 # v1
146159
with:
147160
model: openai/gpt-4o-mini
148-
max-tokens: 200
161+
max-tokens: 300
149162
system-prompt: >
150-
You are a GitHub issue triage assistant. Identify duplicates by
151-
semantic similarity. Respond only with JSON, no markdown.
163+
You are a GitHub issue triage assistant. Identify clear duplicates
164+
and near-related issues by semantic similarity. Always include a
165+
non-empty reason. Respond only with JSON, no markdown.
152166
prompt-file: prompt.txt
153167
- name: Parse matches
154168
id: parse
@@ -162,10 +176,13 @@ jobs:
162176
try { parsed = JSON.parse(raw.trim()); }
163177
catch { try { parsed = JSON.parse(raw.replace(/^\`\`\`(?:json)?\s*/,'').replace(/\s*\`\`\`\s*$/,'').trim()); } catch { process.exit(0); } }
164178
const cur = String(process.env.ISSUE_NUMBER);
165-
const matches = [...new Set((Array.isArray(parsed?.issues)?parsed.issues:[]).map(String).filter(n=>n!==cur))].slice(0,5);
166-
if (!matches.length) process.exit(0);
179+
const normalize = (value) => [...new Set((Array.isArray(value) ? value : []).map(String).filter(n => n && n !== cur))];
180+
const duplicates = normalize(parsed?.duplicates ?? parsed?.issues).slice(0, 5);
181+
const related = normalize(parsed?.related).filter(n => !duplicates.includes(n)).slice(0, 5);
182+
const reason = String(parsed?.reason || '').trim() || 'No clear duplicates or related issues found.';
183+
if (!duplicates.length && !related.length) process.exit(0);
167184
const fs = require('fs');
168-
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'matches=' + JSON.stringify(matches) + '\n');
185+
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'matches=' + JSON.stringify({ duplicates, related, reason }) + '\n');
169186
"
170187
171188
post-duplicates:
@@ -185,12 +202,30 @@ jobs:
185202
const { owner, repo } = context.repo;
186203
const issue_number = context.payload.issue.number;
187204
const MARKER = "<!-- opencodex-dedup-bot -->";
188-
const matches = JSON.parse(process.env.MATCHES || '[]');
189-
if (!matches.length) return;
205+
const payload = JSON.parse(process.env.MATCHES || '{}');
206+
const duplicates = Array.isArray(payload)
207+
? payload
208+
: (Array.isArray(payload.duplicates) ? payload.duplicates : []);
209+
const related = Array.isArray(payload)
210+
? []
211+
: (Array.isArray(payload.related) ? payload.related : []);
212+
const reason = Array.isArray(payload)
213+
? ''
214+
: String(payload.reason || '').trim();
215+
if (!duplicates.length && !related.length) return;
190216
191-
const list = matches.map(n => `- #${n}`).join('\n');
192-
const body = [MARKER, 'Potential duplicates found:', '', list, '',
193-
'_Detected automatically via GitHub Models._'].join('\n');
217+
const sections = [MARKER];
218+
if (duplicates.length) {
219+
sections.push('Potential duplicates found:', '', duplicates.map(n => `- #${n}`).join('\n'), '');
220+
}
221+
if (related.length) {
222+
sections.push('Possibly related issues:', '', related.map(n => `- #${n}`).join('\n'), '');
223+
}
224+
if (reason) {
225+
sections.push(`Reason: ${reason}`, '');
226+
}
227+
sections.push('_Detected automatically via GitHub Models._');
228+
const body = sections.join('\n');
194229
195230
const comments = await github.paginate(github.rest.issues.listComments, {
196231
owner, repo, issue_number, per_page: 100,

0 commit comments

Comments
 (0)