XCP-D error with longitudinal data that is missing one T2w image

Hi everyone! I just wanted to point out a small potential issue that I ran into.

Summary of what happened:

When running XCP-D 26.0.2 on the output of fMRIPrep 23.0.2, if a participant has two sessions with T1 images, but only one session with a T2 image, XCP-D throws an error when trying to find the T1 image. Example:

fMRIPrep input data:
sub-01/ses-01/anat: T1 and T2
sub-01/ses-02/anat: T1 only

fMRIPrep averages and processes the T1s into derivatives/sub-01/anat, but because there is only one T2, it places the T2 into derivatives/sub-01/ses-01/anat.

fMRIPrep output data:
derivatives/sub-01/anat: all relevant averaged T1 data files
derivatives/sub-01/ses-01/anat: T2 only

It appears that XCP-D looks in the derivatives/sub-01/ses-01/anat folder first before looking in derivatives/sub-01/anat. It then finds a T2, but no T1, and tries to continue processing with only a T2, which causes an error when the expected T2 derivatives are missing.

Version:

fMRIPrep 23.0.2
XCP-D 26.0.2

Environment (Docker, Singularity / Apptainer, custom installation):

Singularity for both fMRIPrep and XCP-D.

Data formatted according to a validatable standard?

Yes, BIDS.

Relevant log outputs (up to 20 lines):

260429-08:09:14,515 nipype.workflow IMPORTANT:
	 Building XCP-D's workflow:
           * Preprocessing derivatives path: /BIDSINFOLD.
           * Participant list: ['OPT0230'].
           * Run identifier: 20260429-080846_026bf8b4-dc0f-4665-8722-54b23358d747.
           * Searching for derivatives and atlases: {'tedana_confound_data': PosixPath('/CONFOUNDDATASET'), 'xcpdatlases': PosixPath('/home/xcp_d/.cache/xcp_d/XCPDAtlases'), 'xcpd4s': PosixPath('/home/xcp_d/.cache/xcp_d/AtlasPack')}.
260429-08:09:16,185 nipype.utils WARNING:
	 T2w found, but no T1w. Enabling T2w-only processing.
Process Process-2:
Traceback (most recent call last):
  File "/app/.pixi/envs/xcp-d/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
.............. (removed for brevity) .............
FileNotFoundError: No anat_brainmask found with query: {'datatype': 'anat', 'desc': 'brain', 'extension': '.nii.gz', 'suffix': 'mask', 'session': '01', 'space': 'MNI152NLin6Asym'}

Screenshots / relevant information:

This issue is similar to a previous issue involving two scans where only one has anatomical data: XCP-D error output: Can’t find anatomical image. However, in this case, both scans have some anatomical data, but they both don’t have a T2.

As a temporary fix, if you move derivatives/sub-01/ses-01/anat/sub-01_ses-01_desc-preproc_T2w.nii.gz and its .json to another location, the XCP-D processing correctly finds the T1 image and continues without a T2.