Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
…e is stale Co-authored-by: Cursor <cursoragent@cursor.com>
This branch was successfully 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.
Explanation
SubscriptionDelegationServicewas reusing a stored cash-subscription delegation whenever its periodstartDatewas already in the past. The Subscription API only accepts a storedstartDateinside a window around the start date this checkout would sign: 14 days before that date through 5 minutes after it. A live permission older than 14 days still matched on the client, soPOST /subscriptions/cryptofailed withE214(Delegation startDate must be between …).The fingerprint now takes the checkout's computed
startDateasexpectedStartDateand reuses a stored permission only when its periodstartDateis inside that same window. A non-positivestartDateis rejected. When the checkout start is still in the future (a trial), a live permission also fails the trial floor (now + 1), so a redeemable permission cannot satisfy a trial checkout. BothprepareDelegationandstartSubscriptionWithDelegationalready share this predicate, so both paths sign a new delegation when every stored match is outside the window.The skew constants match
va-mmcx-subscription-api(START_DATE_PAST_SKEW_SECONDS = 14 days,START_DATE_FUTURE_SKEW_SECONDS = 5 minutes). Trial length is unchanged and still comes fromgetDelegationStartDate.isTrialDeferredis gone from the internal fingerprint type; that type is not a package export, so this is not a consumer-facing signature change.References
POST /v1/subscriptions/cryptoreturnedSubscriptionServiceError/errorCode: E214/httpStatus: 400, with bounds spanning exactly 14 days + 5 minutes (non-trial,trialPeriodDays === 0).va-mmcx-subscription-apisrc/delegation/caveat-enforcers/validate.ts.Checklist
Test plan
yarn workspace @metamask/subscription-controller run test(100% coverage on the package)yarn changelog:validateNote
Medium Risk
Changes subscription checkout delegation reuse logic for crypto payments; incorrect window math could cause extra signing or missed reuse, but aligns client behavior with the API and fixes production E214 failures.
Overview
Fixes E214 on crypto subscription checkout by tightening when stored cash-subscription delegations can be reused.
Delegation fingerprinting no longer treats any past
startDateas reusable. It passes the checkout’s computedexpectedStartDateand only reuses a stored permission if its periodstartDatelies in the Subscription API window (14 days before through 5 minutes after that date, aligned withva-mmcx-subscription-api). Trial checkouts also enforce a floor so an immediately redeemable permission cannot satisfy a future start. Stale permissions outside the window causeprepareDelegationandstartSubscriptionWithDelegationto sign and register a new delegation instead of resubmitting an old hash.Tests and changelog cover the >14-day stale case and window boundary behavior.
Reviewed by Cursor Bugbot for commit eb39452. Bugbot is set up for automated code reviews on this repo. Configure here.