Skip to content

Play Billing: deletion cancel hardening and hardware-only store fixes (follow-up to #26129) - #26159

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

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

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Follow-up to #26129 (merged as fca9009 with Play Billing off for everyone: ANDROID_BILLING=stripe, min build 1617, empty cohort). Fixes the round-2 review findings that must land before Play Billing is switched on or the Android build is shown to a Google Play reviewer. No prod switch values change.

Backend (money)

  1. Stale cancel flag. cancel_for_account_deletion no longer skips a purchase because an earlier deletion marked it cancelled. It re-reads Google for every purchase on every run. A purchase the developer already cancelled is recognized from Google's own canceledStateContext.developerInitiatedCancellation, so repeats stay cheap. Sequence tested: grace deletion cancels, restore, the user resubscribes the same purchase (RTDN SUBSCRIPTION_RESTARTED, Google ACTIVE), delete again: cancelled a second time.
  2. Purge wider than cancel. The cancel now walks the user's pointers plus every purchase document with the uid (purchase_keys_for_uid, the same uid equality query the purge uses). Each settled purchase gets account_deletion_confirmed_at. The wipe records the time just before its billing step, and purge_account_records refuses (raises, wipe retries) if any purchase doc lacks a confirmation at or after that time. Nothing is deleted in that case. Tested: a uid-bound purchase with no pointer is cancelled before deletion; a doc confirmed only by an earlier deletion, or never, blocks the purge.
  3. Stuck grace-mode cancel. Every failed grace admission retry in the reconciler now logs with attempt count, age and overdue state (logger.critical once past the due date), emits the existing Account Deletion Wipe Failed deletion telemetry (failed_operations=['grace_immediate_actions'], retry_count, age_seconds, overdue, no token, uid only where existing deletion logs already use it), and records grace_actions_failed_attempts / grace_actions_last_failed_at / grace_actions_overdue on the deletion marker. The wipe is still never dispatched while Google can charge. This is a hard failure, so it uses the deletion error telemetry rather than record_fallback (per .github/agent-docs/fallback-telemetry.md).
  4. Cohort lookup on the subscription route. No code change needed: the route is a sync handler (thread pool), the membership read is get(timeout=1.0, retry=None), read errors become None in _TTLReads._refresh, and user_in_play_cohort catches anything else and returns False. Added tests pinning both: a timed-out read through the real resolver chain returns "not Play" without raising (and the same chain admits a member when the read answers), and the read stays bounded at 1 s with no retry.

App (reviewer-facing, Android hardware-only store)

  1. "Order placed" only on the store's own checkout. A post-purchase path closes the store only on www.omi.me / omi.me under a checkout path, or on checkout.shopify.com. The same words anywhere else go through the normal rules, so a blocked page gets "This page isn't available in the app."
  2. Every *.omi.me host is a store host. app.omi.me (sells Omi Pro), h.omi.me and any other subdomain are blocked from every page, including checkout and off-site payment hops. Only www.omi.me / omi.me with the path allow-list load.
  3. Trial page while Play's offers load or failed. For a Play-billed reader with no loaded Play offer, the timeline card (trial length, date, rows) is replaced by a skeleton while loading and by nothing in the error / Retry state. Stripe-billed and iOS readers keep the 7-day timeline (tested on both platforms).
  4. Web view wiring under test. New test/pages/shop/omi_shop_web_page_test.dart drives OmiWebPage with a fake WebViewPlatform: (a) the device page stays behind the loading state until the marker check returns true; (b) missing marker shows the message with Close, never the page; (c) a throwing script and a script that never answers (new 5 s WebPageCheck.timeout) give the same blocked state; (d) a blocked navigation is prevented and shows the message.
  5. Paid Marketplace apps while the provider is unknown. The paid button now shows the loading state until the first subscription read lands, then Subscribe (Stripe) or "Not available on Android" (Play). The test also caught that the old read used the State's context; it now selects from the build context so the button updates when the read lands.

Product invariants affected

  • INV-MEM-3: backend/services/users/account_deletion.py. The wipe purges Play purchase records only after this run's billing step confirmed each one, and the grace reconciler reports a stuck admission cancel instead of failing silently. Memory and privacy deletion order are unchanged; deletion is never blocked by memory intake state.

How it was verified

  • Backend (one process per file): test_play_billing_money 57, test_play_billing 62, tests/services/users/test_account_deletion 114, tests/routers/test_users 330, test_batch_account_authority_writers 652, test_claim_deletion_wipe_txn 41, test_lake_wipe_step 72, Firestore query guards (test_firestore_query_shapes 633, test_firestore_index_oracle 132, test_firestore_outside_query_contract 31, test_firestore_runtime_witnesses 25, test_port_surface_parity 51), plus the other deletion and billing suites: all passed.
  • App (Flutter 3.44.5): omi_shop_hardware_test, omi_shop_web_page_test, app_detail_paid_billing_test, play_billing_plans_sheet_test and the 22 other paywall, plans sheet, app detail and shop test files: all passed. flutter analyze on the changed files: no new issues.
  • make preflight and scripts/pr-preflight --pr-body-file on this body.
  • Not run: any device or emulator build. The web view tests use a fake platform; the real post-purchase URL and the device proofs listed in the review are still UNVERIFIED.

UI evidence

UI-Evidence: none -- these states only render on Android with Play config or an unknown billing provider; widget tests cover each state (no device build in this change).

Failure class (fixes)

Failure-Class: none

View guided diff Turn on auto-fix

… (follow-up to #26129)

Backend:
- Account deletion re-reads Google for every purchase instead of trusting a stored cancel flag,
  so a purchase resubscribed after a restore is cancelled again.
- The cancel covers every purchase document bound to the uid (the exact set the purge deletes),
  stamps a confirmation time, and the purge refuses any purchase not confirmed in this wipe.
- A failing grace admission cancel logs (critical once overdue), emits deletion telemetry with
  attempt count and age, and records attempts/overdue on the marker; the wipe stays blocked.
- Tests pin the cohort lookup's bounded read and its fail-closed result.

App:
- Post-purchase close only on the store's own checkout; every other *.omi.me host is blocked.
- Trial page shows no trial length, date or timeline for a Play reader until Play's offer loads.
- Marker check times out after 5 s into the blocked state; widget tests drive the web view.
- Paid Marketplace apps wait (loading) while the billing provider is unknown.
@kodjima33
kodjima33 marked this pull request as ready for review November 23, 2026 18:19
@kodjima33
kodjima33 merged commit b56435b into main Nov 23, 2026
70 checks passed
@kodjima33
kodjima33 deleted the play-billing-round2-fixes branch November 23, 2026 18:19
@Git-on-my-level

Copy link
Copy Markdown
Member

Post-merge panel review review-20261123t182447-f152 (luna done; two members pending). Two findings to fix before the Play cohort is non-empty or ANDROID_BILLING=play:

F1 (blocking for Play enablement): backend/utils/play_publisher.py _cancel_one. When cancelling a restorable purchase (user-cancelled, paid time left) fails, the code logs and returns 0. The caller then stamps account_deletion_confirmed_at, and purge_account_records trusts that stamp and deletes the record, while the user can still restore in Google Play and be charged with no Omi account behind it. The same best-effort branch was already in #26129, so this isn't a regression from #26159. Fix: keep the wipe retryable (raise PlayCancelPending) when cancelling a restorable purchase fails, and stamp the confirmation only once Google reports it's neither chargeable nor restorable. Also update the test at test_play_billing_money.py:636-640, which currently expects the unsafe outcome.

F2 (major, app): app/lib/pages/shop/omi_shop.dart _isOmiHost. A trailing-dot host like app.omi.me. gets past the Omi-host block and passes the fromCheckout allow. Fix: strip a terminal DNS dot before comparing, and add a navigation test for https://app.omi.me./.

Shipping is still letting the backend roll carry this PR, because Play is off for everyone (ANDROID_BILLING=stripe, empty cohort) and #26159 is stricter than the code it replaces.

kodjima33 added a commit that referenced this pull request Nov 23, 2026
## 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


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/26163?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/26163?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26163&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. -->
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.

2 participants