Skip to content

feat: handle pull_request_review webhook event for changes_requested on bot PRs (CYPACK-842)#896

Merged
PaytonWebber merged 5 commits intomainfrom
cypack-842
Mar 4, 2026
Merged

feat: handle pull_request_review webhook event for changes_requested on bot PRs (CYPACK-842)#896
PaytonWebber merged 5 commits intomainfrom
cypack-842

Conversation

@cyrusagent
Copy link
Contributor

@cyrusagent cyrusagent commented Feb 23, 2026

Summary

  • PR change request handling: When a reviewer requests changes on a PR created by Cyrus, the agent now automatically acknowledges the review and starts working on the requested changes. Supports both summary-level and line-level review comments.
  • Slack bot token fallback: Fixed Slack bot token not being available when switching from cloud to self-host runtime. The token is now resolved at usage time with a process.env fallback.
  • Empty review body handling: When a review has no summary body (only line-level comments), the agent is instructed to fetch inline comments via gh api.
  • Proxy mode for cloud droplets: Slack webhook verification uses proxy mode when running on cloud droplets (matching GitHub webhook behavior).

Commits

  1. feat: handle pull_request_review webhook event for changes_requested on bot PRs — New pull_request_review event type in cyrus-github-event-transport, EdgeWorker handler with acknowledgement comment, change-request system prompt, and defensive changes_requested state check.
  2. fix: use proxy mode for Slack webhooks on cloud droplets — Aligns Slack webhook verification mode with GitHub webhooks on cloud droplets.
  3. fix: provide fallback prompt when review body is empty — When a review body is empty, instructs the agent to use gh api to read PR review comments.
  4. fix: resolve Slack bot token unavailable after runtime switch — Added getSlackBotToken() helper to SlackChatAdapter with process.env.SLACK_BOT_TOKEN fallback.

Test plan

  • All 754+ package tests pass (pnpm test:packages:run)
  • TypeScript compiles for all modified packages
  • Lint clean
  • F1 test drive for pull_request_review webhook handling
  • Manual validation: runtime switch (cloud → self-host) with Slack bot token

Closes CYPACK-842

@cyrusagent cyrusagent marked this pull request as ready for review February 23, 2026 18:52
cyrusagent and others added 4 commits March 3, 2026 14:31
…on bot PRs (CYPACK-842)

Add support for the pull_request_review GitHub webhook event type so that
when a reviewer requests changes on a PR created by cyrusagent, the client
posts an instant acknowledgement comment and starts working on the changes.

- Add GitHubReview and GitHubPullRequestReviewPayload types
- Extend GitHubEventType union to include pull_request_review
- Add isPullRequestReviewPayload type guard; disambiguate from review comments
- Update all extractor functions to handle review payloads
- Add translatePullRequestReview methods to GitHubMessageTranslator
- Handle pull_request_review in EdgeWorker with acknowledgement comment,
  change request system prompt, and empty review body fallback
- Update core platform data types to include pull_request_review eventType
- Add comprehensive tests for all new functionality

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CYHOST forwards Slack webhooks with Bearer token auth — it verifies
the original Slack signature itself and does not forward the
X-Slack-Signature/X-Slack-Request-Timestamp headers to the droplet.

Only use direct Slack signature verification when both
SLACK_SIGNING_SECRET is set AND CYRUS_HOST_EXTERNAL=true (self-hosted).
Cloud droplets now correctly fall back to proxy mode (Bearer token).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a pull_request_review has an empty body (reviewer only left
line-level comments), the taskInstructions was an empty string.
This caused Claude's API to reject the request with "cache_control
cannot be set for empty text blocks".

Provide a meaningful fallback prompt instructing the agent to read
the review comments to understand what needs to be changed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-842)

Add process.env.SLACK_BOT_TOKEN fallback in SlackChatAdapter so the
token is resolved at usage time rather than only at event-creation time.
During startup transitions (e.g. switching from cloud to self-host),
the env update carrying the token may arrive after the first webhook,
causing the event object to have an undefined slackBotToken. The
fallback ensures the token is picked up once it becomes available in
process.env.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PaytonWebber
Copy link
Collaborator

@cyrusagent does this require the GH token ENV var to be on path at runtime?

@cyrusagent-staging
Copy link

This repository is not configured with Cyrus. Please add it at https://app.atcyrus.com/repos to start using Cyrus here.

@ghost
Copy link

ghost commented Mar 3, 2026

I can't connect to your local environment because the Cyrus process isn't running. Run cyrus in your terminal and keep it running, then mention me again.

@cyrusagent
Copy link

cyrusagent bot commented Mar 3, 2026

No, this PR does not require a new GH token env var. The existing pattern is already in place:

  1. The primary auth mechanism is the GitHub App installation token, forwarded from the proxy via the x-github-installation-token header (line 182 of GitHubEventTransport.ts) and passed through as event.installationToken.

  2. process.env.GITHUB_TOKEN is only used as a fallback — this was already the case before this PR (see EdgeWorker.ts:900, :1166, :1375).

The new pull_request_review handling reuses the exact same event.installationToken || process.env.GITHUB_TOKEN pattern that issue_comment and pull_request_review_comment already use. No new env vars were introduced.

TL;DR: If your deployment already handles GitHub webhooks (with the proxy forwarding installation tokens), this PR works out of the box. The GITHUB_TOKEN fallback is unchanged and only needed for non-GitHub-App setups.

…ts (CYPACK-842)

The mention gate ran before the review-type check, silently dropping all
pull_request_review webhooks when GITHUB_BOT_USERNAME was set. Reorder
guards so the changes_requested state check and mention-skip happen in
the correct sequence. Also add an explicit prNumber null guard, extract
duplicated review-to-comment mapping into buildReviewAsCommentRef, and
use nullish coalescing in getSlackBotToken.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PaytonWebber PaytonWebber merged commit 516ea63 into main Mar 4, 2026
6 checks passed
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.

2 participants