1name: Identify potential duplicates among new bug/crash reports
2
3on:
4 issues:
5 types: [opened]
6 workflow_dispatch:
7 inputs:
8 issue_number:
9 description: "Issue number to analyze (for testing)"
10 required: true
11 type: number
12
13concurrency:
14 group: potential-duplicate-check-${{ github.event.issue.number || inputs.issue_number }}
15 # let's not overspend tokens on multiple parallel checks of the same issue
16 cancel-in-progress: true
17
18jobs:
19 identify-duplicates:
20 if: github.repository == 'zed-industries/zed'
21 runs-on: ubuntu-latest
22 # let's not overspend tokens on checks that went too deep into the rabbit hole
23 timeout-minutes: 5
24 permissions:
25 contents: read
26 issues: read
27
28 steps:
29 - name: Get github app token
30 id: get-app-token
31 uses: actions/create-github-app-token@bef1eaf1c0ac2b148ee2a0a74c65fbe6db0631f1 # v2.1.4
32 with:
33 app-id: ${{ secrets.ZED_COMMUNITY_BOT_APP_ID }}
34 private-key: ${{ secrets.ZED_COMMUNITY_BOT_PRIVATE_KEY }}
35 owner: zed-industries
36
37 - name: Check issue type
38 id: check-type
39 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
40 with:
41 github-token: ${{ steps.get-app-token.outputs.token }}
42 script: |
43 const issueNumber = context.payload.issue?.number || ${{ inputs.issue_number || 0 }};
44 if (!issueNumber) {
45 core.setFailed('No issue number provided');
46 return;
47 }
48
49 const { data: issue } = await github.rest.issues.get({
50 owner: context.repo.owner,
51 repo: context.repo.repo,
52 issue_number: issueNumber
53 });
54
55 const typeName = issue.type?.name;
56 const isTargetType = typeName === 'Bug' || typeName === 'Crash';
57
58 console.log(`Issue #${issueNumber}: "${issue.title}"`);
59 console.log(`Issue type: ${typeName || '(none)'}`);
60 console.log(`Is target type (Bug/Crash): ${isTargetType}`);
61
62 core.setOutput('issue_number', issueNumber);
63 core.setOutput('issue_author', issue.user?.login || '');
64 core.setOutput('is_target_type', isTargetType);
65
66 if (!isTargetType) {
67 console.log('::notice::Skipping - issue type is not Bug or Crash');
68 }
69
70 - name: Check if author is staff
71 if: steps.check-type.outputs.is_target_type == 'true'
72 id: check-staff
73 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
74 with:
75 github-token: ${{ steps.get-app-token.outputs.token }}
76 script: |
77 const author = process.env.ISSUE_AUTHOR || '';
78 if (!author) {
79 console.log('Could not determine issue author, proceeding with check');
80 core.setOutput('is_staff', 'false');
81 return;
82 }
83
84 try {
85 const response = await github.rest.teams.getMembershipForUserInOrg({
86 org: 'zed-industries',
87 team_slug: 'staff',
88 username: author
89 });
90 const isStaff = response.data.state === 'active';
91 core.setOutput('is_staff', String(isStaff));
92 if (isStaff) {
93 console.log(`::notice::Skipping - author @${author} is a staff member`);
94 }
95 } catch (error) {
96 if (error.status === 404) {
97 core.setOutput('is_staff', 'false');
98 } else {
99 throw error;
100 }
101 }
102 env:
103 ISSUE_AUTHOR: ${{ steps.check-type.outputs.issue_author }}
104
105 - name: Checkout repository
106 if: |
107 steps.check-type.outputs.is_target_type == 'true' &&
108 steps.check-staff.outputs.is_staff == 'false'
109 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110 with:
111 fetch-depth: 1
112
113 - name: Analyze for potential duplicates (DRY RUN)
114 if: |
115 steps.check-type.outputs.is_target_type == 'true' &&
116 steps.check-staff.outputs.is_staff == 'false'
117 id: analyze
118 uses: anthropics/claude-code-action@v1
119 with:
120 anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY_ISSUE_DEDUP }}
121 github_token: ${{ steps.get-app-token.outputs.token }}
122
123 prompt: |
124 You are analyzing issue #${{ steps.check-type.outputs.issue_number }} in the zed-industries/zed repository to determine if it might be a duplicate of an existing issue.
125
126 THIS IS A DRY RUN - do not post any comments or modify anything. Only analyze and return your findings.
127
128 ## Instructions
129
130 1. Use mcp__github__get_issue to fetch the full details of issue #${{ steps.check-type.outputs.issue_number }}
131
132 2. Extract key identifying information:
133 - Error messages (exact text)
134 - Stack traces or panic messages
135 - Affected features/components
136 - Steps to reproduce
137 - Platform/OS information
138
139 3. Search for potential duplicates using mcp__github__search_issues with:
140 - Key error messages or panic text (most reliable signal)
141 - Specific feature names or components mentioned
142 - Limit search to repo:zed-industries/zed and recent issues (last 90 days)
143 - Search both open AND closed issues (duplicates may have been closed)
144
145 4. For each potential match, evaluate similarity:
146 - SAME error message or stack trace = high confidence
147 - SAME steps to reproduce with same outcome = high confidence
148 - Similar description but different error/context = low confidence
149 - Vaguely related topic = NOT a duplicate
150
151 ## Critical Guidelines
152
153 - Be VERY conservative. When in doubt, conclude it is NOT a duplicate.
154 - Only flag as potential duplicate if you have HIGH confidence (same error, same repro steps, same root cause).
155 - "Similar topic" or "related feature" is NOT sufficient - the issues must describe the SAME bug.
156 - False positives are worse than false negatives. Users finding their legitimate issue incorrectly flagged as duplicate is a poor experience.
157
158 ## Output
159
160 Return your analysis as JSON with this exact structure. Do not include any other text outside the JSON.
161
162 claude_args: |
163 --max-turns 3
164 --allowedTools mcp__github__get_issue,mcp__github__search_issues,mcp__github__list_issues
165 --json-schema {"type":"object","properties":{"issue_number":{"type":"integer"},"issue_title":{"type":"string"},"is_potential_duplicate":{"type":"boolean"},"confidence":{"type":"string","enum":["high","medium","low","none"]},"potential_duplicates":{"type":"array","items":{"type":"object","properties":{"number":{"type":"integer"},"title":{"type":"string"},"similarity_reason":{"type":"string"}},"required":["number","title","similarity_reason"]}},"analysis_summary":{"type":"string"},"recommendation":{"type":"string","enum":["flag_as_duplicate","needs_human_review","not_a_duplicate"]}},"required":["issue_number","is_potential_duplicate","confidence","potential_duplicates","analysis_summary","recommendation"]}
166
167 - name: Log analysis results
168 if: |
169 steps.check-type.outputs.is_target_type == 'true' &&
170 steps.check-staff.outputs.is_staff == 'false' &&
171 !cancelled()
172 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
173 with:
174 script: |
175 const output = process.env.ANALYSIS_OUTPUT || '';
176
177 console.log('='.repeat(60));
178 console.log('DRY RUN ANALYSIS RESULTS');
179 console.log('='.repeat(60));
180
181 if (!output || output === '') {
182 console.log('No structured output received from analysis');
183 core.summary.addHeading('⚠️ Analysis did not produce output', 2);
184 core.summary.addRaw('The duplicate detection analysis did not return structured output. Check the workflow logs for details.');
185 await core.summary.write();
186 return;
187 }
188
189 try {
190 const analysis = JSON.parse(output);
191
192 console.log(`\nIssue: #${analysis.issue_number} - ${analysis.issue_title || 'N/A'}`);
193 console.log(`Is Potential Duplicate: ${analysis.is_potential_duplicate}`);
194 console.log(`Confidence: ${analysis.confidence}`);
195 console.log(`Recommendation: ${analysis.recommendation}`);
196 console.log(`\nAnalysis Summary:\n${analysis.analysis_summary}`);
197
198 if (analysis.potential_duplicates.length > 0) {
199 console.log(`\nPotential Duplicates Found: ${analysis.potential_duplicates.length}`);
200 for (const dup of analysis.potential_duplicates) {
201 console.log(` - #${dup.number}: ${dup.title}`);
202 console.log(` Reason: ${dup.similarity_reason}`);
203 }
204 } else {
205 console.log('\nNo potential duplicates identified.');
206 }
207
208 console.log('\n' + '='.repeat(60));
209
210 // set summary for workflow run
211 const summaryIcon = analysis.is_potential_duplicate ? '⚠️' : '✅';
212 const summaryText = analysis.is_potential_duplicate
213 ? `Potential duplicate detected (${analysis.confidence} confidence)`
214 : 'No duplicate detected';
215
216 core.summary.addHeading(`${summaryIcon} Issue #${analysis.issue_number}: ${summaryText}`, 2);
217 core.summary.addRaw(`\n**Recommendation:** ${analysis.recommendation}\n\n`);
218 core.summary.addRaw(`**Summary:** ${analysis.analysis_summary}\n\n`);
219
220 if (analysis.potential_duplicates.length > 0) {
221 core.summary.addHeading('Potential Duplicates', 3);
222 const rows = analysis.potential_duplicates.map(d => [
223 `#${d.number}`,
224 d.title,
225 d.similarity_reason
226 ]);
227 core.summary.addTable([
228 [{data: 'Issue', header: true}, {data: 'Title', header: true}, {data: 'Similarity Reason', header: true}],
229 ...rows
230 ]);
231 }
232
233 await core.summary.write();
234
235 } catch (e) {
236 console.log('Failed to parse analysis output:', e.message);
237 console.log('Raw output:', output);
238 core.summary.addHeading('⚠️ Failed to parse analysis output', 2);
239 core.summary.addRaw(`Error: ${e.message}\n\nRaw output:\n\`\`\`\n${output}\n\`\`\``);
240 await core.summary.write();
241 }
242 env:
243 ANALYSIS_OUTPUT: ${{ steps.analyze.outputs.structured_output }}