Repository navigation
fix(billing): post-merge review follow-ups (#21351 period check, reconciliation, rate card tests) - #21439
Conversation
Shadow entitlements treated a paid row as paid without an open period, and reconciliation skipped Stripe drift when a PaymentIntent or referral was also present. Ledger-on unresolved checkout also skipped the cache effects that still run when the ledger is off. Co-authored-by: Cursor <[email protected]>
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c8004dbf5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if persisted is False and webhook_ledger_enabled(): | ||
| return RetryableBillingSkip(status='success') |
There was a problem hiding this comment.
Validate the stored paid period before unlocking content
When BILLING_WEBHOOK_LEDGER_ENABLED=true and checkout persistence fails for an unknown price, this delayed retryable return now lets the preceding block unlock every conversation, memory, and action item based only on the raw stored plan label. A churned user can retain a paid plan value with an expired current_period_end; get_user_valid_subscription() deliberately treats that row as Basic, but get_user_subscription() plus is_paid_plan() does not. Thus an unresolved checkout can durably restore paid content without establishing a valid entitlement. Gate these effects on a currently valid paid subscription (or on a successful new persistence) before returning the retryable skip.
Useful? React with 👍 / 👎.
| for uid, user in by_uid.items(): | ||
| stored = user.get('subscription') or {} | ||
| manual_payment = stored.get('subscription_id') | ||
| stripe_entitled = entitled.get(uid) or [] |
There was a problem hiding this comment.
Preserve special grants when only Stripe prices are unknown
If a PaymentIntent grant or claimed referral also has an active/trialing Stripe subscription whose price is unknown, stripe_entitled is nonempty, so the new guards suppress manual_payment_entitlement/referral_trial_entitlement; execution then reaches if unknown and not candidates: continue, which explicitly treats that Stripe row as unable to prove access. The report therefore loses the known special-grant classification and emits only unknown_price, contrary to the reconciliation model that unknown prices are uncertainty rather than evidence of another entitlement. Suppress the special bucket only when there is at least one recognized Stripe candidate.
Useful? React with 👍 / 👎.
| # Floor so the dormant cap never rounds above break-even. Plus ($16.36 → | ||
| # 16360) and Pro ($44.09 → 44090) are ratified inputs; this is the same rule | ||
| # at the $199 Architect price. | ||
| _ARCHITECT_MONTHLY_PRICE_USD = Decimal('199') |
There was a problem hiding this comment.
Derive the budget from the subscriber's billing interval
This certifies the plan-wide Architect monthly budget from the $199 monthly price, but get_entitlement_version() returns that same budget for every Architect ladder price, including annual subscriptions whose effective monthly revenue is lower when the annual offer includes a discount. Once an annual Architect price is assigned ladder_v1, a 189,463-unit monthly cap can therefore exceed its per-month break-even amount even though the helper and test remain green. Avoid hard-coding one live Stripe amount into the catalog facade; derive or ratify the budget against every supported billing interval (using the limiting net monthly revenue).
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
A stored paid label with a missing, zero, or past period is Basic. Credit invalidation and trial-cache clear stay unconditional, and the reconciliation runbook now matches the pi_/referral and price-map collision rules. Co-authored-by: Cursor <[email protected]>
…ixture Resolved checkout still unlocks after the open-period gate: the plan is written with Stripe's current_period_end and get_user_valid_subscription returns that row. The fixture stubbed the re-read as None. Co-authored-by: Cursor <[email protected]>
Summary
Post-merge review follow-ups for the subscription overhaul. Each item was checked against current
origin/mainbefore editing.#21351
current_period_end, matchingget_user_valid_subscription. A paid row with a missing, zero, or past period resolves to basic.test_free_and_old_paid_records_stay_legacycovers those cases; other paid-resolution tests pass an open period so they still exercise price-before-label behavior.validate_entitlement_compatibilityreturns diagnostics for a missing plan id or a missing legacy policy key instead of raisingKeyError, including the CLI--base-refpath.#21352
189463is documented as the §4 break-even derivation (price − Stripe 2.9% + $0.30 − the published $3.465491536615313 fixed cost, floored at $0.001) and locked by test. The arithmetic matches the catalog value, so the number is unchanged.test_realtime_metadata_separate_reasoning_is_priced_at_text_output_rateprices a non-empty modality split plus siblingreasoning_tokensand locksmicro_units10349603.test_self_hosted_deepgram_retains_unknown_compute_proxyasserts the unknown-compute proxy micro-units, not the Nova-3 card.#21370
adopted_active_paidclaim. Currentmainreads it for the early-cancel grace log, and customer-id / telemetry already followdecision.effects.transition(): a paid row with the same subscription id isduplicate_checkout; basic with the same id isnew_checkout; a different paid id isreplacement_checkout.#21371
pi_grants and claimed referrals stay in their own buckets only when that uid has no entitled Stripe subscription. Otherwisewrong_plan,stale_period, andpaid_in_stripe_basic_in_firestoreare still counted.test_multiple_subscriptions_are_not_arbitrarily_selectedstores a plan and price that match neither subscription, so a silent pick of the first sub fails.#21372
IFSempty, so a pasted restricted key is trimmed.RetryableBillingSkip. Conversations, memories, and action items unlock only whenget_user_valid_subscriptionis a paid plan with an open period; a paid label with a missing, zero, or past period does not unlock. The stored plan is still not written.#21397and the coordinator render review were not touched.Test plan
BACKEND_UNIT_TEST_FILE_LISTcovering entitlement versions, rate card, billing reconciliation, stripe webhook behavior, stripe event ledger, subscription ingestion characterization, and firestore read-ops cache, viabackend/test.sh(240 passed)scripts/pr-preflight --lane local(31 checks passed)Product invariants affected
none
Failure class (fixes)
Failure-Class: none
Line-Count-Exception: backend/routers/payment.py | 1741 -> 1746 | Unresolved checkout unlocks only a paid plan whose billing period is still open.
UI-Evidence: none -- backend billing shadow and reconciliation only; no client surface
🤖 Generated with Claude Code