Skip to content

fix: add_comment silently skips when integration token can't write to discussions#39926

Merged
pelikhan merged 5 commits into
mainfrom
copilot/investigate-fix-js-runtime-locks
Jun 18, 2026
Merged

fix: add_comment silently skips when integration token can't write to discussions#39926
pelikhan merged 5 commits into
mainfrom
copilot/investigate-fix-js-runtime-locks

Conversation

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

When add_comment targets a GitHub Discussion and the runner's GITHUB_TOKEN lacks discussions:write, the GraphQL mutation returns "Resource not accessible by integration". Previously this returned {success: false} — a hard failure that failed the entire safe-outputs job. It should be a skippable configuration mismatch, the same way resolve_pr_review_thread handles the identical error.

Changes

  • add_comment.cjs: Add isDiscussionIntegrationAccessError() that checks both the top-level error message and GraphQL errors[] array. In the discussion retry catch block, return {success: false, skipped: true} with a core.warning pointing to safe-outputs.add-comment.github-token rather than propagating a fatal failure.
  • add_comment.test.cjs: Two new tests — one for mutation error string, one for the GraphQL errors[] array variant.
  • safe_outputs_handlers.cjs: addCommentHandler now refuses calls that include reply_to_id (a discussion-only threading field) when discussions: true is not set in the safe-outputs.add-comment configuration. This gives the agent immediate, actionable feedback at MCP time before anything is written to NDJSON, rather than a late execution-phase failure.
  • safe_outputs_handlers.test.cjs: Two new tests covering the MCP-phase refusal (no discussions: true + reply_to_id → error with guidance) and the allowed path (discussions: true + reply_to_id → success).
// Before: hard failure at execution time
core.error(`Failed to add comment to discussion: ${discussionErrorMessage}`);
return { success: false, error: discussionErrorMessage };

// After (execution phase): skipped with actionable warning
core.warning(`...configuration mismatch...Use safe-outputs.add-comment.github-token with discussions:write scope.`);
return { success: false, skipped: true, error: warningMessage };

// After (MCP phase): immediate refusal when reply_to_id targets a discussion
return buildIntentErrorResponse(
  "add_comment with reply_to_id targets a GitHub Discussion, but discussion comments are not enabled..."
);

Copilot AI and others added 3 commits June 18, 2026 00:06
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…skipped in add_comment

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…mment

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title fix: treat "Resource not accessible by integration" for discussions as skipped in add_comment fix: add_comment silently skips when integration token can't write to discussions Jun 18, 2026
Copilot AI requested a review from pelikhan June 18, 2026 00:14
@pelikhan pelikhan marked this pull request as ready for review June 18, 2026 00:24
Copilot AI review requested due to automatic review settings June 18, 2026 00:24
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot the safeoutputs MCP handler should refuse add comment to discussions when discussions are not enabled.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Not ready to approve

It introduces a misleading sync/source-of-truth comment in actions/setup-cli/install.sh that contradicts the documented generation flow and should be corrected before merge.

Pull request overview

This PR adjusts the add_comment safe-output handler to treat a missing discussions:write permission (manifesting as “Resource not accessible by integration” from the Discussion GraphQL mutation) as a skippable configuration mismatch rather than a hard failure, aligning behavior with other handlers that skip on integration permission mismatches.

Changes:

  • Add isDiscussionIntegrationAccessError() to detect the integration access error via either the top-level error message or errors[] entries.
  • In the discussion fallback/retry path, emit an actionable core.warning and return { success: false, skipped: true } instead of failing the safe-outputs job.
  • Add tests covering both error-string and GraphQL errors[] variants of the integration access error.
File summaries
File Description
actions/setup/js/add_comment.cjs Detects “Resource not accessible by integration” for discussion comment attempts and returns a skipped result with a configuration warning.
actions/setup/js/add_comment.test.cjs Adds regression tests ensuring the discussion integration access error is treated as skipped (not fatal).
actions/setup-cli/install.sh Updates the header sync comment (currently appears to be self-referential/misleading).

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.


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

Comment thread actions/setup-cli/install.sh Outdated
set +o histexpand

# Kept in sync with install-gh-aw.sh — edit that file, then copy to this path.
# Kept in sync with actions/setup-cli/install.sh — edit this file, then copy to that path.
… in MCP handler

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the safeoutputs MCP handler should refuse add comment to discussions when discussions are not enabled.

Done. The addCommentHandler in safe_outputs_handlers.cjs now checks the discussions config flag when reply_to_id is present (the only unambiguously discussion-specific field available at MCP time). If discussions: true is not set in safe-outputs.add-comment, the handler immediately returns an actionable error:

"add_comment with reply_to_id targets a GitHub Discussion, but discussion comments are not enabled for this workflow. Set 'discussions: true' in the workflow's safe-outputs.add-comment configuration to enable discussion comments and request discussions:write permission."

This prevents the entry from being written to NDJSON at all, so no silent skip or late execution failure occurs. Two new tests cover the refusal and the allowed path (commit fix: refuse add_comment with reply_to_id when discussions not enabled in MCP handler).

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

…up-cli/install.sh

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Done in 74c7169. Fixed the self-referential sync comment by updating install-gh-aw.sh (the source) to use the explicit filename: # Kept in sync with actions/setup-cli/install.sh — edit install-gh-aw.sh, then copy to that path. This reads correctly in both the source and the generated copy. make sync-action-scripts propagated the change to actions/setup-cli/install.sh.

@github-actions github-actions Bot mentioned this pull request Jun 18, 2026
@pelikhan pelikhan merged commit 24e6da8 into main Jun 18, 2026
42 checks passed
@pelikhan pelikhan deleted the copilot/investigate-fix-js-runtime-locks branch June 18, 2026 02:00
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.

3 participants