YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(app): stop fabricating a subscription_plan that contradicts the entitlement (#5781)
Louis Beaumont6ce45931c33a
diff --git a/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx b/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsxindex 5b5e44077..394828788 100644--- a/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx+++ b/apps/screenpipe-app-tauri/components/app-entitlement-gate.tsx@@ -304,13 +304,18 @@ export function AppEntitlementGate({gateReportedRef.current = true;posthog.capture("app_entitlement_gate_shown", {logged_in: Boolean(user?.token),+ // Must follow the same precedence as the render branches below (and as+ // `gate_path`). Checking unknown-policy before enterprise-app reported+ // "plan_verification_required" for users who were actually looking at the+ // "enterprise app required" screen — both flags are true at once, since an+ // unknown plan is what clears hasConsumerAppSubscription in the first place.reason: shouldGateForEnterpriseLogin? "enterprise_login_required"- : shouldGateForConsumerLogin- ? "consumer_login_required"- : shouldGateForUnknownConsumerPolicy- ? "plan_verification_required"- : "enterprise_app_required",+ : shouldGateForEnterpriseApp+ ? "enterprise_app_required"+ : shouldGateForConsumerLogin+ ? "consumer_login_required"+ : "plan_verification_required",plan: user?.subscription_plan ?? null,app_entitled: user?.app_entitled ?? null,// Diagnostics for the enterprise post-update loop (SCR-132).diff --git a/apps/screenpipe-app-tauri/lib/app-entitlement.test.ts b/apps/screenpipe-app-tauri/lib/app-entitlement.test.tsindex ae7a862e1..d01c45fbd 100644--- a/apps/screenpipe-app-tauri/lib/app-entitlement.test.ts+++ b/apps/screenpipe-app-tauri/lib/app-entitlement.test.ts@@ -368,6 +368,96 @@ describe("app entitlement", () => {expect(hasCloudEntitlement(normalized)).toBe(true);});+ // The server computes `subscription_plan` per request and may omit it while+ // still returning a complete entitlement. Falling back to an invented label+ // ("pro"/"standard") then contradicted the entitlement's own plan, and+ // hasVerifiedPaidPlanAt requires the two to match exactly — so a fully paid+ // account collapsed to "unknown" policy and was shown the enterprise-app gate.+ it("adopts entitlement.plan when the API omits subscription_plan", () => {+ const normalized = normalizeAppUser(+ {+ id: "user_lifetime",+ app_entitled: true,+ cloud_subscribed: false,+ entitlement: {+ active: true,+ plan: "lifetime",+ source: "lifetime",+ checked_at: NOW.toISOString(),+ features: { app: true },+ },+ },+ "token",+ );++ expect(normalized.subscription_plan).toBe("lifetime");+ expect(getLocalPlanPolicy(normalized)).toBe("verified-paid");+ expect(hasConsumerAppSubscription(normalized)).toBe(true);+ });++ it("does not fabricate 'pro' over a richer entitlement plan", () => {+ const normalized = normalizeAppUser(+ {+ id: "user_pro_ultra",+ app_entitled: true,+ cloud_subscribed: true,+ entitlement: {+ active: true,+ plan: "pro_ultra",+ source: "subscription",+ checked_at: NOW.toISOString(),+ features: { app: true, cloud: true },+ },+ },+ "token",+ );++ expect(normalized.subscription_plan).toBe("pro_ultra");+ expect(getLocalPlanPolicy(normalized)).toBe("verified-paid");+ });++ it("still prefers an explicit server subscription_plan over the entitlement", () => {+ const normalized = normalizeAppUser(+ {+ id: "user_explicit",+ app_entitled: true,+ subscription_plan: "team",+ entitlement: {+ active: true,+ plan: "team",+ source: "subscription",+ checked_at: NOW.toISOString(),+ features: { app: true },+ },+ },+ "token",+ );++ expect(normalized.subscription_plan).toBe("team");+ expect(getLocalPlanPolicy(normalized)).toBe("verified-paid");+ });++ it("keeps explicit server denial at 'none' even when the entitlement names a plan", () => {+ const normalized = normalizeAppUser(+ {+ id: "user_revoked",+ app_entitled: false,+ cloud_subscribed: false,+ entitlement: {+ active: true,+ plan: "lifetime",+ source: "lifetime",+ checked_at: NOW.toISOString(),+ features: { app: true },+ },+ },+ "token",+ );++ expect(normalized.subscription_plan).toBe("none");+ expect(hasAppEntitlement(normalized)).toBe(false);+ });+it("does not let cloud_subscribed override explicit server app denial", () => {const normalized = normalizeAppUser({diff --git a/apps/screenpipe-app-tauri/lib/app-entitlement.ts b/apps/screenpipe-app-tauri/lib/app-entitlement.tsindex 515b3d0eb..88d9749d7 100644--- a/apps/screenpipe-app-tauri/lib/app-entitlement.ts+++ b/apps/screenpipe-app-tauri/lib/app-entitlement.ts@@ -561,9 +561,23 @@ export function normalizeAppUser(rawUser: any, token: string): AppUser {// Explicit server denial is stronger than a stale users.plan label left by a// canceled or refunded account.const explicitlyFree = rawUser?.app_entitled === false && !cloudSubscribed;+ // The server computes `subscription_plan` per request and can omit it while+ // still returning a full entitlement. The cloud_subscribed/app_entitled+ // fallbacks below invent a *label* ("pro"/"standard"), and the entitlement is+ // passed through verbatim — so inventing one when the entitlement already+ // names a plan guarantees the two disagree. hasVerifiedPaidPlanAt requires+ // them to be exactly equal, so that mismatch collapses the account to+ // "unknown" policy, which in turn clears hasConsumerAppSubscription and trips+ // the enterprise-app gate for a fully paid consumer account. Prefer the+ // entitlement's own plan so the two sides cannot diverge.+ const rawEntitlementPlan =+ typeof rawEntitlement?.plan === "string" && rawEntitlement.plan.trim()+ ? rawEntitlement.plan+ : null;const subscriptionPlan = explicitlyFree? "none": (rawUser?.subscription_plan ??+ rawEntitlementPlan ??(cloudSubscribed ? "pro" : appEntitled ? "standard" : null));const entitlement = explicitlyFree? {