Skip to content

Fix add_comment to handle discussion numbers via fallback to GraphQL#14125

Merged
pelikhan merged 2 commits intomainfrom
copilot/debug-add-comment-issue
Feb 6, 2026
Merged

Fix add_comment to handle discussion numbers via fallback to GraphQL#14125
pelikhan merged 2 commits intomainfrom
copilot/debug-add-comment-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

When add_comment receives an explicit item_number that references a discussion, it attempts REST API (issues.createComment) which returns 404. The handler only checked event context to determine API choice, not the target type.

Changes

  • Fallback logic in add_comment.cjs: On 404 from REST API with explicit item_number, retry via GraphQL as discussion
  • Test coverage: 4 scenarios validating fallback behavior, non-existent targets, and backward compatibility with context-based resolution

Behavior

// Before: Silent failure
add_comment({ item_number: 14117, body: "..." })
// → REST API 404 → Warning → skipped: true

// After: Automatic retry
add_comment({ item_number: 14117, body: "..." })
// → REST API 404 → GraphQL retry → Comment posted to discussion

Context-based targets (no explicit item_number) unchanged.

Original prompt

Reference: https://github.com/github/gh-aw/actions/runs/21751193840/job/62749881866#step:6:1

Debug why the add comment failed to find the target and fix the JavaScript code.

Custom agent used: agentic-workflows
GitHub Agentic Workflows (gh-aw) - Create, debug, and upgrade AI-powered workflows with intelligent prompt routing


💡 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.

When an explicit item_number is provided and the REST API returns 404 (not found as issue/PR),
the handler now retries the operation as a discussion using GraphQL. This fixes the issue where
users provide a discussion number but the code incorrectly tries to use the issues REST API.

Changes:
- Add fallback logic in add_comment.cjs to retry as discussion on 404
- Add comprehensive tests for discussion fallback behavior
- Update error messages to distinguish between issue/PR and discussion failures

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JavaScript code to resolve add comment target issue Fix add_comment to handle discussion numbers via fallback to GraphQL Feb 6, 2026
Copilot AI requested a review from pelikhan February 6, 2026 13:21
@pelikhan pelikhan marked this pull request as ready for review February 6, 2026 13:24
Copilot AI review requested due to automatic review settings February 6, 2026 13:24
@pelikhan pelikhan added the smoke label Feb 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Changeset Generator failed. Please review the logs for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions github-actions bot added bug Something isn't working workflows labels Feb 6, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the add_comment handler to automatically retry as a discussion when an explicitly provided item_number returns 404 from the REST API. Previously, providing a discussion number to add_comment would result in a silent failure since the handler only used event context to determine API choice.

Changes:

  • Added fallback logic in add_comment.cjs that catches 404 errors from REST API calls with explicit item_number, then retries via GraphQL as a discussion
  • Added comprehensive test coverage with 4 test scenarios validating the fallback behavior, error handling for non-existent targets, and backward compatibility with context-based resolution

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
actions/setup/js/add_comment.cjs Implements fallback logic (lines 506-582) to retry 404 errors from REST API as discussion calls via GraphQL when item_number is explicitly provided
actions/setup/js/add_comment.test.cjs Adds 4 comprehensive test scenarios (lines 749-954) covering successful fallback, non-existent targets, no-retry conditions, and discussion context handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

throw new Error(`Discussion #${itemNumber} not found in ${itemRepo}`);
}

core.info(`Found discussion #${itemNumber}, adding comment...`);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The fallback logic does not respect the hide-older-comments configuration. When a 404 occurs and the code retries as a discussion, it directly adds the comment without calling hideOlderComments. This means that if hide-older-comments is enabled and the fallback succeeds, older comments won't be hidden as expected. Consider calling hideOlderComments before adding the comment in the fallback path, similar to the primary flow at lines 433-437.

Suggested change
core.info(`Found discussion #${itemNumber}, adding comment...`);
core.info(`Found discussion #${itemNumber}, adding comment...`);
// Respect hide-older-comments configuration in the fallback-to-discussion path
if (config["hide-older-comments"]) {
await hideOlderComments(github, {
owner: repoParts.owner,
repo: repoParts.repo,
number: itemNumber,
isDiscussion: true,
});
}

Copilot uses AI. Check for mistakes.
Comment on lines +512 to +535
// Try to find and comment on the discussion
const discussionQuery = `
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
discussion(number: $number) {
id
}
}
}
`;
const queryResult = await github.graphql(discussionQuery, {
owner: repoParts.owner,
repo: repoParts.repo,
number: itemNumber,
});

const discussionId = queryResult?.repository?.discussion?.id;
if (!discussionId) {
throw new Error(`Discussion #${itemNumber} not found in ${itemRepo}`);
}

core.info(`Found discussion #${itemNumber}, adding comment...`);
const comment = await commentOnDiscussion(github, repoParts.owner, repoParts.repo, itemNumber, processedBody, null);

Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The GraphQL query to check if the discussion exists (lines 513-521) duplicates logic that already exists in the commentOnDiscussion function (lines 215-226). The commentOnDiscussion function already retrieves the discussion ID and throws an error if the discussion is not found. This duplicated query adds an unnecessary API call. Consider removing this duplicate check and directly calling commentOnDiscussion, then handling the error from that function.

Suggested change
// Try to find and comment on the discussion
const discussionQuery = `
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
discussion(number: $number) {
id
}
}
}
`;
const queryResult = await github.graphql(discussionQuery, {
owner: repoParts.owner,
repo: repoParts.repo,
number: itemNumber,
});
const discussionId = queryResult?.repository?.discussion?.id;
if (!discussionId) {
throw new Error(`Discussion #${itemNumber} not found in ${itemRepo}`);
}
core.info(`Found discussion #${itemNumber}, adding comment...`);
const comment = await commentOnDiscussion(github, repoParts.owner, repoParts.repo, itemNumber, processedBody, null);
core.info(`Attempting to add comment to discussion #${itemNumber}...`);
const comment = await commentOnDiscussion(
github,
repoParts.owner,
repoParts.repo,
itemNumber,
processedBody,
null
);

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Agent Container Tool Check - Smoke Test Results

Tool Status Version
bash GNU bash 5.2.21
sh available
git 2.52.0
jq 1.7
yq v4.50.1
curl 8.5.0
gh 2.86.0
node v20.20.0
python3 3.12.3
go go1.24.12
java ⚠️ Binary exists but shell execution fails
dotnet ⚠️ Binary exists but shell execution fails

Result: 10/12 tools fully functional ✅
Issues: Java and .NET binaries are present at expected paths but cannot be executed through the shell (possible environment configuration issue)

Details

  • Java binary: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java (ELF executable verified)
  • .NET binary: /usr/share/dotnet/dotnet (ELF executable verified)
  • Both executables return unexpected output when invoked, suggesting a shell environment issue rather than missing tools

AI generated by Agent Container Smoke Test

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Smoke Test Results

PRs Reviewed:

Test Results:

  • ✅ GitHub MCP
  • ✅ Safe Inputs GH CLI
  • ✅ Serena MCP
  • ✅ Playwright
  • ✅ File Writing
  • ✅ Bash Tool
  • ✅ Discussion Interaction
  • ✅ Build gh-aw
  • ✅ Workflow Dispatch

Overall Status: PASS ✅

cc @pelikhan

AI generated by Smoke Copilot

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@pelikhan pelikhan merged commit 922a31d into main Feb 6, 2026
207 of 209 checks passed
@pelikhan pelikhan deleted the copilot/debug-add-comment-issue branch February 6, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working smoke-copilot workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants