{"record":{"id":"8479e35f31eb3fe8","repo":"chatboxai/chatbox","slug":"image-generation-requires-an-active-chat-session","errorCode":null,"errorMessage":"Image generation requires an active chat session.","messagePattern":"Image generation requires an active chat session\\.","errorType":"validation","errorClass":"ChatboxCliUsageError","httpStatus":null,"severity":"warning","filePath":"src/renderer/packages/chatbox-cli/images.ts","lineNumber":155,"sourceCode":"    if (existing.signature !== signature) {\n      return Promise.reject(new Error(`Tool call ${key} was reused with different image arguments.`))\n    }\n    return existing.promise\n  }\n  const promise = create()\n  executionCache.set(key, { signature, promise })\n  void promise.catch(() => {\n    if (executionCache.get(key)?.promise === promise) executionCache.delete(key)\n  })\n  if (executionCache.size > 100) {\n    const oldest = executionCache.keys().next().value\n    if (typeof oldest === 'string') executionCache.delete(oldest)\n  }\n  return promise\n}\n\nasync function generateImage(context: ChatboxCliCommandContext): Promise<Record<string, unknown>> {\n  if (!context.sessionId) throw new ChatboxCliUsageError('Image generation requires an active chat session.')\n  if (!context.toolCallId) throw new ChatboxCliUsageError('Image generation requires a tool call id.')\n  const sessionId = context.sessionId\n  const toolCallId = context.toolCallId\n  const requestedPrompt = stringFlag(context.parsed, 'prompt') ?? context.parsed.positionals.join(' ').trim()\n  if (!requestedPrompt) throw new ChatboxCliUsageError('Missing --prompt.')\n  if (requestedPrompt.length > 8_000) throw new ChatboxCliUsageError('Prompt must be at most 8000 characters.')\n\n  const requestedProvider = stringFlag(context.parsed, 'provider')\n  const requestedModelId = stringFlag(context.parsed, 'model')\n  const requestedCount = integerFlag(context.parsed, 'count', { defaultValue: 1, min: 1, max: 4 })\n  const requestedAspectRatio = stringFlag(context.parsed, 'aspect-ratio')\n  const requestedStyle = stringFlag(context.parsed, 'style')\n  if (requestedStyle && requestedStyle !== 'vivid' && requestedStyle !== 'natural') {\n    throw new ChatboxCliUsageError('--style must be vivid or natural.')\n  }\n  const parsedStyle: 'vivid' | 'natural' | undefined =\n    requestedStyle === 'vivid' || requestedStyle === 'natural' ? requestedStyle : undefined\n  const approvedRequest =","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/chatbox-cli/images.ts#L137-L173","documentation":"ChatboxCliUsageError thrown at the top of generateImage when context.sessionId is falsy. Image generation is a session-scoped, callback-driven background task and cannot run without an active conversation to bind the resulting record and callback to.","triggerScenarios":"Invoking 'image generate' from a context with no active chat session (e.g. a global/background tool invocation, or before any conversation is loaded).","commonSituations":"An LLM attempting image generation outside a chat turn, a test harness that did not seed sessionId, or a UI flow that lost the active-session reference.","solutions":["Ensure the command is dispatched within an active conversation so context.sessionId is set.","In the caller, check for an active session before offering the image-generate action.","If programmatically driven, open/load a session first and pass its id into the tool context."],"exampleFix":"// before\nawait executeChatboxCliCommand({ argv: ['image','generate','--prompt', p] }, { ...ctx, sessionId: undefined })\n\n// after\nif (!activeSessionId) return openConversationFirst()\nawait executeChatboxCliCommand({ argv: ['image','generate','--prompt', p] }, { ...ctx, sessionId: activeSessionId })","handlingStrategy":"validation","validationCode":"if (!ctx.sessionId) {\n  return { error: 'Open a conversation before generating images', kind: 'usage' }\n}\nawait executeChatboxCliCommand({ argv: ['image','generate','--prompt', prompt] }, ctx)","typeGuard":"function hasActiveSession(ctx: { sessionId?: string }): ctx is { sessionId: string } {\n  return typeof ctx.sessionId === 'string' && ctx.sessionId.length > 0\n}","tryCatchPattern":"const res = await executeChatboxCliCommand({ argv: ['image','generate','--prompt', p] }, ctx)\nif (!res.ok && res.kind === 'usage' && res.error.includes('active chat session')) {\n  // open/load a conversation first, then retry\n}","preventionTips":["Only offer image generation from within an active conversation.","Check for an active session in the caller before dispatching.","Seed sessionId in test harnesses before invoking generate."],"tags":["chatbox-cli","usage","image-generation","validation"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}