Skip to content

fix: stop re-running code reviews on non-code webhook events (#93, #95) - #104

Merged
OkiriGabriel merged 5 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/review-trigger-events
Oct 20, 2026
Merged

OkiriGabriel merged 5 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/review-trigger-events

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

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 (including comment_created, which the agent's own
posted review comments cause, re-triggering reviews in a loop) and any payload containing a
pullrequest object; the GitLab handler accepted MR metadata edits and approvals, and its
context 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:

  • Bitbucket enqueues only on pullrequest:created and pullrequest:updated; comment, merge and
    decline events (and a PR payload without an event key) are acknowledged as ignored.
  • GitLab enqueues on open, reopen, and update only when object_attributes.oldrev is
    present (a code change); metadata-only updates and approved are ignored.
  • Both record the head commit in the review context (head_sha).
  • The incident queue derives a stable incident id from the SHA-256 of
    [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 incident
    id and enqueues nothing — across pending, processing, completed and failed states. A different
    head, repository, MR/PR, provider or org enqueues separately.
  • Terminal (completed/failed) review records keep their identity but are compacted by the
    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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • New platform/collector support

Platform/Component

  • Core Agent
  • Kubernetes
  • CI/CD (specify: ____________)
  • Cloud Provider (specify: ____________)
  • ArgoCD
  • Docker
  • API Server
  • Tools/Executor
  • Documentation
  • Tests

Testing

  • Unit tests added/updated
  • Integration tests pass
  • Manual testing performed
  • Tested with dummy data
  • Tested in production-like environment

Test Configuration

OS: Linux (Debian 13)
Python Version: 3.11
Kubernetes Version: (not applicable)
Cloud Provider: (not applicable)

42 new parametrized cases in tests/test_security.py cover both providers: ignored event classes
enqueue 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 one
across all four queue states (driven through the real IncidentQueue over 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 -q ends at
88 passed; the full suite runs in CI.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

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)

Nitjsefnie and others added 4 commits October 19, 2026 18:24
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 OkiriGabriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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, or update with oldrev.
  • Deduping on (org, platform, repo, change, head_sha) handles Bitbucket updated events 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) plus get_json for each key, per org, every QUEUE_POLL_INTERVAL_SEC (default 5s)
  • list_pending_org_ids: get_json for 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):

  1. Write a small dedupe marker with put_json_if_absent at a key outside queue/, for example review_dedupe/<id>.json.
  2. 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 no review_claims fence, _state_key or _get_processing special cases.
  3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants