Skip to content

fix(billing): post-merge review follow-ups (#21351 period check, reconciliation, rate card tests) - #21439

Merged
Git-on-my-level merged 5 commits into
mainfrom
fix/billing-post-merge-nits
Oct 13, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
fix/billing-post-merge-nits

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Post-merge review follow-ups for the subscription overhaul. Each item was checked against current origin/main before editing.

#21351

  • Paid shadow resolution now requires an open current_period_end, matching get_user_valid_subscription. A paid row with a missing, zero, or past period resolves to basic. test_free_and_old_paid_records_stay_legacy covers those cases; other paid-resolution tests pass an open period so they still exercise price-before-label behavior.
  • validate_entitlement_compatibility returns diagnostics for a missing plan id or a missing legacy policy key instead of raising KeyError, including the CLI --base-ref path.

#21352

  • Architect dormant budget 189463 is 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_rate prices a non-empty modality split plus sibling reasoning_tokens and locks micro_units 10349603.
  • test_self_hosted_deepgram_retains_unknown_compute_proxy asserts the unknown-compute proxy micro-units, not the Nova-3 card.

#21370

  • Declined the unused-adopted_active_paid claim. Current main reads it for the early-cancel grace log, and customer-id / telemetry already follow decision.effects.
  • The checkout duplicate test now locks transition(): a paid row with the same subscription id is duplicate_checkout; basic with the same id is new_checkout; a different paid id is replacement_checkout.

#21371

  • pi_ grants and claimed referrals stay in their own buckets only when that uid has no entitled Stripe subscription. Otherwise wrong_plan, stale_period, and paid_in_stripe_basic_in_firestore are still counted.
  • test_multiple_subscriptions_are_not_arbitrarily_selected stores a plan and price that match neither subscription, so a silent pick of the first sub fails.
  • A price map that collides with a catalog price id exits 2 with no report, instead of overriding the catalog plan.

#21372

  • The reconciliation runbook no longer sets IFS empty, so a pasted restricted key is trimmed.
  • Unresolved checkout with the webhook ledger on still invalidates credits and clears the trial cache before RetryableBillingSkip. Conversations, memories, and action items unlock only when get_user_valid_subscription is 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.

#21397 and the coordinator render review were not touched.

Test plan

  • BACKEND_UNIT_TEST_FILE_LIST covering entitlement versions, rate card, billing reconciliation, stripe webhook behavior, stripe event ledger, subscription ingestion characterization, and firestore read-ops cache, via backend/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

View guided diff Turn on auto-fix

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T23:22:02.128783Z 6d71497 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1042 to +1043
if persisted is False and webhook_ledger_enabled():
return RetryableBillingSkip(status='success')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Git-on-my-level and others added 4 commits October 14, 2026 05:28
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]>
@Git-on-my-level
Git-on-my-level merged commit 455b124 into main Oct 13, 2026
57 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/billing-post-merge-nits branch October 13, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant