fix: guard against double-approve/reject on resolved approvals#278
Open
aramirez087 wants to merge 6 commits intoabhi1693:masterfrom
Open
fix: guard against double-approve/reject on resolved approvals#278aramirez087 wants to merge 6 commits intoabhi1693:masterfrom
aramirez087 wants to merge 6 commits intoabhi1693:masterfrom
Conversation
The PATCH /boards/{id}/approvals/{id} endpoint accepted status changes
on already-resolved approvals. A client retry or race condition could
re-trigger the approval side-effect (e.g. a second X API post).
Resolved approvals (status = approved | rejected) are now immutable.
Any attempt to change their status returns 409 Conflict with a clear
message indicating the current and requested status.
Covers: approve→approve, reject→reject, approve→reject, reject→approve,
approved→pending, rejected→pending.
Found by: Sentinel (QA lead agent) integration tests — task 3.4.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes resolved approvals (status approved/rejected) immutable by rejecting any subsequent status updates with a 409 Conflict, and updates the test suite to cover the new immutability behavior.
Changes:
- Add an early
409guard inupdate_approvalto block status updates once an approval is resolved. - Update/expand approval conflict tests to assert
409responses for double-approve/double-reject and attempts to change resolved approvals.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/app/api/approvals.py | Adds immutability guard for resolved approvals inside update_approval. |
| backend/tests/test_approvals_pending_conflicts.py | Reworks and adds tests validating 409 behavior when attempting to update resolved approvals. |
The resolved-approval guard makes the `if target_status == "pending" and prior_status != "pending"` branch unreachable — the only non-pending prior statuses are "approved" and "rejected", which now early-raise. Remove the dead code as suggested in review. The `load_task_ids_by_approval` import stays (used elsewhere in the file). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes the approval update behavior to treat resolved approvals (approved/rejected) as immutable with respect to status changes, and updates the backend test suite to cover the new 409-conflict semantics for repeated or invalid status updates.
Changes:
- Add a 409 guard in
update_approvalpreventing any status mutation once an approval is resolved. - Replace/extend approval update tests to assert 409 responses for double-approve, double-reject, approving a rejected approval, and reopening a resolved approval to pending.
- Update expected error payload shape in tests (
message,current_status,requested_status).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
backend/app/api/approvals.py |
Enforces “resolved approvals are immutable” by rejecting status updates for approved/rejected approvals with a 409 detail payload. |
backend/tests/test_approvals_pending_conflicts.py |
Adds/adjusts asyncio tests to validate the new 409 behavior and error details for various resolved-status update attempts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
approved/rejected) are now immutable — any attempt to change their status returns409 ConflictBug
PATCH /boards/{id}/approvals/{id}accepted status changes on already-resolved approvals. Calling approve on an already-approved item silently returned 200 and updatedresolved_at, which could trigger duplicate external actions downstream.Found by: automated integration tests (task 3.4 — route handler coverage).
Change
backend/app/api/approvals.py— 11-line guard added before the existing pending-conflict check:backend/tests/test_approvals_pending_conflicts.py— 3 new tests + 1 updated:test_update_approval_rejects_double_approvetest_update_approval_rejects_double_rejecttest_update_approval_rejects_approving_rejectedtest_update_approval_rejects_reopening_resolved_to_pending(updated from prior test)Test plan
make backend-test— 472 passed, 0 failed🤖 Generated with Claude Code