Skip to content

Fix duplicate expiration comments on discussions#11690

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-comments-on-closed-discussions
Jan 24, 2026
Merged

Fix duplicate expiration comments on discussions#11690
pelikhan merged 3 commits intomainfrom
copilot/fix-comments-on-closed-discussions

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

Fix: Prevent duplicate comments on closed discussions

Problem Analysis

The close_expired_discussions.cjs script was adding multiple comments to discussions that should already be closed.

Root Cause:

  1. Script searches for OPEN discussions with expiration markers
  2. If the close operation fails after adding a comment, the discussion remains OPEN
  3. Next run finds the same discussion again and adds another comment
  4. This repeats, causing duplicate comments

Solution:

  • Analyze the codebase to understand the issue
  • Add hasExpirationComment() function to check for existing comments
  • Skip adding duplicate comments on already-processed discussions
  • Use XML marker <!-- gh-aw-closed --> for reliable detection
  • Create comprehensive test coverage for the fix (7 tests, all passing)
  • Run pre-commit validation (make agent-finish)
  • Verify the fix works correctly

Changes Made

actions/setup/js/close_expired_discussions.cjs:

  1. Added hasExpirationComment() function that queries a discussion's comments to check if an expiration comment already exists
  2. Modified main loop to check for existing expiration comments before adding a new one
  3. If a comment already exists, skip adding a duplicate but still attempt to close the discussion
  4. Added tracking of skipped discussions and updated summary output
  5. Uses XML marker <!-- gh-aw-closed --> for reliable duplicate detection (instead of text pattern)

actions/setup/js/close_expired_discussions.test.cjs (new file):

  • Comprehensive test coverage with 7 test cases
  • Tests for duplicate comment prevention
  • Tests for normal comment addition
  • Tests for edge cases (empty comments, no discussions, non-expired discussions)
  • All tests passing ✅

How It Works

  1. Before: Script would add a comment and try to close, then repeat on next run if close failed
  2. After: Script checks for existing expiration comments using XML marker, only adds if none exists, preventing duplicates

Testing

All new tests pass:

✓ close_expired_discussions.test.cjs (7 tests) 30ms

Note: Some pre-existing test failures in pkg/workflow are unrelated to this change.

Original prompt

Review the agentic maintenance JavaScript code that expires discussions. It seems to keep adding comments to closed discussions.

See this discussion where multiple comments are added although it is already closed

#11057


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Add hasExpirationComment() function to check for existing comments
- Skip adding duplicate comments if one already exists
- Still close discussions that have comments but remain open
- Add comprehensive test coverage for duplicate prevention
- Update summary to show skipped discussions count

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix comment addition to closed discussions in agentic maintenance code Fix duplicate expiration comments on discussions Jan 24, 2026
Copilot AI requested a review from pelikhan January 24, 2026 19:02
}

const comments = result.node.comments.nodes || [];
const expirationCommentPattern = /This discussion was automatically closed because it expired on/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use xml comment marker like gh-aw-closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9646d1e. Now using <!-- gh-aw-closed --> XML marker for reliable duplicate detection.

- Add <!-- gh-aw-closed --> marker to expiration comments
- Check for XML marker instead of text pattern for duplicate detection
- Update tests to include XML marker in mock comments

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
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