Skip to content

fix: make complete_review idempotent and return 409 on re-completion (issue #1873) - #1907

Merged
komalharshita merged 2 commits into
komalharshita:mainfrom
ionfwsrijan:fix/1873-complete-review-idempotent
Aug 16, 2026
Merged

fix: make complete_review idempotent and return 409 on re-completion (issue #1873)#1907
komalharshita merged 2 commits into
komalharshita:mainfrom
ionfwsrijan:fix/1873-complete-review-idempotent

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Problem

complete_review is not idempotent: calling it twice on the same review recomputes the score, overwrites completed_at/overall_score/status, and increments submission["review_count"] a second time. A client retry or double-click silently inflated the review count and re-stamped the completed review, even though the API always returned 200.

Fix

  • Added ReviewAlreadyCompletedError in src/utils/code_review.py.
  • complete_review now raises ReviewAlreadyCompletedError when review["completed_at"] is already set, before recomputing scores or touching the submission. review_count is only ever incremented on the transition from a non-completed state.
  • The route catches the new exception and returns HTTP 409 Conflict; the completed review and its review_count/metrics remain untouched.

Files changed

  • src/utils/code_review.py — new ReviewAlreadyCompletedError; idempotency guard in complete_review.
  • src/routes/main_routes.py — catch ReviewAlreadyCompletedError and return 409.
  • tests/test_code_review.py — regression test asserting double-completion raises the error, does not inflate review_count, and does not restamp completed_at/overall_score/summary.

Testing

  • Isolated test run of tests/test_code_review.py — 20 passed (19 existing + 1 new).
  • Route simulation confirmed first complete returns 200 (review_count=1), second complete returns 409 and leaves review_count=1.

Closes #1873

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@ionfwsrijan is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread src/routes/main_routes.py Fixed
@komalharshita
komalharshita merged commit 721b1fe into komalharshita:main Aug 16, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: complete_review is not idempotent - retries inflate review_count and restamp completed reviews

3 participants