[#<issue-number>] Improve export streaming and quota enforcement - #1601
Open
PHADAR6 wants to merge 8 commits into
Open
Conversation
|
@PHADAR6 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Author
|
@Disciplr-Org Hi! This PR is open and ready for review — happy to address any feedback. Thanks! |
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.
Overview
This PR makes export streaming and quota enforcement deterministic, atomic, and recoverable. It introduces an explicit export job state machine, atomic quota reservation, idempotent submission handling, stale-response guards, and a DLQ for failed jobs. The implementation enforces invariants at the database and service layers so concurrent requests cannot oversubscribe org quotas, duplicate submissions, or replay a failed on-chain action. Scope is limited to the export/export-quota feature; unrelated public behavior is preserved.
Related Issue
Refs #
Changes
🧭 Deterministic Export Job State Machine
[MODIFY]
src/services/exportService.tspending,quota_checked,streaming,completed,rejected,cancelled,failed,dlq.retry_key; duplicate submissions return the existing job instead of creating a new one.[ADD]
db/migrations/20260428130000_create_export_jobs.cjsjob_idandretry_key, check constraint onstate, and monotonicupdated_at.[ADD]
db/migrations/20260602130000_add_s3_key_to_export_jobs.cjs🔐 Atomic Quota Enforcement
[MODIFY]
src/services/quotaService.tsused + reserved <= total_limitwith row-level locks and conditional updates.[ADD]
db/migrations/20260602000000_create_org_quotas.cjstotal_limit,used,reserved, andversioncolumns for optimistic concurrency.🔁 Duplicate, Stale, and Recovery Handling
[MODIFY]
src/routes/exports.tsjob_idandstate; stale/superseded attempts return409 Conflict.[ADD]
db/migrations/20260725000000_create_export_dlq_entries.cjsjob_id,org_id,request_hash,failure_stage,attempt_count, andcreated_at.[ADD]
src/routes/exports.quota.test.tsVerification Results
Design tradeoffs:
job_id/statecannot receive stale-response conflict detection; the API falls back to returning the canonical current state.job_id/stateconflict handlingRefs #<issue-number>Closes #1536