Skip to content

Review queue rescans every historical review, Bitbucket queues reviews for non-open pull requests, and a failed review never retries #108

Closed

Description

@Nitjsefnie

Bug Description

Three observed behaviours in the code-review queue, all visible on main at c3bbc90.

  1. The review dedupe record is also the queue record, and it lives in the prefix the poll loop scans. A code review is stored at queue/reviews/<incident_id>.json, and that object stays for the life of the deployment because it is what dedupes a repeated webhook. The queue worker polls every QUEUE_POLL_INTERVAL_SEC (default 5 s) and, each pass, calls IncidentQueue.claim_next (which lists queue/pending/ and queue/reviews/ and reads every key), IncidentQueue.recover_stale_processing (which lists and reads every queue/reviews/ key), and IncidentQueue.list_pending_org_ids (which reads every queue/reviews/ key in the bucket). Retention does not remove those objects; IncidentStore._compact_terminal_review replaces a finished record with a four-field minimal copy and keeps the key. So the number of storage reads per poll grows without bound with the number of reviews the deployment has ever processed, on a path whose steady-state answer is "nothing to do".

  2. A Bitbucket pull request that is no longer open still queues a code review. The Bitbucket webhook accepts pullrequest:created and pullrequest:updated and rejects only draft/state == "DRAFT". A pullrequest:updated payload whose pullrequest.state is MERGED or DECLINED, carrying a source.commit.hash not seen before, is accepted and enqueued. The GitLab handler is keyed on action and does not accept merge or close, so this is Bitbucket-only.

  3. A review that ends failed can never run again for that commit. The dedupe record is the queue record and it survives every state, including failed. A review that dies on a transient error, such as a model API timeout, leaves its record behind; every later webhook for the same head is deduped against it, so the review is never retried and the failure is permanent for that commit.

Steps to Reproduce

  1. Configure storage and a webhook secret.
  2. Send a signed Bitbucket pullrequest:created payload with pullrequest.state = "OPEN". A review is queued.
  3. Complete it, then let retention run past AUDIT_RETENTION_DAYS. The queue/reviews/<id>.json object remains, compacted.
  4. Repeat with pullrequest.state = "MERGED" (or "DECLINED") and a fresh source.commit.hash. A code review is queued for a pull request that is already closed.
  5. For the third behaviour: let a review end failed (any transient error on the processing path), then deliver the same head again. No review runs.

Expected Behavior

  • The number of storage reads performed by an idle poll pass does not grow with the number of reviews the deployment has previously processed. Dedupe still holds: the same review head is not queued twice, and no interrupted write can either drop a review that was never queued or queue one twice.
  • A Bitbucket webhook whose pull request is not OPEN is ignored, with no enqueue. An OPEN pull request still queues exactly one review per head.
  • A review that ended failed can be re-enqueued by a later delivery for the same head, exactly once. A review that completed still dedupes.

Actual Behavior

  • An idle poll pass reads every historical review object: list_keys over the review prefix plus one get_json per key, three times per interval, per org.
  • A MERGED or DECLINED Bitbucket pull request with an unseen head is enqueued as a code_review.
  • A failed review's head is deduped forever, so the review never retries.

Environment

  • OS: any
  • Python Version: 3.10 / 3.11 / 3.12 (the CI matrix)
  • Agent Version/Commit: c3bbc901b6b17fd473c4df2b26a078eab2816213
  • Deployment Method: any backend (MemoryStorage, S3, GCS, Azure)
  • Platform: Bitbucket Cloud webhooks

Configuration

QUEUE_POLL_INTERVAL_SEC=5
AUDIT_RETENTION_DAYS=90

Additional Context

This is a follow-up to #104. The storage-layout change was requested in review on that pull request but the merge landed without it, and the review-trigger regression tests that #104 added to tests/test_security.py were dropped when main was merged into the branch, so neither behaviour is covered by a test today. The third behaviour was raised in the same review.

Possible Solution

Not verified. The shape suggested in the #104 review: write a small dedupe marker with put_json_if_absent at a key outside queue/, and enqueue a normal queue/pending/ entry only when that write created the marker, so the claim, recovery, completed and failed paths keep working unchanged and retention can treat the markers as ordinary objects. For the third behaviour, the same review offers two options: allow re-enqueue when the existing marker is for a failed review, or delete the marker in mark_failed for review incidents.

Activity

  1. changed the title [-]Review queue polls read every historical review record, and Bitbucket queues reviews for non-open pull requests[/-] [+]Review queue rescans every historical review, Bitbucket queues reviews for non-open pull requests, and a failed review never retries[/+] on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions