Skip to content

Fix: Skip already-closed discussions in expiration workflow#11912

Merged
pelikhan merged 2 commits intomainfrom
copilot/fix-expired-discussions-code
Jan 26, 2026
Merged

Fix: Skip already-closed discussions in expiration workflow#11912
pelikhan merged 2 commits intomainfrom
copilot/fix-expired-discussions-code

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

The close_expired_discussions script was attempting to process discussions that had been closed between the initial search (which filters for OPEN state) and the processing phase, resulting in comments being added to closed discussions.

Changes

  • Modified hasExpirationComment() to return {hasComment, isClosed} instead of boolean

    • Fetches closed field in GraphQL query alongside comment check
  • Added closed state guard in processing loop

    • Skip discussions where isClosed === true before attempting any operations
  • Updated test coverage to verify closed discussions are skipped

// Before: Only checked for duplicate comments
const hasComment = await hasExpirationComment(github, discussion.id);
if (hasComment) {
  await closeDiscussionAsOutdated(github, discussion.id); // Could fail if already closed
}

// After: Check closed state first
const { hasComment, isClosed } = await hasExpirationComment(github, discussion.id);
if (isClosed) {
  continue; // Skip entirely
}

The fix eliminates the race condition window where discussions closed by other processes would still be processed.

Original prompt

Review the agentic maintenance code that closes expired discussions.

It should not be adding comments to discussions who are already closed.

See this comment #10338 (comment) which was added a closed discussion.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Modified hasExpirationComment to also fetch and return the discussion's closed state.
Added logic to skip processing discussions that are already closed before attempting to close them.
Added test case to verify closed discussions are properly skipped.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with adding comments to closed discussions Fix: Skip already-closed discussions in expiration workflow Jan 26, 2026
Copilot AI requested a review from pelikhan January 26, 2026 17:34
@pelikhan pelikhan marked this pull request as ready for review January 26, 2026 17:36
@pelikhan pelikhan merged commit 15569c9 into main Jan 26, 2026
@pelikhan pelikhan deleted the copilot/fix-expired-discussions-code branch January 26, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants