Skip to content

Welcome credits: atomic $1 grant for the first 50 accounts #32

Closed

Description

@ElbertePlinio

Refs pickforge/pickforge#135 and pickforge/pickforge#152.

Goal

Grant $1.00 in hosted credits once to each of the first 50 eligible PickForge accounts, without allowing races, retries, or client calls to exceed the budget.

Locked contract

  • Exactly 100 USD cents per recipient
  • At most 50 recipients globally
  • At most one welcome grant per user
  • Atomic under concurrent account creation/retries
  • Server-side kill switch, default-on for launch and reversible without a client release
  • No recurring free allowance
  • Ledger remains the balance source of truth
  • No client-controlled amount, reason, or eligibility

Implementation plan

  • Characterize the existing auth/profile/ledger provisioning path
  • Add the smallest transactional database contract with explicit privileges/RLS
  • Wire the existing server-owned provisioning path
  • Add concurrency, retry/idempotency, cap, kill-switch, and authorization tests
  • Run Supabase advisors plus platform typecheck/test/build
  • Document rollout and emergency disable procedure

Validation

  • 100 concurrent eligible attempts produce exactly 50 grants
  • repeated attempts for a recipient do not change balance or recipient count
  • disabled switch produces no grant
  • anon/authenticated clients cannot forge or directly invoke a grant

No pricing packs or refund policy are decided here.

Activity

  1. ElbertePlinio commented on Jul 12, 2026

    @ElbertePlinio
    MemberAuthor

    Implementation started in isolated worktree/branch feat/welcome-credits-first-50.

    Current phase: characterize existing auth provisioning, credit ledger, Edge Function ownership, migrations, and database-test conventions before locking the transaction shape.

  2. ElbertePlinio commented on Jul 12, 2026

    @ElbertePlinio
    MemberAuthor

    Architecture locked after repository + adversarial review:

    • Account identity = Supabase user UUID. Delete/recreate may consume another remaining slot, but lifetime spend never exceeds $50. No durable email/provider fingerprint tombstone.
    • Eligible = new non-anonymous auth.users inserts after the campaign is enabled; no backfill.
    • Private singleton campaign row: enabled + monotonic issued_count constrained 0..50. Amount and cap are fixed SQL constants, not configurable/client input.
    • Separate AFTER INSERT trigger, SECURITY DEFINER with empty search_path, no public RPC/Edge Function.
    • Row lock, fixed ledger insert, and counter increment share the auth transaction. Unexpected failures abort account creation rather than committing an eligible account without its grant.
    • Kill switch is an operator SQL update documented in the runbook.
    • Real local database tests and a 100-way Bun SQL concurrency harness are required; string assertions alone are insufficient.
  3. changed the title [-]Welcome credits: atomic grant for the first 50 accounts[/-] [+]Welcome credits: atomic $1 grant for the first 50 accounts[/+] on Jul 12, 2026
  4. ElbertePlinio commented on Jul 12, 2026

    @ElbertePlinio
    MemberAuthor

    Implementation complete; shipping PR next.

    • Fixed $1 grant, once per Supabase user UUID
    • Monotonic global cap of 50, preserved after account deletion
    • Atomic auth trigger with row locking and fixed ledger metadata
    • Operator SQL kill switch; no client RPC
    • Private schema, RLS, empty search path, explicit privilege revocation
    • 23 real pgTAP behavior/security checks
    • 100 concurrent signups -> exactly 50 grants
    • Failed ledger grant rolls back account creation and the counter
    • Fresh database migration, full platform check, and security advisors green
    • Independent security, CI, and anti-overengineering reviews clean
  5. ElbertePlinio commented on Jul 12, 2026

    @ElbertePlinio
    MemberAuthor

    PR opened: #33

    CI and the automatic Codex review are in progress on commit bd7f4b1.

  6. ElbertePlinio commented on Jul 12, 2026

    @ElbertePlinio
    MemberAuthor

    PR #33 is review-clean on bd7f4b1: both CI jobs passed and the automatic Codex review returned a clean thumbs-up with no findings. Merging.

  7. ElbertePlinio commented on Jul 12, 2026

    @ElbertePlinio
    MemberAuthor

    Merged via #33 as 0e65485. The first-50 welcome-credit contract and its real database CI gate are now on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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