Skip to content

fix: prevent race condition in private annotation note creation#349

Merged
leotrs merged 2 commits intomainfrom
std-kt58
Mar 27, 2026
Merged

fix: prevent race condition in private annotation note creation#349
leotrs merged 2 commits intomainfrom
std-kt58

Conversation

@leotrs
Copy link
Copy Markdown
Collaborator

@leotrs leotrs commented Mar 27, 2026

Summary

  • Added SELECT FOR UPDATE lock on the annotation row before checking the max-1-note limit for private annotations, preventing concurrent requests from both passing the check and inserting duplicate notes
  • Added test for delete-and-recreate flow to verify soft-delete-aware counting works correctly

Test plan

  • Existing test_private_annotation_single_note_limit passes (sequential limit enforcement)
  • New test_private_annotation_note_limit_after_delete_and_recreate passes (soft-delete aware)
  • test_shared_annotation_multiple_notes passes (shared annotations unaffected)
  • Full backend suite: 721 passed, 0 failed

🤖 Generated with Claude Code

Use SELECT FOR UPDATE on the annotation row to serialize concurrent
requests, preventing two requests from both passing the max-1-note
check and inserting duplicate notes on private annotations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

Deploy Preview for rsm-studio-site canceled.

Name Link
🔨 Latest commit 1d2cf80
🔍 Latest deploy log https://app.netlify.com/projects/rsm-studio-site/deploys/69c6674bb482360008e431f1

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

Deploy Preview for rsm-studio-frontend canceled.

Name Link
🔨 Latest commit 1d2cf80
🔍 Latest deploy log https://app.netlify.com/projects/rsm-studio-frontend/deploys/69c6674c46a63f00083d4aa0

… check

scalar() returns Optional[int], causing mypy error when compared with >= 1.
scalar_one() is safe here since COUNT() always returns exactly one row.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leotrs leotrs merged commit 3da43b3 into main Mar 27, 2026
18 checks passed
@leotrs leotrs deleted the std-kt58 branch March 27, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant