feat(db): add service fee assessment schema and billing ADR - #5236
feat(db): add service fee assessment schema and billing ADR#5236jeanduplessis wants to merge 9 commits into
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryIncremental docs-only follow-up aligns SPEC, VALIDATION, and ADR 0004 with the two-table exemption-log design; previous schema-mismatch findings are resolved. Files Reviewed (3 files)
Previous Review Summaries (4 snapshots, latest commit 2e27cdb)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 2e27cdb)Status: 4 Issues Found | Recommendation: Address before merge Executive SummaryThe schema reduction is consistent, but SPEC/VALIDATION still describe the removed two-table exemption write, a third assessment table/ Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (7 files)
Fix these issues in Kilo Cloud Previous review (commit 88b4136)Status: 2 Issues Found | Recommendation: Address before merge Executive SummaryThe latest commit fixed the ADR invariant cross-reference and started fixing the Phase 6 numbering, but the renumbering is incomplete ( Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (2 files)
Notes: Incremental review of commit 88b4136 (two one-line documentation fixes). The ADR fix was verified against the Invariants section — Invariant 11 is indeed the Stripe test-mode coupon-allocation proof. The previous duplicate Fix these issues in Kilo Cloud Previous review (commit 97a395c)Status: 3 Issues Found | Recommendation: Address before merge Executive SummaryThe new service-fee GOAL/SPEC/VALIDATION plan documents are internally consistent and arithmetically correct; the findings are minor documentation issues: a duplicated Phase 6 step number, a missing Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (9 files)
Notes: Incremental review of commit 97a395c (three new Fix these issues in Kilo Cloud Previous review (commit 8d5603a)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe new service-fee assessment schema, exemption tables, constraints, and migration are consistent and additive; the only finding is a wrong invariant cross-reference in ADR 0004 (Invariant 10 cited instead of Invariant 11). Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (6 files)
Notes: Reviewed by grok-4.6 · Input: 61.2K · Output: 6.8K · Cached: 235.6K Review guidance: REVIEW.md from base branch |
Introduce the assessment and exemption tables, plus the operator runbook and ADR that define one assessment per commercial event. No runtime billing behavior changes yet.
On-call runbooks live in kilo-org/on-call. Leave the ADR here as the engineering record.
Co-authored-by: kilo-code-bot[bot] <240665456+kilo-code-bot[bot]@users.noreply.github.com>
Co-authored-by: kilo-code-bot[bot] <240665456+kilo-code-bot[bot]@users.noreply.github.com>
e996029 to
f5731b3
Compare
|
Superseded by #5383, which consolidates the complete service-fee implementation into one PR against main. |
Summary
Defines the service-fee requirements, technical design, and validation plan, then adds the reduced database schema needed to retain fee decisions and organization exemptions.
Why this change is needed
Adding a 5% Stripe line item covers the charge, but not the cases where no line exists: an exempt organization, a pre-activation purchase, a zero-rounded fee, or a fail-open error. The agreed scope also requires expected-versus-settled reporting, proportional refunds, dispute adjustments, and one commercial event across Checkout, Invoice, PaymentIntent, and Charge objects.
This is the first PR in a stacked series. It makes those requirements and tradeoffs reviewable before any runtime billing path starts charging a fee. Operator procedures belong in
kilo-org/on-call, not this repo.Stack: #5236 (this PR) → #5262 → #5263 → #5264 → #5265 → #5266.
How this is addressed
GOAL.mdas the product requirements source,SPEC.mdas the technical design, andVALIDATION.mdas the end-to-end proof contract.stripe_service_fee_assessmentsas one durable row per commercial billing event, with unique Stripe object indexes and outcome/amount constraints.assessment_keydirectly as the assessment primary key and derive eligibility fromoutcomerather than storing either value twice.organization_service_fee_exemptionslog. Its newest row is current state, while assessments retain the exact historical row used for an exemption decision.Human Verification
.plans/service-fees/GOAL.md.pnpm drizzle:verify-bootstrap.Reviewer Notes
Human Reviewer Flags
GOAL.mdbefore judging whether the assessment table is necessary. In particular: durable missed-fee records, historical exemptions, settled-only reporting, refunds, and disputes.organization_audit_logs.0221_snapshot.jsonis generated Drizzle metadata. Review0221_goofy_true_believers.sqlandschema.ts, not the snapshot.Code Reviewer Agent
Code Reviewer Notes
organization_service_fee_exemptionsis the complete log and current state is its newest row; there is no duplicated current-state table.stripe_service_fee_assessmentshas 32 columns. Its application-owned assessment key is the primary key, andoutcomeis the only decision-state column.outcome = exemptiffexemption_idis set, so an exempt assessment points to the exact log row that justified it.