{"record":{"id":"1ee999b9bb724c69","repo":"bytebase/bytebase","slug":"task-run-d-not-found-in-project-s-1ee999","errorCode":null,"errorMessage":"task run %d not found in project %s","messagePattern":"task run (.+?) not found in project (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/store/task_run.go","lineNumber":310,"sourceCode":"\t\tSET started_at = now(), updated_at = now()\n\t\tWHERE id = ? AND project = ?\n\t`, taskRunID, projectID)\n\n\tquery, args, err := q.ToSQL()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to build sql\")\n\t}\n\n\tresult, err := s.GetDB().ExecContext(ctx, query, args...)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to update task run start at\")\n\t}\n\trowsAffected, err := result.RowsAffected()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to get affected task run count\")\n\t}\n\tif rowsAffected == 0 {\n\t\treturn errors.Errorf(\"task run %d not found in project %s\", taskRunID, projectID)\n\t}\n\treturn nil\n}\n\n// CreatePendingTaskRuns creates pending task runs.\n// This operation is idempotent and safe for concurrent calls:\n// - Excludes skipped tasks and tasks that already have active (PENDING/RUNNING/DONE) task runs\n// - Uses ON CONFLICT DO NOTHING to handle race conditions where two requests try to create the same task run\n// - The unique constraint on (task_id, attempt) ensures no duplicates\nfunc (s *Store) CreatePendingTaskRuns(ctx context.Context, creator string, creates ...*TaskRunMessage) error {\n\tif len(creates) == 0 {\n\t\treturn nil\n\t}\n\tprojectID := creates[0].ProjectID\n\tfor _, create := range creates[1:] {\n\t\tif create.ProjectID != projectID {\n\t\t\treturn common.Errorf(common.Invalid, \"all task runs in a batch must belong to the same project\")\n\t\t}","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/store/task_run.go#L292-L328","documentation":"UpdateTaskRunStartAt requires the task_run row identified by the full composite key (project, id). If the UPDATE affects zero rows, it reports 'task run %d not found in project %s' (backend/store/task_run.go:309-311). Task run IDs are allocated per project by nextProjectID, so the id alone is ambiguous — the project scope must match too.","triggerScenarios":"Calling Store.UpdateTaskRunStartAt(ctx, projectID, taskRunID) where no task_run row has both that project and id: the run was deleted, the id belongs to a different project, or a mistyped/unpadded id was passed.","commonSituations":"The task run was already finished/purged before execution attempted to start it; a caller mixed up IDs across projects (per-project IDs collide, e.g. both projects have id 101); a typo in projectID.","solutions":["Verify the task run exists with a query scoped by both project and id.","Confirm the caller passes the correct projectID alongside the task run id.","Handle the case where the run was already terminated — skip or log instead of treating as fatal.","Check for cross-project ID confusion since ids are only unique per project."],"exampleFix":"// before\nif err := store.UpdateTaskRunStartAt(ctx, projectID, taskRunID); err != nil {\n\treturn err\n}\n// after\nerr := store.UpdateTaskRunStartAt(ctx, projectID, taskRunID)\nif err != nil && strings.Contains(err.Error(), \"not found in project\") {\n\tlog.Warnf(\"task run %d/%s already gone; skipping\", taskRunID, projectID)\n\treturn nil\n}\nreturn err","handlingStrategy":"validation","validationCode":"run, err := store.GetTaskRun(ctx, projectID, taskRunID)\nif err != nil {\n\treturn fmt.Errorf(\"task run %d/%s does not exist: %w\", taskRunID, projectID, err)\n}","typeGuard":null,"tryCatchPattern":"if err := store.UpdateTaskRunStartAt(ctx, projectID, taskRunID); err != nil {\n\tif strings.Contains(err.Error(), \"not found in project\") {\n\t\tlog.Warnf(\"run %d/%s vanished; skipping\", taskRunID, projectID)\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["Always pass the full (project, id) composite key from the same source that created the run.","Never assume task run ids are globally unique — they are per-project.","Check the run's lifecycle state before attempting to start it."],"tags":["task-run","not-found","composite-primary-key"],"backgroundTag":"resource-not-found","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}