Skip to content

Handle @mentions in PR review submissions - #314

Merged
jwbron merged 2 commits into
mainfrom
egg/handle-review-mentions
Feb 8, 2026
Merged

jwbron merged 2 commits into
mainfrom
egg/handle-review-mentions

Conversation

@james-in-a-box

@james-in-a-box james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Handle @mentions in PR review submissions

The on-mention workflow handled issue_comment, pull_request_review_comment, and issues events, but not pull_request_review events (full review submissions). When a user submitted a review body containing @james-in-a-box, the workflow never triggered because pull_request_review:submitted was not a registered event.

This adds pull_request_review:submitted as a trigger with corresponding handling throughout the pipeline:

  • Mention detection condition checks github.event.review.body
  • Acknowledgment posts a comment (no reaction API exists for reviews)
  • Checkout ref and result comment steps handle the event's payload structure
  • Prompt builder extracts review body and fetches any inline comments attached to the review

Reproducer: PR #311 — jwbron submitted a review tagging @james-in-a-box which was silently ignored.

Issue: none

Test plan:

  • Submit a review on a PR with @james-in-a-box in the body
  • Verify the on-mention workflow triggers
  • Verify egg acknowledges, checks out the PR branch, and responds

Authored-by: egg

The on-mention workflow only handled pull_request_review_comment events
(inline code comments), not pull_request_review events (full review
submissions). When a user submitted a review with @james-in-a-box in
the body, the workflow never triggered.

Add pull_request_review:submitted as a trigger event, with corresponding
mention detection, acknowledgment, checkout ref, and prompt building
logic. The prompt builder also fetches any inline comments attached to
the review for full context.

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No agent-mode design concerns.

The new pull_request_review event handler follows the same patterns as the existing issue_comment and pull_request_review_comment handlers. The context assembled is lightweight orientation data:

  • Metadata (PR number, title, state, branches) — exactly what the agent needs to understand the task
  • Changed files list (filenames only) — not diffs, just a list to orient the agent
  • Recent comments (last 10, truncated) — helps the agent understand conversation context
  • Review body and inline comments — the actual feedback to address

This aligns well with the guidelines. The script provides orientation (what PR, what feedback, what branch) rather than constraining the agent with pre-fetched diffs. The agent is free to explore the codebase, fetch file contents it needs, and decide how to address the feedback.

The inline review comments include diff_hunk which is a small snippet around each comment — this is reasonable context for understanding what each comment refers to, not excessive pre-fetching.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review: Handle @mentions in PR review submissions

The PR correctly addresses the gap where pull_request_review:submitted events were not triggering the on-mention workflow. The implementation follows existing patterns. I found issues that need attention.


Issue 1: Missing null/empty fallback for review_body extraction

Location: action/build-mention-prompt.sh:267

Problem: The review_body is extracted without a null fallback:

review_body=$(jq_raw '.review.body')

But other body fields in the script use // "" to handle null:

issue_body=$(truncate_text "$(jq_raw '.issue.body // ""')" "$MAX_BODY_CHARS")
pr_body_raw=$(echo "$pr_details" | jq -r '.body // ""')

GitHub reviews can have null bodies — for example, when a reviewer submits an "Approve" or "Request changes" with only inline comments and no summary body. When jq -r encounters null, it outputs the literal string null rather than an empty string.

Impact: The prompt would contain the literal text null instead of being empty, which would confuse the agent.

Fix:

review_body=$(jq_raw '.review.body // ""')

Issue 2: diff_hunk in review comments is not truncated

Location: action/build-mention-prompt.sh:292-293

Problem: The inline review comments fetched via the API include diff_hunk without truncation:

review_comments=$(gh_api_safe "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}/reviews/${review_id}/comments" \
  --jq '.[] | "### \(.path):\(.line // .original_line // "?")\n\(.diff_hunk)\n\n\(.body)\n"' 2>/dev/null || true)

Compare with the existing pull_request_review_comment handler at line 201, which properly truncates:

diff_hunk=$(truncate_text "$(jq_raw '.comment.diff_hunk // ""')" "$MAX_BODY_CHARS")

Impact: A review with many inline comments could produce an excessively large prompt, hitting the MAX_PROMPT_CHARS limit or consuming unnecessary context. The final truncate_text "$prompt" "$MAX_PROMPT_CHARS" at line 367 will catch it, but individual diff hunks could be huge before that global truncation kicks in.

Suggested fix: Either truncate each diff_hunk within the jq expression (complex), or post-process the output to limit each hunk. Alternatively, add a note that this is an accepted limitation for V1.


Issue 3: Potential null handling issue in workflow condition

Location: .github/workflows/on-mention.yml:23

Problem: The condition checks:

