{"record":{"id":"c532efd0b1b51cd8","repo":"bytebase/bytebase","slug":"task-run-d-not-found-in-project-s","errorCode":null,"errorMessage":"task run %d not found in project %s","messagePattern":"task run (.+?) not found in project (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/runner/taskrun/database_migrate_executor.go","lineNumber":203,"sourceCode":"\treturn nil\n}\n\nfunc (exec *DatabaseMigrateExecutor) runStandardMigration(ctx context.Context, driverCtx context.Context, task *store.TaskMessage, taskRunUID int64, sheet *store.SheetMessage, instance *store.InstanceMessage, database *store.DatabaseMessage, project *store.ProjectMessage) (*storepb.TaskRunResult, error) {\n\t// Handle prior backup if enabled.\n\t// TransformDMLToSelect will automatically filter out DDL statements,\n\t// so this works correctly for mixed DDL+DML statements.\n\tvar priorBackupDetail *storepb.PriorBackupDetail\n\tif task.Payload.GetEnablePriorBackup() {\n\t\t// Check if this specific task run wants to skip backup.\n\t\ttaskRun, err := exec.store.GetTaskRunV1(ctx, &store.FindTaskRunMessage{\n\t\t\tProjectID: database.ProjectID,\n\t\t\tUID:       &taskRunUID,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to get task run\")\n\t\t}\n\t\tif taskRun == nil {\n\t\t\treturn nil, errors.Errorf(\"task run %d not found in project %s\", taskRunUID, database.ProjectID)\n\t\t}\n\n\t\tskipBackup := taskRun.PayloadProto.GetSkipPriorBackup()\n\t\tif !skipBackup {\n\t\t\texec.store.CreateTaskRunLogS(ctx, database.ProjectID, taskRunUID, time.Now(), exec.profile.ReplicaID, &storepb.TaskRunLog{\n\t\t\t\tType:             storepb.TaskRunLog_PRIOR_BACKUP_START,\n\t\t\t\tPriorBackupStart: &storepb.TaskRunLog_PriorBackupStart{},\n\t\t\t})\n\n\t\t\t// Check if we should skip backup or not.\n\t\t\tif common.EngineSupportPriorBackup(database.Engine) {\n\t\t\t\tvar backupErr error\n\t\t\t\tpriorBackupDetail, backupErr = exec.backupData(ctx, driverCtx, sheet.Statement, task.Payload, task, instance, database)\n\t\t\t\tif backupErr != nil {\n\t\t\t\t\texec.store.CreateTaskRunLogS(ctx, database.ProjectID, taskRunUID, time.Now(), exec.profile.ReplicaID, &storepb.TaskRunLog{\n\t\t\t\t\t\tType: storepb.TaskRunLog_PRIOR_BACKUP_END,\n\t\t\t\t\t\tPriorBackupEnd: &storepb.TaskRunLog_PriorBackupEnd{\n\t\t\t\t\t\t\tError: backupErr.Error(),","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/runner/taskrun/database_migrate_executor.go#L185-L221","documentation":"Errorf thrown when GetTaskRunV1 succeeds but returns nil, meaning no task run with the given UID exists in the given project. The executor needs the task run payload (e.g. skipPriorBackup) to continue, so the migration fails. This is a dangling-reference case rather than a store failure.","triggerScenarios":"taskRunUID passed to runStandardMigration does not resolve: the task run row was deleted, the UID/project pair mismatches, or the executor was invoked with a stale UID from a different project.","commonSituations":"Historical task runs purged while a retry re-executes; task run moved across projects after database reassignment; metadata cleanup scripts removed rows referenced by in-flight tasks.","solutions":["Confirm the task run UID still exists under the given project via the API (GET /v1/projects/{project}/taskRuns).","Cancel the orphaned task and start a new migration issue.","Check for cleanup/retention jobs deleting task runs prematurely."],"exampleFix":"// before: retry executes with a purged taskRunUID\nretry(taskRunUID=123) // row deleted\n// after: validate existence before retry\nif tr, _ := store.GetTaskRunV1(ctx, &store.FindTaskRunMessage{ProjectID: pid, UID: &uid}); tr == nil {\n    // create a fresh issue/task instead of retrying\n}","handlingStrategy":"validation","validationCode":"const tr = await api.getTaskRun(projectId, taskRunUid);\nif (!tr) throw new Error(`task run ${taskRunUid} missing in project ${projectId}`);","typeGuard":"function taskRunExists(t: TaskRun | null | undefined): t is TaskRun { return t != null; }","tryCatchPattern":"try {\n  await runTask(task);\n} catch (e) {\n  if (/task run \\d+ not found in project/.test(String(e))) {\n    // cancel the orphaned task and create a fresh issue\n  }\n}","preventionTips":["Do not purge task run rows referenced by in-flight or retryable tasks.","Re-resolve task run UIDs after moving databases between projects.","Align retention cleanup with task scheduling."],"tags":["task-run","not-found","project"],"backgroundTag":"record-not-found","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}