Skip to content

Play Billing: final pre-switch-on fixes (follow-up to #26159) - #26163

Merged
kodjima33 merged 3 commits into
mainfrom
play-billing-final-fixes
Nov 23, 2026
Merged

kodjima33 merged 3 commits into
mainfrom
play-billing-final-fixes

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Last pre-switch-on follow-up to #26159 (merged as b56435b; Play Billing still off for everyone). It covers the general review's three nits and the money review's must-fixes 1 to 5 from the #26159 reviews. No prod switch values change.

App (cherry-picked a3c129f23d, reviewed)

  • Trailing-dot hosts (general 1, money 5): omi_shop.dart strips one trailing root dot before every host comparison, so https://app.omi.me./ and https://www.omi.me./products/omi-pro get the same decisions as their normal forms (blocked from checkout and payment pages too). Tests cover both from each origin.
  • Paid Marketplace button after a failed billing read (general 2): while the first subscription read is in flight the button shows loading. If that read failed it shows "Not available on Android" (never the payment link), and opening the app page retries the read once. During the retry it goes back to loading, then to Subscribe for a Stripe reader or stays unavailable for a Play reader.
  • No trial length while the provider is unknown (general 3): on Android, while the billing provider is unknown (read in flight or failed), the trial page shows no trial length, date or timeline: a skeleton while loading and nothing after a failure. Stripe-billed and iOS readers keep the 7-day timeline.

Backend (money)

  1. One unreadable purchase no longer blocks the others. cancel_for_account_deletion catches PlayCancelPending per purchase, keeps cancelling and stamping the rest, and raises the first error at the end. The unconfirmed purchase is not stamped, so the purge keeps refusing until a retry confirms it. Test: two purchases, the first read 503s, the second is ACTIVE: the second is cancelled and stamped, and the wipe still fails as pending.
  2. Marker failure fields reset. A new grace intent (merged write) and a restore both write grace_actions_failed_attempts=0, grace_actions_last_failed_at=None, grace_actions_overdue=False. Tests: fail 5 times and go overdue, restore, delete again: the merged marker is back to zero with no overdue flag, and the next failed attempt is recorded as attempt 1.
  3. Purge re-reads Google. play_publisher.purge_account_records reads Google once per purchase immediately before the delete (one extra read per purchase per wipe run). If a purchase can charge or be restored again, it raises PlayCancelPending (token hash only) and nothing is deleted; the retried wipe cancels it again. Test: cancel, resubscribe the same purchase, purge refuses and keeps the doc, the next run cancels again and the purge goes through.
  4. Alerting: not added here, on purpose. This repo does own alerting: Grafana rules in backend/charts/monitoring/alerts/*.json, mirrored into alert-rules.json, fed by Prometheus counters or Cloud Monitoring log-based metrics, and guarded by backend/tests/unit/test_monitoring_alert_rule_contract.py. Two failure classes rule out a quick rule. FC-alert-rule-scans-raw-log-lines bans rules that query raw log lines. FC-alert-never-provably-fired requires a new rule's expression to be evaluated against real bad and good history before merge, and with Play off there is no bad period to evaluate. A proper rule (new counter, rule, metric-inventory entry, contract test, measured evaluation) is larger than this PR's budget and should follow once one Play deletion has run. Until then an operator should alert in Cloud Logging on the backend service with:
    severity=CRITICAL AND (textPayload:"delete_account grace immediate-action retry failed" OR jsonPayload.message:"delete_account grace immediate-action retry failed") AND (textPayload:"overdue=True" OR jsonPayload.message:"overdue=True")
    (the line also carries attempts= and age_seconds=). The PostHog Account Deletion Wipe Failed event keeps no uid and no marker reference: none of its sibling deletion events carry one, so none is added.

Product invariants affected

  • INV-MEM-3: account deletion (backend/database/account_deletion_grace.py marker fields, utils/play_publisher.py cancel and purge used by services/users/account_deletion.py). 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 61, test_play_billing 62, tests/services/users/test_account_deletion 114, test_claim_deletion_wipe_txn 42, test_batch_account_authority_writers 653, test_lake_wipe_step 72, tests/routers/test_users 330: all passed.
  • App (Flutter 3.44.5): omi_shop_hardware_test 10, app_detail_paid_billing_test 4, play_billing_plans_sheet_test 27, omi_shop_web_page_test 5, trial_paywall_page_test 5, app_install_flow_test 19: all passed. flutter analyze on the changed files: only a pre-existing info at trial_paywall_page.dart:182.
  • scripts/pr-preflight --pr-body-file on this body and the push gate.
  • Not run: any device, emulator or live Google call.

UI evidence

UI-Evidence: none -- state changes on existing screens, no new screen. On Android: the paid Marketplace app button (loading while the billing provider is unknown; "Not available on Android" after a failed read; one retry when the page opens), and the trial paywall timeline (hidden: skeleton while the provider read is in flight, nothing after it failed). Hosts ending in a dot in the hardware-only store get the same block message as their normal form. 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

…, no trial length while the provider is unknown
…rker failure fields, re-read Google before purge

- cancel_for_account_deletion keeps going when one purchase cannot be confirmed, cancels and stamps
  the rest, then raises the first PlayCancelPending.
- A new grace intent and a restore reset grace_actions_failed_attempts, grace_actions_last_failed_at
  and grace_actions_overdue, so a second deletion counts from zero.
- purge_account_records reads Google once per purchase right before deleting and refuses (wipe
  retries) when a purchase can charge or be restored again.
@kodjima33
kodjima33 marked this pull request as ready for review November 23, 2026 19:09
@kodjima33
kodjima33 merged commit a93d3a5 into main Nov 23, 2026
73 checks passed
@kodjima33
kodjima33 deleted the play-billing-final-fixes branch November 23, 2026 19:18
kodjima33 added a commit that referenced this pull request Nov 23, 2026
…ook, failed-read state (follow-up to #26163) (#26165)

## 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
#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


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/26165?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26165?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26165&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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