(github.event_name == 'pull_request_review' && (contains(github.event.review.body, '@james-in-a-box') || contains(github.event.review.body, '@egg')))

When review.body is null (which happens for reviews with only inline comments), the contains() function behavior is not well-documented. Testing suggests it returns false for null inputs, which is the desired behavior here. However, the existing handlers use contains(github.event.comment.body, ...) where comment.body is always a string.

Severity: Low — likely correct behavior, but the difference in data contracts across event types is worth noting. Consider whether a defensive github.event.review.body != null && prefix is warranted for clarity.


Observation: Redundant stderr redirect

Location: action/build-mention-prompt.sh:293

review_comments=$(gh_api_safe "repos/..." ... 2>/dev/null || true)

The gh_api_safe wrapper already handles stderr and returns 0 on failure. The 2>/dev/null || true is redundant but harmless.


Observation: Consistent pattern

The implementation correctly mirrors the existing pull_request_review_comment handler's structure:

  • Fetches PR details, files, recent comments
  • Builds a prompt with the same sections
  • Handles checkout ref determination in the workflow

The review state is surfaced (Review state: ${review_state}), which is useful context for the agent.


Verdict: Request Changes

Issue 1 (null fallback for review_body) is a bug that will produce confusing prompts. Issue 2 (untruncated diff hunks) is a correctness concern that may cause issues with large reviews.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@jwbron

jwbron commented Feb 8, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box address this feedback #314 (review)

- Add null fallback for review_body extraction to handle reviews
  submitted with only inline comments (no summary body)
- Truncate diff_hunk in review comments to prevent excessively
  large prompts from reviews with many inline comments
- Add defensive null check in workflow condition for review.body
- Remove redundant stderr redirect (gh_api_safe handles it)

Authored-by: egg

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. All feedback addressed in 1b16121:

Issue 1 (null fallback): Added // "" fallback for review_body extraction at line 267.

Issue 2 (diff_hunk truncation): Rewrote the review comments fetching to process each comment individually in bash, applying truncate_text to each diff_hunk. This uses base64 encoding to safely handle multi-line content and applies the same $MAX_BODY_CHARS limit used elsewhere.

Issue 3 (null check in condition): Added github.event.review.body != null && prefix for explicit null handling.

Observation (redundant stderr): Removed as part of the Issue 2 rewrite — the new code uses gh_api_safe directly without the redundant 2>/dev/null || true.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agent-mode design re-review: No concerns with the follow-up changes.

The diff_hunk truncation at line 297 (truncate_text "$diff_hunk" "$MAX_BODY_CHARS") is a positive change from an agent-mode perspective — it prevents excessively large context from reviews with many inline comments while still providing enough snippet to orient the agent on what each comment refers to.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-review: All previous issues addressed

The four issues from my previous review have been properly fixed:

  1. Null fallback for review_body — Fixed at line 267 with // ""
  2. diff_hunk truncation — Fixed at lines 295-307; each comment is processed individually with truncate_text applied to each diff_hunk
  3. Null check in workflow condition — Fixed at line 23 with github.event.review.body != null &&
  4. Redundant stderr redirect — Removed in the rewrite

New Issue: Subshell variable loss in review comments loop

Location: action/build-mention-prompt.sh:295-307

Problem: The while read loop runs in a subshell due to the pipe from echo ... | jq ... | while. In bash, variables assigned in a subshell are not visible to the parent shell. The review_comments variable captures the output correctly via command substitution, so this works. However, if someone later tries to modify this pattern (e.g., to count comments or accumulate state), they'll encounter unexpected behavior.

Severity: Low — informational. The current code works correctly because the entire loop output is captured by command substitution. No fix required, but a comment noting this pattern would prevent future confusion.


Verdict: Approve

All blocking issues from the previous review have been resolved correctly. The implementation follows existing patterns in the codebase and the code is correct.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@jwbron
jwbron merged commit ceafb5b into main Feb 8, 2026
15 checks passed
github-actions Bot pushed a commit that referenced this pull request Feb 8, 2026
Update documentation to reflect PR review submission support added in
commit ceafb5b (PR #314).

The on-mention workflow now handles pull_request_review events (full
review submissions with @mention in the body) in addition to
pull_request_review_comment events (inline code comments).

Triggered by: https://github.com/anthropics/egg/pull/314

Authored-by: egg
jwbron added a commit that referenced this pull request Feb 8, 2026
…320)

Update documentation to reflect PR review submission support added in
commit ceafb5b (PR #314).

The on-mention workflow now handles pull_request_review events (full
review submissions with @mention in the body) in addition to
pull_request_review_comment events (inline code comments).

Triggered by: https://github.com/anthropics/egg/pull/314

Authored-by: egg

Co-authored-by: jwbron <8340608+jwbron@users.noreply.github.com>
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