yikart/AiToEarn · error · AppException
InvalidAiTaskId
InvalidAiTaskId
Error message
InvalidAiTaskId
What it means
In DashScopeVideoService.callback, the incoming query result's output.task_id is looked up via aiLogRepo.getByTaskId. If no AI log exists with that task id, or the found log's channel is not AiLogChannel.Dashscope, the service throws AppException(ResponseCode.InvalidAiTaskId) because the callback cannot be attributed to a known DashScope task.
Source
Thrown at project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/dashscope/dashscope.service.ts:341
if (!updatedAiLog) {
return aiLog.response!
}
await this.aiAvailability.recordAsyncComplete(
taskId,
{ provider: 'dashscope', operation: 'videoGeneration', model: aiLog.request.providerModel ?? aiLog.model },
{ success: false, latencyMs: elapsedMs, errorMessage },
)
return callbackData
}
async callback(queryResult: DashscopeQueryVideoTaskResponse): Promise<DashscopeVideoCallbackDto> {
const taskId = queryResult.output.task_id
const aiLog = await this.aiLogRepo.getByTaskId(taskId)
if (!aiLog || aiLog.channel !== AiLogChannel.Dashscope) {
throw new AppException(ResponseCode.InvalidAiTaskId)
}
const dashscopeAiLog = aiLog as DashscopeVideoAiLog
if (dashscopeAiLog.status !== AiLogStatus.Generating) {
return dashscopeAiLog.response!
}
const status = queryResult.output.task_status
if (status === DashscopeTaskStatus.Pending || status === DashscopeTaskStatus.Running) {
return {
id: taskId,
status,
requestId: queryResult.request_id,
providerModel: dashscopeAiLog.request.providerModel,
}
}
const elapsedMs = Date.now() - dashscopeAiLog.startedAt.getTime()View on GitHub (pinned to d3aa8bea5b)
Solutions
- Verify the task_id in the callback exists in the ai_logs collection and has channel='dashscope'.
- Confirm the callback is hitting the same environment/database where createFromRequest persisted the log.
- Check webhook routing so only DashScope-originated results reach this callback method.
- If the log was intentionally removed, ignore/ACK the callback instead of treating it as a client error.
Example fix
// before
const aiLog = await this.aiLogRepo.getByTaskId(taskId)
if (!aiLog || aiLog.channel !== AiLogChannel.Dashscope) {
throw new AppException(ResponseCode.InvalidAiTaskId)
}
// after (log the id before failing to speed diagnosis)
const aiLog = await this.aiLogRepo.getByTaskId(taskId)
if (!aiLog || aiLog.channel !== AiLogChannel.Dashscope) {
this.logger.warn({ taskId }, 'Unknown DashScope task in callback')
throw new AppException(ResponseCode.InvalidAiTaskId)
} Defensive patterns
Strategy: validation
Validate before calling
function isDashscopeCallback(res: { output?: { task_id?: string } }): boolean {
return typeof res.output?.task_id === 'string' && res.output.task_id.startsWith('') && res.output.task_id.length > 0
}
// before delivering the callback, confirm the task_id exists locally:
const aiLog = await aiLogRepo.getByTaskId(res.output.task_id)
if (!aiLog || aiLog.channel !== 'dashscope') return // ignore unknown callback instead of crashing Try / catch
try {
await dashscopeVideoService.callback(queryResult)
} catch (e) {
if (e instanceof AppException && e.code === ResponseCode.InvalidAiTaskId) {
// unknown/foreign task id: ACK the callback to stop provider retries, log for audit
return
}
throw e
} Prevention
- Ensure webhook endpoints only receive results for tasks created in the same environment.
- Keep ai_logs retention long enough to cover provider callback retries.
- Route callbacks per provider channel; never share one endpoint across providers.
When it happens
Trigger: Callback/poll result arrives with a task_id that (a) was never created by this service, (b) belongs to a log persisted in another DB/environment, or (c) matches a log whose channel is not Dashscope (e.g. a Grok or other provider task id routed to the DashScope callback handler).
Common situations: Provider retries callbacks after the local log was deleted; environments mismatch (task created in staging, callback hits prod); misconfigured webhook routing a foreign task id to this endpoint; duplicate/replayed callbacks with fabricated ids.
Related errors
- InvalidAiTaskId
- InvalidAiTaskId
- InvalidModel
- DashScope HappyHorse does not support image_tail
- DashScope task id is missing
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/8c1ac9ab5b1fdaab.
Report an issue: GitHub.