A desktop app has exactly one job when a license stops being valid: figure out why, and react in proportion. The failure that gets shipped over and over is a single if (!license.IsValid) ShowLockout() that treats an expired trial, a revoked key, a corrupted file, and a two-second network blip as the same event. The customer whose VPN dropped for a moment gets the same red screen as the customer whose key was pulled for non-payment — and the first one files a support ticket that says "your software randomly locked me out."
Key takeaway: The recovery UX is a pure function of three inputs — the verification result, your grace policy, and the clock — mapped to a small set of states, each with its own presentation and its own recovery action. Build that mapping as one reducer, keep transient failure strictly separate from an authoritative negative verdict, and the right screen falls out automatically.
The real question: how many ways can "not valid" actually mean?
"Invalid" is not one state. A verification attempt can land in at least six materially different places, and each one implies a different thing to say and a different button to offer:
public enum LicenseState { Valid, // verified, inside its term Grace, // tolerated: lapsed-but-recent, or service briefly unreachable Expired, // past term and past grace; no current entitlement Revoked, // an authoritative server verdict: this key is dead Tampered, // signature or clock integrity failed locally Missing // no key installed yet } The important cut runs between states the user can recover from and states they cannot. Expired and Missing are fixed by the person at the keyboard — renew, or paste a key. Revoked and Tampered are not; the only honest action is a path to support. Grace is special: nothing is wrong that the user needs to act on, so the app keeps working and heals itself. Collapsing these into one branch is what produces the lockout-on-a-blip bug.
The mechanism: one reducer from result to view
A single verification call returns an outcome, not a boolean. Model it, and model the two failure modes — a verdict (the server or signature said no) versus a transport failure (we could not ask) — as distinct cases, because they must not merge.
public abstract record VerifyOutcome { public sealed record Ok(LicenseClaims Claims) : VerifyOutcome; public sealed record Negative(DenyReason Reason) : VerifyOutcome; // signed verdict public sealed record Unreachable(Exception Cause) : VerifyOutcome; // transport only } public enum DenyReason { Expired, Revoked, BadSignature, ClockRollback, NotFound } Now the whole recovery policy is one pure function. It takes the outcome, how long we have been failing to reach the service, the grace budget, and the clock — and returns the state plus everything the UI needs to render it. No I/O, no timers, trivially unit-testable.
public static LicenseView Reduce( VerifyOutcome outcome, TimeSpan sinceLastGoodCheck, GracePolicy policy, DateTimeOffset now) => outcome switch { VerifyOutcome.Ok ok when ok.Claims.NotAfter > now => LicenseView.Active(ok.Claims), // Term elapsed, but still inside the post-expiry grace budget. VerifyOutcome.Ok ok when now - ok.Claims.NotAfter <= policy.PostExpiry => LicenseView.InGrace(ok.Claims, expiresIn: policy.PostExpiry - (now - ok.Claims.NotAfter)), // We simply could not reach the service: never a lockout while we have grace left. VerifyOutcome.Unreachable when sinceLastGoodCheck <= policy.Offline => LicenseView.InGrace(reason: "Reconnecting…", expiresIn: policy.Offline - sinceLastGoodCheck), VerifyOutcome.Unreachable => LicenseView.Expired(recoverable: true, message: "Offline too long — reconnect to continue."), // Authoritative negatives. Each gets its own screen and its own action. VerifyOutcome.Negative n => n.Reason switch { DenyReason.Expired => LicenseView.Expired(recoverable: true), DenyReason.NotFound => LicenseView.Missing(), DenyReason.Revoked => LicenseView.Blocked(DenyReason.Revoked), // no self-service fix DenyReason.BadSignature => LicenseView.Blocked(DenyReason.BadSignature), DenyReason.ClockRollback=> LicenseView.Blocked(DenyReason.ClockRollback), _ => LicenseView.Blocked(n.Reason), }, _ => LicenseView.Blocked(DenyReason.NotFound), }; Read the order of the cases: an Unreachable outcome can never fall through to a hard block while there is offline grace left. The only way to reach Blocked is a Negative — a signed, unambiguous verdict — or a tamper signal. That single ordering rule is the whole defense against locking out good customers on a bad network.
Unreachable outcomes stay in Grace and heal; only a signed negative verdict crosses into the hard-block states on the right. Wiring it to a view-model that heals itself
The reducer is pure, so the view-model around it is thin: re-run verification on a cadence, feed the outcome through Reduce, and publish the resulting LicenseView. The UI binds to one property and never contains a licensing if of its own.
public sealed class LicenseStatusViewModel : INotifyPropertyChanged { private LicenseView _view = LicenseView.Checking(); public LicenseView View { get => _view; private set { _view = value; OnChanged(); } } public async Task RefreshAsync(CancellationToken ct) { VerifyOutcome outcome = await _license.VerifyAsync(ct); // local Ed25519 + optional revalidation if (outcome is VerifyOutcome.Ok ok) _clockGuard.RecordTrustedTime(ok.Claims.IssuedAt); // advance the high-water mark View = Reduce(outcome, _clockGuard.SinceLastGood, _policy, DateTimeOffset.UtcNow); // Heal automatically: while in Grace, keep retrying on a short backoff. if (View.State == LicenseState.Grace) _retry.Schedule(() => _ = RefreshAsync(ct)); } } _clockGuard is what stops the set-the-clock-back trick. It persists the highest timestamp ever verified, and if the local clock reads earlier than that by more than the skew leeway, VerifyAsync returns Negative(ClockRollback) — which the reducer routes straight to Blocked. For how to size that leeway against legitimate DST and timezone shifts, see the Keyright clock-skew and NotBefore leeway post.
The recovery actions — one per state, nothing more
Each non-Valid state exposes exactly one primary action, and the action matches who can actually fix it:
- Grace — no button. A quiet, non-modal banner ("Working offline — reconnecting…"). The app heals without the user doing anything.
- Expired — a non-blocking "Renew" prompt that opens the purchase or renewal flow, and a "Enter a new key" field. The app stays open; where it makes sense, it degrades to read-only or to the free Community Edition surface instead of going dark.
- Missing — the first-run activation screen: paste a key, hit verify,
RefreshAsyncre-runs. - Revoked / Tampered — these are the only states that justify a hard stop. Show why in plain language and a single "Contact support" path. There is no self-service field, because the user genuinely cannot fix a revoked key themselves; pointing them at support is the honest move. The lookup your support team runs is the why-is-this-blocked flow.
Notice there is no retry button on the hard-block states. Re-verifying a revoked key just returns the same Negative(Revoked); offering "Try again" trains the user to mash it and file a ticket anyway.
Caveats: where this bites
Grace budget is a trade-off, not a free parameter. Too generous and a genuinely expired customer runs for weeks; too tight and a laptop that sleeps over a weekend greets the user with a lockout on Monday. Size policy.Offline against your real usage pattern — the transient-outage grace-window post covers the math.
Degrading to read-only is a product decision, not a licensing one. The reducer can tell you a license is Expired; it cannot tell you which features are safe to leave on. That mapping lives in your entitlement layer, and getting it wrong — leaving a paid export enabled after expiry — undoes the whole point.
The reducer is only as honest as VerifyAsync. If verification swallows a signature failure and returns Unreachable, a tampered key hides in the grace state forever. Signature and clock checks are local and must fail into Negative, never into transport failure. Keep that boundary sharp.
A background re-check must never interrupt work. Run RefreshAsync off the UI thread and let the state change the chrome — a banner, a disabled menu item — rather than throwing a modal over whatever the user is mid-way through typing.
Takeaway
Treat recovery as a pure mapping, not a scatter of if statements. Model the verification outcome as Ok / Negative / Unreachable, keep transport failure strictly out of the lockout path, and reduce the whole thing to one of six states — each with a presentation and a single action that matches who can fix it. Do that and the flaky-network customer heals silently in Grace while the revoked key gets the stop it deserves, and neither one ever sees the other's screen. Keyright's Community Edition is a sound degrade-to target for expired desktop apps; the full recovery and entitlement recipe is in the Keyright docs.

