bytebase/bytebase · error
task run %d not found in project %s
Error message
task run %d not found in project %s
What it means
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.
Source
Thrown at backend/runner/taskrun/database_migrate_executor.go:203
return nil
}
func (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) {
// Handle prior backup if enabled.
// TransformDMLToSelect will automatically filter out DDL statements,
// so this works correctly for mixed DDL+DML statements.
var priorBackupDetail *storepb.PriorBackupDetail
if task.Payload.GetEnablePriorBackup() {
// Check if this specific task run wants to skip backup.
taskRun, err := exec.store.GetTaskRunV1(ctx, &store.FindTaskRunMessage{
ProjectID: database.ProjectID,
UID: &taskRunUID,
})
if err != nil {
return nil, errors.Wrapf(err, "failed to get task run")
}
if taskRun == nil {
return nil, errors.Errorf("task run %d not found in project %s", taskRunUID, database.ProjectID)
}
skipBackup := taskRun.PayloadProto.GetSkipPriorBackup()
if !skipBackup {
exec.store.CreateTaskRunLogS(ctx, database.ProjectID, taskRunUID, time.Now(), exec.profile.ReplicaID, &storepb.TaskRunLog{
Type: storepb.TaskRunLog_PRIOR_BACKUP_START,
PriorBackupStart: &storepb.TaskRunLog_PriorBackupStart{},
})
// Check if we should skip backup or not.
if common.EngineSupportPriorBackup(database.Engine) {
var backupErr error
priorBackupDetail, backupErr = exec.backupData(ctx, driverCtx, sheet.Statement, task.Payload, task, instance, database)
if backupErr != nil {
exec.store.CreateTaskRunLogS(ctx, database.ProjectID, taskRunUID, time.Now(), exec.profile.ReplicaID, &storepb.TaskRunLog{
Type: storepb.TaskRunLog_PRIOR_BACKUP_END,
PriorBackupEnd: &storepb.TaskRunLog_PriorBackupEnd{
Error: backupErr.Error(),View on GitHub (pinned to 1870550677)
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.
Example fix
// before: retry executes with a purged taskRunUID
retry(taskRunUID=123) // row deleted
// after: validate existence before retry
if tr, _ := store.GetTaskRunV1(ctx, &store.FindTaskRunMessage{ProjectID: pid, UID: &uid}); tr == nil {
// create a fresh issue/task instead of retrying
} Defensive patterns
Strategy: validation
Validate before calling
const tr = await api.getTaskRun(projectId, taskRunUid);
if (!tr) throw new Error(`task run ${taskRunUid} missing in project ${projectId}`); Type guard
function taskRunExists(t: TaskRun | null | undefined): t is TaskRun { return t != null; } Try / catch
try {
await runTask(task);
} catch (e) {
if (/task run \d+ not found in project/.test(String(e))) {
// cancel the orphaned task and create a fresh issue
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/c532efd0b1b51cd8.
Report an issue: GitHub.