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