Skip to content

fix: keep the triggering review/comment in prompt context (#1522) - #1525

Open
TemRevil wants to merge 1 commit into
anthropics:mainfrom
TemRevil:fix/pr-review-trigger-context
Open

TemRevil wants to merge 1 commit into
anthropics:mainfrom
TemRevil:fix/pr-review-trigger-context

Conversation

@TemRevil

Copy link
Copy Markdown
Contributor

Fixes #1522.

Problem

filterReviewsToTriggerTime() / filterCommentsToTriggerTime() drop any entity whose submit/creation time is >= triggerTime, to keep content injected at/after the trigger out of the prompt (TOCTOU protection). But the entity that is the trigger is submitted/created exactly at triggerTime, so >= always filtered it out.

For a pull_request_review trigger this dropped the triggering review and all of its inline comments (they hang off the review node, which was removed). When a reviewer submits only inline comments with an empty body, <review_comments> renders "No review comments" and Claude receives nothing about the review it is supposed to respond to.

The edit-time check compounds it: reviews fetch updatedAt, which GitHub stamps at submit time, so even relaxing the submit comparison alone wouldn't be enough.

Fix

Retain the entity whose databaseId matches the triggering webhook payload id, exempting only that one entity from both the submit/create and edit-time checks. The >= comparison is left untouched for every other entity, so post-trigger injection is still filtered — this is deliberately narrower than relaxing >= to >, which would admit any same-second entity.

  • New extractTriggerEntityId(context) returns review.id / comment.id from the payload (mirrors extractTriggerTimestamp).
  • Threaded through fetchGitHubData to both filters (covers pull_request_review, pull_request_review_comment, and issue_comment triggers).
  • databaseId is string-compared: the GraphQL id is a string, the webhook id is a number.

Tests

Added 4 tests to test/data-fetcher.test.ts:

  • the triggering review is dropped without the id and kept when the id is passed;
  • it's kept even when updatedAt is bumped to the submit time (edit-check bypass);
  • a non-trigger review submitted at the same time is still dropped (the exemption is precise);
  • the triggering comment created exactly at trigger time is kept.

bun test test/data-fetcher.test.ts → 80 pass / 0 fail. bun run typecheck clean. Only the two touched source files + the test are changed.

filterReviewsToTriggerTime() and filterCommentsToTriggerTime() drop any
entity whose submit/creation time is >= the trigger time, to exclude
content injected at or after the trigger. But the entity that triggered
the run is submitted/created exactly at the trigger time, so it was
always filtered out. For a pull_request_review trigger this dropped the
triggering review and all of its inline comments; a review with only
inline comments and an empty body left <review_comments> empty and
Claude had nothing to respond to.

Retain the entity whose databaseId matches the triggering webhook payload
id (new extractTriggerEntityId), bypassing both the submit/create and the
edit-time checks for that one entity while leaving the >= comparison
intact for every other entity, so post-trigger injection is still
filtered. databaseId is compared as a string because the GraphQL id is a
string while the webhook payload id is a number.

Fixes anthropics#1522
@TemRevil
TemRevil force-pushed the fix/pr-review-trigger-context branch from 628731a to d84cf91 Compare August 7, 2026 22:30
@TemRevil

TemRevil commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main, the conflict was from #1592 touching this same file for an unrelated timestamp feature. Trigger-entity-id fix is back on top, typecheck and the data-fetcher/tag suites are green.

@TemRevil

Copy link
Copy Markdown
Contributor Author

@ashwin-ant #1526 went in on the 20th, this one has been sitting since July without a look. Still rebased and green as of the 7th, happy to redo it if it has drifted since.

This branch has not been deployed

No deployments
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.

pull_request_review trigger: the triggering review is always filtered out of the prompt context (submittedAt >= triggerTime)

1 participant