Repository navigation
fix: stop re-running code reviews on non-code webhook events (#93, #95) - #104
OkiriGabriel merged 5 commits into
Conversation
Allow created and updated pull request events and record the source head in the review context. Atomically reserve each tenant, provider, repository, change and head identity in queue storage so retries remain deduplicated across queue states. Co-Authored-By: GPT-6.1 Sol <[email protected]>
Derive review incident IDs from the five-field identity and atomically persist their queue records. Keep review state on the same object so redelivery cannot acknowledge a reservation without queued work, and confirm persisted work after ambiguous write failures. Adapt worker claims, recovery and retention to retain those records across queue states. Cover interrupted writes, synchronized failing-owner deliveries, worker recovery and ordinary enqueue compatibility. Co-Authored-By: GPT-6.1 Sol <[email protected]>
Apply configured retention to completed and failed review contexts in both the canonical queue record and the claim snapshot. Retain only identity, terminal status and timestamp in place so dedupe and stale-claim exclusion remain intact. Ignore terminal claim fences during recovery and cover held pending and processing snapshots, post-compaction redelivery, live payload preservation and ordinary retention. Co-Authored-By: GPT-6.1 Sol <[email protected]>
Queue merge-request reviews only for open, reopen, or updates carrying oldrev. Record the head commit for the existing durable review identity. Cover action filtering, tenant and head separation, terminal retries, ambiguous writes, interrupted compaction, and failed pipelines. Co-Authored-By: GPT-6.1 Sol <[email protected]>
OkiriGabriel
left a comment
There was a problem hiding this comment.
Thanks @Nitjsefnie. The event filtering is exactly what #93 and #95 needed:
- Bitbucket only reviews on
pullrequest:created/updated, which ends the comment loop. - GitLab only reviews on
open/reopen, orupdatewitholdrev. - Deduping on
(org, platform, repo, change, head_sha)handles Bitbucketupdatedevents that carry no new commits.
The idea is right, but I'd like the storage layout changed before merging.
Blocking: the queue loop reads every review record ever created, every few seconds
The review record lives in queue/reviews/ and is kept forever, because it is also the dedupe record. Retention only compacts it. But that prefix is scanned on the hot path:
claim_next:list_keys(review_prefix)plusget_jsonfor each key, per org, everyQUEUE_POLL_INTERVAL_SEC(default 5s)list_pending_org_ids:get_jsonfor every review key in the bucket, every poll
With S3, GCS or Azure, 5,000 historical reviews means about 2,000 GETs per second just to find nothing to do, and it keeps growing with every reviewed commit.
Suggested shape (keeps your dedupe semantics and makes the claim path simpler):
- Write a small dedupe marker with
put_json_if_absentat a key outsidequeue/, for examplereview_dedupe/<id>.json. - Only if that write created the marker, enqueue a normal
queue/pending/<id>entry. The existing claim, recover, completed and failed paths then work unchanged, with noreview_claimsfence,_state_keyor_get_processingspecial cases. - Retention can then delete old markers like any other object (or keep them, since they're never scanned).
Also worth deciding
With the current design, a review that ends failed (for example a transient Claude API error) can never run again for that commit; later webhooks are deduped against the failed record. Please allow re-enqueue when the existing marker is for a failed review, or delete the marker in mark_failed for review incidents.
Minor
GitHub pull_request events don't set head_sha, so GitHub reviews aren't deduped. That's out of scope for #93/#95, but pr["head"]["sha"] would be a one-line addition if you want it.
Note: this conflicts with #105 in tests/test_security.py (both append at the end). #105 is merging now, so please rebase.
Description
Bitbucket and GitLab webhooks enqueue a full code review for provider events that carry no new
reviewable code, and repeated deliveries of the same head enqueue the review again. The Bitbucket
handler accepted every
pullrequest:*event (includingcomment_created, which the agent's ownposted review comments cause, re-triggering reviews in a loop) and any payload containing a
pullrequestobject; the GitLab handler accepted MR metadata edits and approvals, and itscontext carried no head identity, so nothing could be deduplicated.
This PR makes both handlers enqueue a review only when new reviewable code actually arrives, and
gives every code-review enqueue a stable per-head identity:
pullrequest:createdandpullrequest:updated; comment, merge anddecline events (and a PR payload without an event key) are acknowledged as ignored.
open,reopen, andupdateonly whenobject_attributes.oldrevispresent (a code change); metadata-only updates and
approvedare ignored.head_sha).[org_id, scm_platform, repo, change_id, head_sha]and creates the queue record atomically(
put_json_if_absent), so a repeated delivery of the same head returns the original incidentid and enqueues nothing — across pending, processing, completed and failed states. A different
head, repository, MR/PR, provider or org enqueues separately.
existing retention pass to a minimal four-field record, so dedupe state never accumulates
review payloads; claim fencing and stale-claimant protection are preserved.
Fixes #93
Fixes #95
Type of Change
Platform/Component
Testing
Test Configuration
42 new parametrized cases in
tests/test_security.pycover both providers: ignored event classesenqueue zero reviews (each with a live-spy positive control), open/reopen/new-head enqueue exactly
one, repeat deliveries of the same
(org, provider, repository, change, head)enqueue exactly oneacross all four queue states (driven through the real
IncidentQueueover in-memory storage,including 8-thread concurrent deliveries), tenant separation, draft/WIP exclusion, and that the
failed-pipeline branch still enqueues. Deterministic fault-injection tests cover interrupted
writes, ambiguous write acknowledgement, and retention compaction at the fence/canonical write
boundary. Both provider mutations were individually reintroduced during development and each was
caught by its named test. Locally,
python3 -m pytest tests/test_security.py -qends at88 passed; the full suite runs in CI.
Checklist
Breaking Changes
None. The webhook API surface, authentication, and response shapes are unchanged; events that
previously re-triggered reviews now receive the same HTTP 200 acknowledgement with
status: "ignored".Additional Notes
The per-head dedupe applies to events that carry a head commit (real provider payloads do);
enqueues without a complete identity keep the pre-existing ordinary queue behavior.
Generated by GPT-6.1 Sol (implementation, review), GPT-6 Astra (review), GLM-5.3-Flash (lead)