chatboxai/chatbox · error · Error

Unknown session type: ${session.type}, generate failed

Error message

Unknown session type: ${session.type}, generate failed

What it means

orchestratePictureGeneration only knows how to handle session.type === 'picture'; any other type reaching the final else branch throws. This is a routing assertion — the function should only be entered for picture sessions.

Source

Thrown at src/renderer/stores/session/pictures.ts:109

          message: userMessage,
          num: settings.imageGenerateNum || 1,
        },
        async (picBase64) => {
          const storageKey = StorageKeyGenerator.picture(`${session.id}:${targetMsg.id}:${imageIndex++}`)
          // Image needs to be stored in indexedDB, if using OpenAI's image link directly, the link will expire over time
          await storage.setBlob(storageKey, picBase64)
          await insertImage({ type: 'image', storageKey })
        }
      )
      targetMsg = {
        ...targetMsg,
        generating: false,
        cancel: undefined,
        status: [],
      }
      await modifyMessage(sessionId, targetMsg, true)
    } else {
      throw new Error(`Unknown session type: ${session.type}, generate failed`)
    }
    appleAppStore.tickAfterMessageGenerated()
  } catch (err: unknown) {
    targetMsg = handleGenerationError(err, targetMsg, settings)
    await modifyMessage(sessionId, targetMsg, true)
  }
}

View on GitHub (pinned to 81571269ad)

Solutions

  1. Fix the caller to route only picture sessions into orchestratePictureGeneration; add a type guard at the call site.
  2. Return early for unknown types instead of throwing so a routing bug does not crash the message.
  3. Add the new session type to the orchestrator dispatch when introducing one.
  4. Assert session.type at the entry and log the offending caller stack.

Example fix

// before
} else {
  throw new Error(`Unknown session type: ${session.type}, generate failed`)
}
// after
} else {
  log.error('orchestratePictureGeneration: unsupported session type', { sessionType: session.type, sessionId })
  return
}
Defensive patterns

Strategy: validation

Validate before calling

if (session.type !== 'picture') {
  log.error('orchestratePictureGeneration: unsupported type', { sessionType: session.type })
  return
}

Type guard

function isPictureSession(s: { type: string }): s is { type: 'picture' } {
  return s.type === 'picture'
}

Prevention

When it happens

Trigger: orchestratePictureGeneration invoked with a session whose type is not 'picture' (e.g. 'chat', 'agent', 'memo'). The caller routed a non-picture session into the picture orchestrator.

Common situations: A caller dispatch bug (e.g. a switch on session.type falls through incorrectly), a new session type added without updating the orchestrator dispatch, or session.type mutated to an unexpected value.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/e6b1b080b1aded7e. Report an issue: GitHub.