Repository navigation
Description
Bug Description
Three observed behaviours in the code-review queue, all visible on main at c3bbc90.
-
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 everyQUEUE_POLL_INTERVAL_SEC(default 5 s) and, each pass, callsIncidentQueue.claim_next(which listsqueue/pending/andqueue/reviews/and reads every key),IncidentQueue.recover_stale_processing(which lists and reads everyqueue/reviews/key), andIncidentQueue.list_pending_org_ids(which reads everyqueue/reviews/key in the bucket). Retention does not remove those objects;IncidentStore._compact_terminal_reviewreplaces 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". -
A Bitbucket pull request that is no longer open still queues a code review. The Bitbucket webhook accepts
pullrequest:createdandpullrequest:updatedand rejects onlydraft/state == "DRAFT". Apullrequest:updatedpayload whosepullrequest.stateisMERGEDorDECLINED, carrying asource.commit.hashnot seen before, is accepted and enqueued. The GitLab handler is keyed onactionand does not acceptmergeorclose, so this is Bitbucket-only. -
A review that ends
failedcan never run again for that commit. The dedupe record is the queue record and it survives every state, includingfailed. 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
- Configure storage and a webhook secret.
- Send a signed Bitbucket
pullrequest:createdpayload withpullrequest.state = "OPEN". A review is queued. - Complete it, then let retention run past
AUDIT_RETENTION_DAYS. Thequeue/reviews/<id>.jsonobject remains, compacted. - Repeat with
pullrequest.state = "MERGED"(or"DECLINED") and a freshsource.commit.hash. A code review is queued for a pull request that is already closed. - 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
OPENis ignored, with no enqueue. AnOPENpull request still queues exactly one review per head. - A review that ended
failedcan 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_keysover the review prefix plus oneget_jsonper key, three times per interval, per org. - A
MERGEDorDECLINEDBitbucket pull request with an unseen head is enqueued as acode_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=90Additional 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
[-]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[/+]