Skip to content

Improve send comments to ai - #12150

Merged
AmethystLiang merged 4 commits into
mainfrom
improve-send-comments-to-ai
Aug 3, 2026
Merged

AmethystLiang merged 4 commits into
mainfrom
improve-send-comments-to-ai

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Describe the user-visible change.

Screenshots

  • Add screenshots or a screen recording for any new or changed UI behavior.
  • If there is no visual change, say No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

AI Review Report

Summarize the code review you ran with your AI coding agent. Include the main risks it checked, what it flagged, and what you changed or verified as a result.
Confirm that the review explicitly checked cross-platform compatibility for macOS, Linux, and Windows, including shortcuts, labels, paths, shell behavior, and any Electron-specific platform differences touched by this PR.

Security Audit

Provide a basic security audit summary from your AI coding agent. Call out any input handling, command execution, path handling, auth, secrets, dependency, or IPC risks that were reviewed, plus any follow-up needed.

Notes

Call out any platform-specific behavior, risks, or follow-up work.

Orca now automatically replies to selected comments after launching an
agent to resolve them. Review-thread comments get nested replies; review
summaries and issue comments get top-level @-replies. Payloads are
snapshotted at queue time and posted only after prompt delivery
succeeds. Bounded concurrency (4) prevents SSH slowdown.
Combine N unresolvable comments into a single PR conversation reply to avoid timeline spam. Review threads still get one nested reply each. Refactor helper functions to pr-comment-fixing-reply-body.ts and change replyAsConversation(comment, body) → replyAsConversation(body).
@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR significantly improves the "send comments to AI" flow by adding post-launch acknowledgement (fixing replies) to selected PR comments on GitHub. After an agent prompt is delivered, Orca now posts a "Fixing. Will be in the next commit" reply—either as a nested thread reply for inline review comments, or as a single batched conversation comment for review summaries and top-level comments—before resolving host threads.

  • New pr-comments-ai-launch-ack.ts: Centralises acknowledgement logic with bounded concurrency (PR_COMMENT_ACK_MAX_CONCURRENCY = 4), a canPostPRReviewThreadReply guard that correctly rejects #pullrequestreview-N anchors, and a resolvePRReviewReplyThreadId fallback that refuses ambiguous path-only matches (fixing the thread-misfiling issue noted in the previous review).
  • New pr-comment-fixing-reply-body.ts: Builds reply bodies, stripping [bot] login suffixes for GitHub App mentions and batching multiple conversation-type comments into a single readable post.
  • Launch lifecycle in ChecksPanel: Introduces onLaunchAccepted/onLaunchAborted callbacks so the ack payload is claimed atomically when the tab exists, and returned if prompt delivery fails—preventing double-posts and stale replies on subsequent launches. A commentResolutionAckBusy flag blocks re-entry while an ack is still running.

Confidence Score: 5/5

Safe to merge; the new ack lifecycle is well-tested and protected against double-posts, stale replies, and panel churn.

The core orchestration (claim/release/consume lifecycle, bounded-concurrency ack loop, canPostPRReviewThreadReply classification) is backed by a 704-line test file covering stale-context mid-loop, failed thread resolves, batched conversation replies, and delivery-failure abort. The only open issue is a missing i18n key for a non-GitHub dialog description path, which falls back to readable English text and does not affect functionality.

Files Needing Attention: The abf59262fb locale key used in ChecksPanel.tsx for the GitLab/no-target description is absent from all five locale JSON files and should be added before the next localisation pass.

Important Files Changed

Filename Overview
src/renderer/src/components/right-sidebar/pr-comments-ai-launch-ack.ts New core module; well-tested logic for canPostPRReviewThreadReply, bounded-concurrency ack loop, and module-level singleton for surviving dialog re-renders.
src/renderer/src/components/right-sidebar/pr-comment-fixing-reply-body.ts New helper for building reply bodies; correctly strips [bot] suffix, truncates long snippets, and batches multiple conversation-type comments into one post.
src/renderer/src/components/right-sidebar/ChecksPanel.tsx Complex ref-based lifecycle management added; logic is sound but the abf59262fb i18n key used for the GitLab/no-target description path is missing from all locale files.
src/renderer/src/components/right-sidebar/runSourceControlAgentActionStart.ts Adds onLaunchAccepted/onLaunchAborted lifecycle and wraps onSaveAgentDefault in try/catch to prevent stranded bookkeeping after recipe-save failures.
src/renderer/src/components/right-sidebar/pr-comments-ai-launch-ack.test.ts Comprehensive 704-line test file covering canPostPRReviewThreadReply, batching, bounded concurrency, stale-context handling, and the pending-ack singleton.
src/renderer/src/components/GitHubItemDialog.tsx Reply routing now uses canPostPRReviewThreadReply (broader than the old comment.path check) and attaches parent metadata via attachPRReviewReplyParent for correct sidebar grouping.
src/renderer/src/components/PullRequestPage.tsx Parallel changes to GitHubItemDialog.tsx: same canPostPRReviewThreadReply/buildPRCommentConversationReplyBody/attachPRReviewReplyParent adoption.
src/renderer/src/components/right-sidebar/useSourceControlAgentActionDialog.ts Passes new lifecycle callbacks through; refactors four near-identical useCallback patterns into a resetPlanAfter HOF using useMemo.
src/renderer/src/i18n/locales/en.json Four existing keys updated, one new key (7e4b2a19c0) added; abf59262fb key used in ChecksPanel for the non-GitHub path is absent from all locale files.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant CP as ChecksPanel
    participant D as SourceControlAgentActionDialog
    participant R as runSourceControlAgentActionStart
    participant GH as GitHub API

    U->>CP: clicks "Resolve Comments With AI"
    CP->>CP: setPendingPRCommentAiAck(payload)
    CP->>D: open dialog (commentResolution payload)
    U->>D: "confirms prompt & clicks Start"
    D->>R: runSourceControlAgentActionStart()
    R->>R: launchAgentInNewTab()
    R-->>CP: onLaunchAccepted()
    CP->>CP: "claimPendingCommentResolutionForLaunch()<br/>(moves payload to claimedRef, sets AckBusy=true)"
    R->>R: await promptDeliveryResult
    alt prompt delivered
        R-->>CP: onLaunched()
        CP->>CP: consumeClaimedCommentResolutionAfterDelivery()
        par per thread group (bounded 4x concurrency)
            CP->>GH: addPRReviewCommentReply(Fixing. Will be in the next commit)
            CP->>GH: resolvePRReviewThread(threadId)
        end
        par batched conversation groups
            CP->>GH: addPRConversationComment(batched body)
        end
        CP-->>U: toast (resolved N, replied M, skipped K, failed F)
    else prompt delivery failed
        R-->>CP: onLaunchAborted()
        CP->>CP: "releaseClaimedCommentResolutionAfterFailedLaunch()<br/>(returns payload to pending, AckBusy=false)"
    end
Loading

Reviews (2): Last reviewed commit: "Handle bot account mentions in PR conver..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a2a9040a-47da-4736-8b21-75c530801463

📥 Commits

Reviewing files that changed from the base of the PR and between 1f40f21 and c12d725.

📒 Files selected for processing (1)
  • src/renderer/src/components/right-sidebar/ChecksPanel.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/right-sidebar/ChecksPanel.tsx

📝 Walkthrough

Walkthrough

The PR adds deferred AI acknowledgements for selected pull request comments. It posts nested review-thread replies when supported and batches standalone conversation replies. It resolves eligible threads after successful replies, limits concurrent requests, tracks pending launch state, and handles stale or failed launches. Pull request surfaces preserve thread metadata and render nested replies. Launch lifecycle callbacks distinguish session creation from prompt-delivery success. Review prompts, status messages, and translations report reply, resolution, skipped, and failure counts.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only repeats the template and omits the user-visible summary, testing results, screenshots, AI review, security audit, and notes. Replace the template placeholders with the actual change summary, testing results, UI evidence, AI review findings, security audit, and platform-specific notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 51.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: improving comment sending to AI during pull-request comment resolution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/GitHubItemDialog.tsx (1)

3276-3284: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

The conversation-reply fallback builds an unresolvable bot mention in both PR surfaces. Both surfaces build the fallback body as @${comment.author} ${replyBody}. A GitHub App login carries a [bot] suffix, so @coderabbitai[bot] renders literally and never notifies the bot. This PR narrows the review-thread branch with canPostPRReviewThreadReply, which routes bot-authored review summaries into this fallback, so the broken mention is now reachable. buildPRCommentConversationReplyBody in src/renderer/src/components/right-sidebar/pr-comment-fixing-reply-body.ts already strips the suffix.

  • src/renderer/src/components/GitHubItemDialog.tsx#L3276-L3284: replace the body template literal with buildPRCommentConversationReplyBody(comment.author, replyBody) and import the helper.
  • src/renderer/src/components/PullRequestPage.tsx#L3420-L3428: apply the same replacement and import.
