Skip to content

Money-path observability, Stripe idempotency, ledger scaling #43

Description

@ElbertePlinio

From the 2026-07-19 complementary swarm review (read-only, complementary to #37 — assumed landing; no overlap).

P1 — money-path observability

  • Zero logging on the entire money path (no console.* in packages/billing/src, packages/edge-shared/src, supabase/functions). A refund_terminal_failure (money stuck) surfaces as an anonymous 500. Add structured console.error at: createStripeWebhookHandler catch (edge-shared/src/index.ts:849-851), accountErrorResponse sites (:1026,1030), billing databaseError/BillingError throw sites — include event.id, event.type, checkout_session_id, error code.
  • recordStripeEventBestEffort swallows every insert error (billing/src/index.ts:919-931). Log swallowed errors; only treat 23505 as ignorable.

P1 — Stripe idempotency

  • Checkout Session creation has no idempotencyKey (billing/src/index.ts:295-306) while refunds correctly use one (:647). Add a deterministic idempotency key to session creation.

P1 — ledger scaling

  • Balance is sum(amount_cents) over the full ledger, computed twice per router request; ledger grows one row per ~2¢ call. Add a covering index / running-balance or cached-balance strategy (additive migration only, per chore: reconcile hosted Supabase migration history #35).

P2 — simplify

  • Delete duplicated settle/finalize/deleteCustomers trio in createDeleteAccountHandler (edge-shared/src/index.ts:728-733).
  • Hoist duplicated Deno adapter boilerplate (requiredEnv/createCallerSupabase/withCors) from 5 functions into edge-shared.

Validation

  • bun test workspace; deno check all touched functions; pgTAP for any migration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions