Repository navigation
fix(billing): closure cleanup ends a renewal Stripe will never collect, so it always reaches the customer delete (ISSUE-1588) - #976
2witstudios wants to merge 11 commits into
Conversation
…solves (ISSUE-1588) A partial reread still resolves nothing, except a terminal canceled payment that was never paid, captured or timed as paid: the default payment of a voided invoice. Its resolved basis is 'canceled' beside 'pre_closure', and the payment state CHECK gains it (NOT VALID, then validated). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t, so it always reaches the customer delete (ISSUE-1588) The invoices lane voids an owned invoice that moved no money (a draft is finalized with auto_advance off first), then reads it again before its pass. Its default payment, canceled (or still open on the void invoice), resolves as no money moved. A void Stripe refuses (a payment in flight) leaves the invoice to its pass. The Stripe test world gains Stripe's real shapes: the default payment on finalize, collection off on cancel, finalize and void. Two closure journeys walk a draft and a failed renewal at closure; the LAUNCH-15.2 journey's retry is in flight at closure. ADR 0117 and the billing operations doc state the rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Review: fix(billing): closure cleanup ends a renewal Stripe will never collect, so it always reaches the customer delete (ISSUE-1588) at 48b6eb3Reviewer: ag-uvf3wwug · Builder: ag-ivnoirkw The design holds up. An owned invoice is voided only after Checks
Findings
Criteria
OWASP Top 10 (2025)
Privacy & telemetryChecked:
The major finding asks for a classified error code when finalize or void is rejected. That code must carry only Stripe's error Verdict0 blocker / 1 major / 3 minor / 2 nit — CHANGES REQUESTED |
2witstudios
left a comment
There was a problem hiding this comment.
Inline threads for the review comment at #976 (comment). The finding on cleanup-vendor.test.ts (nothing pins auto_advance:false) is in that comment only: the file is not in this diff.
| ), | ||
| // A closed account's uncollected renewal is ended, never collected: the | ||
| // draft is finalized with auto_advance off, so nothing is attempted. | ||
| finalizeInvoice: (id) => |
There was a problem hiding this comment.
major: This is Daisy's first Stripe invoice write; every earlier call only lists or retrieves. Production uses a restricted live key (production-runbook.md:211, :490), which may have Invoices: Read only. A permission error here is swallowed as "refused" by endUncollected (cleanup-invoice-delivery.ts:226-230), with no log, so the ISSUE-1588 loop continues in production while CI is green.
Fix:
- Name Invoices: Write in runbook step 2.
- List the key change for owner sign-off in Operational impact.
- Tell a permission or authentication rejection apart from a business refusal, logged as a classified Stripe
type/codeonly.
There was a problem hiding this comment.
Fixed in e10be59. A finalize or void error is now classified (stripeRefusedStep in cleanup-invoice-delivery.ts). Only an HTTP 400 invalid request (Stripe declining the step: a payment applied or in flight, no longer a draft or open) leaves the invoice to its pass. A permission, authentication, rate or server error is thrown, so the worker logs billing.cleanup.failed (stage delivery) with its code and sends the raw error only to the scrubbed reporter. Test: '…denied for want of permission is reported, never read as a refusal…' (403 propagates). production-runbook.md step 2 now names Invoices: Write. The key change is the owner's: filed as ISSUE-1618 (human, owner, Pending decisions), and the PR's Operational impact lists it.
| stripe.invoices.voidInvoice( | ||
| id, | ||
| {}, | ||
| { ...options, idempotencyKey: `daisy-cleanup-void-${id}` }, |
There was a problem hiding this comment.
minor (SUSPECTED): This idempotency key is fixed per invoice. Stripe replays a stored 4xx or 5xx for the same key for 24 h. If a void is refused while a retry is processing and that retry then fails, every later pass replays the refusal for about 24 h, and billing_cleanup_overdue fires at 2 h. The finalize key on line 61 has the same problem.
Fix: scope the key to the attempt (for example, the claim id), or drop it. Finalize and void are already idempotent by invoice state, and the re-read decides.
There was a problem hiding this comment.
Fixed in e10be59: no fixed keys. Finalize and void are idempotent by state (a repeat is refused as no longer a draft or open, and the re-read decides), so they are sent without an idempotency key, and an earlier refusal can never be replayed.
| const parsed = invoice.safeParse(raw); | ||
| if (!parsed.success || parsed.data.amount_paid !== 0) return null; | ||
| if (parsed.data.status === 'draft') return 'finalize'; | ||
| return parsed.data.status === 'open' ? 'void' : null; |
There was a problem hiding this comment.
minor (SUSPECTED): In Stripe, an uncollectible invoice is still payable and can still be voided, and its default payment stays open. paymentStatus maps only void, so a closed account with an uncollectible invoice keeps that payment owed: the same restart loop, if the account's failed-payment setting marks invoices uncollectible.
Fix: void uncollectible with amount_paid 0 too, and let the test world allow it as its own error text says. Alternatively, pin the required setting in billing-native.md.
There was a problem hiding this comment.
Fixed in e10be59: an uncollectible invoice with amount_paid 0 is voided too, since it is still payable. uncollected-invoice.test.ts now expects 'void' for it. The reader still maps only a payment on a void invoice to canceled, because an uncollectible one can still be paid; once voided, it reads canceled.
| ); | ||
| try { | ||
| current = await input.port.invoice(invoiceId); | ||
| } catch { |
There was a problem hiding this comment.
nit: No unit test covers a re-read that fails after a finalize or void (null, which becomes failure). Add a case where the second invoice() throws and the job records failure, never a pass.
There was a problem hiding this comment.
Added in e10be59: in the same new test, a void whose invoice then cannot be read again records failure and starts no pass.
| amount_paid: minor, | ||
| }); | ||
|
|
||
| /** |
There was a problem hiding this comment.
nit: This JSDoc attaches to the private UncollectedInvoiceStep type, not to the exported function. Move it below the type.
There was a problem hiding this comment.
Fixed in e10be59: the JSDoc now sits on uncollectedInvoiceStep, with the uncollectible case added. The type alias is left bare.
…ead as a refusal; no fixed keys replay a refusal; an uncollectible renewal is voided too; the vendor test pins auto_advance=false; the runbook names Invoices: Write (ISSUE-1588) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/review (CHANGES REQUESTED, 0 blocker / 1 major / 3 minor / 2 nit) is answered in e10be59. Each inline thread has its reply. Also: cleanup-vendor.test.ts now pins finalize's body |
| () => false, | ||
| (error: unknown) => { | ||
| if (stripeRefusedStep(error)) return true; | ||
| throw error; |
There was a problem hiding this comment.
Important: A Stripe timeout, connection error, 429 (rate limit or lock_timeout) or 5xx on finalize or void is now thrown out of the delivery instead of being recorded as a retryable failure. Any error without statusCode === 400 is rethrown here, and the worker only catches it and reports billing.cleanup.failed. No failure is recorded, so retryAt and attempts never advance and the claim stays held until claimMs (30s) expires. The job is then claimed again every 30s with no backoff, sending another read and void to Stripe and another error report each time. A persistent 403 (a key still on Invoices: Read) repeats every 30s indefinitely. Every other port call in cleanup turns transport failures into failure(); cleanup-subscription-delivery.ts says "only transport failures become vendor retry".
Fix: return failure(input, request) for errors with no statusCode, 429 or >=500, and rethrow only 401/403, or record a failure and report them as well.
There was a problem hiding this comment.
Fixed in 0d34335. Every finalize or void error is now reported through an injected failed. The worker wires it to billing.cleanup.failed, stage invoice_end: classified log, raw error only to the scrubbed reporter. Only a 400 (Stripe declining the step) leaves the invoice to its pass. Any other error (no status, 429, 5xx, 401/403) returns null, so the delivery records failure, and attempts and retryAt advance with the job's backoff. Nothing is thrown out of the delivery any more. Test: '…denied for want of permission is reported and retried…' (403 reported, failure recorded, no pass).
| raw, | ||
| ); | ||
| if (!owned || owned.invoiceId !== invoiceId) return failure(input, request); | ||
| const ended = await endUncollected(input, invoiceId, raw); |
There was a problem hiding this comment.
Important: The uncollected renewal is ended only in startCurrent, before a pass exists. In the LAUNCH-15.2 shape (a retry in flight), the void is refused and the pass starts on the open invoice. If that in-flight retry then fails instead of landing, the invoice stays open with amount_paid 0 and collection turned off. advanceCurrent never tries to end it again, so its payment stays open/owed and the customer is never deleted. That is the ISSUE-1588 stuck state. The same gap applies to accounts whose invoice pass had already started before this deploys.
Fix: retry endUncollected once a pass finds its invoice still open and unpaid, or defer the pass while a refusal was caused by a processing payment. Also check whether any recheck path brings such accounts back through startCurrent.
There was a problem hiding this comment.
Covered by the restart, and the ADR now says so. When every lane completes with money still owed, progressCleanupScan returns startCleanup(jobId, retryAt) (billing-cleanup-scans.ts). That re-scans from fresh pages, and selected() builds each invoice frame with pass: null. So on the next round the invoice goes through startCurrent → endUncollected again. A void refused because a retry was in flight is tried again once that retry has failed, and accounts whose pass began before this deploys reach it the same way. endUncollected's doc in 0d34335 states this.
| } catch { | ||
| return null; | ||
| } | ||
| if (refused) return current; |
There was a problem hiding this comment.
Important: After a refusal, this returns the re-read invoice even when that invoice now allows the next step. Example: finalize returns 400 because the draft was already finalized, for instance by a second delivery after the 30s claim expired. The re-read shows open with amount_paid 0, but the loop returns without voiding it, and the pass then starts on an invoice that is never ended (see the comment on line 194).
Fix: on a refusal, keep looping when uncollectedInvoiceStep(current) gives a step other than the one just refused, and stop only when the same step would repeat.
There was a problem hiding this comment.
Fixed in 0d34335. After a refusal the loop stops only if the re-read asks for the same step again. A draft another delivery already finalized re-reads as open, so the loop goes on to void it.
| const stripeRefusedStep = (error: unknown) => | ||
| typeof error === 'object' && | ||
| error !== null && | ||
| (error as { readonly statusCode?: unknown }).statusCode === 400; |
There was a problem hiding this comment.
Important: Every HTTP 400 is treated as Stripe refusing the step because of the invoice's state. Validation errors also return 400: an invalid parameter, or customer_tax_location_invalid from finalize when Stripe Tax is on. Those are silently left to the pass with no report, so a draft that can never be finalized keeps the account owed and nobody is told.
Fix: match Stripe's state-refusal error codes (error.code) explicitly, and rethrow or report every other 400.
There was a problem hiding this comment.
Partly changed in 0d34335. Every 400 is now reported (billing.cleanup.failed, stage invoice_end), so a finalize Stripe rejects for a validation reason, such as a tax location, is no longer silent. I did not match specific error codes: Stripe documents no code for 'a payment is applied or in flight', so a code allow-list would turn that expected refusal into a retry loop. Leaving every 400 to the pass is safe for money, because the pass's facts decide and nothing is forgiven without a canceled payment. The report makes a stuck account visible beside the overdue alert.
| const ended = await endUncollected(input, invoiceId, raw); | ||
| if (ended === null) | ||
| return input.running() ? failure(input, request) : ('idle' as const); | ||
| raw = ended; |
There was a problem hiding this comment.
Nit (optional): No running() check follows the vendor awaits in endUncollected. That function returns current when !input.running(), and the loop also exits after its second re-read without checking. startCurrent then goes on to recordInvoices, a database write, after shutdown has begun. Before this change, if (!input.running()) return 'idle' sat directly before that write.
Fix: add if (!input.running()) return 'idle' as const; after raw = ended;.
There was a problem hiding this comment.
Fixed in 0d34335: if (!input.running()) return 'idle' now sits directly after endUncollected and before recordInvoices.
| export function uncollectedInvoiceStep(raw: unknown): UncollectedInvoiceStep { | ||
| const parsed = invoice.safeParse(raw); | ||
| if (!parsed.success || parsed.data.amount_paid !== 0) return null; | ||
| if (parsed.data.status === 'draft') return 'finalize'; |
There was a problem hiding this comment.
Important (please verify): Stripe applies the customer's credit balance when an invoice is finalized. If that credit covers the renewal, finalizeInvoice turns the draft paid with no charge, so the void then fails and the closed account's credit is used up on a renewal this change meant to forgive. Before this change the draft was left alone. Check how the pass handles a paid invoice that has no charge or refundable InvoicePayment, so it does not leave the account owed.
Fix: skip finalizing, or delete the draft instead (Stripe allows deleting draft invoices), when starting_balance is negative, or handle a credit-paid result explicitly.
There was a problem hiding this comment.
Fixed in 0d34335 for the money, and filed for the liveness. A draft whose starting_balance is negative (customer credit), or missing (no credit can be ruled out), is no longer finalized, so the credit is never spent on a forgiven renewal. Such a draft is left to its pass and stays owed, as before this PR, until a follow-up ends it without applying credit (delete the draft, or settle the balance first). That is filed as ISSUE-1620. ADR 0117 names it, and uncollected-invoice.test.ts covers the credit draft.
| (ISSUE-1588). Cancelling the subscription turns off collection of its open and | ||
| draft invoices without ending them, so a renewal still a draft at closure, or | ||
| open after a failed charge, would stay owed for ever. When the invoices lane | ||
| reads an owned invoice that moved no money (`amount_paid` 0, `draft` or |
There was a problem hiding this comment.
Nit (optional): This ADR text says the cleanup ends invoices that are draft or open. uncollectedInvoiceStep also voids uncollectible invoices, and its unit test checks that. Fix: add uncollectible to the ADR text so the decision matches the code.
There was a problem hiding this comment.
Fixed in 0d34335: the ADR now says draft, open or uncollectible (still payable), and states the error handling and the credit case.
…e and void (typecheck) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…retried with backoff unless Stripe declined the step; a refusal goes on when the invoice asks for another step; a draft carrying customer credit is left alone (ISSUE-1620); shutdown is checked before the write (ISSUE-1588) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review: fix(billing): closure cleanup ends a renewal Stripe will never collect, so it always reaches the customer delete (ISSUE-1588) at 0d34335Reviewer: owner · Builder: ag-ivnoirkw This is a difference review of Every earlier finding is fixed. The money model is sound:
I checked the builder's answer on What remains is about how loudly the cleanup reports, and one fix that has no test. Checks
Earlier findings
Findings
Criteria
OWASP Top 10 (2025), new commits only
Privacy & telemetryChecked:
If minor 1 adds a Verdict0 blocker / 0 major / 2 minor / 2 nit — APPROVE WITH MINORS |
| ).then( | ||
| () => 'done' as const, | ||
| (error: unknown) => { | ||
| input.failed(error); |
There was a problem hiding this comment.
minor: This reports every rejection, including the 400 this PR expects while a payment is in flight. recoverableFailure captures each one with no throttle. A refused void leaves the pass owed, so the cleanup restarts at now + progressMs (1 s) and is reported once more every round. A finalize rejected with a validation 400 is reported every round, with no end. The log line is also errorCode: INTERNAL with no cause, so a refusal and a 403 denial look the same.
Fix: give the sink a cause reader that returns a fixed class only (stripe_refused, stripe_denied or stripe_unavailable). Log an expected 400 without capturing it, or capture it once per job. Keep capturing denials and outages.
There was a problem hiding this comment.
Partly fixed in b91e5c2, the rest filed. The invoice step's failures now go through their own sink, which has a cause reader (invoiceStepError, invoice-step-error.ts). Its billing.cleanup.failed log line carries cause stripe-refused (400), stripe-denied (401/403) or stripe-unavailable (no status, 429, 5xx), never Stripe's message, so a refusal and a denial now read differently. Capturing an expected refusal once per job rather than every round needs a per-job memory in the reporter path. That is filed as ISSUE-1621, since it arrived after the clean verdict and is not a few lines.
| } | ||
| // A refusal ends the attempt unless the invoice now asks for another | ||
| // step (a draft another delivery already finalized, say). | ||
| if (outcome === 'refused' && uncollectedInvoiceStep(current) === next) |
There was a problem hiding this comment.
minor: This fix has no test. If it is reverted to if (outcome === 'refused') return current;, every test still passes: no port refuses a finalize.
Fix: add a delivery case where finalize throws { statusCode: 400 } and the re-read answers open with amount_paid 0. Assert finalize refused, read, void, read, then the pass start.
There was a problem hiding this comment.
Added in b91e5c2: 'a refused finalize goes on to void when the invoice already reads open'. Finalize throws a 400 and the re-read answers open; the test expects read draft, finalize refused, read open, void, read void and then the pass start. Reverting line 249 to if (outcome === 'refused') return current; fails it.
| function voidInvoice(_call: Call, invoiceId: string): Reply { | ||
| const invoice = invoices.get(invoiceId); | ||
| if (!invoice) return missing('invoice', invoiceId); | ||
| if (invoice.status !== 'open') |
There was a problem hiding this comment.
nit: The production code now voids uncollectible (uncollected-invoice.ts:35), and Stripe allows it, as this function's own error text says. This check still refuses it. Fix: allow open or uncollectible.
There was a problem hiding this comment.
Fixed in b91e5c2: the world's voidInvoice accepts open or uncollectible, and its Invoice status admits uncollectible. The same commit adds the test for a draft without starting_balance (left alone).
…by its class (stripe-refused, -denied, -unavailable); tests pin the refusal continuation and the draft without a balance; the test world voids an uncollectible invoice (ISSUE-1588) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review: fix(billing): closure cleanup ends a renewal Stripe will never collect, so it always reaches the customer delete (ISSUE-1588) at b91e5c2Reviewer: ag-38tvs8xj · Builder: ag-ivnoirkw This is a difference review of Every earlier finding is fixed, or answered with a filed follow-up I accept. The new code is small and correct:
Checks
Earlier findings
Findings
CriteriaThe plan's criteria are unchanged in this range. They are restated at this SHA:
PARTIAL means only that CI integration is pending. Nothing failed. OWASP Top 10 (2025), new commit only
Privacy & telemetry
Verdict0 blocker / 0 major / 0 minor / 2 nit — APPROVE WITH MINORS |
| 'billing.cleanup.failed', | ||
| 'billing.cleanup', | ||
| 'Closed-account billing cleanup remains owed', | ||
| invoiceStepError, |
There was a problem hiding this comment.
nit: No test checks that this sink is given invoiceStepError. If the fourth argument is dropped, every test still passes, and the invoice_end log goes back to a bare INTERNAL. Fix: add a cleanup-worker.test.ts case where a void answers 400 and the log line carries cause: 'stripe-refused'. Or have the delivery take the classifier, so its own test checks it.
There was a problem hiding this comment.
Filed with ISSUE-1621, which owns this reporting path: once-per-job capture of an expected refusal, and a worker-level test that the invoice-end sink logs cause: 'stripe-refused'. The wiring is one argument at cleanup-worker.ts:59, beside invoice-step-error.test.ts, which pins the classes. It arrived after the clean verdict and is not a few lines in this worker, which has no log-capturing test harness for a vendor answer.
| if (status === 400) return 'stripe-refused'; | ||
| return status === 401 || status === 403 | ||
| ? 'stripe-denied' | ||
| : 'stripe-unavailable'; |
There was a problem hiding this comment.
nit: A 402, 404 or 409 also comes out as stripe-unavailable, but the JSDoc says that class means Stripe could not be reached. Retrying with backoff is still correct, but a 404 for an invoice that is gone would read as an outage in the logs. Fix: keep stripe-unavailable for no status, 429 and 5xx, and give any other 4xx its own class. Or reword the JSDoc.
There was a problem hiding this comment.
Reworded in f92723d (a comment only): stripe-unavailable now reads 'any other answer (no reply, a rate limit, a server error, another client error), which the lane retries with backoff'. The behaviour is unchanged. A finer fourth class can ride ISSUE-1621.
…ackoff (difference review nit) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ISSUE-1588) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… club_manager_admission (ISSUE-1588) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Change
ISSUE-1588 is confirmed, and this PR fixes it. A member who closes their account with a renewal Stripe will never collect no longer leaves their closure cleanup owed for ever.
Why it looped. The cleanup cancels the subscription with
invoice_now:false. Stripe's cancel turns off collection (auto_advance:false) on the subscription's open and draft invoices without ending them. Two ordinary cases then never finish:zero_membership, so the invoice staysowed.open. Only a paid, pre-closure payment resolved, so it staysowed/payment_unresolved.In both cases the cleanup restarts instead of deleting, every time, and only the 2 h
billing_cleanup_overduealert named it. The Stripe test world hid both:failRenewalmade no payment, and cancel never stopped collection.The fix.
amount_paid0, anddraft,openoruncollectible, which is still payable), it voids it, then reads it again before the pass. A draft is finalized first withauto_advance:false, so nothing is collected. The decision is pure (uncollectedInvoiceStep).billing.cleanup.failed, stageinvoice_end.failure, so the job retries with backoff.starting_balance) is not finalized, so the credit is never spent on a forgiven renewal. It stays owed, as before this PR, until ISSUE-1620 ends it without applying the credit.canceledresolves on a new basiscanceled, besidepre_closure, when nothing was paid, captured or timed as paid. That is no money moved, so no refund action is created. A payment still reportedopenon a void invoice reads as canceled: void is terminal and a void invoice is never payable. Stripe's docs do not say whether voiding cancels the default payment, so both readings resolve. Every finalized invoice has its default payment, so the pass keeps ADR 0117's nonzero membership and its database guards unchanged. The payment state CHECK gains the basis, addedNOT VALIDand then validated (two folders, per docs/operations/database.md).openuntil paid;beginCollection).What a member with an uncollected renewal sees. Nothing more from Daisy after closing: no charge, no retry, no dunning. If they open an old Stripe invoice link, it reads void. The Stripe customer is then deleted.
What the owner's Business page counts. Nothing new and nothing lost. No refund action is created (no money moved). MRR and paying counts already drop at closure, when the subscription is cancelled. The overdue cleanup alert stops firing for these accounts.
PageSpace
Builder: ag-ivnoirkw
Criteria
endUncollected), uncollected-invoice.tsfinalizeInvoicewithauto_advance:false,voidInvoice)canceledWithoutMoney), billing-payment-observation-retention.ts; packages/db/src/schema/billing-payment-observation-checks.ts; payment-observation-reader.ts (paymentStatus)auto_advance=false, void body empty)Validation
Machine budget: focused unit tests locally only. CI runs typecheck, lint, knip, integration and e2e.
bun test src/billing*(packages/protocol): pass, including the new canceled-resolution cases.bun test src/features/billing/(apps/web): 272 pass.tsgo --noEmit(packages/protocol, packages/db): clean.tsgo --noEmit(apps/web, outside Next's generated route types, which CI generates): clean.bun migrations:check: PASS, 19 committed), andbun pr:prepare 976 --base origin/mainis clean. CI is re-running at the merged head.Changed test assertions
uncollected-invoice.test.ts, added in this PR:
uncollectiblewith nothing paid now expects'void', after review.billing-closure-cleanup.integration.ts (LAUNCH-15.2 journey): the scenario now puts Stripe's retry in flight at closure (
world.beginCollection) before the payment lands mid-pass. Its assertion is unchanged: refund in full, then delete. Stripe would otherwise have the cleanup void the renewal, and a void invoice cannot later be collected.The test world's InvoicePayments now carry their real status (
open,paid,canceled), andamount_paidis null until paid. A paid payment reads exactly as before.Operational impact
Owner action before production (ISSUE-1618, human-only): the live restricted Stripe key needs Invoices: Write. This PR is Daisy's first invoice write. Until the key has it, closure cleanup reports
billing.cleanup.failed(stagedelivery) and the account stays owed, as today. docs/operations/production-runbook.md step 2 now says so.Two migrations:
payment_canceled_resolution(CHECK replacedNOT VALID) andpayment_canceled_resolution_validated(validated in a block that warns rather than fails).The CHECK only widens, so no stored row can break it.
No configuration change.
New Stripe calls from the cleanup worker:
POST /v1/invoices/:id/finalizeandPOST /v1/invoices/:id/void. Their only target is a closed account's owned invoice with nothing paid.Architecture
ADR 0117 gains the rule: an uncollected renewal is ended, and a canceled payment resolves. The nonzero-membership rule and its guards are unchanged. The cleanup vendor port gains
finalizeInvoiceandvoidInvoice.Compliance & telemetry
None. No new data class, purpose, processor, retention, log field or analytics event. Stripe remains the only processor, with two more calls on data it already holds.
🤖 Generated with Claude Code