Skip to content

Play Billing: purge waits only on chargeable purchases, deletion runbook, failed-read state (follow-up to #26163) - #26165

Merged
kodjima33 merged 1 commit into
mainfrom
play-billing-last-fixes
Nov 23, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
play-billing-last-fixes

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Follow-up to #26163 (merged as a93d3a5; Play Billing still off for everyone). It fixes must-fixes 1 to 4 and the nits from that PR's review. No prod switch values change.

Changes

  1. Purge no longer waits out paid time. The pre-purge Google read now refuses only a purchase that can charge, using the existing _CHARGEABLE_STATES (ACTIVE, IN_GRACE_PERIOD, ON_HOLD, PAUSED, PENDING). A user-cancelled purchase with paid time left still gets the best-effort developer cancel in the cancel step. The purge then proceeds whatever Google answered, with a warning naming the masked purchase key, so erasure no longer stalls at play_billing_records until the paid time ends. Tests: CANCELED with 20 days left and the developer cancel rejected (400): the purge goes through. ACTIVE or IN_GRACE_PERIOD at purge: still refused. Read error (503) at purge: still refused.

  2. Operator instructions live in the repo. New backend/docs/runbooks/play-billing-deletion.md (48 lines) covers:

    • The two stuck states: the grace-mode cancel keeps failing at admission, or the wipe fails on Play at its billing step or at play_billing_records.
    • Why the old filter never matched: the backend logs in text mode (backend/main.py default_format='text'), so logger.critical lands as severity ERROR.
    • Cloud Logging filters built on severity>=ERROR: the text is checked against the code's messages and against what sanitize() leaves (it masks the purchase key to a1b***5f6, and the filter text survives it).
    • The PostHog failure events.
    • What an operator does for a 403, a 5xx or a chargeable-again purchase, and for a purchase not confirmed in this run.

    A wipe failing at play_billing_records already went through the shared failure path (wipe_status=failed, ERROR log, Account Deletion Wipe Failed). But failed_operations listed only the derived purge's best-effort failures whenever there were any, hiding the step that actually failed. It now always includes the failing step. Test: a best-effort failure, then a refusal at the Play-records step → failed_operations == ['speech_profile_audio', 'play_billing_records'], no uid in the event.

  3. Dedicated failed-read state. UsageProvider keeps _subscriptionReadFailed, which only a subscription read sets (null or exception) and clears (at its start and on success), and which a session reset clears. billingProviderFailed and billingProviderPending are based on it, not on the shared _error that usage, plans and checkout calls clear. restorePurchases still reads _error right after its own subscription read, unchanged. Tests: a failed subscription read followed by a successful usage read (which clears _error) stays failed. Retry shows on the outline and trial paywalls, with no timeline skeleton, and "Not available" on the paid app button. A successful subscription read clears the state.

  4. Retry-on-open test (a3c129f23d). The paid app page is opened after a failed read and a usage read that cleared the shared error. Exactly one more read runs, and five forced rebuilds start no more. A Stripe reader ends on Subscribe, and a second failure ends on "Not available".

  5. Nits.

    • Hosts: _hostOf strips every trailing dot, and test rows cover app.omi.me.., h.omi.me... and www.omi.me..; these fail on the old one-dot strip.
    • Skeleton height: not changed. The real timeline card's height depends on its content: measured in a widget test it is 265 px at 430 wide and 535 px at 360 wide at normal text size, and up to 1747 px at 1.3x text. No constant skeleton matches it. Matching exactly would mean laying out the hidden card with its 7-day text still in the tree, which Play Billing: deletion cancel hardening and hardware-only store fixes (follow-up to #26129) #26159 removed on purpose. The skeleton stays 120 px, and the page can shift when the read lands.

Product invariants affected

  • INV-MEM-3: backend/services/users/account_deletion.py wipe failure telemetry now names the failing step, and the Play purge (utils/play_publisher.py) no longer holds erasure on a purchase that cannot charge. Deletion still never completes while Google can charge; memory and privacy deletion order are unchanged.

How it was verified

  • Backend, one process per file: test_play_billing_money 65, test_play_billing 62, tests/services/users/test_account_deletion 115, test_lake_wipe_step 72, test_account_deletion_single_executor 9: all passed.
  • App (Flutter 3.44.5): play_billing_plans_sheet_test 29, app_detail_paid_billing_test 6, omi_shop_hardware_test 10, omi_shop_web_page_test 5, the trial, outline, router, plans sheet, onboarding and app install suites, and the four usage_provider_* test files: all passed. flutter analyze on the changed files: no issues.
  • scripts/pr-preflight --pr-body-file on this body and the push gate.
  • Not run: any device, emulator, live Google call or live Cloud Logging query (the runbook filters are checked against the code and the logging setup, not against the real log stream).

UI evidence

UI-Evidence: none -- state changes on existing Android screens, no new screen: after a failed subscription read the outline and trial paywalls keep showing Retry and the paid Marketplace app button keeps showing "Not available on Android" even after other reads succeed; opening the paid app page retries the read once. Android device evidence comes from the pending emulator test; widget tests cover each state.

Failure class (fixes)

Failure-Class: none

View guided diff Turn on auto-fix

…ok, dedicated subscription-read failure state

- The pre-purge Google read refuses only a chargeable purchase (ACTIVE, IN_GRACE_PERIOD, ON_HOLD,
  PAUSED, PENDING). A user-cancelled purchase with paid time left no longer holds erasure until the
  paid time ends.
- Wipe failure telemetry always names the failing step, including play_billing_records after
  best-effort derived purge failures.
- backend/docs/runbooks/play-billing-deletion.md: both stuck states, Cloud Logging filters that match
  the text-mode lines (severity>=ERROR), operator steps.
- UsageProvider tracks a failed subscription read in its own flag, so usage and plans reads no longer
  turn the failed state back into pending.
- Tests for the paid app page's retry on open; hosts drop every trailing dot.
@kodjima33
kodjima33 marked this pull request as ready for review November 23, 2026 19:28
@kodjima33
kodjima33 merged commit e2d1353 into main Nov 23, 2026
72 checks passed
@kodjima33
kodjima33 deleted the play-billing-last-fixes branch November 23, 2026 20:07
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.
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