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(safety): desktop cloud Create reads lyrics and trigger word only when the run sends them (B30)

purple7990168bd5ce
diff --git a/src/hooks/__tests__/useCloudCreate-b30-nur-was-geschickt-wird.test.ts b/src/hooks/__tests__/useCloudCreate-b30-nur-was-geschickt-wird.test.ts
new file mode 100644
index 00000000..0c5e051b
--- /dev/null
+++ b/src/hooks/__tests__/useCloudCreate-b30-nur-was-geschickt-wird.test.ts
@@ -0,0 +1,117 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * B30-Rest (3.0.9, Q1): the store keeps lyrics and trigger word across modes.
+ * The desktop cloud Create read them on every run, so a word typed in Music or
+ * Training blocked an image run that never sends it. Same rule as the web fix
+ * fb714de4: only what the run sends is checked.
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { renderHook, act } from '@testing-library/react'
+
+const hoisted = vi.hoisted(() => {
+ class FakeCloudJobError extends Error {
+ status: number
+ code?: string
+ retryAfterMs?: number
+ constructor(message: string, status: number) {
+ super(message)
+ this.status = status
+ }
+ }
+ return {
+ policySnapshot: 'strict' as 'strict' | 'soft' | 'off' | null,
+ submitCloudJob: vi.fn(async () => ({ id: 'job-1' })),
+ uploadInput: vi.fn(async () => 'uploaded/path'),
+ getJob: vi.fn(),
+ cancelJob: vi.fn(async () => ({ status: 'canceled' })),
+ // 'canceled' short-circuits the post-submit result handling in both
+ // generate() and makeVoice() cleanly, this test only cares about what
+ // happens BEFORE submitCloudJob, not the full success path.
+ pollJob: vi.fn(async () => ({ id: 'job-1', status: 'canceled' as const })),
+ FakeCloudJobError,
+ }
+})
+const { submitCloudJob, uploadInput } = hoisted
+
+vi.mock('../useContentPolicy', () => ({
+ contentPolicySnapshot: () => hoisted.policySnapshot,
+ loadContentPolicy: async () => hoisted.policySnapshot ?? 'soft',
+}))
+
+vi.mock('../../api/cloud/jobs', () => ({
+ submitCloudJob: (...a: Parameters<typeof hoisted.submitCloudJob>) => hoisted.submitCloudJob(...a),
+ uploadInput: (...a: Parameters<typeof hoisted.uploadInput>) => hoisted.uploadInput(...a),
+ getJob: (...a: Parameters<typeof hoisted.getJob>) => hoisted.getJob(...a),
+ cancelJob: (...a: Parameters<typeof hoisted.cancelJob>) => hoisted.cancelJob(...a),
+ pollJob: (...a: Parameters<typeof hoisted.pollJob>) => hoisted.pollJob(...a),
+ CloudJobError: hoisted.FakeCloudJobError,
+}))
+
+vi.mock('../../stores/cloudCatalogStore', () => ({
+ defaultCloudModel: () => ({ id: 'test-model' }),
+ modelForOp: () => 'test-model',
+ resolveOpPick: () => 'test-model',
+ cloudModelById: () => undefined,
+ cloudMediaLive: () => true,
+ // No rule by length for the test model: the start sends no ceiling.
+ lengthPrice: () => undefined,
+ lengthCredits: () => 0,
+}))
+
+import { useCloudCreate } from '../useCloudCreate'
+import { useCreateStore } from '../../stores/createStore'
+import { blockMessageFor } from '../../lib/render/safety'
+
+beforeEach(() => {
+ submitCloudJob.mockClear()
+ uploadInput.mockClear()
+ hoisted.policySnapshot = 'off'
+ useCreateStore.setState({
+ prompt: '',
+ negativePrompt: '',
+ musicLyrics: '',
+ triggerWord: '',
+ removebg: false,
+ utilityOp: null,
+ cloudOp: null,
+ mode: 'image',
+ imageSubMode: 'text2img',
+ isGenerating: false,
+ error: null,
+ } as Partial<ReturnType<typeof useCreateStore.getState>>)
+})
+
+describe('B30-Rest: the desktop cloud check reads only what this run sends', () => {
+ it('lyrics left from the music tab do not block an image run', async () => {
+ useCreateStore.setState({ prompt: 'a nude woman on a beach at sunset', musicLyrics: 'back to the schoolgirl days' })
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => { await result.current.generate() })
+ expect(useCreateStore.getState().error).toBeNull()
+ expect(submitCloudJob).toHaveBeenCalledOnce()
+ })
+
+ it('a trigger word left from training does not block an image run', async () => {
+ useCreateStore.setState({ prompt: 'a nude woman on a beach at sunset', triggerWord: 'teen' })
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => { await result.current.generate() })
+ expect(useCreateStore.getState().error).toBeNull()
+ expect(submitCloudJob).toHaveBeenCalledOnce()
+ })
+
+ it('the prompt itself is still read: a minor + sexual prompt stays blocked', async () => {
+ useCreateStore.setState({ prompt: 'a nude teen on a beach', musicLyrics: 'la la' })
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => { await result.current.generate() })
+ expect(useCreateStore.getState().error).toBe(blockMessageFor('csam'))
+ expect(submitCloudJob).not.toHaveBeenCalled()
+ })
+
+ it('a trigger word a training run sends is still read', async () => {
+ useCreateStore.setState({ cloudOp: 'character', characterTab: 'train', triggerWord: 'nude teen' } as Partial<ReturnType<typeof useCreateStore.getState>>)
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => { await result.current.generate() })
+ expect(useCreateStore.getState().error).toBe(blockMessageFor('csam'))
+ expect(submitCloudJob).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.ts
index d9f3e9c5..110574ad 100644
--- a/src/hooks/useCloudCreate.ts
+++ b/src/hooks/useCloudCreate.ts
@@ -344,8 +344,15 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
// below either way; this only saves the round trip when the client
// already knows the verdict (B3).
{
- // The negative prompt is read apart (B30, safety.ts).
- const verdict = clientSafety(`${prompt} ${s.musicLyrics} ${s.triggerWord}`, s.negativePrompt)
+ // The negative prompt is read apart (B30, safety.ts). Only what this
+ // run sends is read, same conditions as the params below: the store
+ // keeps negative prompt, lyrics and trigger word across modes, and a
+ // field this mode neither shows nor sends must not block it unseen
+ // (B30, web fix fb714de4).
+ const sendsClassicKnobs = !studioModel && !specialOp && op !== 'removebg' && op !== 'upscale' && op !== 'eraser'
+ const lyrics = op === 'music' && !studioModel ? s.musicLyrics : ''
+ const triggerWord = op === 'lora-train' ? s.triggerWord : ''
+ const verdict = clientSafety(`${prompt} ${lyrics} ${triggerWord}`, sendsClassicKnobs ? s.negativePrompt : '')
if (verdict.blocked) {
s.setError(blockMessageFor(verdict.reason))
return