feat(billing): persist transactional Stripe entitlement claims - #564
feat(billing): persist transactional Stripe entitlement claims#564seonghobae wants to merge 7 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Review failedAn error occurred during the review process. Please try again later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Buyer/data-integrity objective
Refs #488. This Draft child of #563 persists deterministic Stripe entitlement-policy decisions as append-only tenant-bound claim evidence. It selects current accepted Subscription/Invoice evidence itself, preserves exact source provenance, uses optimistic previous-decision concurrency to reject competing reconciliation, atomically advances a per-Subscription current head, and still does not mutate plan/session/RBAC authority or directly grant product access.
Exact current stack
feat/stripe-invoice-current-projection-488@74965da5be2dc78f29f73cece891d49b4527fc7e;c176efda6abbd3796fab776484422bb8efc612a8;Any parent/head movement invalidates this ancestry statement until freshly reconciled.
Durable decision contract
billing_stripe_entitlement_decisionsis append-only audit history with evaluated Subscription/Invoice observations, previous-decision link, action/reason, exact resulting claim provenance, and bounded evaluation/recording times;billing_stripe_entitlement_claim_headsstores one current decision pointer per Stripe Subscription and is not an authorization token;latest_invoice_idinside the transaction;expectedPreviousDecisionIdis an optimistic compare-and-swap token; mismatch returns a stable conflict rather than last-writer-wins history;server/db.mjsinstalls the schema at bootstrap after Subscription/Invoice evidence schemas and creates the production repository withderiveStripeSubscriptionEntitlement; request handlers do not create billing schema.Claim-head tenant-integrity repair
Fresh source review found that the previous schema independently referenced
claim_heads.subscription_idandclaim_heads.decision_idwithout proving that the pointed decision belonged to the same Subscription. A schema-valid mismatched head could therefore bind one Subscription identity to another Subscription's entitlement decision; downstream effective-plan reads could consume the mismatchedentitledvalue.TDD repair:
bb3d90ca02c5191025cb0039a903c3b845c8f71badded a realistic in-memory SQLite regression that creates decisions for two Subscriptions and requires a cross-Subscription head rebind to fail while a same-Subscription advance succeeds;c176efda6abbd3796fab776484422bb8efc612a8adds a composite candidate keyUNIQUE(subscription_id, decision_id)to decisions and a composite foreign key from claim heads to that exact pair;DatabaseSyncreproduction against the exact repaired DDL is GREEN: cross-Subscription rebind raisesFOREIGN KEY constraint failed, leaves the original head intact, and same-Subscription advance succeeds;The effective parent→child diff remains bounded to the claim-ledger slice plus this focused integrity regression; no auth/session, Clearfolio, attachment, workflow, dependency lockfile, scanner suppression, or branch-protection artifact is changed.
Current exact-head evidence
Fresh repository-native workflows for exact head
c176efda6abbd3796fab776484422bb8efc612a8are queued and therefore non-passing:32345673483;32345673484; and32345673936.There are no submitted reviews or review threads on this exact head. No predecessor-head, queued, absent, synthetic, status-only, author-only, or model-only evidence is treated as approval.
Scope boundary
This slice persists claim evidence only. It does not write
orgs.plan, issue capabilities, change membership/RBAC, or apply a grant/revoke to any authorization path. #565 owns effective-plan application and now inherits this exact claim-head integrity repair; #568 owns buyer-visible billing status and likewise inherits it through #565.Remain Draft. Do not integrate independently of #563 and its prerequisite stack. Exact-head deterministic/browser/coverage/security/dependency/supply-chain/review evidence must be regenerated on the unchanged final head before integration.