Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(account): a failed renewal is shown as one, with the way to pay it

purpled43134b511cf
diff --git a/src/api/cloud/jobs.ts b/src/api/cloud/jobs.ts
index 7dfdd629..db0b8445 100644
--- a/src/api/cloud/jobs.ts
+++ b/src/api/cloud/jobs.ts
@@ -105,6 +105,12 @@ export interface CloudMe {
* what the invoice contradicts. Absent on older servers = unknown, which
* every surface reads as "promise nothing". */
paidPlan?: boolean
+ /** True while a renewal payment of this account failed and no paid plan
+ * is active. Independent of status: pack credits keep such an account
+ * 'active' on tier 'starter'. Absent on older servers = false. */
+ pastDue?: boolean
+ /** The plan waiting for that payment (hosted | hosted-pro | hosted-max). */
+ pastDueTier?: string | null
}
}
diff --git a/src/components/auth/AccountPanel.tsx b/src/components/auth/AccountPanel.tsx
index 6abbf52c..4d3a60b7 100644
--- a/src/components/auth/AccountPanel.tsx
+++ b/src/components/auth/AccountPanel.tsx
@@ -14,7 +14,9 @@ import { MONOGRAM } from '../layout/brand'
import { openExternal } from '../../api/backend'
import { formatCount } from '../../lib/formatters'
import { countUnsyncedAccountMemories } from '../../lib/memory-unsynced'
+import { PAST_DUE_ACTION, PAST_DUE_BADGE, PAST_DUE_WALLET_LINE, pastDueLine } from '../../lib/past-due'
import { Modal } from '../ui/Modal'
+import { Hinweis } from '../ui/Hinweis'
/**
* Run a sign-out and report what happened, in that order.
@@ -132,6 +134,8 @@ export function AccountPanel() {
const user = useCloudAuthStore((s) => s.user)
const licenseActive = useCloudAuthStore((s) => s.licenseActive)
const quota = useCloudAuthStore((s) => s.quota)
+ const pastDue = useCloudAuthStore((s) => s.pastDue)
+ const pastDueTier = useCloudAuthStore((s) => s.pastDueTier)
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
@@ -265,7 +269,7 @@ export function AccountPanel() {
<div>
<div className="text-[0.7rem] text-gray-900 dark:text-gray-100">{user.email ?? user.id}</div>
<div className="text-[0.65rem] text-gray-500">
- {licenseActive ? `Plan: ${quota?.tier ?? 'active'}` : 'No active plan'}
+ {licenseActive ? `Plan: ${quota?.tier ?? 'active'}` : pastDue ? PAST_DUE_BADGE : 'No active plan'}
</div>
</div>
<button
@@ -311,6 +315,24 @@ export function AccountPanel() {
</p>
)}
+ {/* A failed renewal, said in plain words with the way to settle it.
+ Until 3.0.5 this account read "No active plan" and was offered a new
+ one. Paying happens on lu-labs.ai, the app does not touch Stripe. */}
+ {pastDue && (
+ <div className="space-y-1.5" data-testid="past-due-notice">
+ <Hinweis ton="fehler">
+ {pastDueLine(pastDueTier)}
+ {licenseActive ? ` ${PAST_DUE_WALLET_LINE}` : ''}
+ </Hinweis>
+ <button
+ onClick={() => void openExternal(`${CLOUD_BASE}/account`)}
+ className="flex items-center gap-1 px-2 py-1 rounded text-[0.65rem] font-medium border border-gray-200 dark:border-white/10 bg-gray-100 dark:bg-white/5 text-gray-800 dark:text-gray-200 hover:bg-gray-200 dark:hover:bg-white/10 transition-colors"
+ >
+ <ExternalLink size={10} /> {PAST_DUE_ACTION}
+ </button>
+ </div>
+ )}
+
{licenseActive && quota ? (
<div className="space-y-2">
{/* One shared compute-credit wallet, chat, images, video and voice
@@ -323,17 +345,23 @@ export function AccountPanel() {
/>
</div>
) : (
- <p className="text-[0.7rem] text-gray-600 dark:text-gray-400">
- Pick a plan to unlock cloud rendering and chat.
- </p>
+ !pastDue && (
+ <p className="text-[0.7rem] text-gray-600 dark:text-gray-400">
+ Pick a plan to unlock cloud rendering and chat.
+ </p>
+ )
)}
- <button
- onClick={() => void openExternal(`${CLOUD_BASE}/${licenseActive ? 'account' : 'pricing'}`)}
- className="flex items-center gap-1 text-[0.65rem] text-gray-500 hover:text-gray-800 dark:hover:text-gray-200 transition-colors"
- >
- <ExternalLink size={10} /> {licenseActive ? 'Manage subscription' : 'View plans'} on lu-labs.ai
- </button>
+ {/* Not next to the notice: the server refuses a new plan until the open
+ invoice is settled, and its button already leads to the account. */}
+ {!(pastDue && !licenseActive) && (
+ <button
+ onClick={() => void openExternal(`${CLOUD_BASE}/${licenseActive ? 'account' : 'pricing'}`)}
+ className="flex items-center gap-1 text-[0.65rem] text-gray-500 hover:text-gray-800 dark:hover:text-gray-200 transition-colors"
+ >
+ <ExternalLink size={10} /> {licenseActive ? 'Manage subscription' : 'View plans'} on lu-labs.ai
+ </button>
+ )}
</div>
)
}
diff --git a/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx b/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx
new file mode 100644
index 00000000..e2e4a634
--- /dev/null
+++ b/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx
@@ -0,0 +1,104 @@
+// @vitest-environment jsdom
+/**
+ * A renewal payment that failed (license.pastDue in /api/me, web ee31e7f9).
+ *
+ * Until 3.0.5 the panel said "No active plan" and "Pick a plan" to a customer
+ * whose card had merely bounced, and offered the plans again. The server
+ * refuses that purchase until the open invoice is paid, so the one honest
+ * thing to show is the failed payment and the way to the invoice.
+ *
+ * Run: npx vitest run src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx
+ */
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import type { CloudQuota } from '../../../lib/render/cloud-jobs'
+
+vi.mock('../../../hooks/useCloudAuth', () => ({
+ useCloudAuth: () => ({ status: 'signed-in', login: vi.fn(), signup: vi.fn(), logout: vi.fn() }),
+}))
+vi.mock('../../../api/cloud/supabase', () => ({ loginWithProvider: vi.fn() }))
+const openExternal = vi.fn(async () => {})
+vi.mock('../../../api/backend', () => ({ openExternal }))
+
+const { AccountPanel } = await import('../AccountPanel')
+const { useCloudAuthStore } = await import('../../../stores/cloudAuthStore')
+
+const SENTENCE = 'The last payment for your Pro plan failed, so the plan is paused. Pay the open invoice to bring it back.'
+const WALLET = 'Credits you bought stay usable in the meantime.'
+
+const walletQuota: CloudQuota = {
+ tier: 'starter',
+ period: '2026-10',
+ limits: { credits: 5000 },
+ costs: { image: 10, video: 100 },
+ used: { credits_used: 1200 },
+ remaining: { credits: 3800 },
+}
+
+const signIn = (account: Partial<Parameters<ReturnType<typeof useCloudAuthStore.getState>['setSignedIn']>[1]>) =>
+ useCloudAuthStore.getState().setSignedIn(
+ { id: 'u1', email: '[email protected]' },
+ { licenseActive: false, tier: null, access: true, quota: null, paidPlan: false, ...account },
+ )
+
+afterEach(() => {
+ cleanup()
+ openExternal.mockClear()
+ useCloudAuthStore.getState().setSignedOut()
+})
+
+describe('a failed renewal without credits', () => {
+ it('says so instead of "No active plan" and leads to the invoice', () => {
+ signIn({ pastDue: true, pastDueTier: 'hosted-pro' })
+ render(<AccountPanel />)
+
+ expect(screen.getByText('Payment failed')).toBeTruthy()
+ expect(screen.queryByText('No active plan')).toBeNull()
+ expect(screen.getByTestId('past-due-notice').textContent).toContain(SENTENCE)
+ expect(screen.getByTestId('past-due-notice').textContent).not.toContain(WALLET)
+ // Nothing here sells a new plan: the server refuses one until the invoice is paid.
+ expect(screen.queryByText(/Pick a plan/)).toBeNull()
+ expect(screen.queryByText(/View plans/)).toBeNull()
+
+ fireEvent.click(screen.getByText('Pay open invoice'))
+ expect(openExternal).toHaveBeenCalledTimes(1)
+ expect(openExternal).toHaveBeenCalledWith('https://lu-labs.ai/account')
+ })
+
+ it('says "your plan" when the server does not name one', () => {
+ signIn({ pastDue: true, pastDueTier: null })
+ render(<AccountPanel />)
+ expect(screen.getByTestId('past-due-notice').textContent).toContain('The last payment for your plan failed')
+ })
+})
+
+describe('a failed renewal with pack credits left', () => {
+ it('keeps the plan line and the meter, and adds the notice with the wallet sentence', () => {
+ signIn({ licenseActive: true, tier: 'starter', quota: walletQuota, pastDue: true, pastDueTier: 'hosted-pro' })
+ render(<AccountPanel />)
+
+ expect(screen.getByText('Plan: starter')).toBeTruthy()
+ expect(screen.queryByText('Payment failed')).toBeNull()
+ expect(screen.getByTestId('past-due-notice').textContent).toContain(`${SENTENCE} ${WALLET}`)
+ expect(screen.getByText('Cloud credits (this billing period)')).toBeTruthy()
+ expect(screen.getByText(/Manage subscription/)).toBeTruthy()
+ })
+})
+
+describe('no failed payment', () => {
+ it('an account without a plan reads as before', () => {
+ signIn({})
+ render(<AccountPanel />)
+ expect(screen.getByText('No active plan')).toBeTruthy()
+ expect(screen.getByText(/Pick a plan/)).toBeTruthy()
+ expect(screen.getByText(/View plans/)).toBeTruthy()
+ expect(screen.queryByTestId('past-due-notice')).toBeNull()
+ })
+
+ it('a paying account shows no notice', () => {
+ signIn({ licenseActive: true, tier: 'hosted', quota: { ...walletQuota, tier: 'hosted' }, paidPlan: true })
+ render(<AccountPanel />)
+ expect(screen.getByText('Plan: hosted')).toBeTruthy()
+ expect(screen.queryByTestId('past-due-notice')).toBeNull()
+ })
+})
diff --git a/src/hooks/useCloudAuth.ts b/src/hooks/useCloudAuth.ts
index e02775d4..223438ad 100644
--- a/src/hooks/useCloudAuth.ts
+++ b/src/hooks/useCloudAuth.ts
@@ -13,6 +13,7 @@ import { refreshCatalog } from '../stores/cloudCatalogStore'
import { useProviderStore } from '../stores/providerStore'
import { useSettingsStore } from '../stores/settingsStore'
import { stopAllBackgroundWork } from '../lib/background-shutdown'
+import { pastDueFromLicense } from '../lib/past-due'
import type { CloudQuota } from '../lib/render/cloud-jobs'
const REFRESH_MS = 5 * 60_000
@@ -71,7 +72,10 @@ async function probeAccount(): Promise<void> {
if (stale()) return
void refreshCatalog()
}
- store.setSignedIn({ id: me.user.id, email: me.user.email }, { licenseActive, tier, access, paidPlan, quota })
+ store.setSignedIn(
+ { id: me.user.id, email: me.user.email },
+ { licenseActive, tier, access, paidPlan, ...pastDueFromLicense(me.license), quota },
+ )
syncChatProvider()
syncAppMode()
} catch (err) {
diff --git a/src/lib/__tests__/past-due.test.ts b/src/lib/__tests__/past-due.test.ts
new file mode 100644
index 00000000..7cebcec3
--- /dev/null
+++ b/src/lib/__tests__/past-due.test.ts
@@ -0,0 +1,94 @@
+/**
+ * A failed renewal as /api/me reports it (license.pastDue, license.pastDueTier,
+ * web commit ee31e7f9), and the words the account panel puts on it.
+ *
+ * Two things can go wrong without anyone noticing: an older server that does
+ * not send the fields is read as "payment failed", or the sentences drift away
+ * from the ones the web account page shows for the very same account.
+ *
+ * Run: LU_WEB_REPO=/path/to/web npx vitest run src/lib/__tests__/past-due.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { existsSync, readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import {
+ PAST_DUE_ACTION,
+ PAST_DUE_BADGE,
+ PAST_DUE_WALLET_LINE,
+ pastDueFromLicense,
+ pastDueLine,
+} from '../past-due'
+
+describe('reading the fields off /api/me', () => {
+ it('an older server that sends neither field means no failed payment', () => {
+ expect(pastDueFromLicense({ status: 'none' })).toEqual({ pastDue: false, pastDueTier: null })
+ expect(pastDueFromLicense({ status: 'active', tier: 'hosted' })).toEqual({ pastDue: false, pastDueTier: null })
+ expect(pastDueFromLicense(undefined)).toEqual({ pastDue: false, pastDueTier: null })
+ })
+
+ it('pack credits keep the account active and the failed payment is still read', () => {
+ expect(
+ pastDueFromLicense({ status: 'active', tier: 'starter', pastDue: true, pastDueTier: 'hosted-pro' }),
+ ).toEqual({ pastDue: true, pastDueTier: 'hosted-pro' })
+ })
+
+ it('an account without credits reads the same two fields', () => {
+ expect(pastDueFromLicense({ status: 'none', pastDue: true, pastDueTier: null })).toEqual({
+ pastDue: true,
+ pastDueTier: null,
+ })
+ })
+
+ it('only a literal true counts, and a tier without the flag is dropped', () => {
+ const odd = { status: 'none', pastDue: 'yes', pastDueTier: 'hosted' } as unknown as Parameters<
+ typeof pastDueFromLicense
+ >[0]
+ expect(pastDueFromLicense(odd)).toEqual({ pastDue: false, pastDueTier: null })
+ expect(pastDueFromLicense({ status: 'active', pastDue: false, pastDueTier: 'hosted' })).toEqual({
+ pastDue: false,
+ pastDueTier: null,
+ })
+ })
+})
+
+describe('the sentence', () => {
+ it('names the plan the way the Cloud gate names it', () => {
+ expect(pastDueLine('hosted')).toBe(
+ 'The last payment for your Hosted plan failed, so the plan is paused. Pay the open invoice to bring it back.',
+ )
+ expect(pastDueLine('hosted-pro')).toContain('your Pro plan')
+ expect(pastDueLine('hosted-max')).toContain('your Max plan')
+ })
+
+ it('says "your plan" when the plan is unknown', () => {
+ for (const tier of [null, 'starter', 'something-new']) {
+ expect(pastDueLine(tier)).toBe(
+ 'The last payment for your plan failed, so the plan is paused. Pay the open invoice to bring it back.',
+ )
+ }
+ })
+})
+
+const REL_PATH = 'apps/web/lib/billing/past-due.ts'
+const WEB = process.env.LU_WEB_REPO?.trim() ? resolve(process.env.LU_WEB_REPO.trim()) : undefined
+const WEB_FILE = WEB ? resolve(WEB, REL_PATH) : ''
+const HAS_WEB = WEB_FILE !== '' && existsSync(WEB_FILE)
+if (!HAS_WEB) {
+ process.stderr.write('[past-due] wording parity skipped: set LU_WEB_REPO to a web checkout that has ' + REL_PATH + '.\n')
+}
+
+describe.skipIf(!HAS_WEB)('the wording is the web wording', () => {
+ const web = HAS_WEB ? readFileSync(WEB_FILE, 'utf8') : ''
+
+ it('badge, button and wallet line are the same strings', () => {
+ for (const text of [PAST_DUE_BADGE, PAST_DUE_ACTION, PAST_DUE_WALLET_LINE]) {
+ expect(web).toContain(`'${text}'`)
+ }
+ })
+
+ it('the sentence is built from the same template', () => {
+ const [head, tail] = pastDueLine(null).split('your plan')
+ expect(web).toContain("'your plan'")
+ expect(web).toContain('`' + head + '${plan}' + tail + '`')
+ })
+})
diff --git a/src/lib/past-due.ts b/src/lib/past-due.ts
new file mode 100644
index 00000000..db518d6c
--- /dev/null
+++ b/src/lib/past-due.ts
@@ -0,0 +1,42 @@
+// A renewal payment that failed (license.pastDue in /api/me), in the words the
+// web account page uses (apps/web/lib/billing/past-due.ts). The sentences are
+// copied, not rephrased, and a parity test holds them to the web source.
+//
+// House rule: none of this is rendered in or above a prompt field. A failed
+// payment is an account matter and is shown where the account is managed.
+
+import type { CloudMe } from '../api/cloud/jobs'
+
+/** Plan names as the Cloud gate writes them on its plan buttons. */
+const PLAN_NAMES: Record<string, string> = {
+ hosted: 'Hosted',
+ 'hosted-pro': 'Pro',
+ 'hosted-max': 'Max',
+}
+
+/** The sentence that replaces "No active plan" while a renewal is unpaid. */
+export function pastDueLine(tier: string | null): string {
+ const name = tier ? PLAN_NAMES[tier] : undefined
+ const plan = name ? `your ${name} plan` : 'your plan'
+ return `The last payment for ${plan} failed, so the plan is paused. Pay the open invoice to bring it back.`
+}
+
+/** Added when pack credits keep the account working in the meantime. */
+export const PAST_DUE_WALLET_LINE = 'Credits you bought stay usable in the meantime.'
+
+export const PAST_DUE_ACTION = 'Pay open invoice'
+
+/** Stands where "No active plan" stood while nothing else is active. */
+export const PAST_DUE_BADGE = 'Payment failed'
+
+/**
+ * Reads the two fields off /api/me. A server from before 2026-10-05 does not
+ * send them, and that reads as "no failed payment": only a literal true counts.
+ */
+export function pastDueFromLicense(license: CloudMe['license'] | null | undefined): {
+ pastDue: boolean
+ pastDueTier: string | null
+} {
+ const pastDue = license?.pastDue === true
+ return { pastDue, pastDueTier: pastDue ? (license?.pastDueTier ?? null) : null }
+}
diff --git a/src/stores/cloudAuthStore.ts b/src/stores/cloudAuthStore.ts
index c70686e2..b9d7a3fe 100644
--- a/src/stores/cloudAuthStore.ts
+++ b/src/stores/cloudAuthStore.ts
@@ -27,11 +27,18 @@ export interface CloudAccount {
* und das verspricht nichts (siehe lib/flash-entitlement).
*/
paidPlan?: boolean | null
+ /** A renewal payment failed and no paid plan is active. Says nothing about
+ * licenseActive: pack credits keep an unpaid account working. */
+ pastDue?: boolean
+ /** The plan that is waiting for that payment, null otherwise. */
+ pastDueTier?: string | null
quota: CloudQuota | null
}
interface CloudAuthState extends CloudAccount {
paidPlan: boolean | null
+ pastDue: boolean
+ pastDueTier: string | null
/** 'probing' until the keychain session restore + first /api/me resolve. */
status: 'probing' | 'signed-out' | 'signed-in'
user: CloudUser | null
@@ -48,12 +55,22 @@ export const useCloudAuthStore = create<CloudAuthState>()((set) => ({
tier: null,
access: true,
paidPlan: null,
+ pastDue: false,
+ pastDueTier: null,
quota: null,
setSignedOut: () =>
- set({ status: 'signed-out', user: null, licenseActive: false, tier: null, access: true, paidPlan: null, quota: null }),
+ set({
+ status: 'signed-out', user: null, licenseActive: false, tier: null, access: true,
+ paidPlan: null, pastDue: false, pastDueTier: null, quota: null,
+ }),
setSignedIn: (user, account) =>
- set({ status: 'signed-in', user, ...account, paidPlan: account.paidPlan ?? null }),
+ set({
+ status: 'signed-in', user, ...account,
+ paidPlan: account.paidPlan ?? null,
+ pastDue: account.pastDue === true,
+ pastDueTier: account.pastDue === true ? (account.pastDueTier ?? null) : null,
+ }),
setQuota: (quota) => set({ quota }),
}))