Repository navigation
fix: refresh subscription after automatic renewal - #3089
Open
PimpinPumpkin wants to merge 1 commit into
Open
PimpinPumpkin wants to merge 1 commit into
PimpinPumpkin wants to merge 1 commit into
Conversation
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
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.
Problem
After a subscription renews automatically, Super notes can still be read-only and show the "Your subscription expired on…" banner.
GetFeatureStatuscompares the cached subscription'sendsAtwith 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 changeendsAtwithout 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
SubscriptionManagerchecks 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.DidFetchSubscription→FeaturesAvailabilityChangedflow, which Super already listens to, so an open note can be unlocked without a restart.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_untilcheck 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 passFeaturestests: all 42 passpackages/services/src/Domain/Subscriptionservicestests that could run pass (143). Two suites (VaultServiceandSyncLocalVaultsWithRemoteSharedVaults) couldn't start because I only installed part of the monorepo and they couldn't resolve@notifee/react-nativeand@standardnotes/snjs. They also fail to start without this change.tscforserviceswith--types jest,node. The only error was the missing@notifee/react-nativemodule, 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