Repository navigation
Refresh the plan when the app resumes and when Plans & Billing opens - #26181
Merged
Merged
Conversation
After cancelling or resubscribing in Google Play (or the Stripe portal), the sheet kept the old renew/ends line until the app was relaunched. Re-read the subscription on resume (at most once per 30 s, never signed out), when the plans sheet opens, and once more 5 s after returning from Google Play's subscription page, since Play notifies the server a few seconds later.
kodjima33
marked this pull request as ready for review
November 24, 2026 00:56
A resume read that left before a Google Play verify could still be in flight when verify returned, and the post-purchase read joined it, so a reader who had just paid saw Free. fetchSubscription(fresh: true) now waits for an in-flight read and reads once more; every caller that reads after a server change uses it. The resume read is skipped while a Play purchase is being confirmed, its window is 2 minutes and starts only after a successful read, a Google Play page that fails to open no longer arms the follow-up, and the lifecycle hook is a small observer widget with its own tests.
DemoBillingUsage.fetchSubscription takes the new fresh flag. The manual finish test's forceRefreshConversations override predates the reconcileHeldRecordings parameter on main, which breaks the analyzer there.
kodjima33
added a commit
that referenced
this pull request
Nov 24, 2026
…nds the purchase, runbook cancel step (#26189) ## What changed and why Five small items the reviewers of #26165 and #26181 left open. None changes a price, a purchase path or an entitlement rule. 1. **Plans sheet keeps Retry after a failed plan read** (`play_plans_content.dart`, `PlayPlansLoading`). The loading state decided "failed" from the provider's shared error. A successful usage read clears that error, so the sheet went back to a skeleton with no Retry while the plan read was still known to have failed. It now uses `billingProviderFailed`, the same flag the paywalls and the paid app button use since #26165. 2. **A token store error ends the purchase as failed** (`play_billing.dart`, `_deliver`). If reading or writing the pending-token store threw, the purchase was never finished: the paywall waited forever and `PlayBilling.busy` stayed true, which since #26181 also switches the resume read off for the session. `_deliver` now catches, logs and returns a failed result. The cleanup write after the server has answered has its own catch, so a plan the server granted is still reported as bought; the token is then sent once more on the next launch. 3. **Trial paywall's "was something bought before the reader left" check reads fresh** (`trial_paywall_page.dart`). It could join a resume read that started before the purchase and offer the monthly trial to someone who had just paid. The 4 s timeout still bounds it. 4. **Runbook** (`backend/docs/runbooks/play-billing-deletion.md`): the step for a purchase stuck more than a day told the operator to find the order in Play Console by the user's order. By then the account's email is deleted and the purchase document holds no order id. It now points at the stored `purchase_token` and the cancel call the wipe makes. 5. **Test that Home mounts `PlanRefreshOnResume`**, so removing the wrapper fails a test. ## Product invariants affected none ## How it was verified - New tests, each checked to fail without its fix: - `play_billing_plans_sheet_test.dart`: the plans sheet loading state shows the error state, a usage read clears the shared error, and the error state with Retry is still there (shimmer before the fix). - `play_billing_test.dart`: a purchase with a token store that throws returns `failed` and `busy` is false (hung before the fix). A store that fails only on the cleanup write still returns `purchased`. - `plan_refresh_on_resume_test.dart`: Home's source mounts `PlanRefreshOnResume`. - `flutter test test/unit/play_billing_test.dart test/widgets/play_billing_plans_sheet_test.dart test/widgets/plan_refresh_on_resume_test.dart`: 70 passed. `flutter analyze` on the changed files: no new issues. ## UI evidence UI-Evidence: none -- no layout or copy change; the existing "Unable to load plans" state with Retry now stays on screen in a case where it used to fall back to the existing skeleton ## Failure class No `fix:` commits; no declaration required.
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.
What changed and why
On Android build 1.0.598 (1620), a Google Play-billed subscriber cancelled in Google Play's subscription page (Plans & Billing → Manage subscription) and came back with Back. The sheet still said "Your Omi Pro plan will renew on ." Closing and reopening the sheet did not help; only relaunching the app showed "ends". Resubscribing had the same problem the other way round. The server row was right within seconds both times, so the app was simply not reading
GET /v1/users/me/subscriptionagain.The app now reads the plan again:
PlanRefreshOnResume, wraps Home's content and callsUsageProvider.refreshOnResume.PlayBilling.busy). The Play sheet closing is not the reader coming back, and the purchase reads on its own.PlansSheet.initState, so every host that shows the sheet gets it). The last answer stays on screen while the read runs and updates in place. A failed read keeps the working sheet, with no skeleton and no error state.Race this PR introduced, and its fix
fetchSubscription()shares a read that is already in flight. With the resume read added, the Play purchase sheet closing fired a GET at once, while the verify POST started alongside it. If that GET was still in flight when verify returned, the post-purchasefetchSubscription()joined it and got the stale Free answer. A reader who had just paid then saw Free under the success toast. The reviewer reproduced it: 1 GET, plan still basic.The fix has two parts:
fetchSubscription(fresh: true). Use it when the server just changed. A read already in flight may have started before the change, so the call waits for it and then issues one more read. Its future completes with that later read, and fresh callers arriving meanwhile share the same later read.Callers that read after a server change, all now
fresh: true(fromgrep -rn fetchSubscription app/lib):pages/paywall/paywall_checkout.dart::85):107):146)pages/settings/widgets/plans_sheet.dart::610):619):719)providers/usage_provider.dart:_deliverPendingPlayTokens)restorePurchases(Play restore)redeemUserSubscriptionCode(code applied)cancelUserSubscriptionupgradeUserSubscriptionpages/settings/widgets/plans/prepaid_code_sheet.dart:83-84: prepaid code redeemed (the read now and the one 4 s later)pages/settings/widgets/cancel_subscription_sheet.dart:223: retention offer acceptedpages/settings/widgets/yearly_switch.dart:217: yearly switchpages/home/widgets/monthly_switch_sheet.dart:82, 91: payment-issue monthly switch, after an answer and after no answerpages/home/widgets/payment_issue_row.dart:180: customer portal returnPlain reads, unchanged: startup, screen opens, paywall gates, quota invalidation and the backlog poll.
Also in this PR, to get the analyzer green:
integration_test/visual_audit/demo_billing.darttakes thefreshflag.test/widgets/finish_opens_conversation_test.dart'sforceRefreshConversationsoverride now acceptsreconcileHeldRecordings. The analyzer onmainfails without it, because Show manual finish progress on Home v3 #26080's override predates the parameter added in 9e3cc7c.Product invariants affected
none
How it was verified
app/test/widgets/plan_refresh_on_resume_test.dart(13 tests) uses a fake server whose GET answers with what the server held when the request arrived:PlayPlansContent→PaywallCheckout→PlayBilling). A resume GET is held open carrying Free, the purchase is verified, and then the stale answer lands. The app ends on Pro and exactly 2 GETs were issued. Withoutfresh: truethe same test sees 1 GET.PlanRefreshOnResumedriven byhandleAppLifecycleStateChanged: 1 read on resume when signed in, 0 when signed out, 0 when leaving.fetchSubscriptionnow acceptfresh.test/pages/home.flutter analyzereports no errors.UI evidence
UI-Evidence: none -- no layout or copy change; the existing Plans & Billing line now switches between "Your Omi Pro plan will renew on ." and "Your Omi Pro plan ends ." after a resume, after reopening the sheet, and after Google Play's follow-up read, and a just-bought plan shows as Pro instead of Free; device evidence comes from the Android emulator test on the internal build after merge
Failure class
No
fix:commits; no declaration required.