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(create): die drei Geldgruende bekommen ihren eigenen Satz

purple18cc4870f212
diff --git a/src/hooks/__tests__/a-429-is-not-always-money.test.ts b/src/hooks/__tests__/a-429-is-not-always-money.test.ts
index c6e71001..4735f7b0 100644
--- a/src/hooks/__tests__/a-429-is-not-always-money.test.ts
+++ b/src/hooks/__tests__/a-429-is-not-always-money.test.ts
@@ -1,48 +1,67 @@
+// @vitest-environment jsdom
/**
* What Create says when the render queue answers 429 (src/hooks/useCloudCreate.ts).
*
- * LU Cloud answers 429 for three different things — the per-user burst guard,
- * an upstream provider throttle, and an empty wallet (lib/http-status carries
- * the same policy for the chat path). All three used to reach the user as
- * "Monthly credit budget exhausted, upgrade your plan", so a subscriber who
- * had simply clicked twice too fast was told to buy a bigger plan while the
- * credits meter next to the message still showed a balance. On a billed
- * product that is a false sales pitch, so the wallet case has to be identified
- * rather than assumed.
+ * LU Cloud answers 429 for five different things: the per-user burst guard, an
+ * upstream provider throttle, an empty wallet, the monthly video budget and the
+ * monthly character trainings. All of them once reached the user as "Monthly
+ * credit budget exhausted, upgrade your plan", so a subscriber who had simply
+ * clicked twice too fast was told to buy a bigger plan while the credits meter
+ * next to the message still showed a balance.
+ *
+ * R5-49, R5-50, R5-52: the repair after that was a `/credit/i` test on the
+ * message, and the server's video-budget sentence carries the word "credits".
+ * The wrong branch won, and the customer was offered a plan change instead of
+ * the pack that unblocks him. `trainings_exhausted` does not carry the word at
+ * all and fell into the throttle text, which points at a clock that never runs
+ * out. The code the server sends decides now; the heuristic is gone.
*/
-import { describe, it, expect } from 'vitest'
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { throttleMessage } from '../useCloudCreate'
import { CloudJobError } from '../../api/cloud/client'
+import { CREDITS_EXHAUSTED_EVENT } from '../../lib/credits-exhausted'
const UPGRADE = /upgrade your plan/
+/** Gedankenstriche, beide Sorten. Kundentext traegt keine. */
+const STRICHE = /[–—]/
-describe('the wallet case, and only the wallet case, mentions the plan', () => {
- it('trusts the server code', () => {
+describe('jeder Geldgrund traegt seinen eigenen Satz, wortgleich mit dem Web', () => {
+ it('empty wallet', () => {
const err = new CloudJobError('too many requests', 429, { code: 'credits_exhausted' })
- expect(throttleMessage(err)).toMatch(UPGRADE)
+ expect(throttleMessage(err)).toBe("You're out of credits. Load up your credits or upgrade your plan.")
+ })
+
+ it('monthly video budget, and it names the pack that actually unblocks it', () => {
+ const err = new CloudJobError('monthly video budget exhausted, buy credits', 429, { code: 'video_budget_exhausted' })
+ expect(throttleMessage(err))
+ .toBe("This month's video budget is used up. Top-up credits keep video going, or upgrade your plan.")
})
- it('and the message the server sends today, in case the code is absent', () => {
- expect(throttleMessage(new CloudJobError('monthly credit budget exhausted', 429))).toMatch(UPGRADE)
+ it('monthly character trainings, and it does not point at a clock', () => {
+ const err = new CloudJobError('no trainings left', 429, { code: 'trainings_exhausted' })
+ expect(throttleMessage(err)).toBe("Your plan's character trainings for this month are used up.")
+ expect(throttleMessage(err)).not.toMatch(/try again|wait/i)
+ })
+
+ it('no customer sentence carries a dash', () => {
+ for (const code of ['credits_exhausted', 'video_budget_exhausted', 'trainings_exhausted', undefined]) {
+ expect(throttleMessage(new CloudJobError('slow down', 429, code ? { code } : undefined))).not.toMatch(STRICHE)
+ }
+ expect(throttleMessage(new CloudJobError('slow down', 429, { retryAfterMs: 42_000 }))).not.toMatch(STRICHE)
})
})
describe('a throttle is named as a throttle', () => {
- it('says wait, not pay, for the per-user burst guard', () => {
- const err = new CloudJobError('too many requests', 429, { retryAfterMs: 42_000 })
- const msg = throttleMessage(err)
+ it('says wait, not pay, for a real burst 429', () => {
+ const msg = throttleMessage(new CloudJobError('too many requests', 429))
+ expect(msg).toBe('Too many requests at once. Wait a moment and try again.')
expect(msg).not.toMatch(UPGRADE)
- expect(msg).toMatch(/not your credit balance/)
- // The burst window is fixed and up to a minute long — retry-after is the
- // only number that tells the user when it is actually worth clicking.
- expect(msg).toContain('42s')
})
- it('says the same without a retry-after header', () => {
- const err = new CloudJobError('provider is rate limiting', 429)
- const msg = throttleMessage(err)
+ it('keeps the retry-after number, the only one worth clicking on', () => {
+ const msg = throttleMessage(new CloudJobError('too many requests', 429, { retryAfterMs: 42_000 }))
expect(msg).not.toMatch(UPGRADE)
- expect(msg).toMatch(/try again/i)
+ expect(msg).toContain('42s')
})
it('does not invent a countdown from a missing or zero wait', () => {
@@ -54,6 +73,33 @@ describe('a throttle is named as a throttle', () => {
it('rounds a sub-second wait up rather than telling the user 0s', () => {
expect(throttleMessage(new CloudJobError('slow down', 429, { retryAfterMs: 250 }))).toContain('1s')
})
+
+ it('NEGATIVKONTROLLE: a message that merely says "credits" is not a money answer', () => {
+ // Genau der Satz, der die alte Heuristik gekippt hat, nur ohne Code.
+ const err = new CloudJobError('monthly credit budget exhausted', 429)
+ expect(throttleMessage(err)).toBe('Too many requests at once. Wait a moment and try again.')
+ expect(throttleMessage(err)).not.toMatch(UPGRADE)
+ })
+})
+
+describe('der Renderweg oeffnet den Kaufdialog, nicht nur der Chatweg', () => {
+ const seen = vi.fn()
+ beforeEach(() => {
+ seen.mockClear()
+ window.addEventListener(CREDITS_EXHAUSTED_EVENT, seen)
+ })
+ afterEach(() => window.removeEventListener(CREDITS_EXHAUSTED_EVENT, seen))
+
+ it('fires on the empty wallet', () => {
+ throttleMessage(new CloudJobError('too many requests', 429, { code: 'credits_exhausted' }))
+ expect(seen).toHaveBeenCalledTimes(1)
+ })
+
+ it('NEGATIVKONTROLLE: an ordinary 429 opens nothing', () => {
+ throttleMessage(new CloudJobError('too many requests', 429, { retryAfterMs: 1000 }))
+ throttleMessage(new CloudJobError('monthly credit budget exhausted', 429))
+ expect(seen).not.toHaveBeenCalled()
+ })
})
describe('the metadata the message needs actually survives the client', () => {
diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.ts
index 2cfe2859..167d9bd8 100644
--- a/src/hooks/useCloudCreate.ts
+++ b/src/hooks/useCloudCreate.ts
@@ -30,6 +30,7 @@ import {
cloudMediaLive,
} from '../stores/cloudCatalogStore'
import { checkPromptSafety, SAFETY_BLOCK_MESSAGE } from '../lib/render/safety'
+import { signalCreditsExhausted } from '../lib/credits-exhausted'
import { resolveRunSeed } from '../lib/run-seed'
// Character-Studio generation endpoint per trained-LoRA family (fast default;
@@ -67,24 +68,40 @@ function opProgressVerb(op: string): string {
// What a 429 from the render queue actually means.
//
-// The queue answers 429 for three different things (lib/http-status states the
-// same policy for the chat path): the per-user burst guard, an upstream
-// provider throttle — both transient, both carrying retry-after — and an empty
-// wallet, which is the only one paying more fixes. Every one of them used to
-// read "Monthly credit budget exhausted, upgrade your plan", so a subscriber
+// The queue answers 429 for five different things (lib/http-status states the
+// same policy for the chat path): the per-user burst guard and an upstream
+// provider throttle, both transient and both carrying retry-after, and three
+// that are about money, each with a different way out. Every one of them used
+// to read "Monthly credit budget exhausted, upgrade your plan", so a subscriber
// who was merely clicking too fast, with credits left in the meter next to the
-// message, was told to buy a bigger plan. That is a sales pitch for a refusal
-// the money would not have prevented, so the wallet case has to be positively
-// identified — by the server's own `code`, or failing that by a message that
-// actually talks about credits — and everything else says what it is.
+// message, was told to buy a bigger plan.
+//
+// The repair after that asked `/credit/i` about the message, and the server's
+// video-budget sentence carries the word "credits". The wrong branch won and
+// the customer was offered a plan change instead of the pack that unblocks him
+// (R5-49). `trainings_exhausted` carries the word nowhere and fell into the
+// throttle text, which points at a clock that never runs out (R5-50). So the
+// code the server sends decides, in that order, and the heuristic is gone: a
+// message is prose, a code is a decision. Wordings come from the web
+// (apps/web/hooks/useCloudCreate.ts), because the same refusal must not read
+// differently depending on which of the two apps the customer happens to use.
export function throttleMessage(err: CloudJobError): string {
- if (err.code === 'credits_exhausted' || /credit/i.test(err.message)) {
- return 'Monthly credit budget exhausted, upgrade your plan or wait for the next period.'
+ switch (err.code) {
+ case 'credits_exhausted':
+ // R5-52: the buy dialog had exactly one caller and it sat in the chat
+ // path, so a render that ran the wallet dry left the customer with a red
+ // line and no way to pay.
+ signalCreditsExhausted()
+ return "You're out of credits. Load up your credits or upgrade your plan."
+ case 'video_budget_exhausted':
+ return "This month's video budget is used up. Top-up credits keep video going, or upgrade your plan."
+ case 'trainings_exhausted':
+ return "Your plan's character trainings for this month are used up."
}
const secs = err.retryAfterMs && err.retryAfterMs > 0 ? Math.ceil(err.retryAfterMs / 1000) : null
return secs
- ? `Too many requests right now — the render queue is throttling, not your credit balance. Try again in ${secs}s.`
- : 'Too many requests right now — the render queue is throttling, not your credit balance. Give it a moment and try again.'
+ ? `Too many requests at once. Wait ${secs}s and try again.`
+ : 'Too many requests at once. Wait a moment and try again.'
}
// Decoded by hand instead of fetch(dataUrl): the webview CSP's connect-src