Skip to content

fix: refresh subscription after automatic renewal - #3089

Open
PimpinPumpkin wants to merge 1 commit into
standardnotes:mainfrom
PimpinPumpkin:fix/refresh-expired-subscription
Open

PimpinPumpkin wants to merge 1 commit into
standardnotes:mainfrom
PimpinPumpkin:fix/refresh-expired-subscription

Conversation

@PimpinPumpkin

Copy link
Copy Markdown

Problem

After a subscription renews automatically, Super notes can still be read-only and show the "Your subscription expired on…" banner.

GetFeatureStatus compares the cached subscription's endsAt with the current time. Apart from opening the subscription preferences, the subscription is only refetched on launch, sign-in, session restore, or when the user's roles change. A renewal can change endsAt without changing the user's roles, so if the app stays open, it can keep using the old date. The same can happen if the request at launch fails.

Auto-sync doesn't solve this: while the WebSocket is open, it only syncs when the server reports changed items. It also doesn't refetch the subscription.

Fix

  • After launch, SubscriptionManager checks once a minute whether the cached subscription has expired. This check is local, so no extra requests are made while the subscription is active. An interval is used instead of a single timeout so that it also works after the device wakes from sleep.
  • If it has expired, the subscription is refetched. If it hasn't been renewed or the request fails, the delay between attempts doubles, up to one hour.
  • The response is only applied if the subscription has been renewed. This uses the existing DidFetchSubscription → FeaturesAvailabilityChanged flow, which Super already listens to, so an open note can be unlocked without a restart.
  • If the server still reports the subscription as expired, observers aren't notified. Otherwise, checking just before a renewal is processed could make an open note read-only while someone is typing.
  • The timer is cleared on deinit.

This doesn't add a grace period or change who can use paid features. If the server hasn't processed the renewal, features that are already locked stay locked until a later check finds it. It also doesn't change the separate valid_until check for third-party components.

Testing

I added tests for renewal while the app is open, delayed renewals and failed requests, not notifying observers while still expired, making no extra requests while active, the one-hour limit, and deinit. Before the fix, the renewal, retry and one-hour-limit tests failed.

  • SubscriptionManager.spec.ts: all 23 tests pass
  • snjs Features tests: all 42 pass
  • ESLint passes on packages/services/src/Domain/Subscription
  • All services tests that could run pass (143). Two suites (VaultService and SyncLocalVaultsWithRemoteSharedVaults) couldn't start because I only installed part of the monorepo and they couldn't resolve @notifee/react-native and @standardnotes/snjs. They also fail to start without this change.
  • My partial install was missing React's types, so I ran tsc for services with --types jest,node. The only error was the missing @notifee/react-native module, and it's the same without this change.

Not tested: I haven't run the full build, tested this in the desktop, web or mobile apps, or tested it with a real subscription renewal. The tests use a mocked API and fake timers. I ran into the lockout as a subscriber, but the cause was found by reading the code and reproduced only in unit tests, so I can't confirm it's the only cause.

AI disclosure

This PR was made with substantial help from AI. Claude (via Claude Code) investigated the issue, wrote the code, tests and this description, and ran the checks above, at my request.

🤖 Generated with Claude Code

A renewal can change the subscription end date without changing the
user's roles. While the app stays open, none of the events that refetch
the subscription may fire, so the cached end date passes and paid
editors such as Super become read-only despite the renewal.

Check for a renewal while the cached subscription is expired, backing
off to at most once per hour. Only apply a renewed subscription, so that
a delayed renewal can't make an open editor read-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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