claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

auto-close-duplicates wipes an issue's existing labels when closing it as a duplicate

Open gypsy5oul opened this issue 2 months ago • 3 comments

closeIssueAsDuplicate in scripts/auto-close-duplicates.ts closes the issue with a PATCH /repos/{owner}/{repo}/issues/{number} that includes labels: ['duplicate']:

https://github.com/anthropics/claude-code/blob/dec92bc87ab6fe9c7be0fcba1f97966f902dd243/scripts/auto-close-duplicates.ts#L73-L82

On that endpoint the labels parameter will "replace the set of labels on this issue" (Update an issue), so every issue closed by the auto-close job loses its existing area/platform/triage labels and keeps only duplicate.

Suggested fix: keep the PATCH for state: 'closed' / state_reason: 'duplicate', and add the label with POST /repos/{owner}/{repo}/issues/{number}/labels ({ labels: ['duplicate'] }), which adds rather than replaces (Add labels to an issue). The workflow already grants issues: write.

A ready commit with this change (+8/−2): https://github.com/gypsy5oul/claude-code/commit/7b12a6f

I tried to open it as a PR, but PR creation is restricted on this repository, so I'm filing it here instead.

gypsy5oul avatar Sep 29 '26 13:09 gypsy5oul

I put together a fix for this, but PR creation is restricted to collaborators here so I couldn't open one.

  • Branch: https://github.com/aarochu/claude-code/tree/fix/auto-close-keep-labels
  • Commit: https://github.com/aarochu/claude-code/commit/81abbc60917980bdfa12546e06fecf8709462aa8

It drops labels from the close PATCH and adds duplicate with POST /issues/{n}/labels afterwards, the same way scripts/sweep.ts already adds stale.

I checked it by running the actual script under bun against a stubbed GitHub API that follows the real label semantics (PATCH replaces, POST appends). An issue labelled bug, area:tui, platform:macos came out as just ["duplicate"] on main, and as ["bug", "area:tui", "platform:macos", "duplicate"] with the fix. The closing comment still gets posted, and tsc --noEmit passes.

To pick it up:

git fetch https://github.com/aarochu/claude-code.git fix/auto-close-keep-labels
git cherry-pick 81abbc6

aarochu avatar Nov 08 '26 08:11 aarochu

The consolidated, tested fix for this is ready: 7151c1c on shuhuNB515/claude-code (raw patch).

What it changes for this issue specifically:

  • closeIssueAsDuplicate() no longer sends PATCH /issues/{n} with labels: ['duplicate'] (which replaces the whole label set per the REST docs). It PATCHes only state / state_reason, then adds the duplicate label additively via POST /issues/{n}/labels.
  • Decision logic was extracted into pure functions (shouldAutoClose, extractDuplicateIssueNumber, isDedupeComment) with 11 regression tests in scripts/auto-close-duplicates.test.ts.

The same commit also fixes #80506 (full pagination for comments/reactions) and #79146 (thumbs-down honored from any user), since all three touch the same close-duplicate code path.

Sharing as a patch link rather than a PR, since this repo hasn't had a fork PR created since August and PR creation is blocked for outside accounts. Happy to open a PR if that channel reopens.

Test run:

$ bun test scripts/auto-close-duplicates.test.ts
 11 pass, 0 fail

shuhuNB515 avatar Nov 28 '26 08:11 shuhuNB515

A minimal fix for this is on serhiileniv/claude-code:fix/auto-close-preserve-labels (commit 7963eef, ~15 lines). It's shared as a branch because fork PR creation is currently blocked for outside accounts.

  • Adds duplicate via POST /issues/{n}/labels (additive), then PATCHes only state / state_reason. Labeling comes first on purpose: if the close fails, the issue stays open and the next run retries. Closing first could leave a closed issue with no duplicate label that is never revisited.
  • Skips pull requests in the /issues listing; they're never candidates and each cost a comments request.

Checked against a mock GitHub API: an issue labeled [bug, area:tui] ends with [duplicate] on main and [bug, area:tui, duplicate] on the branch.

This is independent of #80508 (pagination, #80506) and doesn't include the #79146 policy change, so each can be merged on its own.

serhiileniv avatar Nov 28 '26 13:11 serhiileniv