Skip to content

fix(github): reply in the triggering review thread#37574

Open
chAwater wants to merge 1 commit into
anomalyco:devfrom
chAwater:review-thread-reply
Open

fix(github): reply in the triggering review thread#37574
chAwater wants to merge 1 commit into
anomalyco:devfrom
chAwater:review-thread-reply

Conversation

@chAwater

@chAwater chAwater commented Jul 17, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #37560

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When opencode is triggered from an inline review comment (pull_request_review_comment event), the reply is posted to the PR conversation as a top-level comment instead of the review thread it was asked in.


the createComment() always calls issues.createComment

async function createComment(body: string) {
// Only called for non-schedule events, so issueId is defined
console.log("Creating comment...")
return await octoRest.rest.issues.createComment({
owner,
repo,
issue_number: issueId!,
body,
})
}

which should be pulls.createReplyForReviewComment for review comment,
like the addReaction, using the reactions.createForPullRequestReviewComment

async function addReaction(commentType?: "issue" | "pr_review") {
// Only called for non-schedule events, so triggerCommentId is defined
console.log("Adding reaction...")
if (triggerCommentId) {
if (commentType === "pr_review") {
return await octoRest.rest.reactions.createForPullRequestReviewComment({
owner,
repo,
comment_id: triggerCommentId!,
content: AGENT_REACTION,
})
}

And I also add a try-catch block to prevent failure (such as no permission or the comment being deleted) and fall back to old behavior.

the comment.in_reply_to_id is the root of the thread, also refer to #26689, but I think its on the wrong file

How did you verify your code works?

(The verification was done with the help of opencode)

  • Ran the fixed code locally via the handler's built-in mock-event mode: opencode github run --event <json>, which feeds a webhook payload into the exact code path that runs in GitHub Actions.
    USE_GITHUB_TOKEN=true GITHUB_TOKEN=$(gh auth token) MODEL=<provider/model> GITHUB_RUN_ID=0 SHARE=false bun run --conditions=browser packages/opencode/src/index.ts github run --event "$(cat event.json)"

  • All comments were created by real GitHub API calls on a real PR (throwaway repo) — no mocking of the GitHub API.
    gh api repos/<owner>/<repo>/pulls/comments/<comment_id> | jq '{eventName:"pull_request_review_comment", actor:"<you>", repo:{owner:"<owner>",repo:"<repo>"}, payload:{comment:(. + {body:"/oc <prompt>"}), pull_request:{number:<PR>, title:"test"}}}' > event.json

  • Test on a closed PR

    • Top-level review comment (click + on a diff line) → reply lands inside the review thread
    • Reply inside an existing thread → reply attaches to the thread's root comment
    • File-level comment ("Add comment on file", subject_type: file) → reply lands inside that thread
    • Regular timeline comment (issue_comment event) → still posts as a top-level comment (unchanged behavior)

BTW: I found an unrelated bug on the reaction emoji with use_github_token during the verification, maybe I will report it later 😄

Screenshots / recordings

None

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

GitHub Action replies in the PR conversation instead of the triggering comment in review thread

1 participant