{"record":{"id":"349b44bfd58d30f8","repo":"yikart/AiToEarn","slug":"invalidaitaskid-349b44","errorCode":"InvalidAiTaskId","errorMessage":"ResponseCode.InvalidAiTaskId","messagePattern":"ResponseCode\\.InvalidAiTaskId","errorType":"error_code","errorClass":"AppException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/video.service.ts","lineNumber":186,"sourceCode":"    const finishedAt = aiLog.duration\n      ? new Date(aiLog.startedAt.getTime() + aiLog.duration)\n      : undefined\n\n    if (aiLog.status === AiLogStatus.Failed) {\n      return {\n        ...base,\n        status: TaskStatus.Failure,\n        videoUrl: undefined,\n        coverUrl: savedMedia.coverUrl ? FileUtil.buildUrl(savedMedia.coverUrl) : undefined,\n        mediaId: savedMedia.mediaId,\n        groupId: savedMedia.groupId,\n        error: { message: aiLog.errorMessage ?? 'Video task failed' },\n        finishedAt,\n      }\n    }\n\n    if (!aiLog.response) {\n      throw new AppException(ResponseCode.InvalidAiTaskId)\n    }\n\n    const channelResult = this.getChannelTaskResult(aiLog)\n\n    return {\n      ...base,\n      ...channelResult,\n      coverUrl: savedMedia.coverUrl ? FileUtil.buildUrl(savedMedia.coverUrl) : undefined,\n      mediaId: savedMedia.mediaId,\n      groupId: savedMedia.groupId,\n      finishedAt,\n    }\n  }\n\n  async ensureSavedMediaByAiLogId(aiLogId: string): Promise<void> {\n    const aiLog = await this.aiLogRepo.getById(aiLogId)\n    if (!aiLog || aiLog.type !== AiLogType.Video) {\n      return","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/video.service.ts#L168-L204","documentation":"InvalidAiTaskId thrown in transformToCommonResponse when a video AI log is in a terminal/succeeded state (not Generating, not Failed) but has no `response` payload stored. The task cannot be mapped to a common response because the provider result is missing, and the service reports this as an invalid/unusable task record.","triggerScenarios":"Querying getVideoTaskStatus or listVideoTasks for a task whose aiLog reached a non-generating, non-failed status without a persisted provider `response` — e.g. status set to success by a callback that did not save the response body, or a log partially written.","commonSituations":"Provider callback succeeded but response-saving step failed or was skipped; data migration dropped the response field; task record manually edited in MongoDB; querying right at a race where status flipped but response write is pending.","solutions":["Verify the task id is correct and re-query — if the log was mid-write the response may appear shortly after.","Inspect the aiLog document in MongoDB: check `status` vs presence of `response` to confirm data corruption.","Trigger the status sync/callback path (ensureSavedVideoMedia / channel refresh) to backfill the response, or mark the log Failed so the failure branch returns instead of throwing.","Fix the callback handler so `response` is saved atomically with the status change."],"exampleFix":"// before\nif (aiLog.status === 'success') return transformToCommonResponse(aiLog) // throws if response missing\n// after\nif (aiLog.status === 'success' && !aiLog.response) {\n  return { status: TaskStatus.Failure, error: { message: 'provider response missing' } }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await videoService.getVideoTaskStatus({ taskId })\n} catch (e) {\n  if (e instanceof AppException && e.code === 'InvalidAiTaskId') {\n    // treat as unrecoverable record; surface 'task record incomplete' to caller or re-sync from provider\n  }\n}","preventionTips":["Persist provider `response` atomically with status transitions in callbacks.","Add a periodic reconciliation job that refetches provider status for logs missing response.","Monitor for aiLogs with terminal status and null response."],"tags":["data-integrity","task-status","video-generation"],"backgroundTag":"incomplete-task-record","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}