As part of $lookup sub-pipeline correlation analysis, we try to detect the largest prefix of the pipeline which is non-correlated and temporarily cache the result instead of re-running for each document in the outer pipeline. This optimization relies on each aggregation stage correctly reporting it's variable dependencies, which may include a variable defined in the 'let' of the $lookup.
However $graphLookup does not fully report its dependencies for the 'restrictSearchWithMatch' option, which means if its contained in a $lookup sub-pipeline then it may be incorrectly treated as non-correlated.
- related to
SERVER-63845 Separate interface to get set of referenced variables from DocumentSource::getDependencies()