🧹 Nitpick comments (4)
src/renderer/src/components/GitHubItemDialog.tsx (2)

3262-3297: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hoist the routing condition into a local constant.

The same expression item.type === 'pr' && canPostPRReviewThreadReply(comment) decides the request at Line 3263 and the optimistic update at Line 3294. A future edit can change one occurrence only, and the posted reply would then be decorated with the wrong metadata.

♻️ Proposed refactor
+      const isReviewThreadReply = item.type === 'pr' && canPostPRReviewThreadReply(comment)
       // Why: nest under review threads (path/threadId/discussion_r); never post a
       // separate top-level conversation comment for those.
-      const result =
-        item.type === 'pr' && canPostPRReviewThreadReply(comment)
+      const result = isReviewThreadReply
           ? await addPRReviewCommentReplyForRepo({
-      onCommentAdded(
-        item.type === 'pr' && canPostPRReviewThreadReply(comment)
-          ? attachPRReviewReplyParent(result.comment, comment)
-          : result.comment
-      )
+      onCommentAdded(
+        isReviewThreadReply ? attachPRReviewReplyParent(result.comment, comment) : result.comment
+      )

156-159: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Two PR conversation surfaces now depend on the launch-ack module for generic helpers. canPostPRReviewThreadReply and attachPRReviewReplyParent describe PR review-thread reply targets. They do not describe agent launch acknowledgement. Both surfaces import the launch-ack module only to reach them, which points the dependency in the wrong direction. Move both helpers into a dedicated module, for example src/renderer/src/components/right-sidebar/pr-comment-reply-target.ts, and re-export them from pr-comments-ai-launch-ack.ts for existing callers.

  • src/renderer/src/components/GitHubItemDialog.tsx#L156-L159: import both helpers from the new module.
  • src/renderer/src/components/PullRequestPage.tsx#L149-L152: import both helpers from the new module.
src/renderer/src/components/right-sidebar/checks-panel-content.tsx (1)

2021-2044: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

The nested-reply composer receives the left rail twice.

The wrapper adds ml-3 border-l-2 border-border/50 pl-3 for every comment in a thread group. renderReplyComposer runs in two positions:

  • Under group.root at Line 2090, outside presentation.repliesContainer.
  • Under each nested reply at Line 2104, inside presentation.repliesContainer, which already applies ml-3 border-l-2 border-border/50 (see pr-comment-presentation.ts Line 228).

In the second position the composer shows a doubled indent and two stacked rails. Key the indentation off the composer position instead of group.kind.

♻️ Proposed refactor
-  const renderReplyComposer = (comment: PRComment): React.ReactNode =>
+  const renderReplyComposer = (comment: PRComment, nested = false): React.ReactNode =>
     replyingCommentId === comment.id && onReply ? (
       <div
         className={cn(
           'px-3 pb-2',
           // Why: nest the composer under the parent the same way GitHub nests thread replies.
-          group.kind === 'thread' && 'ml-3 border-l-2 border-border/50 pl-3'
+          // The replies container already draws the rail, so only the root composer adds one.
+          group.kind === 'thread' && !nested && 'ml-3 border-l-2 border-border/50 pl-3'
         )}
       >
-                {renderReplyComposer(reply)}
+                {renderReplyComposer(reply, true)}
src/renderer/src/components/right-sidebar/runSourceControlAgentActionStart.test.ts (1)

108-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for launch acceptance on the onStart branch.

The new tests exercise acceptance only through the launchAgentInNewTab branch. The source also calls notifyLaunchAccepted() in the onStart branch at lines 91-93 of runSourceControlAgentActionStart.ts. That branch has different semantics: it never awaits a delivery result, so onLaunchAborted must never fire after a successful onStart.

Add a case that supplies onStart returning true and asserts onLaunchAccepted fired once and onLaunchAborted never fired. Add a second case where onStart returns false and assert neither callback fired.

🧪 Proposed test additions
+  it('accepts an onStart launch and never aborts it', async () => {
+    const onLaunchAccepted = vi.fn()
+    const onLaunchAborted = vi.fn()
+    const onStart = vi.fn().mockResolvedValue(true)
+
+    await expect(
+      runSourceControlAgentActionStart(
+        buildArgs({ onStart, onLaunchAccepted, onLaunchAborted })
+      )
+    ).resolves.toBe(true)
+
+    expect(onLaunchAccepted).toHaveBeenCalledTimes(1)
+    expect(onLaunchAborted).not.toHaveBeenCalled()
+    expect(mocks.onLaunched).toHaveBeenCalledTimes(1)
+  })
+
+  it('reports neither callback when onStart declines the launch', async () => {
+    const onLaunchAccepted = vi.fn()
+    const onLaunchAborted = vi.fn()
+    const onStart = vi.fn().mockResolvedValue(false)
+
+    await expect(
+      runSourceControlAgentActionStart(
+        buildArgs({ onStart, onLaunchAccepted, onLaunchAborted })
+      )
+    ).resolves.toBe(false)
+
+    expect(onLaunchAccepted).not.toHaveBeenCalled()
+    expect(onLaunchAborted).not.toHaveBeenCalled()
+  })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0e7f7e9f-df93-4220-b088-60a7bb9d0c35

📥 Commits

Reviewing files that changed from the base of the PR and between d426e35 and 786c82c.

📒 Files selected for processing (20)
  • src/renderer/src/components/GitHubItemDialog.tsx
  • src/renderer/src/components/PullRequestPage.tsx
  • src/renderer/src/components/pr-comments-resolution-prompt.ts
  • src/renderer/src/components/right-sidebar/ChecksPanel.tsx
  • src/renderer/src/components/right-sidebar/SourceControlAgentActionDialog.tsx
  • src/renderer/src/components/right-sidebar/checks-panel-content.tsx
  • src/renderer/src/components/right-sidebar/pr-comment-fixing-reply-body.ts
  • src/renderer/src/components/right-sidebar/pr-comment-presentation.test.ts
  • src/renderer/src/components/right-sidebar/pr-comment-presentation.ts
  • src/renderer/src/components/right-sidebar/pr-comments-ai-launch-ack.test.ts
  • src/renderer/src/components/right-sidebar/pr-comments-ai-launch-ack.ts
  • src/renderer/src/components/right-sidebar/runSourceControlAgentActionStart.test.ts
  • src/renderer/src/components/right-sidebar/runSourceControlAgentActionStart.ts
  • src/renderer/src/components/right-sidebar/useSourceControlAgentActionDialog.ts
  • src/renderer/src/components/right-sidebar/useSourceControlAgentActionStart.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json

Comment thread src/renderer/src/i18n/locales/en.json Resolved
Comment thread src/renderer/src/i18n/locales/ja.json Resolved
Use buildPRCommentConversationReplyBody to properly handle GitHub App
bot accounts, which don't resolve as @-mentions. Enforce delivery semantics
with type-safe PendingPRCommentAiAck payloads and improve error handling
around agent launch to prevent stranded state.
Move comment-resolution payload ref clears and latest-callback mirrors
into effects so render stays pure for the static analysis gate.
@AmethystLiang
AmethystLiang merged commit 5941c6c into main Aug 3, 2026
42 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Post fixing replies after launching PR comment resolution agents

Orca now automatically replies to selected comments after launching an
agent to resolve them. Review-thread comments get nested replies; review
summaries and issue comments get top-level @-replies. Payloads are
snapshotted at queue time and posted only after prompt delivery
succeeds. Bounded concurrency (4) prevents SSH slowdown.

* Batch conversation replies instead of posting per-comment

Combine N unresolvable comments into a single PR conversation reply to avoid timeline spam. Review threads still get one nested reply each. Refactor helper functions to pr-comment-fixing-reply-body.ts and change replyAsConversation(comment, body) → replyAsConversation(body).

* Handle bot account mentions in PR conversation replies

Use buildPRCommentConversationReplyBody to properly handle GitHub App
bot accounts, which don't resolve as @-mentions. Enforce delivery semantics
with type-safe PendingPRCommentAiAck payloads and improve error handling
around agent launch to prevent stranded state.

* Fix React Doctor ref-mutated-during-render errors in ChecksPanel

Move comment-resolution payload ref clears and latest-callback mirrors
into effects so render stays pure for the static analysis gate.
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.

1 participant