{"record":{"id":"51836fbfe9eed024","repo":"yikart/AiToEarn","slug":"invalidaitaskid-51836f","errorCode":"InvalidAiTaskId","errorMessage":"InvalidAiTaskId","messagePattern":"InvalidAiTaskId","errorType":"error_code","errorClass":"AppException","httpStatus":400,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/grok/grok.service.ts","lineNumber":273,"sourceCode":"  extractInput(request: GrokVideoAiLog['request']) {\n    return {\n      prompt: request.prompt || '',\n      image: request.referenceImages ?? request.image,\n      duration: request.duration,\n      aspectRatio: request.aspectRatio,\n      resolution: request.resolution,\n      videoUrl: request.videoUrl,\n    }\n  }\n\n  /**\n   * 用户查询任务状态（含实时查询 Grok API）\n   */\n  async getTask(userId: string, userType: UserType, logId: string): Promise<GrokVideoCallbackDto> {\n    const aiLog = await this.aiLogRepo.getByIdAndUserId(logId, userId, userType)\n\n    if (aiLog == null || !aiLog.taskId || aiLog.type !== AiLogType.Video || aiLog.channel !== AiLogChannel.Grok) {\n      throw new AppException(ResponseCode.InvalidAiTaskId)\n    }\n    const grokAiLog = aiLog as GrokVideoAiLog\n\n    if (grokAiLog.status !== AiLogStatus.Generating) {\n      return grokAiLog.response!\n    }\n    try {\n      const result = await this.grokLibService.getVideoStatus(grokAiLog.taskId!)\n      return await this.callback(result, grokAiLog)\n    }\n    catch (e) {\n      let errorMessage: string = (e as Error).message\n      let code = '500'\n      if (e instanceof AxiosError) {\n        const status = e?.response?.status\n        if (status && status >= 400 && status < 500) {\n          const data = e.response?.data\n          errorMessage = data?.error || data?.code || `Grok API error (${status})`","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/grok/grok.service.ts#L255-L291","documentation":"In GrokVideoService.getTask, the logId is resolved with aiLogRepo.getByIdAndUserId(logId, userId, userType). The request is rejected with AppException(ResponseCode.InvalidAiTaskId) when the log is not found or is invalid for Grok video polling: it has no taskId, is not of type AiLogType.Video, or its channel is not AiLogChannel.Grok. This guards that users can only query their own valid Grok video tasks.","triggerScenarios":"Calling getTask with (a) a logId that does not exist or belongs to another user/userType, (b) a log whose task record never got a provider taskId, (c) a non-video log id, or (d) a video log from a different channel (e.g. Dashscope) passed to the Grok service.","commonSituations":"Client caches log ids across environments or accounts; calling the Grok status endpoint with a DashScope task log id; task submission failed before taskId was persisted; deleted logs still referenced by the frontend.","solutions":["Confirm the logId is a valid Grok video log owned by the requesting userId/userType.","Check the log document: type must be 'video', channel must be 'grok', and taskId must be set.","Use the correct channel-specific status endpoint for logs from other providers.","If the log is missing a taskId, the original submission failed — resubmit the generation instead of polling."],"exampleFix":"// before\nconst res = await grokVideoService.getTask(userId, userType, dashscopeLogId) // wrong channel\n// after\nconst res = aiLog.channel === AiLogChannel.Grok\n  ? await grokVideoService.getTask(userId, userType, aiLog.id)\n  : await dashscopeVideoService.getTask(userId, userType, aiLog.id)","handlingStrategy":"validation","validationCode":"function canPollGrokTask(log: { id: string; userId: string; userType: string; type: string; channel: string; taskId?: string } | null, userId: string, userType: string): boolean {\n  return !!log\n    && log.userId === userId\n    && log.userType === userType\n    && log.type === 'video'\n    && log.channel === 'grok'\n    && !!log.taskId\n}","typeGuard":"function isGrokVideoAiLog(log: any): log is GrokVideoAiLog {\n  return log != null\n    && typeof log.taskId === 'string' && log.taskId.length > 0\n    && log.type === AiLogType.Video\n    && log.channel === AiLogChannel.Grok\n}","tryCatchPattern":"try {\n  const status = await grokVideoService.getTask(userId, userType, logId)\n} catch (e) {\n  if (e instanceof AppException && e.code === ResponseCode.InvalidAiTaskId) {\n    // refresh log list / re-check ownership; do not retry blindly\n  }\n  throw e\n}","preventionTips":["Only pass log ids obtained from the same user's Grok video submissions.","Use channel-specific status endpoints for each provider's logs.","Handle 'log has no taskId' as a failed submission in the UI rather than polling."],"tags":["grok","video-generation","invalid-task-id","authorization"],"backgroundTag":"invalid-task-id","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}