Skip to content

add-comment: support reply_to_id field in agent output for discussion threading #24355

@corygehr

Description

@corygehr

Problem

When a workflow triggered by workflow_dispatch posts a comment to a Discussion via add-comment, the comment is always top-level. There's no way for the agent to specify which comment to thread under.

The replyToId logic in add_comment.cjs (line 593) only works for discussion_comment-triggered workflows:

 const replyToId = context.eventName === "discussion_comment" && !hasExplicitItemNumber 
   ? await resolveTopLevelDiscussionCommentId(githubClient, context.payload?.comment?.node_id) 
   : null;

This means any workflow triggered via dispatch-workflow — even one that receives a parent comment node ID as an input — cannot thread its reply.

Use case

We run a multi-level compliance agent system (CentralRepoOps pattern). When a reviewer posts /feedback on a specialist's Discussion comment:

  1. Feedback workflow (triggered by discussion_comment) parses the command and identifies the specialist
  2. Feedback workflow dispatches the specialist via dispatch-workflow with the target repo and context
  3. Specialist re-evaluates and posts a 🔄 Updated reply to the Discussion

Step 3 always produces a top-level comment because the specialist runs under workflow_dispatch. The reviewer has to scroll to find it, and the Discussion thread becomes hard to follow.

We can already pass the parent comment node_id through dispatch inputs to the specialist — we just need a way for the specialist to hand it to the add-comment handler.

Proposed solution

Add optional reply_to_id field to the add-comment agent output message:

 {
   "type": "add_comment",
   "item_number": 240,
   "body": "🔄 Updated finding...",
   "reply_to_id": "DC_kwDOParentComment456"
 }

In add_comment.cjs, the handler would check message.reply_to_id when the event is NOT discussion_comment (or as a user-specified override):

 const replyToId = context.eventName === "discussion_comment" && !hasExplicitItemNumber
   ? await resolveTopLevelDiscussionCommentId(githubClient, context.payload?.comment?.node_id)
   : (message.reply_to_id || null);

The resolveTopLevelDiscussionCommentId helper should also be applied to message.reply_to_id to handle cases where the caller passes a reply node ID instead of a top-level one.

Context

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions