Repository navigation
fix(id-verification): create the Persona inquiry before the charge, not after (#948) - #965
Merged
Merged
Conversation
…ot after (#948) Item 2 of #948, the last one open. /confirm called createPersonaInquiry between a successful charge and the id_verifications insert that records it. persona_inquiry_id is NOT NULL, so Persona being down did not degrade the flow — it made the row unwritable: the customer had paid, no verification could be created without an inquiry, a retried /confirm called Persona again and failed again, and once the client lost the payment intent id nothing could finish the job. #949 made the charge recoverable; the verification was not. /request now mints the inquiry before the Stripe intent exists and carries its id on the intent metadata and the ledger row, so /confirm makes no network call on the normal path. Persona down means /request returns 503 with nothing charged. Chosen over "record the payment first and retry the inquiry" because persona_inquiry_id is NOT NULL: that route needed a nullable-column migration, a new status, a retry sweep and another cron. This needs none. resolvePersonaInquiry keeps a fallback chain — intent metadata, then ledger metadata, then a fresh inquiry — so intents in flight when this deploys still complete. tests/routers/id-verification-rest.test.ts asserts the inquiry stored on id_verifications is the one that existed before the charge was possible. Measured green, then red on the pre-fix route with the tests unchanged (`ledger metadata carries no persona_inquiry_id`), then green again. It is not in GATED.txt: it needs STRIPE_MOCK_MODE inside the function runtime and `supabase start` has no --env-file, so CI cannot give it that. The file carries the command it was verified with; wiring the gate is #937. Co-Authored-By: Claude Opus 5 <[email protected]>
6 tasks
Contributor
📊 Performance Benchmark Results |
4 tasks
Contributor
Author
|
CI green: 11 pass, 4 skipping, none red — including Edge function types, which is the job that disagrees with my local run. Filed that as #969 with the evidence; it is not caused by this PR, and Ready to merge whenever you want it. Nothing here moves money: no environment has Stripe keys, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the last open box on #948.
The gap
/confirmcalledcreatePersonaInquirybetween a successful charge and theid_verificationsinsert that records it.core.id_verifications.persona_inquiry_idisNOT NULL, so Persona being down did not degrade the flow — it made the row unwritable:/confirmcalls Persona again and fails again#949 made the charge recoverable (the
payment_transactionsrow is written before theclient_secretis handed out), so this was no longer invisible — a succeeded ledger row withid_verification_idNULL. But the customer still had no verification and no path to one.The fix
/requestnow creates the Persona inquiry before the Stripe PaymentIntent exists, and carries its id on the intent's metadata and on the ledger row./confirmreads it from there, so on the normal path there is no network call at all between a successful charge and the record of it.This is the issue's first option ("call it before confirming") rather than its second ("record the payment first and let the inquiry be retried"), because
persona_inquiry_idis NOT NULL: recording first would have needed a migration to make it nullable, a new status value, a retry sweep and another cron. Moving the call needs none of that, and it inverts the failure in the direction you want — Persona down now means/requestreturns 503 with nothing charged, instead of a paid customer with nothing to show for it.resolvePersonaInquirykeeps a fallback chain — intent metadata → ledger metadata → mint a new one — so intents already in flight when this deploys still complete rather than stranding someone who has paid. Only that last branch makes a network call, and only for a pre-change intent.The cost is an orphan inquiry when a customer abandons checkout. Persona inquiries that are created and never started expire on their side, and
reference_idis the worker's id so they stay traceable. That is a much better failure than charging for a verification we then cannot create.Verification
tests/routers/id-verification-rest.test.ts— two tests against the realapifunction and the real database, Stripe in mock mode:They assert the invariant, not the happy path: that the inquiry id stored on
id_verificationsis the one that existed before the charge was possible.Red path measured. With the route reverted to
origin/mainand the tests unchanged:Then green again with the fix restored. Green → red → green, not just green.
Also: edge-fn type ratchet —
apimeasures 334, exactly its baseline;deno fmtclean on the route; biome lint clean;pnpm prepushgreen.What I did not do, and why
The test is not in
GATED.txt. It needsSTRIPE_MOCK_MODE=1inside the function's runtime, and nothing provides that:supabase starthas no--env-file, so the shared edge runtime CI brings up cannot see it, and without itloadStripeClientthrowsStripe API key is not configured.before either route does anything interesting. Listing it in the gate would list a file that cannot pass, which is the one thing that file's header forbids.So the suite carries the exact command it was verified with, and the recipe generalises to every REST payment route — which is #937. I have commented there rather than opening a new issue. I am aware this is the shape I complained about in #961; the difference is that the run path is written down in the file and the follow-up is scoped, not that it is fine.
No Stripe round trip is proven. No environment has Stripe keys, so the mock is the only Stripe these tests have seen. What is proven is the ordering and the metadata handoff.
One thing I could not explain. Locally the ratchet reports
trpc/routers/teams.router.tsat 2 errors against a baseline of 1 — az.date({ message })(zod 4 syntax) on a line from #190. It reproduces on a cleanmainworktree with dependencies installed, and CI's "Edge function types" job passes onmain, so local and CI disagree about a gate. Not caused by this PR and not fixed here, but a gate that disagrees with itself is worth someone's attention.🤖 Generated with Claude Code