Skip to content

fix(api): make daily submission quota race-free - #111

Open
anuraggdubey wants to merge 2 commits into
NEARBuilders:mainfrom
anuraggdubey:fix-issue-93-race-free-quota
Open

anuraggdubey wants to merge 2 commits into
NEARBuilders:mainfrom
anuraggdubey:fix-issue-93-race-free-quota

Conversation

@anuraggdubey

Copy link
Copy Markdown
Contributor

Summary

Fixes #93.

The daily submission quota is now enforced atomically per Activity Source:

submit event
  acquire transaction-scoped source lock
  check idempotency key
  count recent submissions
  reject with TOO_MANY_REQUESTS when quota is full
  reserve submission
  release lock

Changes:

  • Added a PostgreSQL advisory transaction lock for quota-limited sources.
  • Preserved idempotent retries and 409 CONFLICT behavior.
  • Added concurrent quota regression coverage.
  • Updated the Signing Identity rotation runbook.

Evidence

  • Before: Concurrent submissions could pass the quota count before either reservation was inserted.
  • After: The quota check and reservation occur under a per-source transaction lock.
  • TypeScript check passed.
  • Activity ingestion and credential integration tests passed: 21 tests.
  • Concurrent submissions correctly allow only the remaining quota and reject excess requests.
  • Final diff contains only three intended files.

This branch has not been deployed

No deployments
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.

Make the daily submission quota race-free

1 participant