fix: prevent race condition in approval decisions#2
Closed
Conversation
CRITICAL: Use atomic UPDATE with status='pending' check in WHERE clause to prevent concurrent requests from both deciding the same approval. Before: Two concurrent requests could both read status='pending' and both modify the approval, causing duplicate notifications and confused audit trails. After: Only one request wins the race; the other gets None (already decided). Uses RETURNING clause to get the updated approval. Adds test_concurrent_decisions_race_condition to verify the fix.
Collaborator
Author
|
Implemented directly on master (a87af3f). Same atomic UPDATE fix, cleaner version without the silent decided_via default change. |
acartag7
pushed a commit
that referenced
this pull request
Mar 9, 2026
- POST /api/v1/bundles/evaluate — playground endpoint for testing contracts in dashboard (dashboard auth only, never called by agents) - GET /api/v1/stats/contracts — per-contract coverage stats with time-window filtering (since/until) - GET /api/v1/deployments — list deployments with env filter + limit - SSE bundle_uploaded event fired on bundle upload - Amend CLAUDE.md Principle #2 to document evaluate exception - 32 new tests (12 evaluate, 3 stats, 4 deployments, 1 SSE, 10 adversarial security, 2 tenant isolation) - 140/140 total tests pass, 0 regressions
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
Fixes a CRITICAL race condition in
submit_decision()that could allow two concurrent requests to both decide the same approval.The Problem
Attack Scenario:
The Fix
Use an atomic UPDATE with
status='pending'in the WHERE clause:Only ONE request wins the race. The other gets
None(already decided).Testing
Added
test_concurrent_decisions_race_conditionwhich simulates two concurrent decisions:asyncio.gather()with two decision attemptsSecurity Impact
Checklist